未验证 提交 8c972f9d 编写于 作者: P Phodal Huang

fix: use reverse for git history change

上级 947cb814
......@@ -2,7 +2,7 @@
GitLogs
```
git log --all --numstat --date=short --pretty="format:[%h] %aN %ad %s" --numstat
git log --all --numstat --date=short --pretty="format:[%h] %aN %ad %s" --numstat --reverse
```
Related Projects: [https://github.com/bast/gitink](https://github.com/bast/gitink)
......
......@@ -18,7 +18,6 @@ var currentCommitMessage CommitMessage
var currentFileChanges []FileChange
var commitMessages []CommitMessage
var (
rev = `\[([\d|a-f]{5,12})\]`
author = `(.*?)\s\d{4}-\d{2}-\d{2}`
......@@ -34,7 +33,7 @@ var (
)
func BuildCommitMessage() []CommitMessage {
historyArgs := []string{"log", "--pretty=format:[%h] %aN %ad %s", "--date=short", "--numstat"}
historyArgs := []string{"log", "--pretty=format:[%h] %aN %ad %s", "--date=short", "--numstat", "--reverse"}
cmd := exec.Command("git", historyArgs...)
out, err := cmd.CombinedOutput()
if err != nil {
......@@ -91,20 +90,21 @@ func GetTeamSummary(messages []CommitMessage) []TeamSummary {
infos := make(map[string]TeamInformation)
for _, commitMessage := range messages {
for _, change := range commitMessage.Changes {
if moveReg.MatchString(change.File) {
infos = switchFile(infos, change.File)
fileName := change.File
if moveReg.MatchString(fileName) {
infos, fileName = switchFile(infos, fileName)
}
if infos[change.File].EntityName == "" {
if infos[fileName].EntityName == "" {
authors := make(map[string]string)
authors[commitMessage.Author] = commitMessage.Author
revs := make(map[string]string)
revs[commitMessage.Rev] = commitMessage.Rev
infos[change.File] = *&TeamInformation{change.File, authors, revs}
infos[fileName] = *&TeamInformation{fileName, authors, revs}
} else {
infos[change.File].Authors[commitMessage.Author] = commitMessage.Author
infos[change.File].Revs[commitMessage.Rev] = commitMessage.Rev
infos[fileName].Authors[commitMessage.Author] = commitMessage.Author
infos[fileName].Revs[commitMessage.Rev] = commitMessage.Rev
}
}
}
......@@ -122,22 +122,24 @@ func GetTeamSummary(messages []CommitMessage) []TeamSummary {
}
// 反向查询
func switchFile(infos map[string]TeamInformation, changedFile string) map[string]TeamInformation {
func switchFile(infos map[string]TeamInformation, changedFile string) (map[string]TeamInformation, string) {
changed := moveReg.FindStringSubmatch(changedFile)
// examples: cmd/{call_graph.go => call.go}
if len(changed) >= 5 {
oldFileName := changed[1] + changed[2] + changed[4]
newFileName := changed[1] + changed[3] + changed[4]
fmt.Println(infos, oldFileName, newFileName)
if _, ok := infos[oldFileName]; ok {
oldInfo := infos[oldFileName]
delete(infos, oldFileName)
oldInfo.EntityName = newFileName
infos[newFileName] = oldInfo
changedFile = newFileName
}
}
return infos
return infos, changedFile
}
type TopAuthor struct {
......
......@@ -2,7 +2,6 @@ package test_test
import (
"coca/core/domain/gitt"
"fmt"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
......@@ -30,25 +29,39 @@ var _ = Describe("Git Parser", func() {
Context("Test for Move file", func() {
It("should have a current file move update", func() {
messages := gitt.BuildMessageByInput(`
[d00f01214b] Phodal Huang 2019-12-19 update files
[d00f0124d] Phodal Huang 2019-12-19 update files
0 0 core/domain/bs/BadSmellApp.go
[1d00f0124b] Phodal Huang 2019-12-19 update files
1 1 cmd/bs.go
0 0 core/adapter/bs/BadSmellApp.go
0 0 core/domain/bs/BadSmellApp.go
[d00f04111b] Phodal Huang 2019-12-18 refactor: move bs to adapter
1 1 cmd/bs.go
5 5 core/{domain => adapter}/bs/BadSmellApp.go
[1d00f0124b] Phodal Huang 2019-12-19 update files
[d00f01214b] Phodal Huang 2019-12-19 update files
1 1 cmd/bs.go
0 0 core/domain/bs/BadSmellApp.go
0 0 core/adapter/bs/BadSmellApp.go
`)
summary := gitt.GetTeamSummary(messages)
Expect(summary[0].EntityName).To(Equal("core/adapter/bs/BadSmellApp.go"))
Expect(summary[1].EntityName).To(Equal("cmd/bs.go"))
Expect(len(summary)).To(Equal(2))
})
It("support for first path change", func() {
messages := gitt.BuildMessageByInput(`
[333] Phodal Huang 2019-12-19 update files
0 0 src/domain/gitt/README.md
[d00f0124d] Phodal Huang 2019-12-19 update files
0 0 core/domain/bs/BadSmellApp.go
0 0 {src => core}/domain/gitt/README.md
`)
summary := gitt.GetTeamSummary(messages)
fmt.Println(summary)
Expect(summary[0].EntityName).To(Equal("cmd/bs.go"))
Expect(summary[1].EntityName).To(Equal("core/domain/bs/BadSmellApp.go"))
Expect(summary[0].EntityName).To(Equal("core/domain/gitt/README.md"))
Expect(len(summary)).To(Equal(1))
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册