1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-09 07:25:23 +02:00

add github individual issue report

This commit is contained in:
Elliott Stoneham 2016-06-27 11:54:38 +01:00
parent 8efb288f75
commit df52dcc8c1
4 changed files with 197 additions and 33 deletions

View file

@ -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;
}

View file

@ -34,6 +34,9 @@
<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 showIssueNum}}
{{input id="issue-number" value=config.issueNum type="number" min="1" step="1" enter='onIssueNumChange'}}
{{/if}}
{{#if showCommits}}
<div class="input-control">
<label>Branches</label>

View file

@ -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)

View file

@ -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
Issues []githubIssue
IssueNum int
IssueNumActivity []githubIssueActivity
}
var renderTemplates = map[string]string{
"commits": `
"commits_data": `
<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">
@ -50,12 +56,35 @@ var renderTemplates = map[string]string{
</div>
</div>
`,
"open_issues": `
"issues_data": `
<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}}
{{range $data := .Issues}}
<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>
`,
"issuenum_data": `
<div class="section-github-render">
<p>Activity for issue #{{.IssueNum}} in repository <a href="{{ .Repo.URL }}/issues">{{.Repo.Name}}.</a></p>
<div class="github-board">
<ul class="github-list">
{{range $data := .IssueNumActivity}}
<li class="github-commit-item">
<a class="link" href="{{$data.URL}}">
<div class="github-avatar">
@ -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 {