From 90c27b03e55e7fb43ee488007695c2e3f3fd45b6 Mon Sep 17 00:00:00 2001 From: Daniel Rocha Date: Sun, 4 Sep 2022 10:37:04 -0300 Subject: [PATCH] bugfix(load commits and tags): commits and tags loader fixed --- src/gitscm/commit.go | 35 ++++++++++++++++++----------------- src/gitscm/tag.go | 24 ++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/gitscm/commit.go b/src/gitscm/commit.go index db662aa..73daeb9 100644 --- a/src/gitscm/commit.go +++ b/src/gitscm/commit.go @@ -16,6 +16,7 @@ func LoadCommitFromBegin() ([]GitCommit, error) { "rev-list", "--max-parents=0", "HEAD", + "-1", }, } @@ -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 } @@ -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 } @@ -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 { @@ -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), "") } @@ -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), "") } @@ -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), "") } @@ -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), "") -} \ No newline at end of file +} diff --git a/src/gitscm/tag.go b/src/gitscm/tag.go index 1755c90..018d423 100644 --- a/src/gitscm/tag.go +++ b/src/gitscm/tag.go @@ -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]) }, }