1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-21 14:19:43 +02:00

add github summary report, tidy SVG constant handling

This commit is contained in:
Elliott Stoneham 2016-08-05 11:44:35 +01:00
parent a7ae6d7503
commit e33d6715aa
6 changed files with 391 additions and 256 deletions

View file

@ -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))

View file

@ -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 = `
<span title="Open issue">
<svg height="16" version="1.1" viewBox="0 0 14 16" width="14"><path d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
</span>
`
closedIsvg = `
<span title="Closed issue">
<svg height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M7 10h2v2H7v-2zm2-6H7v5h2V4zm1.5 1.5l-1 1L12 9l4-4.5-1-1L12 7l-1.5-1.5zM8 13.7A5.71 5.71 0 0 1 2.3 8c0-3.14 2.56-5.7 5.7-5.7 1.83 0 3.45.88 4.5 2.2l.92-.92A6.947 6.947 0 0 0 8 1C4.14 1 1 4.14 1 8s3.14 7 7 7 7-3.14 7-7l-1.52 1.52c-.66 2.41-2.86 4.19-5.48 4.19v-.01z"></path></svg>
</span>
`
)
func init() {
reports[tagIssuesData] = report{refreshIssues, renderIssues, `
<div class="section-github-render">
<h3>Issues</h3>
<p>
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}}
<span class="github-issue-label" style="background-color:#{{$label.Color}}">{{$label.Name}}</span>
@ -81,13 +91,9 @@ func init() {
<a class="link" href="{{$data.URL}}">
<div class="issue-avatar">
{{if $data.IsOpen}}
<span title="Open issue">
<svg height="16" version="1.1" viewBox="0 0 14 16" width="14"><path d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
</span>
` + openIsvg + `
{{else}}
<span title="Closed issue">
<svg height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M7 10h2v2H7v-2zm2-6H7v5h2V4zm1.5 1.5l-1 1L12 9l4-4.5-1-1L12 7l-1.5-1.5zM8 13.7A5.71 5.71 0 0 1 2.3 8c0-3.14 2.56-5.7 5.7-5.7 1.83 0 3.45.88 4.5 2.2l.92-.92A6.947 6.947 0 0 0 8 1C4.14 1 1 4.14 1 8s3.14 7 7 7 7-3.14 7-7l-1.52 1.52c-.66 2.41-2.86 4.19-5.48 4.19v-.01z"></path></svg>
</span>
` + closedIsvg + `
{{end}}
</div>
<div class="github-commit-body">
@ -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
}

View file

@ -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 = `<path d="M8 2H6V0h2v2zm4 5H2c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h10l2 2-2 2zM8 4H6v2h2V4zM6 16h2V8H6v8z"></path>`
openMSsvg = `
<span title="Open milestone">
<svg height="16" width="14" version="1.1" viewBox="0 0 14 16">
` + rawMSsvg + `
</svg>
</span>
`
closedMSsvg = `
<span title="Closed milestone">
<svg height="8" width="7" version="1.1" viewBox="0 0 14 16">
` + rawMSsvg + `
</svg>
</span>
`
)
func init() {
reports[tagMilestonesData] = report{refreshMilestones, renderMilestones, `
<div class="section-github-render">
@ -71,13 +87,9 @@ func init() {
<a class="link" href="{{$data.URL}}">
<div class="issue-avatar">
{{if $data.IsOpen}}
<span title="Open issue">
<svg height="16" version="1.1" viewBox="0 0 14 16" width="14"><path d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
</span>
` + openMSsvg + `
{{else}}
<span title="Closed issue">
<svg height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M7 10h2v2H7v-2zm2-6H7v5h2V4zm1.5 1.5l-1 1L12 9l4-4.5-1-1L12 7l-1.5-1.5zM8 13.7A5.71 5.71 0 0 1 2.3 8c0-3.14 2.56-5.7 5.7-5.7 1.83 0 3.45.88 4.5 2.2l.92-.92A6.947 6.947 0 0 0 8 1C4.14 1 1 4.14 1 8s3.14 7 7 7 7-3.14 7-7l-1.52 1.52c-.66 2.41-2.86 4.19-5.48 4.19v-.01z"></path></svg>
</span>
` + closedMSsvg + `
{{end}}
</div>
<div class="github-commit-body">
@ -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
}

View file

@ -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
}

View file

@ -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 = `<path d="M11 11.28V5c-.03-.78-.34-1.47-.94-2.06C9.46 2.35 8.78 2.03 8 2H7V0L4 3l3 3V4h1c.27.02.48.11.69.31.21.2.3.42.31.69v6.28A1.993 1.993 0 0 0 10 15a1.993 1.993 0 0 0 1-3.72zm-1 2.92c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zM4 3c0-1.11-.89-2-2-2a1.993 1.993 0 0 0-1 3.72v6.56A1.993 1.993 0 0 0 2 15a1.993 1.993 0 0 0 1-3.72V4.72c.59-.34 1-.98 1-1.72zm-.8 10c0 .66-.55 1.2-1.2 1.2-.65 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path>`
openPRsvg = `
<span title="Open Pull Request" >
<svg height="16" width="12" version="1.1" viewBox="0 0 12 16">
` + rawPRsvg + `
</svg>
</span>
`
closedPRsvg = `
<span title="Closed Pull Request" >
<svg height="8" width="6" version="1.1" viewBox="0 0 12 16">
` + rawPRsvg + `
</svg>
</span>
`
)
func init() {
reports[tagPullRequestData] = report{refreshPullReqs, renderPullReqs, `
<div class="section-github-render">
<h3>Pull Requests</h3>
<p>
During the period since {{.Config.Since}}{{.Config.DateMessage}}, {{.ClosedPRs}} pull requests were closed, while {{.OpenPRs}} remain open.
</p>
<div class="github-board">
<ul class="github-list">
{{range $data := .PullRequests}}
@ -69,13 +81,9 @@ func init() {
<a class="link" href="{{$data.URL}}">
<div class="issue-avatar">
{{if $data.IsOpen}}
<span title="Open Pull Request" >
<svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path d="M11 11.28V5c-.03-.78-.34-1.47-.94-2.06C9.46 2.35 8.78 2.03 8 2H7V0L4 3l3 3V4h1c.27.02.48.11.69.31.21.2.3.42.31.69v6.28A1.993 1.993 0 0 0 10 15a1.993 1.993 0 0 0 1-3.72zm-1 2.92c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zM4 3c0-1.11-.89-2-2-2a1.993 1.993 0 0 0-1 3.72v6.56A1.993 1.993 0 0 0 2 15a1.993 1.993 0 0 0 1-3.72V4.72c.59-.34 1-.98 1-1.72zm-.8 10c0 .66-.55 1.2-1.2 1.2-.65 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path></svg>
</span>
` + openPRsvg + `
{{else}}
<span title="Closed Pull Request" >
<svg aria-hidden="true" height="8" version="1.1" viewBox="0 0 12 16" width="6"><path d="M11 11.28V5c-.03-.78-.34-1.47-.94-2.06C9.46 2.35 8.78 2.03 8 2H7V0L4 3l3 3V4h1c.27.02.48.11.69.31.21.2.3.42.31.69v6.28A1.993 1.993 0 0 0 10 15a1.993 1.993 0 0 0 1-3.72zm-1 2.92c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zM4 3c0-1.11-.89-2-2-2a1.993 1.993 0 0 0-1 3.72v6.56A1.993 1.993 0 0 0 2 15a1.993 1.993 0 0 0 1-3.72V4.72c.59-.34 1-.98 1-1.72zm-.8 10c0 .66-.55 1.2-1.2 1.2-.65 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path></svg>
</span>
` + closedPRsvg + `
{{end}}
</div>
<div class="github-commit-body">
@ -101,52 +109,54 @@ func getPullReqs(client *gogithub.Client, config *githubConfig) ([]githubPullReq
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.PullRequestListOptions{
Sort: "updated",
State: state,
ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}}
opts := &gogithub.PullRequestListOptions{
Sort: "updated",
State: state,
ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}}
guff, _, err := client.PullRequests.List(orb.Owner, orb.Repo, opts)
guff, _, err := client.PullRequests.List(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 {
up := ""
if v.UpdatedAt != nil {
up = (*v.UpdatedAt).Format(milestonesTimeFormat)
}
if include {
up := ""
if v.UpdatedAt != nil {
up = (*v.UpdatedAt).Format(milestonesTimeFormat)
}
ret = append(ret, githubPullRequest{
Repo: rName,
Name: *v.Title,
URL: *v.HTMLURL,
IsOpen: *v.State == "open",
UpdatedAt: up,
})
ret = append(ret, githubPullRequest{
Repo: rName,
Name: *v.Title,
URL: *v.HTMLURL,
IsOpen: *v.State == "open",
UpdatedAt: up,
})
}
}
}
}
hadRepo[rName] = true
}
hadRepo[rName] = true
}

View file

@ -0,0 +1,91 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
package github
import (
"sort"
gogithub "github.com/google/go-github/github"
)
const (
tagSummaryData = "summaryData"
)
// sort branches in order that that should be presented.
type branchesToSort []githubBranch
func (s branchesToSort) Len() int { return len(s) }
func (s branchesToSort) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s branchesToSort) Less(i, j int) bool {
return s[i].URL < s[j].URL
}
func init() {
reports[tagSummaryData] = report{refreshSummary, renderSummary, `
<div class="section-github-render">
<h3>Summary</h3>
<div class="github-board">
For repository branches:
<ul>
{{range $data := .Config.Lists}}
{{if $data.Included}}
<li>
<a class="link" href="{{$data.URL}}">
{{$data.Owner}}/{{$data.Repo}}:{{$data.Name}}
</a>
</li>
{{end}}
{{end}}
</ul>
<table style="width:80%">
<tr>
<th></th>
<th colspan=2>Closed since {{.Config.Since}}{{.Config.DateMessage}}</th>
<th colspan=2>Still Open</th>
  </tr>
<tr>
<td>Milestones</td>
<th width=20>` + closedMSsvg + `</td>
<td>{{.ClosedMS}}</td>
<td width=20>` + openMSsvg + `</td>
<td>{{.OpenMS}}</td>
</tr>
<tr>
<td>Issues</td>
<td>` + closedIsvg + `</td>
<td>{{.ClosedIssues}}</td>
<td>` + openIsvg + `</td>
<td>{{.OpenIssues}}</td>
</tr>
<tr>
<td>Pull requests</td>
<td>` + closedPRsvg + `</td>
<td>{{.ClosedPRs}}</td>
<td>` + openPRsvg + `</td>
<td>{{.OpenPRs}}</td>
</tr>
</table>
</div>
</div>
`}
}
func refreshSummary(gr *githubRender, config *githubConfig, client *gogithub.Client) (err error) {
return nil
}
func renderSummary(payload *githubRender, c *githubConfig) error {
sort.Stable(branchesToSort(c.Lists)) // get the configured branches in a sensible order before printing
return nil
}