mirror of
https://github.com/documize/community.git
synced 2025-07-21 14:19:43 +02:00
improve github commit list presentation
This commit is contained in:
parent
7c72b72bae
commit
ba1512c7cd
3 changed files with 146 additions and 133 deletions
|
@ -15,30 +15,29 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"sort"
|
"sort"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/documize/community/core/log"
|
"github.com/documize/community/core/log"
|
||||||
|
|
||||||
gogithub "github.com/google/go-github/github"
|
gogithub "github.com/google/go-github/github"
|
||||||
)
|
)
|
||||||
|
|
||||||
type githubBranchCommits struct {
|
const commitTimeFormat = "January 2 2006, 15:04"
|
||||||
Name string `json:"name"`
|
|
||||||
URL string `json:"url"`
|
|
||||||
CommitCount int `json:"commitCount"`
|
|
||||||
Days []githubDayCommits `json:"days"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type githubDayCommits struct {
|
|
||||||
Day string `json:"day"`
|
|
||||||
Commits []githubCommit `json:"commits"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type githubCommit struct {
|
type githubCommit struct {
|
||||||
Date string `json:"date"`
|
Owner string `json:"owner"`
|
||||||
Message string `json:"message"`
|
Repo string `json:"repo"`
|
||||||
URL template.URL `json:"url"`
|
ShowRepo bool `json:"showRepo"`
|
||||||
Name string `json:"name"`
|
Branch string `json:"branch"`
|
||||||
Avatar string `json:"avatar"`
|
ShowBranch bool `json:"ShowBranch"`
|
||||||
|
Date string `json:"date"`
|
||||||
|
BinDate time.Time `json:"-"`
|
||||||
|
ShowDate bool `json:"ShowDate"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Avatar string `json:"avatar"`
|
||||||
|
ShowUser bool `json:"ShowUser"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
URL template.URL `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type githubAuthorStats struct {
|
type githubAuthorStats struct {
|
||||||
|
@ -50,6 +49,24 @@ type githubAuthorStats struct {
|
||||||
ClosedIssues int `json:"closedIssues"`
|
ClosedIssues int `json:"closedIssues"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// order commits in a way that makes sense of the table
|
||||||
|
type orderCommits []githubCommit
|
||||||
|
|
||||||
|
func (s orderCommits) Len() int { return len(s) }
|
||||||
|
func (s orderCommits) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||||
|
func (s orderCommits) Less(i, j int) bool {
|
||||||
|
if s[i].Repo == s[j].Repo {
|
||||||
|
if s[i].Branch == s[j].Branch {
|
||||||
|
if s[i].BinDate == s[j].BinDate {
|
||||||
|
return s[i].Name < s[j].Name
|
||||||
|
}
|
||||||
|
return s[i].BinDate.Before(s[j].BinDate)
|
||||||
|
}
|
||||||
|
return s[i].Branch < s[j].Branch
|
||||||
|
}
|
||||||
|
return s[i].Repo < s[j].Repo
|
||||||
|
}
|
||||||
|
|
||||||
// sort stats in order that that should be presented.
|
// sort stats in order that that should be presented.
|
||||||
type asToSort []githubAuthorStats
|
type asToSort []githubAuthorStats
|
||||||
|
|
||||||
|
@ -70,7 +87,7 @@ func (s branchByID) Less(i, j int) bool {
|
||||||
|
|
||||||
const tagCommitsData = "commitsData"
|
const tagCommitsData = "commitsData"
|
||||||
|
|
||||||
func getCommits(client *gogithub.Client, config *githubConfig) ([]githubBranchCommits, []githubAuthorStats, error) {
|
func getCommits(client *gogithub.Client, config *githubConfig) ([]githubCommit, []githubAuthorStats, error) {
|
||||||
|
|
||||||
// first make sure we've got all the branches
|
// first make sure we've got all the branches
|
||||||
for _, orb := range config.Lists {
|
for _, orb := range config.Lists {
|
||||||
|
@ -100,19 +117,19 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubBranchCo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sort.Stable(branchByID(config.Lists))
|
sort.Sort(branchByID(config.Lists))
|
||||||
|
|
||||||
authorStats := make(map[string]githubAuthorStats)
|
authorStats := make(map[string]githubAuthorStats)
|
||||||
|
|
||||||
contribBranch := make(map[string]map[string]struct{})
|
contribBranch := make(map[string]map[string]struct{})
|
||||||
|
|
||||||
overall := []githubBranchCommits{}
|
overall := []githubCommit{}
|
||||||
|
|
||||||
for _, orb := range config.Lists {
|
for _, orb := range config.Lists {
|
||||||
if orb.Included {
|
if orb.Included {
|
||||||
|
|
||||||
opts := &gogithub.CommitsListOptions{
|
opts := &gogithub.CommitsListOptions{
|
||||||
SHA: config.Branch,
|
SHA: orb.Name,
|
||||||
ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}}
|
ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}}
|
||||||
|
|
||||||
if config.SincePtr != nil {
|
if config.SincePtr != nil {
|
||||||
|
@ -125,50 +142,37 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubBranchCo
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
day := ""
|
thisBranch := fmt.Sprintf("%s:%s", orb.Repo, orb.Name)
|
||||||
newDay := ""
|
|
||||||
ret := []githubDayCommits{}
|
|
||||||
|
|
||||||
thisBranch := fmt.Sprintf("%s/%s:%s", orb.Owner, orb.Repo, orb.Name)
|
for _, v := range guff {
|
||||||
|
|
||||||
for k, v := range guff {
|
|
||||||
|
|
||||||
if guff[k].Commit != nil {
|
|
||||||
if guff[k].Commit.Committer.Date != nil {
|
|
||||||
y, m, d := (*guff[k].Commit.Committer.Date).Date()
|
|
||||||
newDay = fmt.Sprintf("%s %d, %d", m.String(), d, y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if day != newDay {
|
|
||||||
day = newDay
|
|
||||||
ret = append(ret, githubDayCommits{
|
|
||||||
Day: day,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
var d, m, u string
|
var d, m, u string
|
||||||
|
var bd time.Time
|
||||||
if v.Commit != nil {
|
if v.Commit != nil {
|
||||||
if v.Commit.Committer.Date != nil {
|
if v.Commit.Committer.Date != nil {
|
||||||
// d = fmt.Sprintf("%v", *v.Commit.Committer.Date)
|
// d = fmt.Sprintf("%v", *v.Commit.Committer.Date)
|
||||||
d = v.Commit.Committer.Date.Format("January 2 2006, 15:04")
|
d = v.Commit.Committer.Date.Format(commitTimeFormat)
|
||||||
|
bd = *v.Commit.Committer.Date
|
||||||
}
|
}
|
||||||
if v.Commit.Message != nil {
|
if v.Commit.Message != nil {
|
||||||
m = *v.Commit.Message
|
m = *v.Commit.Message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Use author rather than committer
|
|
||||||
var a, l string
|
// TODO(elliott5) remove this comment
|
||||||
if v.Committer != nil {
|
/*
|
||||||
if v.Committer.Login != nil {
|
var a, l string
|
||||||
l = *v.Committer.Login
|
if v.Committer != nil {
|
||||||
|
if v.Committer.Login != nil {
|
||||||
|
l = *v.Committer.Login
|
||||||
|
}
|
||||||
|
if v.Committer.AvatarURL != nil {
|
||||||
|
a = *v.Committer.AvatarURL
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if v.Committer.AvatarURL != nil {
|
if a == "" {
|
||||||
a = *v.Committer.AvatarURL
|
a = githubGravatar
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if a == "" {
|
|
||||||
a = githubGravatar
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if v.HTMLURL != nil {
|
if v.HTMLURL != nil {
|
||||||
|
@ -184,42 +188,64 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubBranchCo
|
||||||
if v.Author.AvatarURL != nil {
|
if v.Author.AvatarURL != nil {
|
||||||
aa = *v.Author.AvatarURL
|
aa = *v.Author.AvatarURL
|
||||||
}
|
}
|
||||||
cum := authorStats[al]
|
|
||||||
cum.Author = al
|
|
||||||
cum.Avatar = aa
|
|
||||||
cum.CommitCount++
|
|
||||||
/* TODO review, this code removed as too slow
|
|
||||||
cmt, _, err := client.Repositories.GetCommit(orb.Owner, orb.Repo, *v.SHA)
|
|
||||||
if err == nil {
|
|
||||||
if cmt.Stats != nil {
|
|
||||||
if cmt.Stats.Total != nil {
|
|
||||||
cum.TotalChanges += (*cmt.Stats.Total)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
authorStats[al] = cum
|
|
||||||
}
|
}
|
||||||
|
l := al // use author not committer
|
||||||
|
a := aa // ditto
|
||||||
|
|
||||||
ret[len(ret)-1].Commits = append(ret[len(ret)-1].Commits, githubCommit{
|
overall = append(overall, githubCommit{
|
||||||
Name: al,
|
Owner: orb.Owner,
|
||||||
|
Repo: orb.Repo,
|
||||||
|
Branch: orb.Name,
|
||||||
|
Name: l,
|
||||||
Message: m,
|
Message: m,
|
||||||
Date: d,
|
Date: d,
|
||||||
Avatar: aa,
|
BinDate: bd,
|
||||||
|
Avatar: a,
|
||||||
URL: template.URL(u),
|
URL: template.URL(u),
|
||||||
})
|
})
|
||||||
|
|
||||||
if _, ok := contribBranch[al]; !ok {
|
if _, ok := contribBranch[l]; !ok {
|
||||||
contribBranch[al] = make(map[string]struct{})
|
contribBranch[l] = make(map[string]struct{})
|
||||||
}
|
}
|
||||||
contribBranch[al][thisBranch] = struct{}{}
|
contribBranch[l][thisBranch] = struct{}{}
|
||||||
}
|
|
||||||
|
|
||||||
overall = append(overall, githubBranchCommits{
|
cum := authorStats[l]
|
||||||
Name: thisBranch,
|
cum.Author = l
|
||||||
URL: fmt.Sprintf("https://github.com/%s/%s/tree/%s", orb.Owner, orb.Repo, orb.Name),
|
cum.Avatar = a
|
||||||
Days: ret,
|
cum.CommitCount++
|
||||||
})
|
// TODO review, this code removed as too slow
|
||||||
|
//cmt, _, err := client.Repositories.GetCommit(orb.Owner, orb.Repo, *v.SHA)
|
||||||
|
//if err == nil {
|
||||||
|
// if cmt.Stats != nil {
|
||||||
|
// if cmt.Stats.Total != nil {
|
||||||
|
// cum.TotalChanges += (*cmt.Stats.Total)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
authorStats[l] = cum
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Sort(orderCommits(overall))
|
||||||
|
|
||||||
|
for k := range overall {
|
||||||
|
overall[k].ShowRepo = true
|
||||||
|
overall[k].ShowBranch = true
|
||||||
|
overall[k].ShowDate = true
|
||||||
|
overall[k].ShowUser = true
|
||||||
|
if k > 0 {
|
||||||
|
if overall[k].Repo == overall[k-1].Repo {
|
||||||
|
overall[k].ShowRepo = false
|
||||||
|
if overall[k].Branch == overall[k-1].Branch {
|
||||||
|
overall[k].ShowBranch = false
|
||||||
|
if overall[k].Date == overall[k-1].Date {
|
||||||
|
overall[k].ShowDate = false
|
||||||
|
overall[k].ShowUser = overall[k].Name != overall[k-1].Name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,7 +266,6 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubBranchCo
|
||||||
}
|
}
|
||||||
|
|
||||||
func refreshCommits(gr *githubRender, config *githubConfig, client *gogithub.Client) (err error) {
|
func refreshCommits(gr *githubRender, config *githubConfig, client *gogithub.Client) (err error) {
|
||||||
|
|
||||||
gr.BranchCommits, gr.AuthorStats, err = getCommits(client, config)
|
gr.BranchCommits, gr.AuthorStats, err = getCommits(client, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("github refreshCommits:", err)
|
log.Error("github refreshCommits:", err)
|
||||||
|
@ -251,12 +276,8 @@ func refreshCommits(gr *githubRender, config *githubConfig, client *gogithub.Cli
|
||||||
|
|
||||||
func renderCommits(payload *githubRender, c *githubConfig) error {
|
func renderCommits(payload *githubRender, c *githubConfig) error {
|
||||||
payload.CommitCount = 0
|
payload.CommitCount = 0
|
||||||
for l, list := range payload.BranchCommits {
|
for range payload.BranchCommits {
|
||||||
payload.BranchCommits[l].CommitCount = 0
|
payload.CommitCount++
|
||||||
for _, day := range list.Days {
|
|
||||||
payload.BranchCommits[l].CommitCount += len(day.Commits)
|
|
||||||
payload.CommitCount += len(day.Commits)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for a := range payload.AuthorStats {
|
for a := range payload.AuthorStats {
|
||||||
|
@ -274,9 +295,6 @@ func renderCommits(payload *githubRender, c *githubConfig) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(elliott5) - move to templates.go once working
|
|
||||||
// COMMITS
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
reports[tagCommitsData] = report{refreshCommits, renderCommits, commitsTemplate}
|
reports[tagCommitsData] = report{refreshCommits, renderCommits, commitsTemplate}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,33 +42,28 @@ const commitsTemplate = `
|
||||||
</tr>
|
</tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
</table>
|
</table>
|
||||||
{{range $branch := .BranchCommits}}
|
<table>
|
||||||
<h4>
|
{{range $commit := .BranchCommits}}
|
||||||
There are {{ $branch.CommitCount }} commits for branch <a href="{{$branch.URL}}">{{$branch.Name}}</a>.
|
<tr>
|
||||||
</h4>
|
<td>
|
||||||
<div class="github-board">
|
{{if $commit.ShowRepo}}{{$commit.Repo}}{{end}}
|
||||||
{{range $data := $branch.Days}}
|
</td>
|
||||||
<div class="github-group-title">
|
<td>
|
||||||
Commits on {{ $data.Day }}
|
{{if $commit.ShowBranch}}{{$commit.Branch}}{{end}}
|
||||||
</div>
|
</td>
|
||||||
<ul class="github-list">
|
<td>
|
||||||
{{range $commit := $data.Commits}}
|
{{if $commit.ShowDate}}{{$commit.Date}}{{end}}
|
||||||
<li class="github-commit-item">
|
</td>
|
||||||
<a class="link" href="{{$commit.URL}}">
|
<td>
|
||||||
<div class="github-avatar">
|
{{if $commit.ShowUser}}
|
||||||
<img alt="@{{$commit.Name}}" src="{{$commit.Avatar}}" height="36" width="36">
|
<img alt="@{{$commit.Name}}" src="{{$commit.Avatar}}" height="36" width="36"> {{$commit.Name}}
|
||||||
</div>
|
{{end}}
|
||||||
<div class="github-commit-body">
|
</td>
|
||||||
<div class="github-commit-title">{{$commit.Message}}</div>
|
<td>
|
||||||
<div class="github-commit-meta">{{$commit.Name}} committed on {{$commit.Date}}</div>
|
<a class="link" href="{{$commit.URL}}">{{$commit.Message}}</a>
|
||||||
</div>
|
</td>
|
||||||
</a>
|
</tr>
|
||||||
<div class="clearfix" />
|
|
||||||
</li>
|
|
||||||
{{end}}
|
|
||||||
</ul>
|
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
</table>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
|
|
|
@ -23,24 +23,24 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type githubRender struct {
|
type githubRender struct {
|
||||||
Config githubConfig `json:"config"`
|
Config githubConfig `json:"config"`
|
||||||
Repo githubRepo `json:"repo"`
|
Repo githubRepo `json:"repo"`
|
||||||
List []githubBranch `json:"list"`
|
List []githubBranch `json:"list"`
|
||||||
ShowList bool `json:"showList"`
|
ShowList bool `json:"showList"`
|
||||||
ShowIssueNumbers bool `json:"showIssueNumbers"`
|
ShowIssueNumbers bool `json:"showIssueNumbers"`
|
||||||
BranchCommits []githubBranchCommits `json:"branchCommits"`
|
BranchCommits []githubCommit `json:"branchCommits"`
|
||||||
CommitCount int `json:"commitCount"`
|
CommitCount int `json:"commitCount"`
|
||||||
Issues []githubIssue `json:"issues"`
|
Issues []githubIssue `json:"issues"`
|
||||||
SharedLabels []githubSharedLabel `json:"sharedLabels"`
|
SharedLabels []githubSharedLabel `json:"sharedLabels"`
|
||||||
OpenIssues int `json:"openIssues"`
|
OpenIssues int `json:"openIssues"`
|
||||||
ClosedIssues int `json:"closedIssues"`
|
ClosedIssues int `json:"closedIssues"`
|
||||||
Limit int `json:"limit"`
|
Limit int `json:"limit"`
|
||||||
Milestones []githubMilestone `json:"milestones"`
|
Milestones []githubMilestone `json:"milestones"`
|
||||||
OpenMS int `json:"openMS"`
|
OpenMS int `json:"openMS"`
|
||||||
ClosedMS int `json:"closedMS"`
|
ClosedMS int `json:"closedMS"`
|
||||||
OpenPRs int `json:"openPRs"`
|
OpenPRs int `json:"openPRs"`
|
||||||
ClosedPRs int `json:"closedPRs"`
|
ClosedPRs int `json:"closedPRs"`
|
||||||
AuthorStats []githubAuthorStats `json:"authorStats"`
|
AuthorStats []githubAuthorStats `json:"authorStats"`
|
||||||
//PullRequests []githubPullRequest `json:"pullRequests"`
|
//PullRequests []githubPullRequest `json:"pullRequests"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue