1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-22 14:49:42 +02:00

Color common labels

This commit is contained in:
Elliott Stoneham 2016-09-05 09:45:02 +01:00
parent 8183af4bb2
commit d50aa23f34
2 changed files with 43 additions and 32 deletions

View file

@ -22,24 +22,26 @@ import (
) )
type githubIssue struct { type githubIssue struct {
ID int `json:"id"` ID int `json:"id"`
Date string `json:"date"` Date string `json:"date"`
Updated string `json:"dated"` Updated string `json:"dated"`
Message string `json:"message"` Message string `json:"message"`
URL template.URL `json:"url"` URL template.URL `json:"url"`
Name string `json:"name"` Name string `json:"name"`
Avatar string `json:"avatar"` Avatar string `json:"avatar"`
Labels template.HTML `json:"labels"` Labels template.HTML `json:"labels"`
LabelNames []string `json:"labelNames"` LabelNames []string `json:"labelNames"`
IsOpen bool `json:"isopen"` LabelColors []string `json:"labelColors"`
Repo string `json:"repo"` IsOpen bool `json:"isopen"`
Private bool `json:"private"` Repo string `json:"repo"`
Milestone string `json:"milestone"` Private bool `json:"private"`
Milestone string `json:"milestone"`
} }
type githubSharedLabel struct { type githubSharedLabel struct {
Name string `json:"name"` Name string `json:"name"`
Count int `json:"count"` Count int `json:"count"`
Color string `json:"color"`
Repos template.HTML `json:"Repos"` Repos template.HTML `json:"Repos"`
} }
@ -89,13 +91,15 @@ func init() {
reports[tagIssuesData] = report{refreshIssues, renderIssues, issuesTemplate} reports[tagIssuesData] = report{refreshIssues, renderIssues, issuesTemplate}
} }
func wrapLabels(labels []gogithub.Label) (l string, labelNames []string) { func wrapLabels(labels []gogithub.Label) (l string, labelNames []string, labelColors []string) {
labelNames = make([]string, 0, len(labels)) labelNames = make([]string, 0, len(labels))
labelColors = make([]string, 0, len(labels))
for _, ll := range labels { for _, ll := range labels {
labelNames = append(labelNames, *ll.Name) labelNames = append(labelNames, *ll.Name)
labelColors = append(labelColors, *ll.Color)
l += `<span class="github-issue-label" style="background-color:#` + *ll.Color + `">` + *ll.Name + `</span> ` l += `<span class="github-issue-label" style="background-color:#` + *ll.Color + `">` + *ll.Name + `</span> `
} }
return l, labelNames return l, labelNames, labelColors
} }
func getIssues(client *gogithub.Client, config *githubConfig) ([]githubIssue, error) { func getIssues(client *gogithub.Client, config *githubConfig) ([]githubIssue, error) {
@ -144,21 +148,22 @@ func getIssues(client *gogithub.Client, config *githubConfig) ([]githubIssue, er
ms = *v.Milestone.Title ms = *v.Milestone.Title
} }
} }
l, ln := wrapLabels(v.Labels) l, ln, lc := wrapLabels(v.Labels)
ret = append(ret, githubIssue{ ret = append(ret, githubIssue{
Name: n, Name: n,
Avatar: av, Avatar: av,
Message: *v.Title, Message: *v.Title,
Date: v.CreatedAt.Format(issuesTimeFormat), Date: v.CreatedAt.Format(issuesTimeFormat),
Updated: v.UpdatedAt.Format(issuesTimeFormat), Updated: v.UpdatedAt.Format(issuesTimeFormat),
URL: template.URL(*v.HTMLURL), URL: template.URL(*v.HTMLURL),
Labels: template.HTML(l), Labels: template.HTML(l),
LabelNames: ln, LabelNames: ln,
ID: *v.Number, LabelColors: lc,
IsOpen: *v.State == "open", ID: *v.Number,
Repo: repoName(rName), IsOpen: *v.State == "open",
Private: orb.Private, Repo: repoName(rName),
Milestone: ms, Private: orb.Private,
Milestone: ms,
}) })
} }
} }
@ -184,14 +189,18 @@ func refreshIssues(gr *githubRender, config *githubConfig, client *gogithub.Clie
gr.OpenIssues = 0 gr.OpenIssues = 0
gr.ClosedIssues = 0 gr.ClosedIssues = 0
sharedLabels := make(map[string][]string) sharedLabels := make(map[string][]string)
sharedLabelColors := make(map[string]string)
for _, v := range gr.Issues { for _, v := range gr.Issues {
if v.IsOpen { if v.IsOpen {
gr.OpenIssues++ gr.OpenIssues++
} else { } else {
gr.ClosedIssues++ gr.ClosedIssues++
} }
for _, lab := range v.LabelNames { for i, lab := range v.LabelNames {
sharedLabels[lab] = append(sharedLabels[lab], v.Repo) sharedLabels[lab] = append(sharedLabels[lab], v.Repo)
if _, exists := sharedLabelColors[lab]; !exists { // use the first one we see
sharedLabelColors[lab] = v.LabelColors[i]
}
} }
} }
gr.HasIssues = (gr.OpenIssues + gr.ClosedIssues) > 0 gr.HasIssues = (gr.OpenIssues + gr.ClosedIssues) > 0
@ -199,7 +208,7 @@ func refreshIssues(gr *githubRender, config *githubConfig, client *gogithub.Clie
gr.SharedLabels = make([]githubSharedLabel, 0, len(sharedLabels)) // will usually be too big gr.SharedLabels = make([]githubSharedLabel, 0, len(sharedLabels)) // will usually be too big
for name, repos := range sharedLabels { for name, repos := range sharedLabels {
if len(repos) > 1 { if len(repos) > 1 {
thisLab := githubSharedLabel{Name: name, Count: len(repos)} thisLab := githubSharedLabel{Name: name, Count: len(repos), Color: sharedLabelColors[name]}
show := "" show := ""
for i, r := range repos { for i, r := range repos {
if i > 0 { if i > 0 {

View file

@ -32,7 +32,9 @@ const summaryTemplate = `
<tbody class="github"> <tbody class="github">
{{range $slabel := .SharedLabels}} {{range $slabel := .SharedLabels}}
<tr> <tr>
<td style="width:100%;">{{$slabel.Name}} ({{$slabel.Count}}) in {{$slabel.Repos}}</td> <td style="width:100%;">
<span style="background-color:#{{$slabel.Color}}">{{$slabel.Name}} ({{$slabel.Count}})</span> in {{$slabel.Repos}}
</td>
</tr> </tr>
{{end}} {{end}}
</tbody> </tbody>