From 0d71ab2d34989317494549cc1164bae29dcbbc49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Sun, 18 Oct 2020 00:22:37 +0100 Subject: [PATCH] Updated GetGitLog to only include own commits --- z/helpers.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/z/helpers.go b/z/helpers.go index b153b70..e3128c8 100644 --- a/z/helpers.go +++ b/z/helpers.go @@ -134,14 +134,28 @@ func GetISOWeekInMonth(date time.Time) (month int, weeknumber int) { func GetGitLog(repo string, since time.Time, until time.Time) (string, string, error) { var stdout, stderr bytes.Buffer - - cmd := exec.Command("git", "-C", repo, "log", "--since", since.Format("2006-01-02T15:04:05-0700"), "--until", until.Format("2006-01-02T15:04:05-0700"), "--pretty=oneline") + cmd := exec.Command("git", "-C", repo, "config", "user.name") cmd.Stdout = &stdout cmd.Stderr = &stderr err := cmd.Run() if err != nil { return "", "", err } + gitUserStr, gitUserErrStr := string(stdout.Bytes()), string(stderr.Bytes()) + if gitUserStr == "" && gitUserErrStr != "" { + return gitUserStr, gitUserErrStr, errors.New(gitUserErrStr) + } + + stdout.Reset() + stderr.Reset() + + cmd = exec.Command("git", "-C", repo, "log", "--author", gitUserStr, "--since", since.Format("2006-01-02T15:04:05-0700"), "--until", until.Format("2006-01-02T15:04:05-0700"), "--pretty=oneline") + cmd.Stdout = &stdout + cmd.Stderr = &stderr + err = cmd.Run() + if err != nil { + return "", "", err + } stdoutStr, stderrStr := string(stdout.Bytes()), string(stderr.Bytes()) return stdoutStr, stderrStr, nil