mirror of
https://github.com/documize/community.git
synced 2025-07-20 21:59:42 +02:00
remove redundant code
This commit is contained in:
parent
cf6410cfe8
commit
87be56bc4b
9 changed files with 39 additions and 105 deletions
|
@ -21,11 +21,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
authenticated: false,
|
||||
config: {},
|
||||
owners: null,
|
||||
repos: null,
|
||||
noRepos: false,
|
||||
showCommits: false,
|
||||
showIssueNum: false,
|
||||
showLabels: false,
|
||||
|
||||
didReceiveAttrs() {
|
||||
let self = this;
|
||||
|
@ -41,16 +36,9 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
callbackUrl: cfg.authorizationCallbackURL,
|
||||
owner: null,
|
||||
owner_name: "",
|
||||
repo: null,
|
||||
repo_name: "",
|
||||
report: null,
|
||||
lists: [],
|
||||
branch: "",
|
||||
branchURL: "",
|
||||
branchSince: "",
|
||||
branchLines: "30",
|
||||
state: null,
|
||||
issues: "",
|
||||
branchLines: "100",
|
||||
userId: "",
|
||||
pageId: page.get('id'),
|
||||
};
|
||||
|
@ -58,13 +46,8 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
try {
|
||||
let metaConfig = JSON.parse(self.get('meta.config'));
|
||||
config.owner = metaConfig.owner;
|
||||
config.repo = metaConfig.repo;
|
||||
config.report = metaConfig.report;
|
||||
config.lists = metaConfig.lists;
|
||||
config.branchSince = metaConfig.branchSince;
|
||||
config.branchLines = metaConfig.branchLines;
|
||||
config.state = metaConfig.state;
|
||||
config.issues = metaConfig.issues;
|
||||
config.userId = metaConfig.userId;
|
||||
config.pageId = metaConfig.pageId;
|
||||
} catch (e) {}
|
||||
|
@ -175,7 +158,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
}, function (error) { //jshint ignore: line
|
||||
self.set('busy', false);
|
||||
self.set('authenticated', false);
|
||||
self.showNotification("Unable to fetch repository branches");
|
||||
self.showNotification("Unable to fetch repositories");
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
|
@ -229,7 +212,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
onOwnerChange(thisOwner) {
|
||||
this.set('isDirty', true);
|
||||
this.set('config.owner', thisOwner);
|
||||
this.set('config.repos', []);
|
||||
this.set('config.lists', []);
|
||||
this.getOwnerLists();
|
||||
},
|
||||
|
@ -245,15 +227,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
onAction(title) {
|
||||
this.set('busy', true);
|
||||
|
||||
let thisLines = this.get('config.branchLines');
|
||||
if (is.undefined(thisLines) || thisLines === "") {
|
||||
this.set('config.branchLines', 30);
|
||||
} else if (thisLines < 1) {
|
||||
this.set('config.branchLines', 1);
|
||||
} else if (thisLines > 100) {
|
||||
this.set('config.branchLines', 100);
|
||||
}
|
||||
|
||||
let self = this;
|
||||
let page = this.get('page');
|
||||
let meta = this.get('meta');
|
||||
|
@ -262,8 +235,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
meta.set('config', JSON.stringify(this.get('config')));
|
||||
meta.set('externalSource', true);
|
||||
|
||||
let thisReport = this.get('config.report');
|
||||
this.get('sectionService').fetch(page, thisReport.id, this.get('config'))
|
||||
this.get('sectionService').fetch(page, 'content', this.get('config'))
|
||||
.then(function (response) {
|
||||
meta.set('rawBody', JSON.stringify(response));
|
||||
self.set('busy', false);
|
||||
|
|
|
@ -15,16 +15,10 @@
|
|||
<div class="tip">Select organization or username whose repositories you want to show</div>
|
||||
{{ui-select id="owners-dropdown" content=owners action=(action 'onOwnerChange') optionValuePath="id" optionLabelPath="name" selection=config.owner}}
|
||||
</div>
|
||||
{{#if noRepos}}
|
||||
<div class="input-control">
|
||||
<div class="color-error">You have no repositories.</div>
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="input-control">
|
||||
<label>Show items since (default 7 days ago)</label>
|
||||
{{input id="branch-since" value=config.branchSince type="text" }}<br>
|
||||
</div>
|
||||
{{/if}}
|
||||
<div class="input-control">
|
||||
<label>Show items since (default 7 days ago)</label>
|
||||
{{input id="branch-since" value=config.branchSince type="text" }}<br>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -201,7 +201,7 @@ func renderMilestones(payload *githubRender, c *githubConfig) error {
|
|||
}
|
||||
}
|
||||
|
||||
sort.Stable(milestonesToSort(payload.Milestones))
|
||||
sort.Sort(milestonesToSort(payload.Milestones))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue