Show summary in recent changes
All checks were successful
the build was successful

This commit is contained in:
Peter Stuifzand 2019-03-02 14:06:17 +01:00
parent 636f23d834
commit 5d5f537df9
3 changed files with 27 additions and 11 deletions

34
file.go
View File

@ -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)
}

View File

@ -43,6 +43,7 @@ type Revision struct {
type Change struct {
Page string
Date time.Time
Body string
}
type PagesRepository interface {

View File

@ -9,6 +9,7 @@
<tr>
<td>{{ $change.Date }}</td>
<td><a href="/{{ $change.Page }}">{{ $change.Page }}</a></td>
<td>{{ $change.Body }}</td>
</tr>
{{ end }}
</table>