mirror of
https://github.com/documize/community.git
synced 2025-08-08 15:05:28 +02:00
add repo open issues report
This commit is contained in:
parent
8649a47345
commit
6ca92a0dee
4 changed files with 270 additions and 78 deletions
|
@ -21,9 +21,9 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
authenticated: false,
|
||||
config: {},
|
||||
owners: null,
|
||||
noOwners: false, // TODO required?
|
||||
repos: null,
|
||||
noRepos: false,
|
||||
showCommits: false,
|
||||
|
||||
didReceiveAttrs() {
|
||||
let self = this;
|
||||
|
@ -38,11 +38,12 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
clientId: cfg.clientID,
|
||||
callbackUrl: cfg.authorizationCallbackURL,
|
||||
token: "",
|
||||
repo: null,
|
||||
lists: [],
|
||||
owner: null,
|
||||
owner_name: "",
|
||||
repo: null,
|
||||
repo_name: "",
|
||||
report: null,
|
||||
lists: [],
|
||||
branch: "",
|
||||
branchURL: "",
|
||||
branchSince: "",
|
||||
|
@ -53,6 +54,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
let metaConfig = JSON.parse(self.get('meta.config'));
|
||||
config.owner = metaConfig.owner;
|
||||
config.repo = metaConfig.repo;
|
||||
config.report = metaConfig.report;
|
||||
config.lists = metaConfig.lists;
|
||||
} catch (e) {}
|
||||
|
||||
|
@ -93,13 +95,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
|
||||
console.log("owner", thisOwner);
|
||||
|
||||
if (is.null(owners) || is.undefined(owners) || owners.length === 0) {
|
||||
this.set('noOwners', true);
|
||||
return;
|
||||
}
|
||||
|
||||
this.set('noOwners', false);
|
||||
|
||||
if (is.null(thisOwner) || is.undefined(thisOwner)) {
|
||||
if (owners.length) {
|
||||
thisOwner = owners[0];
|
||||
|
@ -109,6 +104,8 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
this.set('config.owner', owners.findBy('id', thisOwner.id));
|
||||
}
|
||||
|
||||
this.set('owner', thisOwner);
|
||||
|
||||
this.get('sectionService').fetch(page, "repos", self.get('config'))
|
||||
.then(function(lists) {
|
||||
self.set('busy', false);
|
||||
|
@ -125,10 +122,8 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
getRepoLists() {
|
||||
this.set('busy', true);
|
||||
|
||||
let self = this;
|
||||
let repos = this.get('repos');
|
||||
let thisRepo = this.get('config.repo');
|
||||
let page = this.get('page');
|
||||
|
||||
console.log("repo", thisRepo);
|
||||
|
||||
|
@ -139,7 +134,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
|
||||
this.set('noRepos', false);
|
||||
|
||||
if (is.null(thisRepo) || is.undefined(thisRepo)) {
|
||||
if (is.null(thisRepo) || is.undefined(thisRepo) || thisRepo.owner !== this.get('config.owner').name) {
|
||||
if (repos.length) {
|
||||
thisRepo = repos[0];
|
||||
this.set('config.repo', thisRepo);
|
||||
|
@ -148,21 +143,88 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
this.set('config.repo', repos.findBy('id', thisRepo.id));
|
||||
}
|
||||
|
||||
this.get('sectionService').fetch(page, "lists", self.get('config'))
|
||||
this.set('repo', thisRepo);
|
||||
|
||||
this.getReportLists();
|
||||
},
|
||||
|
||||
|
||||
getReportLists() {
|
||||
let reports = [];
|
||||
reports[0] = {
|
||||
id: "commits", // used as method for fetching Go data
|
||||
name: "Commits on a branch"
|
||||
};
|
||||
reports[1] = {
|
||||
id: "open_issues", // used as method for fetching Go data
|
||||
name: "Open Issues"
|
||||
};
|
||||
|
||||
this.set("reports", reports);
|
||||
|
||||
let thisReport = this.get('config.report');
|
||||
|
||||
console.log("report", thisReport);
|
||||
|
||||
if (is.null(thisReport) || is.undefined(thisReport)) {
|
||||
thisReport = reports[0];
|
||||
this.set('config.report', thisReport);
|
||||
} else {
|
||||
this.set('config.report', reports.findBy('id', thisReport.id));
|
||||
}
|
||||
|
||||
this.set('report', thisReport);
|
||||
|
||||
this.renderSwitch(thisReport);
|
||||
|
||||
},
|
||||
|
||||
renderSwitch(thisReport) {
|
||||
this.set('showCommits', false);
|
||||
switch (thisReport.id) {
|
||||
case 'commits':
|
||||
this.set('showCommits', true);
|
||||
this.getBranchLists();
|
||||
break;
|
||||
case "open_issues":
|
||||
// nothing to show
|
||||
this.set('busy', false);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
getBranchLists() {
|
||||
this.set('busy', true);
|
||||
|
||||
console.log("branches");
|
||||
|
||||
let self = this;
|
||||
let page = this.get('page');
|
||||
|
||||
this.get('sectionService').fetch(page, "branches", self.get('config'))
|
||||
.then(function(lists) {
|
||||
let savedLists = self.get('config.lists');
|
||||
if (savedLists === null) {
|
||||
savedLists = [];
|
||||
}
|
||||
|
||||
lists.forEach(function(list) {
|
||||
let saved = savedLists.findBy("id", list.id);
|
||||
let included = false;
|
||||
if (is.not.undefined(saved)) {
|
||||
included = saved.included;
|
||||
if (lists.length > 0) {
|
||||
let noIncluded = true;
|
||||
|
||||
lists.forEach(function(list) {
|
||||
let saved = savedLists.findBy("id", list.id);
|
||||
let included = false;
|
||||
if (is.not.undefined(saved)) {
|
||||
included = saved.included;
|
||||
noIncluded = false;
|
||||
}
|
||||
list.included = included;
|
||||
});
|
||||
|
||||
if (noIncluded) {
|
||||
lists[0].included = true; // make the first entry the default
|
||||
}
|
||||
list.included = included;
|
||||
});
|
||||
}
|
||||
|
||||
self.set('config.lists', lists);
|
||||
self.set('busy', false);
|
||||
|
@ -226,10 +288,10 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
},
|
||||
|
||||
onOwnerChange(thisOwner) {
|
||||
console.log(thisOwner);
|
||||
this.set('isDirty', true);
|
||||
this.set('config.owner', thisOwner);
|
||||
this.set('config.repos', []);
|
||||
this.set('config.lists', []);
|
||||
this.getOwnerLists();
|
||||
},
|
||||
|
||||
|
@ -240,6 +302,12 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
this.getRepoLists();
|
||||
},
|
||||
|
||||
onReportChange(thisReport) {
|
||||
this.set('isDirty', true);
|
||||
this.set('config.report', thisReport);
|
||||
this.getReportLists();
|
||||
},
|
||||
|
||||
onCancel() {
|
||||
this.attrs.onCancel();
|
||||
},
|
||||
|
@ -255,7 +323,8 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
meta.set('config', JSON.stringify(this.get('config')));
|
||||
meta.set('externalSource', true);
|
||||
|
||||
this.get('sectionService').fetch(page, "commits", this.get('config'))
|
||||
let thisReport = this.get('config.report');
|
||||
this.get('sectionService').fetch(page, thisReport.id, this.get('config'))
|
||||
.then(function(response) {
|
||||
meta.set('rawBody', JSON.stringify(response));
|
||||
self.set('busy', false);
|
||||
|
|
|
@ -30,22 +30,29 @@
|
|||
{{ui-select id="repos-dropdown" content=repos action=(action 'onRepoChange') optionValuePath="id" optionLabelPath="name" selection=config.repo}}
|
||||
</div>
|
||||
<div class="input-control">
|
||||
<label>Branches</label>
|
||||
<div class="tip">Select branch</div>
|
||||
<div class="github-board">
|
||||
{{#each config.lists as |list|}}
|
||||
<div class="github-list" {{action 'onListCheckbox' list.id}}>
|
||||
{{#if list.included}}
|
||||
<i class="material-icons widget-checkbox checkbox-gray github-list-checkbox">check_box</i>
|
||||
{{else}}
|
||||
<i class="material-icons widget-checkbox checkbox-gray github-list-checkbox">check_box_outline_blank</i>
|
||||
{{/if}}
|
||||
<span class="github-list-title">{{list.name}}</span>
|
||||
</div>
|
||||
{{/each}}
|
||||
<div class="clearfix" />
|
||||
</div>
|
||||
<label>Report</label>
|
||||
<div class="tip">Select report type</div>
|
||||
{{ui-select id="report-dropdown" content=reports action=(action 'onReportChange') optionValuePath="id" optionLabelPath="name" selection=config.report}}
|
||||
</div>
|
||||
{{#if showCommits}}
|
||||
<div class="input-control">
|
||||
<label>Branches</label>
|
||||
<div class="tip">Select branch</div>
|
||||
<div class="github-board">
|
||||
{{#each config.lists as |list|}}
|
||||
<div class="github-list" {{action 'onListCheckbox' list.id}}>
|
||||
{{#if list.included}}
|
||||
<i class="material-icons widget-checkbox checkbox-gray github-list-checkbox">check_box</i>
|
||||
{{else}}
|
||||
<i class="material-icons widget-checkbox checkbox-gray github-list-checkbox">check_box_outline_blank</i>
|
||||
{{/if}}
|
||||
<span class="github-list-title">{{list.name}}</span>
|
||||
</div>
|
||||
{{/each}}
|
||||
<div class="clearfix" />
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -129,6 +129,17 @@ func (t *Provider) Command(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
provider.WriteJSON(w, render)
|
||||
|
||||
case "open_issues":
|
||||
|
||||
render, err := t.getOpenIssues(client, config)
|
||||
if err != nil {
|
||||
log.Error("github getOpenIssues:", err)
|
||||
provider.WriteError(w, "github", err)
|
||||
return
|
||||
}
|
||||
|
||||
provider.WriteJSON(w, render)
|
||||
|
||||
case "owners":
|
||||
|
||||
me, _, err := client.Users.Get("")
|
||||
|
@ -205,7 +216,7 @@ func (t *Provider) Command(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
provider.WriteJSON(w, render)
|
||||
|
||||
case "lists":
|
||||
case "branches":
|
||||
if config.Owner == "" || config.Repo == "" {
|
||||
provider.WriteJSON(w, []githubBranch{}) // we have nothing to return
|
||||
return
|
||||
|
@ -244,6 +255,41 @@ func (*Provider) githubClient(config githubConfig) *gogithub.Client {
|
|||
return gogithub.NewClient(tc)
|
||||
}
|
||||
|
||||
func (*Provider) getOpenIssues(client *gogithub.Client, config githubConfig) ([]githubIssue, error) {
|
||||
|
||||
guff, _, err := client.Issues.ListByRepo(config.Owner, config.Repo, nil)
|
||||
|
||||
ret := []githubIssue{}
|
||||
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
for _, v := range guff {
|
||||
n := ""
|
||||
a := ""
|
||||
p := v.User
|
||||
if p != nil {
|
||||
if p.Name != nil {
|
||||
n = *p.Name
|
||||
}
|
||||
if p.AvatarURL != nil {
|
||||
a = *p.AvatarURL
|
||||
}
|
||||
}
|
||||
ret = append(ret, githubIssue{
|
||||
Name: n,
|
||||
Message: *v.Title,
|
||||
Date: v.UpdatedAt.Format("January 2 2006, 15:04"),
|
||||
Avatar: a,
|
||||
URL: *v.HTMLURL,
|
||||
})
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
|
||||
}
|
||||
|
||||
func (*Provider) getCommits(client *gogithub.Client, config githubConfig) ([]githubBranchCommits, error) {
|
||||
|
||||
opts := &gogithub.CommitsListOptions{
|
||||
|
@ -338,44 +384,43 @@ func (t *Provider) Refresh(configJSON, data string) string {
|
|||
|
||||
c.Clean()
|
||||
|
||||
refreshed, err := t.getCommits(t.githubClient(c), c)
|
||||
switch c.ReportInfo.ID {
|
||||
case "open_issues":
|
||||
refreshed, err := t.getOpenIssues(t.githubClient(c), c)
|
||||
if err != nil {
|
||||
log.Error("unable to get github open issues", err)
|
||||
return data
|
||||
}
|
||||
j, err := json.Marshal(refreshed)
|
||||
if err != nil {
|
||||
log.Error("unable to marshall github open issues", err)
|
||||
return data
|
||||
}
|
||||
return string(j)
|
||||
|
||||
if err != nil {
|
||||
return data
|
||||
default: // to handle legacy data, this handles commits
|
||||
refreshed, err := t.getCommits(t.githubClient(c), c)
|
||||
if err != nil {
|
||||
log.Error("unable to get github commits", err)
|
||||
return data
|
||||
}
|
||||
j, err := json.Marshal(refreshed)
|
||||
if err != nil {
|
||||
log.Error("unable to marshall github commits", err)
|
||||
return data
|
||||
}
|
||||
return string(j)
|
||||
}
|
||||
|
||||
j, err := json.Marshal(refreshed)
|
||||
|
||||
if err != nil {
|
||||
log.Error("unable to marshall github commits", err)
|
||||
return data
|
||||
}
|
||||
|
||||
return string(j)
|
||||
}
|
||||
|
||||
type githubRender struct {
|
||||
Config githubConfig
|
||||
Repo githubRepo
|
||||
Data []githubBranchCommits
|
||||
CommitCount int
|
||||
}
|
||||
|
||||
// Render ... just returns the data given, suitably formatted
|
||||
func (*Provider) Render(config, data string) string {
|
||||
var err error
|
||||
|
||||
raw := []githubBranchCommits{}
|
||||
payload := githubRender{}
|
||||
var c = githubConfig{}
|
||||
|
||||
err = json.Unmarshal([]byte(data), &raw)
|
||||
|
||||
if err != nil {
|
||||
log.Error("unable to unmarshall github data", err)
|
||||
return "Documize internal github json umarshall data error: " + err.Error()
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(config), &c)
|
||||
|
||||
if err != nil {
|
||||
|
@ -384,18 +429,47 @@ func (*Provider) Render(config, data string) string {
|
|||
}
|
||||
|
||||
c.Clean()
|
||||
|
||||
payload.Config = c
|
||||
payload.Repo = c.RepoInfo
|
||||
payload.Data = raw
|
||||
|
||||
for _, list := range raw {
|
||||
payload.CommitCount += len(list.Commits)
|
||||
switch c.ReportInfo.ID {
|
||||
case "open_issues":
|
||||
raw := []githubIssue{}
|
||||
|
||||
if len(data) > 0 {
|
||||
err = json.Unmarshal([]byte(data), &raw)
|
||||
if err != nil {
|
||||
log.Error("unable to unmarshall github open issue data", err)
|
||||
return "Documize internal github json umarshall open issue data error: " + err.Error()
|
||||
}
|
||||
}
|
||||
payload.OpenIssues = raw
|
||||
|
||||
default: // to handle legacy data, this handles commits
|
||||
raw := []githubBranchCommits{}
|
||||
err = json.Unmarshal([]byte(data), &raw)
|
||||
|
||||
if err != nil {
|
||||
log.Error("unable to unmarshall github commit data", err)
|
||||
return "Documize internal github json umarshall data error: " + err.Error()
|
||||
}
|
||||
c.ReportInfo.ID = "commits"
|
||||
payload.BranchCommits = raw
|
||||
for _, list := range raw {
|
||||
payload.CommitCount += len(list.Commits)
|
||||
}
|
||||
}
|
||||
|
||||
t := template.New("github")
|
||||
|
||||
t, err = t.Parse(renderTemplate)
|
||||
tmpl, ok := renderTemplates[c.ReportInfo.ID]
|
||||
if !ok {
|
||||
msg := "github render template not found for: " + c.ReportInfo.ID
|
||||
log.ErrorString(msg)
|
||||
return "Documize internal error: " + msg
|
||||
}
|
||||
|
||||
t, err = t.Parse(tmpl)
|
||||
|
||||
if err != nil {
|
||||
log.Error("github render template.Parse error:", err)
|
||||
|
|
|
@ -13,11 +13,20 @@ package github
|
|||
|
||||
import "strings"
|
||||
|
||||
const renderTemplate = `
|
||||
type githubRender struct {
|
||||
Config githubConfig
|
||||
Repo githubRepo
|
||||
BranchCommits []githubBranchCommits
|
||||
CommitCount int
|
||||
OpenIssues []githubIssue
|
||||
}
|
||||
|
||||
var renderTemplates = map[string]string{
|
||||
"commits": `
|
||||
<div class="section-github-render">
|
||||
<p>There are {{ .CommitCount }} commits for branch <a href="{{.Config.BranchURL}}">{{.Config.Branch}}</a> of repository <a href="{{ .Repo.URL }}">{{.Repo.Name}}.</a></p>
|
||||
<div class="github-board">
|
||||
{{range $data := .Data}}
|
||||
{{range $data := .BranchCommits}}
|
||||
<div class="github-group-title">
|
||||
Commits on {{ $data.Day }}
|
||||
</div>
|
||||
|
@ -40,16 +49,40 @@ const renderTemplate = `
|
|||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
`,
|
||||
"open_issues": `
|
||||
<div class="section-github-render">
|
||||
<p>The issues for repository <a href="{{ .Repo.URL }}/issues">{{.Repo.Name}}.</a></p>
|
||||
<div class="github-board">
|
||||
<ul class="github-list">
|
||||
{{range $data := .OpenIssues}}
|
||||
<li class="github-commit-item">
|
||||
<a class="link" href="{{$data.URL}}">
|
||||
<div class="github-avatar">
|
||||
<img alt="@{{$data.Name}}" src="{{$data.Avatar}}" height="36" width="36">
|
||||
</div>
|
||||
<div class="github-commit-body">
|
||||
<div class="github-commit-title">{{$data.Message}}</div>
|
||||
<div class="github-commit-meta">{{$data.Name}} committed on {{$data.Date}}</div>
|
||||
</div>
|
||||
</a>
|
||||
<div class="clearfix" />
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}
|
||||
|
||||
type githubReport struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type githubOwner 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"` // TODO review field use
|
||||
//URL string `json:"url"`
|
||||
}
|
||||
|
||||
type githubRepo struct {
|
||||
|
@ -83,6 +116,14 @@ type githubCommit struct {
|
|||
Avatar string `json:"avatar"`
|
||||
}
|
||||
|
||||
type githubIssue struct {
|
||||
Date string `json:"date"`
|
||||
Message string `json:"message"`
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Avatar string `json:"avatar"`
|
||||
}
|
||||
|
||||
type githubConfig struct {
|
||||
AppKey string `json:"appKey"` // TODO keep?
|
||||
Token string `json:"token"`
|
||||
|
@ -94,6 +135,7 @@ type githubConfig struct {
|
|||
BranchLines int `json:"branchLines"`
|
||||
OwnerInfo githubOwner `json:"owner"`
|
||||
RepoInfo githubRepo `json:"repo"`
|
||||
ReportInfo githubReport `json:"report"`
|
||||
ClientID string `json:"clientId"`
|
||||
CallbackURL string `json:"callbackUrl"`
|
||||
Lists []githubBranch `json:"lists"`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue