Skip to content

Commit

Permalink
介绍说明
Browse files Browse the repository at this point in the history
  • Loading branch information
jmesyan committed May 19, 2021
1 parent fd789dc commit 9b0180b
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 26 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@

# Dependency directories (remove the comment below to include it)
# vendor/
dist/
.idea/.gitignore
.idea/
report/
32 changes: 32 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This is an example .goreleaser.yml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
#- go generate ./...
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
79 changes: 78 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,79 @@
# week-report
a tool to create week report for who use git
使用git记录生成周报工具


## 安装

### 方式一:源码安装
```
git clone https://github.com/jqiris/week-report
cd week-report & go build & go install
```

### 方式二:直接下载编译文件


## 使用

### 调用week-report命令,确保出现以下内容,保证工具已经正确安装
```
NAME:
week-report - 通过git使用记录产生周报
USAGE:
week-report.exe [global options] command [command options] [arguments...]
COMMANDS:
run, r 产生周报
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--conf value, -c value 指定配置文件 (default: "config.json")
--sdate value, -s value 日报开始日期 (default: (*time.Time)(nil))
--edate value, -e value 日报结束日期 (default: (*time.Time)(nil))
--help, -h show help (default: false)
```

### 选择一个周报目录,然后设置配置文件config.json,范例如下:
```
{
"user": "jqiris",
"project": {
"周报项目": [
"H:\\project\\week-report"
]
},
"output": {
"title": "上周",
"dir": "report",
"filter": [
"test",
"Merge"
]
}
}
```
格式说明:
- user-git账号名称
- project-项目目录,同一个项目可能有多个子项目,产出按照项目名称归类
- output-输出设置
- title-周报标题
- dir-周报输出目录,如果没有,尝试自动生成
- filter-如果git记录里面包含这些关键字会过滤掉

### 执行周报生成命令

- 标准:week-report run ,根据配置文件信息自动生成周报,默认开始时间5天前,结束时间当前时间
- 指定配置文件:week-report -c=xxx.json run ,xxx.json配置文件路径
- 指定开始日期或者结束日期 week-report -s=20210518 -e=20210519 run 日期可选,不设置默认开始时间5天前,结束时间当天


## 说明
命令执行完,会在输出目录生成周报文件,格式week_开始日期_结束日期.txt,同一个项目提交的同一个记录会去重,遇到过滤关键字字段会忽略,
所以如果你的git提交的时候做的的是同一个功能,可以用同一个注释提交,如果你不想日志加入周报生成,可以在记录里加入过滤关键字,生成效果如下,希望大家用的开心,并给我点个赞:

```
上周:
1-周报项目-Initial commit
2-周报项目-周报工具
```
48 changes: 25 additions & 23 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,68 +38,70 @@ func Before(c *cli.Context) error {
return nil
}

