diff --git a/app/app/components/section/github/type-editor.js b/app/app/components/section/github/type-editor.js
index 109e5a14..12b95d13 100644
--- a/app/app/components/section/github/type-editor.js
+++ b/app/app/components/section/github/type-editor.js
@@ -24,6 +24,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
repos: null,
noRepos: false,
showCommits: false,
+ showIssueNum: false,
didReceiveAttrs() {
let self = this;
@@ -47,7 +48,8 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
branch: "",
branchURL: "",
branchSince: "",
- branchLines: 30
+ branchLines: 30,
+ issueNum: "1"
};
try {
@@ -152,13 +154,17 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
getReportLists() {
let reports = [];
reports[0] = {
- id: "commits", // used as method for fetching Go data
+ id: "commits_data", // used as method for fetching Go data
name: "Commits on a branch"
};
reports[1] = {
- id: "open_issues", // used as method for fetching Go data
+ id: "issues_data", // used as method for fetching Go data
name: "Open Issues"
};
+ reports[2] = {
+ id: "issuenum_data", // used as method for fetching Go data
+ name: "Individual issue activity"
+ };
this.set("reports", reports);
@@ -181,13 +187,18 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
renderSwitch(thisReport) {
this.set('showCommits', false);
+ this.set('showIssueNum', false);
switch (thisReport.id) {
- case 'commits':
+ case 'commits_data':
this.set('showCommits', true);
this.getBranchLists();
break;
- case "open_issues":
- // nothing to show
+ case "issues_data":
+ // nothing to show yet
+ this.set('busy', false);
+ break;
+ case "issuenum_data":
+ this.set('showIssueNum', true);
this.set('busy', false);
break;
}
diff --git a/app/app/templates/components/section/github/type-editor.hbs b/app/app/templates/components/section/github/type-editor.hbs
index 6aa343e8..d38ca717 100644
--- a/app/app/templates/components/section/github/type-editor.hbs
+++ b/app/app/templates/components/section/github/type-editor.hbs
@@ -34,6 +34,9 @@
Select report type
{{ui-select id="report-dropdown" content=reports action=(action 'onReportChange') optionValuePath="id" optionLabelPath="name" selection=config.report}}
+ {{#if showIssueNum}}
+ {{input id="issue-number" value=config.issueNum type="number" min="1" step="1" enter='onIssueNumChange'}}
+ {{/if}}
{{#if showCommits}}
diff --git a/documize/section/github/github.go b/documize/section/github/github.go
index 07e7724b..ce00d74f 100644
--- a/documize/section/github/github.go
+++ b/documize/section/github/github.go
@@ -118,7 +118,7 @@ func (t *Provider) Command(w http.ResponseWriter, r *http.Request) {
switch method {
- case "commits":
+ case "commits_data":
render, err := t.getCommits(client, config)
if err != nil {
@@ -129,11 +129,22 @@ func (t *Provider) Command(w http.ResponseWriter, r *http.Request) {
provider.WriteJSON(w, render)
- case "open_issues":
+ case "issues_data":
- render, err := t.getOpenIssues(client, config)
+ render, err := t.getIssues(client, config)
if err != nil {
- log.Error("github getOpenIssues:", err)
+ log.Error("github getIssues:", err)
+ provider.WriteError(w, "github", err)
+ return
+ }
+
+ provider.WriteJSON(w, render)
+
+ case "issuenum_data":
+
+ render, err := t.getIssueNum(client, config)
+ if err != nil {
+ log.Error("github getIssueNum:", err)
provider.WriteError(w, "github", err)
return
}
@@ -255,9 +266,78 @@ func (*Provider) githubClient(config githubConfig) *gogithub.Client {
return gogithub.NewClient(tc)
}
-func (*Provider) getOpenIssues(client *gogithub.Client, config githubConfig) ([]githubIssue, error) {
+func (*Provider) getIssueNum(client *gogithub.Client, config githubConfig) ([]githubIssueActivity, error) {
- guff, _, err := client.Issues.ListByRepo(config.Owner, config.Repo, nil)
+ ret := []githubIssueActivity{}
+
+ issue, _, err := client.Issues.Get(config.Owner, config.Repo, config.IssueNum)
+
+ if err == nil {
+ n := ""
+ a := ""
+ p := issue.User
+ if p != nil {
+ if p.Name != nil {
+ n = *p.Name
+ }
+ if p.AvatarURL != nil {
+ a = *p.AvatarURL
+ }
+ }
+ ret = append(ret, githubIssueActivity{
+ Name: n,
+ Message: *issue.Title, // TODO move?
+ Date: issue.UpdatedAt.Format("January 2 2006, 15:04"),
+ Avatar: a,
+ URL: *issue.HTMLURL,
+ })
+ ret = append(ret, githubIssueActivity{
+ Name: n,
+ Message: *issue.Body,
+ Date: issue.UpdatedAt.Format("January 2 2006, 15:04"),
+ Avatar: a,
+ URL: *issue.HTMLURL,
+ })
+ } else {
+ return ret, err
+ }
+
+ guff, _, err := client.Issues.ListComments(config.Owner, config.Repo, config.IssueNum,
+ &gogithub.IssueListCommentsOptions{ListOptions: gogithub.ListOptions{PerPage: 100}})
+
+ 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, githubIssueActivity{
+ Name: n,
+ Message: *v.Body,
+ Date: v.UpdatedAt.Format("January 2 2006, 15:04"),
+ Avatar: a,
+ URL: *v.HTMLURL,
+ })
+ }
+
+ return ret, nil
+
+}
+
+func (*Provider) getIssues(client *gogithub.Client, config githubConfig) ([]githubIssue, error) {
+
+ guff, _, err := client.Issues.ListByRepo(config.Owner, config.Repo,
+ &gogithub.IssueListByRepoOptions{ListOptions: gogithub.ListOptions{PerPage: 100}})
ret := []githubIssue{}
@@ -385,15 +465,28 @@ func (t *Provider) Refresh(configJSON, data string) string {
c.Clean()
switch c.ReportInfo.ID {
- case "open_issues":
- refreshed, err := t.getOpenIssues(t.githubClient(c), c)
+ case "issuenum_data":
+ refreshed, err := t.getIssueNum(t.githubClient(c), c)
if err != nil {
- log.Error("unable to get github open issues", err)
+ log.Error("unable to get github issue number activity", err)
return data
}
j, err := json.Marshal(refreshed)
if err != nil {
- log.Error("unable to marshall github open issues", err)
+ log.Error("unable to marshall github issue number activity", err)
+ return data
+ }
+ return string(j)
+
+ case "issues_data":
+ refreshed, err := t.getIssues(t.githubClient(c), c)
+ if err != nil {
+ log.Error("unable to get github issues", err)
+ return data
+ }
+ j, err := json.Marshal(refreshed)
+ if err != nil {
+ log.Error("unable to marshall github issues", err)
return data
}
return string(j)
@@ -433,17 +526,30 @@ func (*Provider) Render(config, data string) string {
payload.Repo = c.RepoInfo
switch c.ReportInfo.ID {
- case "open_issues":
+ case "issuenum_data":
+ payload.IssueNum = c.IssueNum
+ raw := []githubIssueActivity{}
+
+ if len(data) > 0 {
+ err = json.Unmarshal([]byte(data), &raw)
+ if err != nil {
+ log.Error("unable to unmarshall github issue activity data", err)
+ return "Documize internal github json umarshall issue activity data error: " + err.Error()
+ }
+ }
+ payload.IssueNumActivity = raw
+
+ case "issues_data":
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()
+ log.Error("unable to unmarshall github issue data", err)
+ return "Documize internal github json umarshall open data error: " + err.Error()
}
}
- payload.OpenIssues = raw
+ payload.Issues = raw
default: // to handle legacy data, this handles commits
raw := []githubBranchCommits{}
@@ -453,7 +559,7 @@ func (*Provider) Render(config, data string) string {
log.Error("unable to unmarshall github commit data", err)
return "Documize internal github json umarshall data error: " + err.Error()
}
- c.ReportInfo.ID = "commits"
+ c.ReportInfo.ID = "commits_data"
payload.BranchCommits = raw
for _, list := range raw {
payload.CommitCount += len(list.Commits)
diff --git a/documize/section/github/model.go b/documize/section/github/model.go
index 3b3e4c8a..0f39c61b 100644
--- a/documize/section/github/model.go
+++ b/documize/section/github/model.go
@@ -11,18 +11,24 @@
package github
-import "strings"
+import (
+ //"github.com/documize/community/wordsmith/log"
+
+ "strings"
+)
type githubRender struct {
- Config githubConfig
- Repo githubRepo
- BranchCommits []githubBranchCommits
- CommitCount int
- OpenIssues []githubIssue
+ Config githubConfig
+ Repo githubRepo
+ BranchCommits []githubBranchCommits
+ CommitCount int
+ Issues []githubIssue
+ IssueNum int
+ IssueNumActivity []githubIssueActivity
}
var renderTemplates = map[string]string{
- "commits": `
+ "commits_data": `
`,
- "open_issues": `
+ "issues_data": `
+`,
+ "issuenum_data": `
+
+
Activity for issue #{{.IssueNum}} in repository {{.Repo.Name}}.
+
+
+ {{range $data := .IssueNumActivity}}
-
@@ -124,6 +153,14 @@ type githubIssue struct {
Avatar string `json:"avatar"`
}
+type githubIssueActivity 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"`
@@ -131,14 +168,15 @@ type githubConfig struct {
Repo string `json:"repo_name"`
Branch string `json:"branch"`
BranchURL string `json:"branchURL"`
- BranchSince string `json:"branchSince"`
- BranchLines int `json:"branchLines"`
+ BranchSince string `json:"branchSince,omitempty"`
+ BranchLines int `json:"branchLines,omitempty"`
OwnerInfo githubOwner `json:"owner"`
RepoInfo githubRepo `json:"repo"`
ReportInfo githubReport `json:"report"`
ClientID string `json:"clientId"`
CallbackURL string `json:"callbackUrl"`
- Lists []githubBranch `json:"lists"`
+ Lists []githubBranch `json:"lists,omitempty"`
+ IssueNum int `json:"issueNum,omitempty,string"`
}
func (c *githubConfig) Clean() {
@@ -153,6 +191,12 @@ func (c *githubConfig) Clean() {
break
}
}
+ // var e error
+ // c.IssueNum, e = strconv.Atoi(c.IssueNumString)
+ // if e != nil {
+ // log.ErrorString("github clean issue number: " + e.Error())
+ // c.IssueNum = 1
+ // }
}
type githubCallbackT struct {