mirror of
https://github.com/documize/community.git
synced 2025-07-21 14:19:43 +02:00
add extra accumulations for proposed github sections
This commit is contained in:
parent
6f0d503cb5
commit
20f77f359e
7 changed files with 692 additions and 641 deletions
|
@ -42,10 +42,12 @@ type githubCommit struct {
|
|||
}
|
||||
|
||||
type githubAuthorStats struct {
|
||||
Author string `json:"author"`
|
||||
Avatar string `json:"avatar"`
|
||||
CommitCount int `json:"commitCount"`
|
||||
//TotalChanges int `json:"totalChanges"`
|
||||
Author string `json:"author"`
|
||||
Avatar string `json:"avatar"`
|
||||
CommitCount int `json:"commitCount"`
|
||||
Repos []string `json:"repos"`
|
||||
OpenIssues int `json:"openIssues"`
|
||||
ClosedIssues int `json:"closedIssues"`
|
||||
}
|
||||
|
||||
// sort stats in order that that should be presented.
|
||||
|
@ -61,13 +63,16 @@ const tagCommitsData = "commitsData"
|
|||
|
||||
func init() {
|
||||
reports[tagCommitsData] = report{refreshCommits, renderCommits, `
|
||||
<h3>Commits</h3>
|
||||
<h3>Contributor activity since {{.Config.Since}}{{.Config.DateMessage}}</h3>
|
||||
<div class="section-github-render">
|
||||
<table style="width:80%">
|
||||
<tr>
|
||||
<th>{{.CommitCount}} commits since {{.Config.Since}}{{.Config.DateMessage}}</th>
|
||||
<th></th>
|
||||
<th>Author</th>
|
||||
<th>Open Issues</th>
|
||||
<th>Closed Issues</th>
|
||||
<th>#commits</th>
|
||||
<th>Branches</th>
|
||||
</tr>
|
||||
{{range $stats := .AuthorStats}}
|
||||
<tr>
|
||||
|
@ -77,7 +82,14 @@ func init() {
|
|||
</div>
|
||||
</td>
|
||||
<td>{{$stats.Author}}</td>
|
||||
<td>{{$stats.OpenIssues}}</td>
|
||||
<td>{{$stats.ClosedIssues}}</td>
|
||||
<td>{{$stats.CommitCount}}</td>
|
||||
<td>
|
||||
{{range $repo := $stats.Repos}}
|
||||
{{$repo}}
|
||||
{{end}}
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
|
@ -117,6 +129,8 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubBranchCo
|
|||
|
||||
authorStats := make(map[string]githubAuthorStats)
|
||||
|
||||
contribBranch := make(map[string]map[string]struct{})
|
||||
|
||||
overall := []githubBranchCommits{}
|
||||
|
||||
for _, orb := range config.Lists {
|
||||
|
@ -136,14 +150,12 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubBranchCo
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
if len(guff) == 0 {
|
||||
return []githubBranchCommits{}, []githubAuthorStats{}, nil
|
||||
}
|
||||
|
||||
day := ""
|
||||
newDay := ""
|
||||
ret := []githubDayCommits{}
|
||||
|
||||
thisBranch := fmt.Sprintf("%s/%s:%s", orb.Owner, orb.Repo, orb.Name)
|
||||
|
||||
for k, v := range guff {
|
||||
|
||||
if guff[k].Commit != nil {
|
||||
|
@ -221,10 +233,15 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubBranchCo
|
|||
Avatar: aa,
|
||||
URL: template.URL(u),
|
||||
})
|
||||
|
||||
if _, ok := contribBranch[al]; !ok {
|
||||
contribBranch[al] = make(map[string]struct{})
|
||||
}
|
||||
contribBranch[al][thisBranch] = struct{}{}
|
||||
}
|
||||
|
||||
overall = append(overall, githubBranchCommits{
|
||||
Name: fmt.Sprintf("%s/%s:%s", orb.Owner, orb.Repo, orb.Name),
|
||||
Name: thisBranch,
|
||||
URL: fmt.Sprintf("https://github.com/%s/%s/tree/%s", orb.Owner, orb.Repo, orb.Name),
|
||||
Days: ret,
|
||||
})
|
||||
|
@ -233,6 +250,12 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubBranchCo
|
|||
|
||||
retStats := make([]githubAuthorStats, 0, len(authorStats))
|
||||
for _, v := range authorStats {
|
||||
repos := contribBranch[v.Author]
|
||||
v.Repos = make([]string, 0, len(repos))
|
||||
for r := range repos {
|
||||
v.Repos = append(v.Repos, r)
|
||||
}
|
||||
sort.Strings(v.Repos)
|
||||
retStats = append(retStats, v)
|
||||
}
|
||||
sort.Stable(asToSort(retStats))
|
||||
|
@ -260,5 +283,18 @@ func renderCommits(payload *githubRender, c *githubConfig) error {
|
|||
payload.CommitCount += len(day.Commits)
|
||||
}
|
||||
}
|
||||
|
||||
for a := range payload.AuthorStats {
|
||||
for i := range payload.Issues {
|
||||
if payload.AuthorStats[a].Author == payload.Issues[i].Name {
|
||||
if payload.Issues[i].IsOpen {
|
||||
payload.AuthorStats[a].OpenIssues++
|
||||
} else {
|
||||
payload.AuthorStats[a].ClosedIssues++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -22,16 +22,17 @@ import (
|
|||
)
|
||||
|
||||
type githubIssue struct {
|
||||
ID int `json:"id"`
|
||||
Date string `json:"date"`
|
||||
Updated string `json:"dated"`
|
||||
Message string `json:"message"`
|
||||
URL template.URL `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Avatar string `json:"avatar"`
|
||||
Labels template.HTML `json:"labels"`
|
||||
IsOpen bool `json:"isopen"`
|
||||
Repo string `json:"repo"`
|
||||
ID int `json:"id"`
|
||||
Date string `json:"date"`
|
||||
Updated string `json:"dated"`
|
||||
Message string `json:"message"`
|
||||
URL template.URL `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Avatar string `json:"avatar"`
|
||||
Labels template.HTML `json:"labels"`
|
||||
LabelNames []string `json:"labelNames"`
|
||||
IsOpen bool `json:"isopen"`
|
||||
Repo string `json:"repo"`
|
||||
}
|
||||
|
||||
// sort issues in order that that should be presented - by date updated.
|
||||
|
@ -73,7 +74,7 @@ const (
|
|||
func init() {
|
||||
reports[tagIssuesData] = report{refreshIssues, renderIssues, `
|
||||
<div class="section-github-render">
|
||||
<h3>Issues</h3>
|
||||
<h3>Issues: {{.ClosedIssues}} closed, {{.OpenIssues}} open</h3>
|
||||
<p>
|
||||
{{if .ShowList}}
|
||||
Including issues labelled
|
||||
|
@ -97,9 +98,9 @@ func init() {
|
|||
{{end}}
|
||||
</div>
|
||||
<div class="github-commit-body">
|
||||
<div class="github-commit-title"><span class="label-name">{{$data.Message}}</span> {{$data.Labels}}</div>
|
||||
<div class="github-commit-title"><span class="label-name">{{$data.Repo}} - {{$data.Message}}</span> {{$data.Labels}}</div>
|
||||
<div class="github-commit-meta">
|
||||
#{{$data.ID}} opened on {{$data.Date}} by {{$data.Name}} in {{$data.Repo}}, last updated {{$data.Updated}}
|
||||
#{{$data.ID}} opened on {{$data.Date}} by {{$data.Name}}, last updated {{$data.Updated}}
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
@ -112,12 +113,13 @@ func init() {
|
|||
`}
|
||||
}
|
||||
|
||||
func wrapLabels(labels []gogithub.Label) string {
|
||||
l := ""
|
||||
func wrapLabels(labels []gogithub.Label) (l string, labelNames []string) {
|
||||
labelNames = make([]string, 0, len(labels))
|
||||
for _, ll := range labels {
|
||||
labelNames = append(labelNames, *ll.Name)
|
||||
l += `<span class="github-issue-label" style="background-color:#` + *ll.Color + `">` + *ll.Name + `</span> `
|
||||
}
|
||||
return l
|
||||
return l, labelNames
|
||||
}
|
||||
|
||||
func getIssues(client *gogithub.Client, config *githubConfig) ([]githubIssue, error) {
|
||||
|
@ -166,17 +168,18 @@ func getIssues(client *gogithub.Client, config *githubConfig) ([]githubIssue, er
|
|||
n = *ptr.Login
|
||||
}
|
||||
}
|
||||
l := wrapLabels(v.Labels)
|
||||
l, ln := 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,
|
||||
Name: n,
|
||||
Message: *v.Title,
|
||||
Date: v.CreatedAt.Format(issuesTimeFormat),
|
||||
Updated: v.UpdatedAt.Format(issuesTimeFormat),
|
||||
URL: template.URL(*v.HTMLURL),
|
||||
Labels: template.HTML(l),
|
||||
LabelNames: ln,
|
||||
ID: *v.Number,
|
||||
IsOpen: *v.State == "open",
|
||||
Repo: rName,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -201,12 +204,32 @@ func refreshIssues(gr *githubRender, config *githubConfig, client *gogithub.Clie
|
|||
|
||||
gr.OpenIssues = 0
|
||||
gr.ClosedIssues = 0
|
||||
sharedLabels := make(map[string][]string)
|
||||
for _, v := range gr.Issues {
|
||||
if v.IsOpen {
|
||||
gr.OpenIssues++
|
||||
} else {
|
||||
gr.ClosedIssues++
|
||||
}
|
||||
for _, lab := range v.LabelNames {
|
||||
sharedLabels[lab] = append(sharedLabels[lab], v.Repo)
|
||||
}
|
||||
}
|
||||
|
||||
gr.SharedLabels = make([]template.HTML, 0, len(sharedLabels)) // will usually be too big
|
||||
for name, repos := range sharedLabels {
|
||||
if len(repos) > 1 {
|
||||
lab := name + ":["
|
||||
for i, r := range repos {
|
||||
if i > 0 {
|
||||
lab += " "
|
||||
}
|
||||
lab += "<a href='https://github.com/" + r +
|
||||
"/issues?q=is%3Aissue+label%3A" + name + "'>" + r + "</a>"
|
||||
}
|
||||
lab += "] "
|
||||
gr.SharedLabels = append(gr.SharedLabels, template.HTML(lab))
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -31,6 +31,7 @@ type githubMilestone struct {
|
|||
CompleteMsg string `json:"completeMsg"`
|
||||
DueDate string `json:"dueDate"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
Progress uint `json:"progress"`
|
||||
}
|
||||
|
||||
// sort milestones in order that that should be presented - by date updated.
|
||||
|
@ -79,7 +80,7 @@ const (
|
|||
func init() {
|
||||
reports[tagMilestonesData] = report{refreshMilestones, renderMilestones, `
|
||||
<div class="section-github-render">
|
||||
<h3>Milestones</h3>
|
||||
<h3>Milestones: {{.ClosedMS}} closed, {{.OpenMS}} open</h3>
|
||||
<div class="github-board">
|
||||
<ul class="github-list">
|
||||
{{range $data := .Milestones}}
|
||||
|
@ -93,7 +94,9 @@ func init() {
|
|||
{{end}}
|
||||
</div>
|
||||
<div class="github-commit-body">
|
||||
<div class="github-commit-title"><span class="label-name">{{$data.Repo}} - {{$data.Name}}</span> </div>
|
||||
<div class="github-commit-title"><span class="label-name">{{$data.Repo}} - {{$data.Name}}</span>
|
||||
<progress value="{{$data.Progress}}" max="100">
|
||||
</div>
|
||||
<div class="github-commit-meta">
|
||||
{{$data.DueDate}} Last updated {{$data.UpdatedAt}}.
|
||||
{{$data.CompleteMsg}} complete {{$data.OpenIssues}} open {{$data.ClosedIssues}} closed
|
||||
|
@ -154,6 +157,8 @@ func getMilestones(client *gogithub.Client, config *githubConfig) ([]githubMiles
|
|||
up = (*v.UpdatedAt).Format(milestonesTimeFormat)
|
||||
}
|
||||
|
||||
progress := float64(*v.ClosedIssues*100) / float64(*v.OpenIssues+*v.ClosedIssues)
|
||||
|
||||
ret = append(ret, githubMilestone{
|
||||
Repo: rName,
|
||||
Name: *v.Title,
|
||||
|
@ -161,9 +166,10 @@ func getMilestones(client *gogithub.Client, config *githubConfig) ([]githubMiles
|
|||
IsOpen: *v.State == "open",
|
||||
OpenIssues: *v.OpenIssues,
|
||||
ClosedIssues: *v.ClosedIssues,
|
||||
CompleteMsg: fmt.Sprintf("%2.0f%%", float64(*v.ClosedIssues*100)/float64(*v.OpenIssues+*v.ClosedIssues)),
|
||||
CompleteMsg: fmt.Sprintf("%2.0f%%", progress),
|
||||
DueDate: dd,
|
||||
UpdatedAt: up,
|
||||
Progress: uint(progress),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ package github
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"time"
|
||||
|
||||
"github.com/documize/community/core/log"
|
||||
|
@ -29,6 +30,7 @@ type githubRender struct {
|
|||
BranchCommits []githubBranchCommits `json:"branchCommits"`
|
||||
CommitCount int `json:"commitCount"`
|
||||
Issues []githubIssue `json:"issues"`
|
||||
SharedLabels []template.HTML `json:"sharedLabels"`
|
||||
OpenIssues int `json:"openIssues"`
|
||||
ClosedIssues int `json:"closedIssues"`
|
||||
Limit int `json:"limit"`
|
||||
|
@ -79,6 +81,16 @@ type githubBranch struct {
|
|||
Color string `json:"color,omitempty"`
|
||||
}
|
||||
|
||||
type githubLabel struct {
|
||||
ID string `json:"id"`
|
||||
Owner string `json:"owner"`
|
||||
Repo string `json:"repo"`
|
||||
Name string `json:"name"`
|
||||
Included bool `json:"included"`
|
||||
URL string `json:"url"`
|
||||
Color string `json:"color,omitempty"`
|
||||
}
|
||||
|
||||
type githubConfig struct {
|
||||
Token string `json:"-"` // NOTE very important that the secret Token is not leaked to the client side, so "-"
|
||||
UserID string `json:"userId"`
|
||||
|
|
|
@ -73,7 +73,7 @@ const (
|
|||
func init() {
|
||||
reports[tagPullRequestData] = report{refreshPullReqs, renderPullReqs, `
|
||||
<div class="section-github-render">
|
||||
<h3>Pull Requests</h3>
|
||||
<h3>Pull Requests: {{.ClosedPRs}} closed, {{.OpenPRs}} open</h3>
|
||||
<div class="github-board">
|
||||
<ul class="github-list">
|
||||
{{range $data := .PullRequests}}
|
||||
|
|
|
@ -34,49 +34,23 @@ func (s branchesToSort) Less(i, j int) bool {
|
|||
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}}
|
||||
<h3>
|
||||
Activity since {{.Config.Since}}{{.Config.DateMessage}} for repository branches [
|
||||
{{range $data := .Config.Lists}}
|
||||
{{if $data.Included}}
|
||||
<a class="link" href="{{$data.URL}}">
|
||||
{{$data.Owner}}/{{$data.Repo}}:{{$data.Name}}
|
||||
</a>
|
||||
{{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>
|
||||
{{end}}
|
||||
]
|
||||
</h3>
|
||||
<h3>
|
||||
Shared Tags:
|
||||
{{range $slabel := .SharedLabels}}
|
||||
{{$slabel}}
|
||||
{{end}}
|
||||
</h3>
|
||||
</div>
|
||||
`}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue