1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-21 22:29:41 +02:00

add user stats where no commits, add HasX flags for template

This commit is contained in:
Elliott Stoneham 2016-08-23 12:52:18 +01:00
parent ba1512c7cd
commit 603db6fc15
4 changed files with 34 additions and 10 deletions

View file

@ -31,7 +31,7 @@ type githubCommit struct {
Branch string `json:"branch"` Branch string `json:"branch"`
ShowBranch bool `json:"ShowBranch"` ShowBranch bool `json:"ShowBranch"`
Date string `json:"date"` Date string `json:"date"`
BinDate time.Time `json:"-"` BinDate time.Time `json:"-"` // only used for sorting
ShowDate bool `json:"ShowDate"` ShowDate bool `json:"ShowDate"`
Name string `json:"name"` Name string `json:"name"`
Avatar string `json:"avatar"` Avatar string `json:"avatar"`
@ -279,18 +279,31 @@ func renderCommits(payload *githubRender, c *githubConfig) error {
for range payload.BranchCommits { for range payload.BranchCommits {
payload.CommitCount++ payload.CommitCount++
} }
payload.HasCommits = payload.CommitCount > 0
for a := range payload.AuthorStats {
for i := range payload.Issues { for i := range payload.Issues {
var author int
for a := range payload.AuthorStats {
if payload.AuthorStats[a].Author == payload.Issues[i].Name { if payload.AuthorStats[a].Author == payload.Issues[i].Name {
author = a
goto found
}
}
// no Author found for issue, so create one
payload.AuthorStats = append(payload.AuthorStats, githubAuthorStats{
Author: payload.Issues[i].Name,
Avatar: payload.Issues[i].Avatar,
})
author = len(payload.AuthorStats) - 1
found:
if payload.Issues[i].IsOpen { if payload.Issues[i].IsOpen {
payload.AuthorStats[a].OpenIssues++ payload.AuthorStats[author].OpenIssues++
} else { } else {
payload.AuthorStats[a].ClosedIssues++ payload.AuthorStats[author].ClosedIssues++
}
}
} }
} }
payload.HasAuthorStats = len(payload.AuthorStats) > 0
sort.Stable(asToSort(payload.AuthorStats))
return nil return nil
} }

View file

@ -136,11 +136,13 @@ func getIssues(client *gogithub.Client, config *githubConfig) ([]githubIssue, er
} }
for _, v := range guff { for _, v := range guff {
n := "" n := "(unassigned)"
ptr := v.User av := githubGravatar
ptr := v.Assignee
if ptr != nil { if ptr != nil {
if ptr.Login != nil { if ptr.Login != nil {
n = *ptr.Login n = *ptr.Login
av = *ptr.AvatarURL
} }
} }
ms := noMilestone ms := noMilestone
@ -152,6 +154,7 @@ func getIssues(client *gogithub.Client, config *githubConfig) ([]githubIssue, er
l, ln := wrapLabels(v.Labels) l, ln := wrapLabels(v.Labels)
ret = append(ret, githubIssue{ ret = append(ret, githubIssue{
Name: n, Name: n,
Avatar: av,
Message: *v.Title, Message: *v.Title,
Date: v.CreatedAt.Format(issuesTimeFormat), Date: v.CreatedAt.Format(issuesTimeFormat),
Updated: v.UpdatedAt.Format(issuesTimeFormat), Updated: v.UpdatedAt.Format(issuesTimeFormat),
@ -197,6 +200,7 @@ func refreshIssues(gr *githubRender, config *githubConfig, client *gogithub.Clie
sharedLabels[lab] = append(sharedLabels[lab], v.Repo) sharedLabels[lab] = append(sharedLabels[lab], v.Repo)
} }
} }
gr.HasIssues = (gr.OpenIssues + gr.ClosedIssues) > 0
gr.SharedLabels = make([]githubSharedLabel, 0, len(sharedLabels)) // will usually be too big gr.SharedLabels = make([]githubSharedLabel, 0, len(sharedLabels)) // will usually be too big
for name, repos := range sharedLabels { for name, repos := range sharedLabels {
@ -215,6 +219,7 @@ func refreshIssues(gr *githubRender, config *githubConfig, client *gogithub.Clie
} }
} }
sort.Stable(sharedLabelsSort(gr.SharedLabels)) sort.Stable(sharedLabelsSort(gr.SharedLabels))
gr.HasSharedLabels = len(gr.SharedLabels) > 0
return nil return nil
} }

View file

@ -165,6 +165,7 @@ func refreshMilestones(gr *githubRender, config *githubConfig, client *gogithub.
gr.ClosedMS++ gr.ClosedMS++
} }
} }
gr.HasMilestones = (gr.OpenMS + gr.ClosedMS) > 0
return nil return nil
} }

View file

@ -29,18 +29,23 @@ type githubRender struct {
ShowList bool `json:"showList"` ShowList bool `json:"showList"`
ShowIssueNumbers bool `json:"showIssueNumbers"` ShowIssueNumbers bool `json:"showIssueNumbers"`
BranchCommits []githubCommit `json:"branchCommits"` BranchCommits []githubCommit `json:"branchCommits"`
HasCommits bool `json:"hasCommits"`
CommitCount int `json:"commitCount"` CommitCount int `json:"commitCount"`
Issues []githubIssue `json:"issues"` Issues []githubIssue `json:"issues"`
HasIssues bool `json:"hasIssues"`
SharedLabels []githubSharedLabel `json:"sharedLabels"` SharedLabels []githubSharedLabel `json:"sharedLabels"`
HasSharedLabels bool `json:"hasSharedLabels"`
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"`
HasMilestones bool `json:"hasMilestones"`
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"`
HasAuthorStats bool `json:"hasAuthorStats"`
//PullRequests []githubPullRequest `json:"pullRequests"` //PullRequests []githubPullRequest `json:"pullRequests"`
} }