From 5d5f537df93b69a3a5373c5f476fd7f1d0e97543 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Sat, 2 Mar 2019 14:06:17 +0100 Subject: [PATCH] Show summary in recent changes --- file.go | 34 ++++++++++++++++++++++++---------- main.go | 1 + templates/recent.html | 3 ++- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/file.go b/file.go index 454f49e..fb37752 100644 --- a/file.go +++ b/file.go @@ -165,7 +165,7 @@ func gitRevision(dirname, page, version string) string { } func (fp *FilePages) RecentChanges() ([]Change, error) { - cmd := exec.Command("git", "log", "--format=--1--%nDate: %aI%n--2--", "--name-only") + cmd := exec.Command("git", "log", "--format=--1--%nDate: %aI%n--2--%n%b%n--3--", "--name-only") cmd.Dir = fp.dirname cmd.Stderr = os.Stderr buf := bytes.Buffer{} @@ -181,29 +181,34 @@ func (fp *FilePages) RecentChanges() ([]Change, error) { scanner := bufio.NewScanner(&buf) - first := false - second := false + state := 0 var changes []Change - var change Change + body := "" + for scanner.Scan() { line := scanner.Text() if line == "--1--" { - second = false - first = true + state = 1 + + body = "" continue } if line == "--2--" { - first = false - second = true + state = 2 continue } - if first && strings.HasPrefix(line, "Date: ") { + if line == "--3--" { + state = 3 + continue + } + + if state == 1 && strings.HasPrefix(line, "Date: ") { line = line[6:] changeTime, err := time.Parse(time.RFC3339, line) if err != nil { @@ -213,13 +218,22 @@ func (fp *FilePages) RecentChanges() ([]Change, error) { continue } - if second { + if state == 2 { + if line == "" { + continue + } + body = body + line + continue + } + + if state == 3 { if line == "" { continue } change.Page = line } + change.Body = body changes = append(changes, change) } diff --git a/main.go b/main.go index 6bb1d1b..1f78dcb 100644 --- a/main.go +++ b/main.go @@ -43,6 +43,7 @@ type Revision struct { type Change struct { Page string Date time.Time + Body string } type PagesRepository interface { diff --git a/templates/recent.html b/templates/recent.html index 5d8fac0..e38ed04 100644 --- a/templates/recent.html +++ b/templates/recent.html @@ -9,7 +9,8 @@ {{ $change.Date }} {{ $change.Page }} + {{ $change.Body }} {{ end }} -{{ end }} \ No newline at end of file +{{ end }}