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:
parent
8efb288f75
commit
df52dcc8c1
4 changed files with 197 additions and 33 deletions
|
@ -24,6 +24,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
||||||
repos: null,
|
repos: null,
|
||||||
noRepos: false,
|
noRepos: false,
|
||||||
showCommits: false,
|
showCommits: false,
|
||||||
|
showIssueNum: false,
|
||||||
|
|
||||||
didReceiveAttrs() {
|
didReceiveAttrs() {
|
||||||
let self = this;
|
let self = this;
|
||||||
|
@ -47,7 +48,8 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
||||||
branch: "",
|
branch: "",
|
||||||
branchURL: "",
|
branchURL: "",
|
||||||
branchSince: "",
|
branchSince: "",
|
||||||
branchLines: 30
|
branchLines: 30,
|
||||||
|
issueNum: "1"
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -152,13 +154,17 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
||||||
getReportLists() {
|
getReportLists() {
|
||||||
let reports = [];
|
let reports = [];
|
||||||
reports[0] = {
|
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"
|
name: "Commits on a branch"
|
||||||
};
|
};
|
||||||
reports[1] = {
|
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"
|
name: "Open Issues"
|
||||||
};
|
};
|
||||||
|
reports[2] = {
|
||||||
|
id: "issuenum_data", // used as method for fetching Go data
|
||||||
|
name: "Individual issue activity"
|
||||||
|
};
|
||||||
|
|
||||||
this.set("reports", reports);
|
this.set("reports", reports);
|
||||||
|
|
||||||
|
@ -181,13 +187,18 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
||||||
|
|
||||||
renderSwitch(thisReport) {
|
renderSwitch(thisReport) {
|
||||||
this.set('showCommits', false);
|
this.set('showCommits', false);
|
||||||
|
this.set('showIssueNum', false);
|
||||||
switch (thisReport.id) {
|
switch (thisReport.id) {
|
||||||
case 'commits':
|
case 'commits_data':
|
||||||
this.set('showCommits', true);
|
this.set('showCommits', true);
|
||||||
this.getBranchLists();
|
this.getBranchLists();
|
||||||
break;
|
break;
|
||||||
case "open_issues":
|
case "issues_data":
|
||||||
// nothing to show
|
// nothing to show yet
|
||||||
|
this.set('busy', false);
|
||||||
|
break;
|
||||||
|
case "issuenum_data":
|
||||||
|
this.set('showIssueNum', true);
|
||||||
this.set('busy', false);
|
this.set('busy', false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,9 @@
|
||||||
<div class="tip">Select report type</div>
|
<div class="tip">Select report type</div>
|
||||||
{{ui-select id="report-dropdown" content=reports action=(action 'onReportChange') optionValuePath="id" optionLabelPath="name" selection=config.report}}
|
{{ui-select id="report-dropdown" content=reports action=(action 'onReportChange') optionValuePath="id" optionLabelPath="name" selection=config.report}}
|
||||||
</div>
|
</div>
|
||||||
|
{{#if showIssueNum}}
|
||||||
|
{{input id="issue-number" value=config.issueNum type="number" min="1" step="1" enter='onIssueNumChange'}}
|
||||||
|
{{/if}}
|
||||||
{{#if showCommits}}
|
{{#if showCommits}}
|
||||||
<div class="input-control">
|
<div class="input-control">
|
||||||
<label>Branches</label>
|
<label>Branches</label>
|
||||||
|
|
|
@ -118,7 +118,7 @@ func (t *Provider) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
switch method {
|
switch method {
|
||||||
|
|
||||||
case "commits":
|
case "commits_data":
|
||||||
|
|
||||||
render, err := t.getCommits(client, config)
|
render, err := t.getCommits(client, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -129,11 +129,22 @@ func (t *Provider) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
provider.WriteJSON(w, render)
|
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 {
|
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)
|
provider.WriteError(w, "github", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -255,9 +266,78 @@ func (*Provider) githubClient(config githubConfig) *gogithub.Client {
|
||||||
return gogithub.NewClient(tc)
|
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{}
|
ret := []githubIssue{}
|
||||||
|
|
||||||
|
@ -385,15 +465,28 @@ func (t *Provider) Refresh(configJSON, data string) string {
|
||||||
c.Clean()
|
c.Clean()
|
||||||
|
|
||||||
switch c.ReportInfo.ID {
|
switch c.ReportInfo.ID {
|
||||||
case "open_issues":
|
case "issuenum_data":
|
||||||
refreshed, err := t.getOpenIssues(t.githubClient(c), c)
|
refreshed, err := t.getIssueNum(t.githubClient(c), c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("unable to get github open issues", err)
|
log.Error("unable to get github issue number activity", err)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
j, err := json.Marshal(refreshed)
|
j, err := json.Marshal(refreshed)
|
||||||
if err != nil {
|
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 data
|
||||||
}
|
}
|
||||||
return string(j)
|
return string(j)
|
||||||
|
@ -433,17 +526,30 @@ func (*Provider) Render(config, data string) string {
|
||||||
payload.Repo = c.RepoInfo
|
payload.Repo = c.RepoInfo
|
||||||
|
|
||||||
switch c.ReportInfo.ID {
|
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{}
|
raw := []githubIssue{}
|
||||||
|
|
||||||
if len(data) > 0 {
|
if len(data) > 0 {
|
||||||
err = json.Unmarshal([]byte(data), &raw)
|
err = json.Unmarshal([]byte(data), &raw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("unable to unmarshall github open issue data", err)
|
log.Error("unable to unmarshall github issue data", err)
|
||||||
return "Documize internal github json umarshall open issue data error: " + err.Error()
|
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
|
default: // to handle legacy data, this handles commits
|
||||||
raw := []githubBranchCommits{}
|
raw := []githubBranchCommits{}
|
||||||
|
@ -453,7 +559,7 @@ func (*Provider) Render(config, data string) string {
|
||||||
log.Error("unable to unmarshall github commit data", err)
|
log.Error("unable to unmarshall github commit data", err)
|
||||||
return "Documize internal github json umarshall data error: " + err.Error()
|
return "Documize internal github json umarshall data error: " + err.Error()
|
||||||
}
|
}
|
||||||
c.ReportInfo.ID = "commits"
|
c.ReportInfo.ID = "commits_data"
|
||||||
payload.BranchCommits = raw
|
payload.BranchCommits = raw
|
||||||
for _, list := range raw {
|
for _, list := range raw {
|
||||||
payload.CommitCount += len(list.Commits)
|
payload.CommitCount += len(list.Commits)
|
||||||
|
|
|
@ -11,18 +11,24 @@
|
||||||
|
|
||||||
package github
|
package github
|
||||||
|
|
||||||
import "strings"
|
import (
|
||||||
|
//"github.com/documize/community/wordsmith/log"
|
||||||
|
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
type githubRender struct {
|
type githubRender struct {
|
||||||
Config githubConfig
|
Config githubConfig
|
||||||
Repo githubRepo
|
Repo githubRepo
|
||||||
BranchCommits []githubBranchCommits
|
BranchCommits []githubBranchCommits
|
||||||
CommitCount int
|
CommitCount int
|
||||||
OpenIssues []githubIssue
|
Issues []githubIssue
|
||||||
|
IssueNum int
|
||||||
|
IssueNumActivity []githubIssueActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
var renderTemplates = map[string]string{
|
var renderTemplates = map[string]string{
|
||||||
"commits": `
|
"commits_data": `
|
||||||
<div class="section-github-render">
|
<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>
|
<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">
|
<div class="github-board">
|
||||||
|
@ -50,12 +56,35 @@ var renderTemplates = map[string]string{
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`,
|
`,
|
||||||
"open_issues": `
|
"issues_data": `
|
||||||
<div class="section-github-render">
|
<div class="section-github-render">
|
||||||
<p>The issues for repository <a href="{{ .Repo.URL }}/issues">{{.Repo.Name}}.</a></p>
|
<p>The issues for repository <a href="{{ .Repo.URL }}/issues">{{.Repo.Name}}.</a></p>
|
||||||
<div class="github-board">
|
<div class="github-board">
|
||||||
<ul class="github-list">
|
<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">
|
<li class="github-commit-item">
|
||||||
<a class="link" href="{{$data.URL}}">
|
<a class="link" href="{{$data.URL}}">
|
||||||
<div class="github-avatar">
|
<div class="github-avatar">
|
||||||
|
@ -124,6 +153,14 @@ type githubIssue struct {
|
||||||
Avatar string `json:"avatar"`
|
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 {
|
type githubConfig struct {
|
||||||
AppKey string `json:"appKey"` // TODO keep?
|
AppKey string `json:"appKey"` // TODO keep?
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
|
@ -131,14 +168,15 @@ type githubConfig struct {
|
||||||
Repo string `json:"repo_name"`
|
Repo string `json:"repo_name"`
|
||||||
Branch string `json:"branch"`
|
Branch string `json:"branch"`
|
||||||
BranchURL string `json:"branchURL"`
|
BranchURL string `json:"branchURL"`
|
||||||
BranchSince string `json:"branchSince"`
|
BranchSince string `json:"branchSince,omitempty"`
|
||||||
BranchLines int `json:"branchLines"`
|
BranchLines int `json:"branchLines,omitempty"`
|
||||||
OwnerInfo githubOwner `json:"owner"`
|
OwnerInfo githubOwner `json:"owner"`
|
||||||
RepoInfo githubRepo `json:"repo"`
|
RepoInfo githubRepo `json:"repo"`
|
||||||
ReportInfo githubReport `json:"report"`
|
ReportInfo githubReport `json:"report"`
|
||||||
ClientID string `json:"clientId"`
|
ClientID string `json:"clientId"`
|
||||||
CallbackURL string `json:"callbackUrl"`
|
CallbackURL string `json:"callbackUrl"`
|
||||||
Lists []githubBranch `json:"lists"`
|
Lists []githubBranch `json:"lists,omitempty"`
|
||||||
|
IssueNum int `json:"issueNum,omitempty,string"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *githubConfig) Clean() {
|
func (c *githubConfig) Clean() {
|
||||||
|
@ -153,6 +191,12 @@ func (c *githubConfig) Clean() {
|
||||||
break
|
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 {
|
type githubCallbackT struct {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue