Skip to content

Commit

Permalink
bugfix(load commits and tags): commits and tags loader fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
danroxha committed Sep 4, 2022
1 parent 52f55aa commit 90c27b0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
35 changes: 18 additions & 17 deletions src/gitscm/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func LoadCommitFromBegin() ([]GitCommit, error) {
"rev-list",
"--max-parents=0",
"HEAD",
"-1",
},
}

Expand All @@ -24,27 +25,27 @@ func LoadCommitFromBegin() ([]GitCommit, error) {
if err != nil {
return []GitCommit{}, err
}

initialCommit := strings.TrimSpace(string(output))
hashList, err := loadCommitsBetween(initialCommit, "HEAD")

if err != nil {
return []GitCommit{}, err
}

gitCommitGroup := []GitCommit{}

for _, hash := range hashList {
commit := GitCommit{
Message: findShortMessageFromCommit(hash),
Hash: hash,
Date: findDateFromCommit(hash),
Author: findAuthorFromCommit(hash),
Hash: hash,
Date: findDateFromCommit(hash),
Author: findAuthorFromCommit(hash),
}

gitCommitGroup = append(gitCommitGroup, commit)
}

return gitCommitGroup, nil
}

Expand All @@ -60,14 +61,14 @@ func LoadCommitsFrom(beginFromCommit string) ([]GitCommit, error) {
for _, hash := range hashList {
commit := GitCommit{
Message: findMessageFromCommit(hash),
Hash: hash,
Date: findDateFromCommit(hash),
Author: findAuthorFromCommit(hash),
Hash: hash,
Date: findDateFromCommit(hash),
Author: findAuthorFromCommit(hash),
}

gitCommitGroup = append(gitCommitGroup, commit)
}

return gitCommitGroup, nil
}

Expand All @@ -82,7 +83,7 @@ func loadCommitsBetween(start string, end string) ([]string, error) {
fmt.Sprintf(`%v..%v`, start, end),
},
}

output, err := log.Execute()

if err != nil {
Expand Down Expand Up @@ -112,7 +113,7 @@ func findDateFromCommit(hash string) string {
panic(err)
}

regx := regexp.MustCompile(`\r\n|[\r\n\v\f\x{0085}\x{2028}\x{2029}]`)
regx := regexp.MustCompile(`\r\n|[\r\n\v\f\x{0085}\x{2028}\x{2029}]`)
return regx.ReplaceAllString(string(output), "")
}

Expand All @@ -133,7 +134,7 @@ func findAuthorFromCommit(hash string) string {
panic(err)
}

regx := regexp.MustCompile(`\r\n|[\r\n\v\f\x{0085}\x{2028}\x{2029}]`)
regx := regexp.MustCompile(`\r\n|[\r\n\v\f\x{0085}\x{2028}\x{2029}]`)
return regx.ReplaceAllString(string(output), "")
}

Expand All @@ -154,7 +155,7 @@ func findMessageFromCommit(hash string) string {
panic(err)
}

regx := regexp.MustCompile(`\r\n|[\r\n\v\f\x{0085}\x{2028}\x{2029}]`)
regx := regexp.MustCompile(`\r\n|[\r\n\v\f\x{0085}\x{2028}\x{2029}]`)
return regx.ReplaceAllString(string(output), "")
}

Expand All @@ -175,7 +176,7 @@ func findShortMessageFromCommit(hash string) string {
if err != nil {
panic(err)
}
regx := regexp.MustCompile(`\r\n|[\r\n\v\f\x{0085}\x{2028}\x{2029}]`)

regx := regexp.MustCompile(`\r\n|[\r\n\v\f\x{0085}\x{2028}\x{2029}]`)
return regx.ReplaceAllString(string(output), "")
}
}
24 changes: 22 additions & 2 deletions src/gitscm/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,41 +238,61 @@ func parseTag(commit string) GitTag {
regexGroup := map[string]func(string) string{
"author": func(content string) string {
regex := regexp.MustCompile(`Author:\s+(.+)`)
match := regex.FindStringSubmatch(content)
if len(match) == 0 {
return ""
}
return strings.TrimSpace(regex.FindStringSubmatch(content)[1])
},
"hash": func(content string) string {
regex := regexp.MustCompile(`commit\s+([a-f0-9]+)`)
match := regex.FindStringSubmatch(content)
if len(match) == 0 {
return ""
}
return strings.TrimSpace(regex.FindStringSubmatch(content)[1])
},
"tagger": func(content string) string {
regex := regexp.MustCompile(`Tagger:\s+(.+)`)
match := regex.FindStringSubmatch(content)
if len(match) == 0 {
return ""
}
return strings.TrimSpace(regex.FindStringSubmatch(content)[1])
},

"datetag": func(content string) string {
regex := regexp.MustCompile(`\w+:\s+(\w+\s+)+(\d:?|\s+?)+\s+(.?\d+)`)
match := regex.FindAllStringSubmatch(content, -1)
if len(match) == 0 {
return ""
}
firstDate := match[0][0]
return strings.TrimSpace(strings.Split(firstDate, ": ")[1])
},
"datecommit": func(content string) string {
regex := regexp.MustCompile(`\w+:\s+(\w+\s+)+(\d:?|\s+?)+\s+(.?\d+)`)
match := regex.FindAllStringSubmatch(content, -1)
if len(match) < 2 {
return ""
}
secondDate := match[1][0]
return strings.TrimSpace(strings.Split(secondDate, ": ")[1])
},
"annonation": func(content string) string {
regex := regexp.MustCompile(`tag\s+(.+)`)
match := regex.FindStringSubmatch(content)
if len(match) == 0 {
return ""
}
return strings.TrimSpace(regex.FindStringSubmatch(content)[1])
},
"stamp": func(content string) string {
regex := regexp.MustCompile(`stamp:\s+'(\w+)'`)
match := regex.FindStringSubmatch(content)

if len(match) == 0 {
return ""
}

return strings.TrimSpace(regex.FindStringSubmatch(content)[1])
},
}
Expand Down

0 comments on commit 90c27b0

Please sign in to comment.