1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-22 06:39:43 +02:00

remove redundant code

This commit is contained in:
Elliott Stoneham 2016-08-26 14:14:00 +01:00
parent cf6410cfe8
commit 87be56bc4b
9 changed files with 39 additions and 105 deletions

View file

@ -258,7 +258,7 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubCommit,
sort.Strings(v.Repos)
retStats = append(retStats, v)
}
sort.Stable(asToSort(retStats))
sort.Sort(asToSort(retStats))
return overall, retStats, nil
@ -302,7 +302,7 @@ func renderCommits(payload *githubRender, c *githubConfig) error {
}
}
payload.HasAuthorStats = len(payload.AuthorStats) > 0
sort.Stable(asToSort(payload.AuthorStats))
sort.Sort(asToSort(payload.AuthorStats))
return nil
}

View file

@ -18,9 +18,12 @@ import (
"html/template"
"io/ioutil"
"net/http"
"strings"
"github.com/documize/community/core/log"
"github.com/documize/community/core/section/provider"
gogithub "github.com/google/go-github/github"
)
// TODO find a smaller image than the one below
@ -157,13 +160,9 @@ func (p *Provider) Refresh(ctx *provider.Context, configJSON, data string) strin
c.Clean()
c.Token = ctx.GetSecrets("token")
var gr = githubRender{}
client := p.githubClient(&c)
for _, rep := range reports {
log.IfErr(rep.refresh(&gr, &c, client))
}
byts, err := json.Marshal(&gr)
byts, err := json.Marshal(refreshReportData(&c, client))
if err != nil {
log.Error("unable to marshall github data", err)
return "internal configuration error '" + err.Error() + "'"
@ -173,6 +172,14 @@ func (p *Provider) Refresh(ctx *provider.Context, configJSON, data string) strin
}
func refreshReportData(c *githubConfig, client *gogithub.Client) *githubRender {
var gr = githubRender{}
for _, rep := range reports {
log.IfErr(rep.refresh(&gr, c, client))
}
return &gr
}
// Render ... just returns the data given, suitably formatted
func (p *Provider) Render(ctx *provider.Context, config, data string) string {
var err error
@ -190,15 +197,20 @@ func (p *Provider) Render(ctx *provider.Context, config, data string) string {
c.Clean()
c.Token = ctx.GetSecrets("token")
err = json.Unmarshal([]byte(data), &payload)
data = strings.TrimSpace(data)
if len(data) == 0 {
// TODO review why this error occurs & if it should be reported - seems to occur for new sections
// log.ErrorString(fmt.Sprintf("Rendered empty github JSON payload as '' for owner %s repos %#v", c.Owner, c.Lists))
return ""
}
err = json.Unmarshal([]byte(data), &payload)
if err != nil {
log.Error("unable to unmarshall github data", err)
return "Please delete and recreate this Github section."
}
payload.Config = c
payload.Repo = c.RepoInfo
payload.Limit = c.BranchLines
payload.List = c.Lists

View file

@ -168,7 +168,7 @@ func getIssues(client *gogithub.Client, config *githubConfig) ([]githubIssue, er
}
sort.Stable(issuesToSort(ret))
sort.Sort(issuesToSort(ret))
return ret, nil
@ -212,7 +212,7 @@ func refreshIssues(gr *githubRender, config *githubConfig, client *gogithub.Clie
gr.SharedLabels = append(gr.SharedLabels, thisLab)
}
}
sort.Stable(sharedLabelsSort(gr.SharedLabels))
sort.Sort(sharedLabelsSort(gr.SharedLabels))
gr.HasSharedLabels = len(gr.SharedLabels) > 0
return nil

View file

@ -52,7 +52,6 @@ func listFailed(method string, config githubConfig, client *gogithub.Client, w h
provider.WriteJSON(w, owners)
case "orgrepos":
var render []githubBranch
@ -96,6 +95,9 @@ func listFailed(method string, config githubConfig, client *gogithub.Client, w h
provider.WriteJSON(w, render)
case "content":
provider.WriteJSON(w, refreshReportData(&config, client))
default:
return true // failed to get a list

View file

@ -201,7 +201,7 @@ func renderMilestones(payload *githubRender, c *githubConfig) error {
}
}
sort.Stable(milestonesToSort(payload.Milestones))
sort.Sort(milestonesToSort(payload.Milestones))
return nil
}

View file

@ -23,7 +23,6 @@ import (
type githubRender struct {
Config githubConfig `json:"config"`
Repo githubRepo `json:"repo"`
List []githubBranch `json:"list"`
ShowList bool `json:"showList"`
ShowIssueNumbers bool `json:"showIssueNumbers"`
@ -55,26 +54,11 @@ type report struct {
var reports = make(map[string]report)
type githubReport struct {
ID string `json:"id"`
Name string `json:"name"`
}
type githubOwner struct {
ID string `json:"id"`
Name string `json:"name"`
}
type githubRepo struct {
ID string `json:"id"`
Name string `json:"name"`
Included bool `json:"included"`
Owner string `json:"owner"`
Repo string `json:"repo"`
Private bool `json:"private"`
URL string `json:"url"`
}
type githubBranch struct {
ID string `json:"id"`
Owner string `json:"owner"`
@ -102,35 +86,20 @@ type githubConfig struct {
UserID string `json:"userId"`
PageID string `json:"pageId"`
Owner string `json:"owner_name"`
Repo string `json:"repo_name"`
Branch string `json:"branch"`
BranchURL string `json:"branchURL"`
BranchSince string `json:"branchSince,omitempty"`
SincePtr *time.Time `json:"-"`
Since string `json:"since"`
Since string `json:"-"`
BranchLines int `json:"branchLines,omitempty,string"`
OwnerInfo githubOwner `json:"owner"`
RepoInfo githubRepo `json:"repo"`
ReportInfo githubReport `json:"report"`
ClientID string `json:"clientId"`
CallbackURL string `json:"callbackUrl"`
Lists []githubBranch `json:"lists,omitempty"`
IssueState githubReport `json:"state,omitempty"`
IssuesText string `json:"issues,omitempty"`
ReportOrder []string `json:"reportOrder,omitempty"`
DateMessage string `json:"dateMessage,omitempty"`
ReportOrder []string `json:"-"`
DateMessage string `json:"-"`
}
func (c *githubConfig) Clean() {
c.Owner = c.OwnerInfo.Name
c.Repo = c.RepoInfo.Repo
for _, l := range c.Lists {
if l.Included {
c.Branch = l.Name
c.BranchURL = l.URL
break
}
}
if len(c.BranchSince) >= len("yyyy/mm/dd hh:ss") {
var since time.Time
tt := []byte("yyyy-mm-ddThh:mm:00Z")
@ -154,9 +123,9 @@ func (c *githubConfig) Clean() {
c.Since = (*c.SincePtr).Format(issuesTimeFormat)
c.ReportOrder = []string{tagSummaryData, tagMilestonesData, tagIssuesData, tagCommitsData}
c.BranchLines = 100 // overide js default of 30 with maximum allowable in one call
c.BranchLines = 100 // overide any existing value with maximum allowable in one call
sort.Stable(branchesToSort(c.Lists)) // get the configured branches in a sensible order for printing
sort.Sort(branchesToSort(c.Lists)) // get the configured branches in a sensible order for display
lastItem := 0
for i := range c.Lists {

View file

@ -13,21 +13,6 @@ package github
import "sort"
// sort repos in order that that should be presented.
type reposToSort []githubRepo
func (s reposToSort) Len() int { return len(s) }
func (s reposToSort) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s reposToSort) Less(i, j int) bool {
return s[i].Name < s[j].Name
}
func sortRepos(in []githubRepo) []githubRepo {
sts := reposToSort(in)
sort.Sort(sts)
return []githubRepo(sts)
}
// sort owners in order that that should be presented.
type ownersToSort []githubOwner