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,6 +120,7 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubBranchCo
overall := []githubBranchCommits{}
for _, orb := range config.Lists {
if orb.Included {
opts := &gogithub.CommitsListOptions{
SHA: config.Branch,
@ -227,7 +228,7 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubBranchCo
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,6 +127,7 @@ 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
@ -175,6 +182,7 @@ func getIssues(client *gogithub.Client, config *githubConfig) ([]githubIssue, er
}
}
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,6 +116,7 @@ func getMilestones(client *gogithub.Client, config *githubConfig) ([]githubMiles
hadRepo := make(map[string]bool)
for _, orb := range config.Lists {
if orb.Included {
rName := orb.Owner + "/" + orb.Repo
if !hadRepo[rName] {
@ -156,9 +169,9 @@ func getMilestones(client *gogithub.Client, config *githubConfig) ([]githubMiles
}
}
}
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,6 +33,8 @@ 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"`
ClosedPRs int `json:"closedPRs"`
@ -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,6 +109,7 @@ func getPullReqs(client *gogithub.Client, config *githubConfig) ([]githubPullReq
hadRepo := make(map[string]bool)
for _, orb := range config.Lists {
if orb.Included {
rName := orb.Owner + "/" + orb.Repo
if !hadRepo[rName] {
@ -147,6 +156,7 @@ func getPullReqs(client *gogithub.Client, config *githubConfig) ([]githubPullReq
}
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
}