diff --git a/core/section/github/commits.go b/core/section/github/commits.go index f2ef8803..cca18362 100644 --- a/core/section/github/commits.go +++ b/core/section/github/commits.go @@ -31,7 +31,7 @@ type githubCommit struct { Branch string `json:"branch"` ShowBranch bool `json:"ShowBranch"` Date string `json:"date"` - BinDate time.Time `json:"-"` + BinDate time.Time `json:"-"` // only used for sorting ShowDate bool `json:"ShowDate"` Name string `json:"name"` Avatar string `json:"avatar"` @@ -279,18 +279,31 @@ func renderCommits(payload *githubRender, c *githubConfig) error { for range payload.BranchCommits { 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.Issues[i].IsOpen { - payload.AuthorStats[a].OpenIssues++ - } else { - payload.AuthorStats[a].ClosedIssues++ - } + 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 { + payload.AuthorStats[author].OpenIssues++ + } else { + payload.AuthorStats[author].ClosedIssues++ + } } + payload.HasAuthorStats = len(payload.AuthorStats) > 0 + sort.Stable(asToSort(payload.AuthorStats)) return nil } diff --git a/core/section/github/issues.go b/core/section/github/issues.go index 93e99547..a81f14be 100644 --- a/core/section/github/issues.go +++ b/core/section/github/issues.go @@ -136,11 +136,13 @@ func getIssues(client *gogithub.Client, config *githubConfig) ([]githubIssue, er } for _, v := range guff { - n := "" - ptr := v.User + n := "(unassigned)" + av := githubGravatar + ptr := v.Assignee if ptr != nil { if ptr.Login != nil { n = *ptr.Login + av = *ptr.AvatarURL } } ms := noMilestone @@ -152,6 +154,7 @@ func getIssues(client *gogithub.Client, config *githubConfig) ([]githubIssue, er l, ln := wrapLabels(v.Labels) ret = append(ret, githubIssue{ Name: n, + Avatar: av, Message: *v.Title, Date: v.CreatedAt.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) } } + gr.HasIssues = (gr.OpenIssues + gr.ClosedIssues) > 0 gr.SharedLabels = make([]githubSharedLabel, 0, len(sharedLabels)) // will usually be too big for name, repos := range sharedLabels { @@ -215,6 +219,7 @@ func refreshIssues(gr *githubRender, config *githubConfig, client *gogithub.Clie } } sort.Stable(sharedLabelsSort(gr.SharedLabels)) + gr.HasSharedLabels = len(gr.SharedLabels) > 0 return nil } diff --git a/core/section/github/milestones.go b/core/section/github/milestones.go index 16114918..f41f6be0 100644 --- a/core/section/github/milestones.go +++ b/core/section/github/milestones.go @@ -165,6 +165,7 @@ func refreshMilestones(gr *githubRender, config *githubConfig, client *gogithub. gr.ClosedMS++ } } + gr.HasMilestones = (gr.OpenMS + gr.ClosedMS) > 0 return nil } diff --git a/core/section/github/model.go b/core/section/github/model.go index d0bb9d99..dcf6bc24 100644 --- a/core/section/github/model.go +++ b/core/section/github/model.go @@ -29,18 +29,23 @@ type githubRender struct { ShowList bool `json:"showList"` ShowIssueNumbers bool `json:"showIssueNumbers"` BranchCommits []githubCommit `json:"branchCommits"` + HasCommits bool `json:"hasCommits"` CommitCount int `json:"commitCount"` Issues []githubIssue `json:"issues"` + HasIssues bool `json:"hasIssues"` SharedLabels []githubSharedLabel `json:"sharedLabels"` + HasSharedLabels bool `json:"hasSharedLabels"` OpenIssues int `json:"openIssues"` ClosedIssues int `json:"closedIssues"` Limit int `json:"limit"` Milestones []githubMilestone `json:"milestones"` + HasMilestones bool `json:"hasMilestones"` OpenMS int `json:"openMS"` ClosedMS int `json:"closedMS"` OpenPRs int `json:"openPRs"` ClosedPRs int `json:"closedPRs"` AuthorStats []githubAuthorStats `json:"authorStats"` + HasAuthorStats bool `json:"hasAuthorStats"` //PullRequests []githubPullRequest `json:"pullRequests"` }