未验证 提交 24d537f7 编写于 作者: P Phodal Huang

feat: add basic change log support

上级 bb400a88
......@@ -13,6 +13,10 @@
- **模型重构**。在包含测试的情况下,通过识别和发现模型的行为,将行为聚合到模型中。
- **微重构**/**代码重构**。对于代码中的坏味道,可以通过 IDE 重构来快速改善即有代码,而不会影响到业务功能。
TODO:
- support get delete files
## Usage
install
......
......@@ -29,7 +29,8 @@ var gitCmd = &cobra.Command{
Short: "git analysis",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
commitMessages := BuildMessageByInput(getCommitMessage())
message := getCommitMessage()
commitMessages := BuildMessageByInput(message)
cModel, _ := json.MarshalIndent(commitMessages, "", "\t")
support.WriteToCocaFile("commits.json", string(cModel))
......
......@@ -2,6 +2,7 @@ package gitt
import (
"fmt"
"github.com/phodal/coca/core/support"
"regexp"
)
......@@ -9,9 +10,25 @@ var (
changeLogRegex = `^(\w*)(?:\((.*)\))?: (.*)$`
)
// high fix
// high features
//
func ShowChangeLogSummary(commits []CommitMessage) {
changeMap := BuildChangeMap(commits)
fmt.Println(changeMap)
for key, value := range changeMap {
sortValue := support.RankByWordCount(value)
maxSize := len(sortValue)
if maxSize > 10 {
maxSize = 10
}
fmt.Println(key + ":")
fmt.Println("---------------------")
for _, val := range sortValue[:maxSize] {
fmt.Println(val.Key, val.Value)
}
fmt.Println("=====================")
}
}
func BuildChangeMap(commits []CommitMessage) map[string]map[string]int {
......@@ -26,12 +43,19 @@ func BuildChangeMap(commits []CommitMessage) map[string]map[string]int {
keyword := matchs[1]
//message := matchs[3]
if _, ok := czMap[keyword];!ok {
czMap[keyword] = make(map[string]int)
}
for _, change := range commit.Changes {
czMap[keyword][change.File]++
file := change.File
file, oldFile, newFile := UpdateMessageForChange(file)
if file != oldFile {
file = newFile
}
czMap[keyword][file]++
}
}
}
......
......@@ -6,7 +6,6 @@ import (
"fmt"
"github.com/phodal/coca/core/domain/gitt/apriori"
"log"
"regexp"
"sort"
"strconv"
"strings"
......@@ -17,22 +16,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}`
date = `\d{4}-\d{2}-\d{2}`
changes = `([\d-]+)[\t\s]+([\d-]+)[\t\s]+(.*)`
complexMoveRegStr = `(.*)\{(.*)\s=>\s(.*)\}(.*)`
basicMoveRegStr = `(.*)\s=>\s(.*)`
revReg = regexp.MustCompile(rev)
authorReg = regexp.MustCompile(author)
dateReg = regexp.MustCompile(date)
changesReg = regexp.MustCompile(changes)
complexMoveReg = regexp.MustCompile(complexMoveRegStr)
basicMvReg = regexp.MustCompile(basicMoveRegStr)
)
func BuildMessageByInput(inputStr string) []CommitMessage {
currentFileChanges = nil
commitMessages = nil
......@@ -107,30 +90,14 @@ func BuildCommitMessageMap(messages []CommitMessage, infos map[string]ProjectInf
// 反向查询
func handleMoveInDirectory(infos map[string]ProjectInfo, changedFile string) (map[string]ProjectInfo, string) {
changed := complexMoveReg.FindStringSubmatch(changedFile)
// examples: cmd/{call_graph.go => call.go}
SUCCESS_MATCH_LENGTH := 5
if len(changed) == SUCCESS_MATCH_LENGTH {
var oldLastChanged = changed[4]
// TODO: support for Windows rename
if changed[2] == "" {
if strings.HasPrefix(oldLastChanged, "/") {
oldLastChanged = oldLastChanged[1:]
}
}
oldFileName := changed[1] + changed[2] + oldLastChanged
newFileName := changed[1] + changed[3] + changed[4]
changedFile, oldFileName, newFileName := UpdateMessageForChange(changedFile)
if changedFile != oldFileName {
infos = switchMapFile(infos, oldFileName, newFileName)
changedFile = newFileName
}
return infos, changedFile
}
func handleMoveFullPath(infos map[string]ProjectInfo, changedFile string) (map[string]ProjectInfo, string) {
fileName := changedFile
changed := basicMvReg.FindStringSubmatch(changedFile)
......@@ -143,7 +110,6 @@ func handleMoveFullPath(infos map[string]ProjectInfo, changedFile string) (map[s
return infos, fileName
}
func switchMapFile(infos map[string]ProjectInfo, oldFileName string, newFileName string) map[string]ProjectInfo {
if _, ok := infos[oldFileName]; ok {
oldInfo := infos[oldFileName]
......
package gitt
import (
"regexp"
"strings"
)
var (
rev = `\[([\d|a-f]{5,12})\]`
author = `(.*?)\s\d{4}-\d{2}-\d{2}`
date = `\d{4}-\d{2}-\d{2}`
changes = `([\d-]+)[\t\s]+([\d-]+)[\t\s]+(.*)`
complexMoveRegStr = `(.*)\{(.*)\s=>\s(.*)\}(.*)`
basicMoveRegStr = `(.*)\s=>\s(.*)`
revReg = regexp.MustCompile(rev)
authorReg = regexp.MustCompile(author)
dateReg = regexp.MustCompile(date)
changesReg = regexp.MustCompile(changes)
complexMoveReg = regexp.MustCompile(complexMoveRegStr)
basicMvReg = regexp.MustCompile(basicMoveRegStr)
)
func UpdateMessageForChange(changedFile string) (string, string, string) {
oldFileName := changedFile
newFileName := changedFile
changed := complexMoveReg.FindStringSubmatch(changedFile)
// examples: cmd/{call_graph.go => call.go}
SUCCESS_MATCH_LENGTH := 5
if len(changed) == SUCCESS_MATCH_LENGTH {
var oldLastChanged = changed[4]
// TODO: support for Windows rename
if changed[2] == "" {
if strings.HasPrefix(oldLastChanged, "/") {
oldLastChanged = oldLastChanged[1:]
}
}
oldFileName = changed[1] + changed[2] + oldLastChanged
newFileName = changed[1] + changed[3] + changed[4]
changedFile = newFileName
}
return changedFile, oldFileName, newFileName
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册