0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-21 22:10:39 +00:00

feat: add authorName and timestamp to git commit

issue: #40
This commit is contained in:
Beatriz Vieira 2022-02-06 20:16:52 -03:00
parent ef2bc8638a
commit 243d73b5c2

View File

@ -7,6 +7,7 @@ import (
"fmt"
"os"
"os/exec"
"strconv"
"strings"
"time"
@ -32,6 +33,8 @@ type Git interface {
// GitCommitLog description of a single commit log.
type GitCommitLog struct {
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"`
}
@ -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]),
Timestamp: timestamp,
AuthorName: content[2],
Hash: content[3],
Message: messageProcessor.Parse(content[4], content[5]),
}
}