//日报产出
//Report 日报产出
func Report(c *cli.Context) error {
s, e, n := c.Timestamp("sdate"), c.Timestamp("edate"), time.Now()
s, e := c.Timestamp("sdate"), c.Timestamp("edate")
if s == nil {
n := time.Now().AddDate(0, 0, -4)
s = &n
}
if e == nil {
n := time.Now()
e = &n
}
sb, ee := utils.TimeToDayBegin(s), utils.TimeToDayEnd(e)
sdate, edate := sb.Format("2006-01-02 15:04:05"), ee.Format("2006-01-02 15:04:05")
osdate, oedate := sb.Format("20060102"), ee.Format("20060102")
logger.Info("week-report:", osdate, "==>", oedate)
sDate, eDate := sb.Format("2006-01-02 15:04:05"), ee.Format("2006-01-02 15:04:05")
osDate, oeDate := sb.Format("20060102"), ee.Format("20060102")
logger.Info("week-report:", osDate, "==>", oeDate)
//获取当前路径
cdir, err := os.Getwd()
cDir, err := os.Getwd()
if err != nil {
return err
}
//分析日志
result := make(map[string][]string)
projects := conf.GetProjectConf()
for pname, pdirs := range projects {
logger.Info("开始分析日志, 项目:" + pname)
for _, pdir := range pdirs {
res, err := analyse(cdir, pdir, pname, sdate, edate)
for pName, pDirs := range projects {
logger.Info("开始分析日志, 项目:" + pName)
for _, pDir := range pDirs {
res, err := analyse(cDir, pDir, pName, sDate, eDate)
if err != nil {
return err
}
if len(res) > 0 {
result[pname] = append(result[pname], res...)
result[pName] = append(result[pName], res...)
}
}
logger.Info("结束分析日志, 项目:" + pname)
logger.Info("结束分析日志, 项目:" + pName)
}
//去重并且过滤关键字
for k, v := range result {
result[k] = filters.Filtering(v)
}
//输出到目录
ocfg := conf.GetOutputConf()
return output(ocfg.Title, ocfg.Dir, osdate, oedate, result)
oCfg := conf.GetOutputConf()
return output(oCfg.Title, oCfg.Dir, osDate, oeDate, result)
}

//analyse 解析日报信息
func analyse(cdir, pdir, name, sdate, edate string) ([]string, error) {
err := os.Chdir(pdir)
func analyse(cDir, pDir, name, sDate, eDate string) ([]string, error) {
err := os.Chdir(pDir)
if err != nil {
return nil, err
}
logcmd := cmd.NewCmd("git", "log", "--author="+conf.GetUserConf(), "--pretty=format:%s", "--after="+sdate, "--before="+edate)
s := <-logcmd.Start()
err = os.Chdir(cdir)
logCmd := cmd.NewCmd("git", "log", "--author="+conf.GetUserConf(), "--pretty=format:%s", "--after="+sDate, "--before="+eDate)
s := <-logCmd.Start()
err = os.Chdir(cDir)
if err != nil {
return nil, err
}
return s.Stdout, nil
}

//output 输出到目录文件
func output(title, dir, sdate, edate string, result map[string][]string) error {
func output(title, dir, sDate, eDate string, result map[string][]string) error {
//开始写入结果
filename := "week_" + sdate + "_" + edate + ".txt"
filename := "week_" + sDate + "_" + eDate + ".txt"
filepath := path.Join(dir, filename)
file, err := os.OpenFile(filepath, os.O_RDWR|os.O_CREATE|os.O_APPEND|os.O_TRUNC, 0644)
if err != nil {
Expand All @@ -110,9 +112,9 @@ func output(title, dir, sdate, edate string, result map[string][]string) error {
file.Write([]byte(title + ":\n"))
}
num := 1
for pname, plist := range result {
for pName, plist := range result {
for _, item := range plist {
vw := fmt.Sprintf("%d-%s-%s\n", num, pname, item)
vw := fmt.Sprintf("%d-%s-%s\n", num, pName, item)
file.Write([]byte(vw))
num += 1
}
Expand Down
2 changes: 1 addition & 1 deletion filters/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func init() {
filterQueue = append(filterQueue, NewKeysFilter())
}

//过滤服务
//Filtering 过滤服务
func Filtering(list []string) (ret []string) {
if len(filterQueue) == 0 {
return list
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/jqiris/week-report
go 1.16

require (
github.com/go-cmd/cmd v1.3.0 // indirect
github.com/go-cmd/cmd v1.3.0
github.com/sirupsen/logrus v1.8.1
github.com/urfave/cli/v2 v2.3.0
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-cmd/cmd v1.3.0 h1:Wet2eYkLouFqyiG+x6P6l8CICRywhRD6sjMNalTSvbs=
github.com/go-cmd/cmd v1.3.0/go.mod h1:l/X/csRuYRDqiQIz9PPJBn4xDrdxgBXeLE9x1BeFU6M=
github.com/go-test/deep v1.0.6 h1:UHSEyLZUwX9Qoi99vVwvewiMC8mM2bf7XEM2nqvzEn8=
github.com/go-test/deep v1.0.6/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
Expand Down

0 comments on commit 9b0180b

Please sign in to comment.