diff --git a/app/app/components/section/github/type-editor.js b/app/app/components/section/github/type-editor.js
index 24940726..109e5a14 100644
--- a/app/app/components/section/github/type-editor.js
+++ b/app/app/components/section/github/type-editor.js
@@ -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);
diff --git a/app/app/templates/components/section/github/type-editor.hbs b/app/app/templates/components/section/github/type-editor.hbs
index 51f0b3cb..6aa343e8 100644
--- a/app/app/templates/components/section/github/type-editor.hbs
+++ b/app/app/templates/components/section/github/type-editor.hbs
@@ -30,22 +30,29 @@
{{ui-select id="repos-dropdown" content=repos action=(action 'onRepoChange') optionValuePath="id" optionLabelPath="name" selection=config.repo}}
+ {{#if showCommits}}
+
+ {{/if}}
{{/if}}
diff --git a/documize/section/github/github.go b/documize/section/github/github.go
index 1cf37589..07e7724b 100644
--- a/documize/section/github/github.go
+++ b/documize/section/github/github.go
@@ -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)
diff --git a/documize/section/github/model.go b/documize/section/github/model.go
index 314e8396..3b3e4c8a 100644
--- a/documize/section/github/model.go
+++ b/documize/section/github/model.go
@@ -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": `
There are {{ .CommitCount }} commits for branch {{.Config.Branch}} of repository {{.Repo.Name}}.
- {{range $data := .Data}}
+ {{range $data := .BranchCommits}}
Commits on {{ $data.Day }}
@@ -40,16 +49,40 @@ const renderTemplate = `
{{end}}
-`
+`,
+ "open_issues": `
+
+`,
+}
+
+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"`