1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-09 07:25:23 +02:00

lint, formatting and wording

This commit is contained in:
Elliott Stoneham 2016-07-01 12:16:49 +01:00
parent e2312b9632
commit 3ba1db63ad
2 changed files with 47 additions and 26 deletions

View file

@ -66,7 +66,7 @@ func authorizationCallbackURL() string {
} }
// Command to run the various functions required... // Command to run the various functions required...
func (t *Provider) Command(w http.ResponseWriter, r *http.Request) { func (p *Provider) Command(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query() query := r.URL.Query()
method := query.Get("method") method := query.Get("method")
@ -117,13 +117,13 @@ func (t *Provider) Command(w http.ResponseWriter, r *http.Request) {
return return
} }
client := t.githubClient(config) client := p.githubClient(config)
switch method { switch method {
case "commits_data": case tagCommitsData:
render, err := t.getCommits(client, config) render, err := p.getCommits(client, config)
if err != nil { if err != nil {
log.Error("github getCommits:", err) log.Error("github getCommits:", err)
provider.WriteError(w, "github", err) provider.WriteError(w, "github", err)
@ -132,9 +132,9 @@ func (t *Provider) Command(w http.ResponseWriter, r *http.Request) {
provider.WriteJSON(w, render) provider.WriteJSON(w, render)
case "issues_data": case tagIssuesData:
render, err := t.getIssues(client, config) render, err := p.getIssues(client, config)
if err != nil { if err != nil {
log.Error("github getIssues:", err) log.Error("github getIssues:", err)
provider.WriteError(w, "github", err) provider.WriteError(w, "github", err)
@ -399,6 +399,14 @@ func (*Provider) getIssueNum(client *gogithub.Client, config githubConfig) ([]gi
} }
*/ */
func wrapLabels(labels []gogithub.Label) string {
l := ""
for _, ll := range labels {
l += `<span class="github-issue-label" style="background-color:#` + *ll.Color + `">` + *ll.Name + `</span> `
}
return l
}
func (*Provider) getIssues(client *gogithub.Client, config githubConfig) ([]githubIssue, error) { func (*Provider) getIssues(client *gogithub.Client, config githubConfig) ([]githubIssue, error) {
ret := []githubIssue{} ret := []githubIssue{}
@ -424,10 +432,7 @@ func (*Provider) getIssues(client *gogithub.Client, config githubConfig) ([]gith
n = *p.Login n = *p.Login
} }
} }
l := "" l := wrapLabels(issue.Labels)
for _, ll := range issue.Labels {
l += `<span class="github-issue-label" style="background-color:#` + *ll.Color + `">` + *ll.Name + `</span> `
}
ret = append(ret, githubIssue{ ret = append(ret, githubIssue{
Name: n, Name: n,
Message: *issue.Title, Message: *issue.Title,
@ -472,10 +477,7 @@ func (*Provider) getIssues(client *gogithub.Client, config githubConfig) ([]gith
n = *ptr.Login n = *ptr.Login
} }
} }
l := "" l := wrapLabels(v.Labels)
for _, ll := range v.Labels {
l += `<span class="github-issue-label" style="background-color:#` + *ll.Color + `">` + *ll.Name + `</span> `
}
ret = append(ret, githubIssue{ ret = append(ret, githubIssue{
Name: n, Name: n,
Message: *v.Title, Message: *v.Title,
@ -571,7 +573,7 @@ func (*Provider) getCommits(client *gogithub.Client, config githubConfig) ([]git
} }
// Refresh ... gets the latest version // Refresh ... gets the latest version
func (t *Provider) Refresh(configJSON, data string) string { func (p *Provider) Refresh(configJSON, data string) string {
var c = githubConfig{} var c = githubConfig{}
err := json.Unmarshal([]byte(configJSON), &c) err := json.Unmarshal([]byte(configJSON), &c)
@ -597,8 +599,8 @@ func (t *Provider) Refresh(configJSON, data string) string {
} }
return string(j)*/ return string(j)*/
case "issues_data": case tagIssuesData:
refreshed, err := t.getIssues(t.githubClient(c), c) refreshed, err := p.getIssues(p.githubClient(c), c)
if err != nil { if err != nil {
log.Error("unable to get github issues", err) log.Error("unable to get github issues", err)
return data return data
@ -610,8 +612,8 @@ func (t *Provider) Refresh(configJSON, data string) string {
} }
return string(j) return string(j)
default: // to handle legacy data, this handles commits case tagCommitsData:
refreshed, err := t.getCommits(t.githubClient(c), c) refreshed, err := p.getCommits(p.githubClient(c), c)
if err != nil { if err != nil {
log.Error("unable to get github commits", err) log.Error("unable to get github commits", err)
return data return data
@ -622,6 +624,11 @@ func (t *Provider) Refresh(configJSON, data string) string {
return data return data
} }
return string(j) return string(j)
default:
msg := "unknown data format: " + c.ReportInfo.ID
log.ErrorString(msg)
return "internal configuration error, " + msg
} }
} }
@ -675,7 +682,7 @@ func (p *Provider) Render(config, data string) string {
} }
payload.IssueNumActivity = raw */ payload.IssueNumActivity = raw */
case "issues_data": case tagIssuesData:
raw := []githubIssue{} raw := []githubIssue{}
if len(data) > 0 { if len(data) > 0 {
@ -701,7 +708,7 @@ func (p *Provider) Render(config, data string) string {
} }
} }
default: // to handle legacy data, this handles commits case tagCommitsData:
raw := []githubBranchCommits{} raw := []githubBranchCommits{}
err = json.Unmarshal([]byte(data), &raw) err = json.Unmarshal([]byte(data), &raw)
@ -709,11 +716,17 @@ func (p *Provider) Render(config, data string) string {
log.Error("unable to unmarshall github commit data", err) log.Error("unable to unmarshall github commit data", err)
return "Documize internal github json umarshall data error: " + err.Error() + "<BR>" + data return "Documize internal github json umarshall data error: " + err.Error() + "<BR>" + data
} }
c.ReportInfo.ID = "commits_data" c.ReportInfo.ID = tagCommitsData
payload.BranchCommits = raw payload.BranchCommits = raw
for _, list := range raw { for _, list := range raw {
payload.CommitCount += len(list.Commits) payload.CommitCount += len(list.Commits)
} }
default:
msg := "unknown data format: " + c.ReportInfo.ID
log.ErrorString(msg)
return "internal configuration error, " + msg
} }
t := template.New("github") t := template.New("github")

View file

@ -19,6 +19,9 @@ import (
"github.com/documize/community/wordsmith/log" "github.com/documize/community/wordsmith/log"
) )
const tagIssuesData = "issues_data"
const tagCommitsData = "commits_data"
type githubRender struct { type githubRender struct {
Config githubConfig Config githubConfig
Repo githubRepo Repo githubRepo
@ -35,7 +38,7 @@ type githubRender struct {
} }
var renderTemplates = map[string]string{ var renderTemplates = map[string]string{
"commits_data": ` tagCommitsData: `
<div class="section-github-render"> <div class="section-github-render">
<p> <p>
There are {{ .CommitCount }} commits for branch <a href="{{.Config.BranchURL}}">{{.Config.Branch}}</a> of repository <a href="{{ .Repo.URL }}">{{.Repo.Name}}.</a> There are {{ .CommitCount }} commits for branch <a href="{{.Config.BranchURL}}">{{.Config.Branch}}</a> of repository <a href="{{ .Repo.URL }}">{{.Repo.Name}}.</a>
@ -66,15 +69,20 @@ var renderTemplates = map[string]string{
</div> </div>
</div> </div>
`, `,
"issues_data": ` tagIssuesData: `
<div class="section-github-render"> <div class="section-github-render">
<p> <p>
The open issues for repository <a href="{{ .Repo.URL }}/issues">{{.Repo.Name}}</a> {{if .ShowIssueNumbers}}
Show Selected Issues
{{else}}
{{ .Config.IssueState.Name }}
{{end}}
for repository <a href="{{ .Repo.URL }}/issues">{{.Repo.Name}}</a>
{{if .ShowList}} {{if .ShowList}}
with label(s) with label(s)
{{range $label := .List}} {{range $label := .List}}
{{if $label.Included}} {{if $label.Included}}
<span style="background-color:#{{$label.Color}}">{{$label.Name}}</span> <span class="github-issue-label" style="background-color:#{{$label.Color}}">{{$label.Name}}</span>
{{end}} {{end}}
{{end}} {{end}}
{{end}}; {{end}};