-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
71 lines (65 loc) · 1.59 KB
/
log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"html/template"
"os"
"path"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
)
type LogPageCommit struct {
Author string
Date string
Hash string
Message string
FileChangeCount int
LinesAdded int
LinesDeleted int
}
type LogPage struct {
RepoData repoData
HasReadMe bool
ReadMePath string
Commits []LogPageCommit
}
func (l *LogPage) renderPage(t *template.Template) {
debug("log page for '%v'", l.RepoData.Name)
output, err := os.Create(path.Join(args.OutputDir, l.RepoData.Name, "log.html"))
checkErr(err)
err = t.Execute(output, l)
checkErr(err)
}
func renderLogPage(data repoData, r *git.Repository) {
t, err := template.ParseFS(htmlTemplates, "template.log.html", "template.partials.html")
checkErr(err)
commits := make([]LogPageCommit, 0)
ref, err := r.Head()
checkErr(err)
cIter, err := r.Log(&git.LogOptions{From: ref.Hash()})
checkErr(err)
err = cIter.ForEach(func(c *object.Commit) error {
stats, err := c.Stats()
added := 0
deleted := 0
for i := 0; i < len(stats); i++ {
stat := stats[i]
added += stat.Addition
deleted += stat.Deletion
}
checkErr(err)
commits = append(commits, LogPageCommit{
Author: c.Author.Name,
Message: c.Message,
Date: c.Author.When.UTC().Format("2006-01-02 15:04:05"),
Hash: c.Hash.String(),
FileChangeCount: len(stats),
LinesAdded: added,
LinesDeleted: deleted,
})
return nil
})
checkErr(err)
(&LogPage{
RepoData: data,
Commits: commits,
}).renderPage(t)
}