0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-13 21:30:40 +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" "fmt"
"os" "os"
"os/exec" "os/exec"
"strconv"
"strings" "strings"
"time" "time"
@ -31,9 +32,11 @@ type Git interface {
// GitCommitLog description of a single commit log. // GitCommitLog description of a single commit log.
type GitCommitLog struct { type GitCommitLog struct {
Date string `json:"date,omitempty"` Date string `json:"date,omitempty"`
Hash string `json:"hash,omitempty"` Timestamp int `json:"timestamp,omitempty"`
Message CommitMessage `json:"message,omitempty"` AuthorName string `json:"authorName,omitempty"`
Hash string `json:"hash,omitempty"`
Message CommitMessage `json:"message,omitempty"`
} }
// GitTag git tag info. // GitTag git tag info.
@ -90,7 +93,7 @@ func (GitImpl) LastTag() string {
// Log return git log. // Log return git log.
func (g GitImpl) Log(lr LogRange) ([]GitCommitLog, error) { 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} params := []string{"log", "--date=short", format}
if lr.start != "" || lr.end != "" { if lr.start != "" || lr.end != "" {
@ -200,10 +203,13 @@ func parseLogOutput(messageProcessor MessageProcessor, log string) []GitCommitLo
func parseCommitLog(messageProcessor MessageProcessor, commit string) GitCommitLog { func parseCommitLog(messageProcessor MessageProcessor, commit string) GitCommitLog {
content := strings.Split(strings.Trim(commit, "\""), logSeparator) content := strings.Split(strings.Trim(commit, "\""), logSeparator)
timestamp, _ := strconv.Atoi(content[1])
return GitCommitLog{ return GitCommitLog{
Date: content[0], Date: content[0],
Hash: content[1], Timestamp: timestamp,
Message: messageProcessor.Parse(content[2], content[3]), AuthorName: content[2],
Hash: content[3],
Message: messageProcessor.Parse(content[4], content[5]),
} }
} }