diff --git a/core/section/github/commits.go b/core/section/github/commits.go index b2c1a0d4..56e0c403 100644 --- a/core/section/github/commits.go +++ b/core/section/github/commits.go @@ -120,114 +120,115 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubBranchCo overall := []githubBranchCommits{} for _, orb := range config.Lists { + if orb.Included { - opts := &gogithub.CommitsListOptions{ - SHA: config.Branch, - ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}} + opts := &gogithub.CommitsListOptions{ + SHA: config.Branch, + ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}} - if config.SincePtr != nil { - opts.Since = *config.SincePtr - } - - guff, _, err := client.Repositories.ListCommits(orb.Owner, orb.Repo, opts) - - if err != nil { - return nil, nil, err - } - - if len(guff) == 0 { - return []githubBranchCommits{}, []githubAuthorStats{}, nil - } - - day := "" - newDay := "" - ret := []githubDayCommits{} - - 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 config.SincePtr != nil { + opts.Since = *config.SincePtr } - if day != newDay { - day = newDay - ret = append(ret, githubDayCommits{ - Day: day, + + guff, _, err := client.Repositories.ListCommits(orb.Owner, orb.Repo, opts) + + if err != nil { + return nil, nil, err + } + + if len(guff) == 0 { + return []githubBranchCommits{}, []githubAuthorStats{}, nil + } + + day := "" + newDay := "" + ret := []githubDayCommits{} + + 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 + if v.Commit != nil { + if v.Commit.Committer.Date != nil { + // d = fmt.Sprintf("%v", *v.Commit.Committer.Date) + d = v.Commit.Committer.Date.Format("January 2 2006, 15:04") + } + if v.Commit.Message != nil { + m = *v.Commit.Message + } + } + /* Use author rather than committer + var a, l string + if v.Committer != nil { + if v.Committer.Login != nil { + l = *v.Committer.Login + } + if v.Committer.AvatarURL != nil { + a = *v.Committer.AvatarURL + } + } + if a == "" { + a = githubGravatar + } + */ + + if v.HTMLURL != nil { + u = *v.HTMLURL + } + + // update of author commits + al, aa := "", githubGravatar + if v.Author != nil { + if v.Author.Login != nil { + al = *v.Author.Login + } + if v.Author.AvatarURL != nil { + 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 + } + + ret[len(ret)-1].Commits = append(ret[len(ret)-1].Commits, githubCommit{ + Name: al, + Message: m, + Date: d, + Avatar: aa, + URL: template.URL(u), }) } - var d, m, u string - if v.Commit != nil { - if v.Commit.Committer.Date != nil { - // d = fmt.Sprintf("%v", *v.Commit.Committer.Date) - d = v.Commit.Committer.Date.Format("January 2 2006, 15:04") - } - if v.Commit.Message != nil { - m = *v.Commit.Message - } - } - /* Use author rather than committer - var a, l string - if v.Committer != nil { - if v.Committer.Login != nil { - l = *v.Committer.Login - } - if v.Committer.AvatarURL != nil { - a = *v.Committer.AvatarURL - } - } - if a == "" { - a = githubGravatar - } - */ - - if v.HTMLURL != nil { - u = *v.HTMLURL - } - - // update of author commits - al, aa := "", githubGravatar - if v.Author != nil { - if v.Author.Login != nil { - al = *v.Author.Login - } - if v.Author.AvatarURL != nil { - 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 - } - - ret[len(ret)-1].Commits = append(ret[len(ret)-1].Commits, githubCommit{ - Name: al, - Message: m, - Date: d, - Avatar: aa, - URL: template.URL(u), + overall = append(overall, githubBranchCommits{ + Name: fmt.Sprintf("%s/%s:%s", orb.Owner, orb.Repo, orb.Name), + URL: fmt.Sprintf("https://github.com/%s/%s/tree/%s", orb.Owner, orb.Repo, orb.Name), + Days: ret, }) } - - overall = append(overall, githubBranchCommits{ - Name: fmt.Sprintf("%s/%s:%s", orb.Owner, orb.Repo, orb.Name), - URL: fmt.Sprintf("https://github.com/%s/%s/tree/%s", orb.Owner, orb.Repo, orb.Name), - Days: ret, - }) - } retStats := make([]githubAuthorStats, 0, len(authorStats)) diff --git a/core/section/github/issues.go b/core/section/github/issues.go index 1be9a550..b71fb856 100644 --- a/core/section/github/issues.go +++ b/core/section/github/issues.go @@ -21,11 +21,6 @@ import ( gogithub "github.com/google/go-github/github" ) -const ( - tagIssuesData = "issuesData" - issuesTimeFormat = "January 2 2006, 15:04" -) - type githubIssue struct { ID int `json:"id"` Date string `json:"date"` @@ -59,14 +54,29 @@ func (s issuesToSort) Less(i, j int) bool { return iDate.Before(jDate) } +const ( + tagIssuesData = "issuesData" + issuesTimeFormat = "January 2 2006, 15:04" + + openIsvg = ` + + + +` + closedIsvg = ` + + + + ` +) + func init() { reports[tagIssuesData] = report{refreshIssues, renderIssues, `

Issues

- During the period since {{.Config.Since}}{{.Config.DateMessage}}, {{.ClosedIssues}} issues were closed, while {{.OpenIssues}} remain open. {{if .ShowList}} - Labelled + Including issues labelled {{range $label := .List}} {{if $label.Included}} {{$label.Name}} @@ -81,13 +91,9 @@ func init() {

{{if $data.IsOpen}} - - - + ` + openIsvg + ` {{else}} - - - + ` + closedIsvg + ` {{end}}
@@ -121,60 +127,62 @@ func getIssues(client *gogithub.Client, config *githubConfig) ([]githubIssue, er hadRepo := make(map[string]bool) for _, orb := range config.Lists { + if orb.Included { - rName := orb.Owner + "/" + orb.Repo + rName := orb.Owner + "/" + orb.Repo - if !hadRepo[rName] { + if !hadRepo[rName] { - for _, state := range []string{"open", "closed"} { + for _, state := range []string{"open", "closed"} { - opts := &gogithub.IssueListByRepoOptions{ - Sort: "updated", - State: state, - ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}} + opts := &gogithub.IssueListByRepoOptions{ + Sort: "updated", + State: state, + ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}} - if config.SincePtr != nil && state == "closed" /* we want all the open ones */ { - opts.Since = *config.SincePtr - } - - /* TODO refactor to select certain lables - for _, lab := range config.Lists { - if lab.Included { - opts.Labels = append(opts.Labels, lab.Name) + if config.SincePtr != nil && state == "closed" /* we want all the open ones */ { + opts.Since = *config.SincePtr } - } - */ - guff, _, err := client.Issues.ListByRepo(orb.Owner, orb.Repo, opts) - - if err != nil { - return ret, err - } - - for _, v := range guff { - n := "" - ptr := v.User - if ptr != nil { - if ptr.Login != nil { - n = *ptr.Login + /* TODO refactor to select certain lables + for _, lab := range config.Lists { + if lab.Included { + opts.Labels = append(opts.Labels, lab.Name) } } - l := wrapLabels(v.Labels) - ret = append(ret, githubIssue{ - Name: n, - Message: *v.Title, - Date: v.CreatedAt.Format(issuesTimeFormat), - Updated: v.UpdatedAt.Format(issuesTimeFormat), - URL: template.URL(*v.HTMLURL), - Labels: template.HTML(l), - ID: *v.Number, - IsOpen: *v.State == "open", - Repo: rName, - }) + */ + + guff, _, err := client.Issues.ListByRepo(orb.Owner, orb.Repo, opts) + + if err != nil { + return ret, err + } + + for _, v := range guff { + n := "" + ptr := v.User + if ptr != nil { + if ptr.Login != nil { + n = *ptr.Login + } + } + l := wrapLabels(v.Labels) + ret = append(ret, githubIssue{ + Name: n, + Message: *v.Title, + Date: v.CreatedAt.Format(issuesTimeFormat), + Updated: v.UpdatedAt.Format(issuesTimeFormat), + URL: template.URL(*v.HTMLURL), + Labels: template.HTML(l), + ID: *v.Number, + IsOpen: *v.State == "open", + Repo: rName, + }) + } } } + hadRepo[rName] = true } - hadRepo[rName] = true } diff --git a/core/section/github/milestones.go b/core/section/github/milestones.go index daf37988..86f6cf0b 100644 --- a/core/section/github/milestones.go +++ b/core/section/github/milestones.go @@ -21,11 +21,6 @@ import ( gogithub "github.com/google/go-github/github" ) -const ( - tagMilestonesData = "milestonesData" - milestonesTimeFormat = "January 2 2006" -) - type githubMilestone struct { Repo string `json:"repo"` Name string `json:"name"` @@ -60,6 +55,27 @@ func (s milestonesToSort) Less(i, j int) bool { } +const ( + tagMilestonesData = "milestonesData" + milestonesTimeFormat = "January 2 2006" + + rawMSsvg = `` + openMSsvg = ` + + + ` + rawMSsvg + ` + + +` + closedMSsvg = ` + + + ` + rawMSsvg + ` + + +` +) + func init() { reports[tagMilestonesData] = report{refreshMilestones, renderMilestones, `
@@ -71,13 +87,9 @@ func init() {
{{if $data.IsOpen}} - - - + ` + openMSsvg + ` {{else}} - - - + ` + closedMSsvg + ` {{end}}
@@ -104,61 +116,62 @@ func getMilestones(client *gogithub.Client, config *githubConfig) ([]githubMiles hadRepo := make(map[string]bool) for _, orb := range config.Lists { - rName := orb.Owner + "/" + orb.Repo + if orb.Included { + rName := orb.Owner + "/" + orb.Repo - if !hadRepo[rName] { + if !hadRepo[rName] { - for _, state := range []string{"open", "closed"} { + for _, state := range []string{"open", "closed"} { - opts := &gogithub.MilestoneListOptions{ - Sort: "updated", - State: state, - ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}} + opts := &gogithub.MilestoneListOptions{ + Sort: "updated", + State: state, + ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}} - guff, _, err := client.Issues.ListMilestones(orb.Owner, orb.Repo, opts) + guff, _, err := client.Issues.ListMilestones(orb.Owner, orb.Repo, opts) - if err != nil { - return ret, err - } + if err != nil { + return ret, err + } - for _, v := range guff { - include := true - if state == "closed" { - if config.SincePtr != nil { - if (*config.SincePtr).After(*v.ClosedAt) { - include = false + for _, v := range guff { + include := true + if state == "closed" { + if config.SincePtr != nil { + if (*config.SincePtr).After(*v.ClosedAt) { + include = false + } } } - } - if include { - dd := "No due date." - if v.DueOn != nil { - // TODO refactor to add message in red if the milestone is overdue - dd = "Due on " + (*v.DueOn).Format(milestonesTimeFormat) + "." - } - up := "" - if v.UpdatedAt != nil { - up = (*v.UpdatedAt).Format(milestonesTimeFormat) - } + if include { + dd := "No due date." + if v.DueOn != nil { + // TODO refactor to add message in red if the milestone is overdue + dd = "Due on " + (*v.DueOn).Format(milestonesTimeFormat) + "." + } + up := "" + if v.UpdatedAt != nil { + up = (*v.UpdatedAt).Format(milestonesTimeFormat) + } - ret = append(ret, githubMilestone{ - Repo: rName, - Name: *v.Title, - URL: *v.HTMLURL, - IsOpen: *v.State == "open", - OpenIssues: *v.OpenIssues, - ClosedIssues: *v.ClosedIssues, - CompleteMsg: fmt.Sprintf("%2.0f%%", float64(*v.ClosedIssues*100)/float64(*v.OpenIssues+*v.ClosedIssues)), - DueDate: dd, - UpdatedAt: up, - }) + ret = append(ret, githubMilestone{ + Repo: rName, + Name: *v.Title, + URL: *v.HTMLURL, + IsOpen: *v.State == "open", + OpenIssues: *v.OpenIssues, + ClosedIssues: *v.ClosedIssues, + CompleteMsg: fmt.Sprintf("%2.0f%%", float64(*v.ClosedIssues*100)/float64(*v.OpenIssues+*v.ClosedIssues)), + DueDate: dd, + UpdatedAt: up, + }) + } } + } - } - + hadRepo[rName] = true } - hadRepo[rName] = true } @@ -175,6 +188,16 @@ func refreshMilestones(gr *githubRender, config *githubConfig, client *gogithub. log.Error("unable to get github milestones", err) return err } + gr.OpenMS = 0 + gr.ClosedMS = 0 + for _, v := range gr.Milestones { + if v.IsOpen { + gr.OpenMS++ + } else { + gr.ClosedMS++ + } + } + return nil } diff --git a/core/section/github/model.go b/core/section/github/model.go index 68c3ae0f..4bc9c640 100644 --- a/core/section/github/model.go +++ b/core/section/github/model.go @@ -33,8 +33,10 @@ type githubRender struct { ClosedIssues int `json:"closedIssues"` Limit int `json:"limit"` Milestones []githubMilestone `json:"milestones"` + OpenMS int `json:"openMS"` + ClosedMS int `json:"closedMS"` PullRequests []githubPullRequest `json:"pullRequests"` - OpenPRs int `json:"openPRs"` + OpenPRs int `json:"openPRs"` ClosedPRs int `json:"closedPRs"` AuthorStats []githubAuthorStats `json:"authorStats"` } @@ -147,7 +149,7 @@ func (c *githubConfig) Clean() { Color: "", }) } - c.ReportOrder = []string{tagMilestonesData, tagIssuesData, tagPullRequestData, tagCommitsData} + c.ReportOrder = []string{tagSummaryData, tagMilestonesData, tagIssuesData, tagPullRequestData, tagCommitsData} c.BranchLines = 100 // overide js default of 30 with maximum allowable in one call } diff --git a/core/section/github/pullrequests.go b/core/section/github/pullrequests.go index 2b11efbe..6957b727 100644 --- a/core/section/github/pullrequests.go +++ b/core/section/github/pullrequests.go @@ -20,11 +20,6 @@ import ( gogithub "github.com/google/go-github/github" ) -const ( - tagPullRequestData = "pullRequestData" - //pullRequestTimeFormat = "January 2 2006" -) - type githubPullRequest struct { Repo string `json:"repo"` Name string `json:"name"` @@ -55,13 +50,30 @@ func (s prToSort) Less(i, j int) bool { } +const ( + tagPullRequestData = "pullRequestData" + + rawPRsvg = `` + openPRsvg = ` + + + ` + rawPRsvg + ` + + + ` + closedPRsvg = ` + + + ` + rawPRsvg + ` + + + ` +) + func init() { reports[tagPullRequestData] = report{refreshPullReqs, renderPullReqs, `

Pull Requests

-

- During the period since {{.Config.Since}}{{.Config.DateMessage}}, {{.ClosedPRs}} pull requests were closed, while {{.OpenPRs}} remain open. -