From 25f526d0363e8a6f6fbdd5f494f11c80dc1c9fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Sat, 17 Oct 2020 13:16:06 +0100 Subject: [PATCH] Implemented GetGitLog --- z/helpers.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/z/helpers.go b/z/helpers.go index 493c31f..fd09c10 100644 --- a/z/helpers.go +++ b/z/helpers.go @@ -2,6 +2,8 @@ package z import ( "os/user" + "os/exec" + "bytes" "regexp" "strconv" "strings" @@ -129,3 +131,18 @@ func GetISOWeekInMonth(date time.Time) (month int, weeknumber int) { return int(changedDate.Month()), int(math.Ceil(float64(changedDate.Day()) / 7.0)); } + +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.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 +}