From 243d73b5c2f7c4d572067a96262ffe1d14541f05 Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Sun, 6 Feb 2022 20:16:52 -0300 Subject: [PATCH] feat: add authorName and timestamp to git commit issue: #40 --- sv/git.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/sv/git.go b/sv/git.go index bab6d14..7474824 100644 --- a/sv/git.go +++ b/sv/git.go @@ -7,6 +7,7 @@ import ( "fmt" "os" "os/exec" + "strconv" "strings" "time" @@ -31,9 +32,11 @@ type Git interface { // GitCommitLog description of a single commit log. type GitCommitLog struct { - Date string `json:"date,omitempty"` - Hash string `json:"hash,omitempty"` - Message CommitMessage `json:"message,omitempty"` + Date string `json:"date,omitempty"` + Timestamp int `json:"timestamp,omitempty"` + AuthorName string `json:"authorName,omitempty"` + Hash string `json:"hash,omitempty"` + Message CommitMessage `json:"message,omitempty"` } // GitTag git tag info. @@ -90,7 +93,7 @@ func (GitImpl) LastTag() string { // Log return git log. func (g GitImpl) Log(lr LogRange) ([]GitCommitLog, error) { - format := "--pretty=format:\"%ad" + logSeparator + "%h" + logSeparator + "%s" + logSeparator + "%b" + endLine + "\"" + format := "--pretty=format:\"%ad" + logSeparator + "%at" + logSeparator + "%cN" + logSeparator + "%h" + logSeparator + "%s" + logSeparator + "%b" + endLine + "\"" params := []string{"log", "--date=short", format} if lr.start != "" || lr.end != "" { @@ -200,10 +203,13 @@ func parseLogOutput(messageProcessor MessageProcessor, log string) []GitCommitLo func parseCommitLog(messageProcessor MessageProcessor, commit string) GitCommitLog { content := strings.Split(strings.Trim(commit, "\""), logSeparator) + timestamp, _ := strconv.Atoi(content[1]) return GitCommitLog{ - Date: content[0], - Hash: content[1], - Message: messageProcessor.Parse(content[2], content[3]), + Date: content[0], + Timestamp: timestamp, + AuthorName: content[2], + Hash: content[3], + Message: messageProcessor.Parse(content[4], content[5]), } }