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) { 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.Dir = fp.dirname
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
buf := bytes.Buffer{} buf := bytes.Buffer{}
@ -181,29 +181,34 @@ func (fp *FilePages) RecentChanges() ([]Change, error) {
scanner := bufio.NewScanner(&buf) scanner := bufio.NewScanner(&buf)
first := false state := 0
second := false
var changes []Change var changes []Change
var change Change var change Change
body := ""
for scanner.Scan() { for scanner.Scan() {
line := scanner.Text() line := scanner.Text()
if line == "--1--" { if line == "--1--" {
second = false state = 1
first = true
body = ""
continue continue
} }
if line == "--2--" { if line == "--2--" {
first = false state = 2
second = true
continue continue
} }
if first && strings.HasPrefix(line, "Date: ") { if line == "--3--" {
state = 3
continue
}
if state == 1 && strings.HasPrefix(line, "Date: ") {
line = line[6:] line = line[6:]
changeTime, err := time.Parse(time.RFC3339, line) changeTime, err := time.Parse(time.RFC3339, line)
if err != nil { if err != nil {
@ -213,13 +218,22 @@ func (fp *FilePages) RecentChanges() ([]Change, error) {
continue continue
} }
if second { if state == 2 {
if line == "" {
continue
}
body = body + line
continue
}
if state == 3 {
if line == "" { if line == "" {
continue continue
} }
change.Page = line change.Page = line
} }
change.Body = body
changes = append(changes, change) changes = append(changes, change)
} }

View File

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

View File

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