1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 13:19:43 +02:00

parameterise reports

This commit is contained in:
Elliott Stoneham 2016-07-25 16:52:56 +01:00
parent 7d38102eb6
commit 18b61e4ad2
8 changed files with 1530 additions and 1503 deletions

110
core/section/github/auth.go Normal file
View file

@ -0,0 +1,110 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
package github
import (
"encoding/json"
"net/http"
"net/url"
"strings"
"github.com/documize/community/core/api/request"
gogithub "github.com/google/go-github/github"
"golang.org/x/oauth2"
)
func clientID() string {
return request.ConfigString(meta.ConfigHandle(), "clientID")
}
func clientSecret() string {
return request.ConfigString(meta.ConfigHandle(), "clientSecret")
}
func authorizationCallbackURL() string {
// NOTE: URL value must have the path and query "/api/public/validate?section=github"
return request.ConfigString(meta.ConfigHandle(), "authorizationCallbackURL")
}
func validateToken(ptoken string) error {
// Github authorization check
authClient := gogithub.NewClient((&gogithub.BasicAuthTransport{
Username: clientID(),
Password: clientSecret(),
}).Client())
_, _, err := authClient.Authorizations.Check(clientID(), ptoken)
return err
}
func (*Provider) githubClient(config githubConfig) *gogithub.Client {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: config.Token},
)
tc := oauth2.NewClient(oauth2.NoContext, ts)
return gogithub.NewClient(tc)
}
// Callback is called by a browser redirect from Github, via the validation endpoint
func Callback(res http.ResponseWriter, req *http.Request) error {
code := req.URL.Query().Get("code")
state := req.URL.Query().Get("state")
ghurl := "https://github.com/login/oauth/access_token"
vals := "client_id=" + clientID()
vals += "&client_secret=" + clientSecret()
vals += "&code=" + code
vals += "&state=" + state
req2, err := http.NewRequest("POST", ghurl+"?"+vals, strings.NewReader(vals))
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req2.Header.Set("Accept", "application/json")
res2, err := http.DefaultClient.Do(req2)
if err != nil {
return err
}
var gt githubCallbackT
err = json.NewDecoder(res2.Body).Decode(&gt)
if err != nil {
return err
}
err = res2.Body.Close()
if err != nil {
return err
}
returl, err := url.QueryUnescape(state)
if err != nil {
return err
}
up, err := url.Parse(returl)
if err != nil {
return err
}
target := up.Scheme + "://" + up.Host + up.Path + "?code=" + gt.AccessToken
http.Redirect(res, req, target, http.StatusTemporaryRedirect)
return nil
}

View file

@ -0,0 +1,195 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
package github
import (
"encoding/json"
"fmt"
"html/template"
"net/http"
"github.com/documize/community/core/log"
"github.com/documize/community/core/section/provider"
gogithub "github.com/google/go-github/github"
)
type githubBranchCommits struct {
Name string `json:"name"`
Day string `json:"day"`
Commits []githubCommit
}
type githubCommit struct {
Date string `json:"date"`
Message string `json:"message"`
URL template.URL `json:"url"`
Name string `json:"name"`
Avatar string `json:"avatar"`
}
const tagCommitsData = "commitsData"
func init() {
reports[tagCommitsData] = report{commandCommitsData, refreshCommits, renderCommits, `
<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>
Showing {{ .Limit }} items {{ .DateMessage }}.
</p>
<div class="github-board">
{{range $data := .BranchCommits}}
<div class="github-group-title">
Commits on {{ $data.Day }}
</div>
<ul class="github-list">
{{range $commit := $data.Commits}}
<li class="github-commit-item">
<a class="link" href="{{$commit.URL}}">
<div class="github-avatar">
<img alt="@{{$commit.Name}}" src="{{$commit.Avatar}}" height="36" width="36">
</div>
<div class="github-commit-body">
<div class="github-commit-title">{{$commit.Message}}</div>
<div class="github-commit-meta">{{$commit.Name}} committed on {{$commit.Date}}</div>
</div>
</a>
<div class="clearfix" />
</li>
{{end}}
</ul>
{{end}}
</div>
</div>
`}
}
func (*Provider) getCommits(client *gogithub.Client, config githubConfig) ([]githubBranchCommits, error) {
opts := &gogithub.CommitsListOptions{
SHA: config.Branch,
ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}}
if config.SincePtr != nil {
opts.Since = *config.SincePtr
}
guff, _, err := client.Repositories.ListCommits(config.Owner, config.Repo, opts)
if err != nil {
return nil, err
}
if len(guff) == 0 {
return []githubBranchCommits{}, nil
}
day := ""
newDay := ""
ret := []githubBranchCommits{}
for k, v := range guff {
if guff[k].Commit != nil {
if guff[k].Commit.Committer.Date != nil {
y, m, d := (*guff[k].Commit.Committer.Date).Date()
newDay = fmt.Sprintf("%s %d, %d", m.String(), d, y)
}
}
if day != newDay {
day = newDay
ret = append(ret, githubBranchCommits{
Name: fmt.Sprintf("%s/%s:%s", config.Owner, config.Repo, config.Branch),
Day: day,
})
}
var a, d, l, m, u string
if v.Commit != nil {
if v.Commit.Committer.Date != nil {
// d = fmt.Sprintf("%v", *v.Commit.Committer.Date)
d = v.Commit.Committer.Date.Format("January 2 2006, 15:04")
}
if v.Commit.Message != nil {
m = *v.Commit.Message
}
}
if v.Committer != nil {
if v.Committer.Login != nil {
l = *v.Committer.Login
}
if v.Committer.AvatarURL != nil {
a = *v.Committer.AvatarURL
}
}
if a == "" {
a = githubGravatar
}
if v.HTMLURL != nil {
u = *v.HTMLURL
}
ret[len(ret)-1].Commits = append(ret[len(ret)-1].Commits, githubCommit{
Name: l,
Message: m,
Date: d,
Avatar: a,
URL: template.URL(u),
})
}
return ret, nil
}
func commandCommitsData(p *Provider, client *gogithub.Client, config githubConfig, w http.ResponseWriter) {
render, err := p.getCommits(client, config)
if err != nil {
log.Error("github getCommits:", err)
provider.WriteError(w, "github", err)
return
}
provider.WriteJSON(w, render)
}
func refreshCommits(p *Provider, c githubConfig, data string) string {
refreshed, err := p.getCommits(p.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)
}
func renderCommits(c *githubConfig, payload *githubRender, data string) error {
raw := []githubBranchCommits{}
if err := json.Unmarshal([]byte(data), &raw); err != nil {
return err
}
c.ReportInfo.ID = tagCommitsData
payload.BranchCommits = raw
for _, list := range raw {
payload.CommitCount += len(list.Commits)
}
return nil
}

View file

@ -15,20 +15,12 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"html/template"
"io/ioutil"
"net/http"
"net/url"
"strconv"
"strings"
"github.com/documize/community/core/api/request"
"github.com/documize/community/core/section/provider"
"github.com/documize/community/core/log"
gogithub "github.com/google/go-github/github"
"golang.org/x/oauth2"
"github.com/documize/community/core/section/provider"
)
// TODO find a smaller image than the one below
@ -55,26 +47,6 @@ func (*Provider) Meta() provider.TypeMeta {
return meta
}
func clientID() string {
return request.ConfigString(meta.ConfigHandle(), "clientID")
}
func clientSecret() string {
return request.ConfigString(meta.ConfigHandle(), "clientSecret")
}
func authorizationCallbackURL() string {
// NOTE: URL value must have the path and query "/api/public/validate?section=github"
return request.ConfigString(meta.ConfigHandle(), "authorizationCallbackURL")
}
func validateToken(ptoken string) error {
// Github authorization check
authClient := gogithub.NewClient((&gogithub.BasicAuthTransport{
Username: clientID(),
Password: clientSecret(),
}).Client())
_, _, err := authClient.Authorizations.Check(clientID(), ptoken)
return err
}
// Command to run the various functions required...
func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
@ -105,16 +77,11 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
if err != nil {
msg := "Bad body"
log.ErrorString("github: " + msg)
provider.WriteMessage(w, "gitub", msg)
provider.WriteMessage(w, "github", msg)
return
}
// get the secret token in the database
ptoken := ctx.GetSecrets("token")
switch method {
case "saveSecret": // secret Token update code
if method == "saveSecret" { // secret Token update code
// write the new one, direct from JS
if err = ctx.SaveSecrets(string(body)); err != nil {
@ -139,18 +106,18 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
config.Clean()
// always use DB version of the token
config.Token = ptoken
config.Token = ctx.GetSecrets("token") // get the secret token in the database
client := p.githubClient(config)
switch method { // the main data handling switch
switch method {
case "checkAuth":
if len(ptoken) == 0 {
if len(config.Token) == 0 {
err = errors.New("empty github token")
} else {
err = validateToken(ptoken)
err = validateToken(config.Token)
}
if err != nil {
// token now invalid, so wipe it
@ -160,462 +127,23 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
return
}
provider.WriteEmpty(w)
return
case tagCommitsData:
render, err := p.getCommits(client, config)
if err != nil {
log.Error("github getCommits:", err)
provider.WriteError(w, "github", err)
return
}
provider.WriteJSON(w, render)
case tagIssuesData:
render, err := p.getIssues(client, config)
if err != nil {
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
}
provider.WriteJSON(w, render)*/
case "owners":
me, _, err := client.Users.Get("")
if err != nil {
log.Error("github get user details:", err)
provider.WriteError(w, "github", err)
return
}
orgs, _, err := client.Organizations.List("", nil)
if err != nil {
log.Error("github get user's organisations:", err)
provider.WriteError(w, "github", err)
return
}
owners := make([]githubOwner, 1+len(orgs))
owners[0] = githubOwner{ID: *me.Login, Name: *me.Login}
for ko, vo := range orgs {
id := 1 + ko
owners[id].ID = *vo.Login
owners[id].Name = *vo.Login
}
owners = sortOwners(owners)
provider.WriteJSON(w, owners)
case "repos":
var render []githubRepo
if config.Owner != "" {
me, _, err := client.Users.Get("")
if err != nil {
log.Error("github get user details:", err)
provider.WriteError(w, "github", err)
return
}
var repos []*gogithub.Repository
if config.Owner == *me.Login {
repos, _, err = client.Repositories.List(config.Owner, nil)
} else {
opt := &gogithub.RepositoryListByOrgOptions{
ListOptions: gogithub.ListOptions{PerPage: 100},
}
repos, _, err = client.Repositories.ListByOrg(config.Owner, opt)
}
if err != nil {
log.Error("github get user/org repositories:", err)
provider.WriteError(w, "github", err)
return
}
for _, vr := range repos {
private := ""
if *vr.Private {
private = " (private)"
}
render = append(render,
githubRepo{
Name: config.Owner + "/" + *vr.Name + private,
ID: fmt.Sprintf("%s:%s", config.Owner, *vr.Name),
Owner: config.Owner,
Repo: *vr.Name,
Private: *vr.Private,
URL: *vr.HTMLURL,
})
}
}
render = sortRepos(render)
provider.WriteJSON(w, render)
case "branches":
if config.Owner == "" || config.Repo == "" {
provider.WriteJSON(w, []githubBranch{}) // we have nothing to return
return
}
branches, _, err := client.Repositories.ListBranches(config.Owner, config.Repo,
&gogithub.ListOptions{PerPage: 100})
if err != nil {
log.Error("github get branch details:", err)
provider.WriteError(w, "github", err)
return
}
render := make([]githubBranch, len(branches))
for kc, vb := range branches {
render[kc] = githubBranch{
Name: *vb.Name,
ID: fmt.Sprintf("%s:%s:%s", config.Owner, config.Repo, *vb.Name),
Included: false,
URL: "https://github.com/" + config.Owner + "/" + config.Repo + "/tree/" + *vb.Name,
}
}
provider.WriteJSON(w, render)
case "labels":
if config.Owner == "" || config.Repo == "" {
provider.WriteJSON(w, []githubBranch{}) // we have nothing to return
return
}
labels, _, err := client.Issues.ListLabels(config.Owner, config.Repo,
&gogithub.ListOptions{PerPage: 100})
if err != nil {
log.Error("github get labels:", err)
provider.WriteError(w, "github", err)
return
}
render := make([]githubBranch, len(labels))
for kc, vb := range labels {
render[kc] = githubBranch{
Name: *vb.Name,
ID: fmt.Sprintf("%s:%s:%s", config.Owner, config.Repo, *vb.Name),
Included: false,
Color: *vb.Color,
}
}
provider.WriteJSON(w, render)
default:
log.ErrorString("Github connector unknown method: " + method)
provider.WriteEmpty(w)
if listFailed(method, config, client, w) {
rep, ok := reports[method]
if !ok {
log.ErrorString("Github connector unknown method: " + method)
provider.WriteEmpty(w)
}
rep.command(p, client, config, w)
}
}
}
func (*Provider) githubClient(config githubConfig) *gogithub.Client {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: config.Token},
)
tc := oauth2.NewClient(oauth2.NoContext, ts)
return gogithub.NewClient(tc)
}
/*
func (*Provider) getIssueNum(client *gogithub.Client, config githubConfig) ([]githubIssueActivity, error) {
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.Login != nil {
n = *p.Login
}
if p.AvatarURL != nil {
a = *p.AvatarURL
}
}
ret = append(ret, githubIssueActivity{
Name: n,
Event: "created",
Message: template.HTML(*issue.Title),
Date: "on " + issue.UpdatedAt.Format("January 2 2006, 15:04"),
Avatar: a,
URL: template.URL(*issue.HTMLURL),
})
ret = append(ret, githubIssueActivity{
Name: n,
Event: "described",
Message: template.HTML(*issue.Body),
Date: "on " + issue.UpdatedAt.Format("January 2 2006, 15:04"),
Avatar: a,
URL: template.URL(*issue.HTMLURL),
})
ret = append(ret, githubIssueActivity{
Name: "",
Event: "Note",
Message: template.HTML("the issue timeline below is in reverse order"),
Date: "",
Avatar: githubGravatar,
URL: template.URL(*issue.HTMLURL),
})
} else {
return ret, err
}
opts := &gogithub.ListOptions{PerPage: config.BranchLines}
guff, _, err := client.Issues.ListIssueTimeline(config.Owner, config.Repo, config.IssueNum, opts)
if err != nil {
return ret, err
}
for _, v := range guff {
if config.SincePtr == nil || v.CreatedAt.After(*config.SincePtr) {
var n, a, m, u string
p := v.Actor
if p != nil {
if p.Name != nil {
n = *p.Name
}
if p.AvatarURL != nil {
a = *p.AvatarURL
}
}
u = fmt.Sprintf("https://github.com/%s/%s/issues/%d#event-%d",
config.Owner, config.Repo, config.IssueNum, *v.ID)
switch *v.Event {
case "commented":
ic, _, err := client.Issues.GetComment(config.Owner, config.Repo, *v.ID)
if err != nil {
log.ErrorString("github error fetching issue event comment: " + err.Error())
} else {
m = *ic.Body
u = *ic.HTMLURL
p := ic.User
if p != nil {
if p.Login != nil {
n = *p.Login
}
if p.AvatarURL != nil {
a = *p.AvatarURL
}
}
}
}
ret = append(ret, githubIssueActivity{
Name: n,
Event: *v.Event,
Message: template.HTML(m),
Date: "on " + v.CreatedAt.Format("January 2 2006, 15:04"),
Avatar: a,
URL: template.URL(u),
})
}
}
return ret, nil
}
*/
func wrapLabels(labels []gogithub.Label) string {
l := ""
for _, ll := range labels {
l += `<span class="github-issue-label" style="background-color:#` + *ll.Color + `">` + *ll.Name + `</span> `
}
return l
}
func (*Provider) getIssues(client *gogithub.Client, config githubConfig) ([]githubIssue, error) {
ret := []githubIssue{}
isRequired := make([]int, 0, 10)
for _, s := range strings.Split(strings.Replace(config.IssuesText, "#", "", -1), ",") {
i, err := strconv.Atoi(strings.TrimSpace(s))
if err == nil {
isRequired = append(isRequired, i)
}
}
if len(isRequired) > 0 {
for _, i := range isRequired {
issue, _, err := client.Issues.Get(config.Owner, config.Repo, i)
if err == nil {
n := ""
p := issue.User
if p != nil {
if p.Login != nil {
n = *p.Login
}
}
l := wrapLabels(issue.Labels)
ret = append(ret, githubIssue{
Name: n,
Message: *issue.Title,
Date: issue.CreatedAt.Format("January 2 2006, 15:04"),
Updated: issue.UpdatedAt.Format("January 2 2006, 15:04"),
URL: template.URL(*issue.HTMLURL),
Labels: template.HTML(l),
ID: *issue.Number,
IsOpen: *issue.State == "open",
})
}
}
} else {
opts := &gogithub.IssueListByRepoOptions{
Sort: "updated",
State: config.IssueState.ID,
ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}}
if config.SincePtr != nil {
opts.Since = *config.SincePtr
}
for _, lab := range config.Lists {
if lab.Included {
opts.Labels = append(opts.Labels, lab.Name)
}
}
guff, _, err := client.Issues.ListByRepo(config.Owner, config.Repo, opts)
if err != nil {
return ret, err
}
for _, v := range guff {
n := ""
ptr := v.User
if ptr != nil {
if ptr.Login != nil {
n = *ptr.Login
}
}
l := wrapLabels(v.Labels)
ret = append(ret, githubIssue{
Name: n,
Message: *v.Title,
Date: v.CreatedAt.Format("January 2 2006, 15:04"),
Updated: v.UpdatedAt.Format("January 2 2006, 15:04"),
URL: template.URL(*v.HTMLURL),
Labels: template.HTML(l),
ID: *v.Number,
IsOpen: *v.State == "open",
})
}
}
return ret, nil
}
func (*Provider) getCommits(client *gogithub.Client, config githubConfig) ([]githubBranchCommits, error) {
opts := &gogithub.CommitsListOptions{
SHA: config.Branch,
ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}}
if config.SincePtr != nil {
opts.Since = *config.SincePtr
}
guff, _, err := client.Repositories.ListCommits(config.Owner, config.Repo, opts)
if err != nil {
return nil, err
}
if len(guff) == 0 {
return []githubBranchCommits{}, nil
}
day := ""
newDay := ""
ret := []githubBranchCommits{}
for k, v := range guff {
if guff[k].Commit != nil {
if guff[k].Commit.Committer.Date != nil {
y, m, d := (*guff[k].Commit.Committer.Date).Date()
newDay = fmt.Sprintf("%s %d, %d", m.String(), d, y)
}
}
if day != newDay {
day = newDay
ret = append(ret, githubBranchCommits{
Name: fmt.Sprintf("%s/%s:%s", config.Owner, config.Repo, config.Branch),
Day: day,
})
}
var a, d, l, m, u string
if v.Commit != nil {
if v.Commit.Committer.Date != nil {
// d = fmt.Sprintf("%v", *v.Commit.Committer.Date)
d = v.Commit.Committer.Date.Format("January 2 2006, 15:04")
}
if v.Commit.Message != nil {
m = *v.Commit.Message
}
}
if v.Committer != nil {
if v.Committer.Login != nil {
l = *v.Committer.Login
}
if v.Committer.AvatarURL != nil {
a = *v.Committer.AvatarURL
}
}
if a == "" {
a = githubGravatar
}
if v.HTMLURL != nil {
u = *v.HTMLURL
}
ret[len(ret)-1].Commits = append(ret[len(ret)-1].Commits, githubCommit{
Name: l,
Message: m,
Date: d,
Avatar: a,
URL: template.URL(u),
})
}
return ret, nil
}
// Refresh ... gets the latest version
func (p *Provider) Refresh(ctx *provider.Context, configJSON, data string) string {
var c = githubConfig{}
@ -630,52 +158,15 @@ func (p *Provider) Refresh(ctx *provider.Context, configJSON, data string) strin
c.Clean()
c.Token = ctx.GetSecrets("token")
switch c.ReportInfo.ID {
/*case "issuenum_data":
refreshed, err := t.getIssueNum(t.githubClient(c), c)
if err != nil {
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 issue number activity", err)
return data
}
return string(j)*/
case tagIssuesData:
refreshed, err := p.getIssues(p.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)
case tagCommitsData:
refreshed, err := p.getCommits(p.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)
default:
msg := "unknown data format: " + c.ReportInfo.ID
rep, ok := reports[c.ReportInfo.ID]
if !ok {
msg := "github report not found for: " + c.ReportInfo.ID
log.ErrorString(msg)
return "internal configuration error, " + msg
return "Documize internal error: " + msg
}
return rep.refresh(p, c, data)
}
// Render ... just returns the data given, suitably formatted
@ -702,90 +193,21 @@ func (p *Provider) Render(ctx *provider.Context, config, data string) string {
payload.DateMessage = "created after " + c.BranchSince
}
switch c.ReportInfo.ID {
/* 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()
}
}
opt := &gogithub.MarkdownOptions{Mode: "gfm", Context: c.Owner + "/" + c.Repo}
client := p.githubClient(c)
for k, v := range raw {
if v.Event == "commented" {
output, _, err := client.Markdown(string(v.Message), opt)
if err != nil {
log.Error("convert commented text to markdown", err)
} else {
raw[k].Message = template.HTML(output)
}
}
}
payload.IssueNumActivity = raw */
case tagIssuesData:
raw := []githubIssue{}
if len(data) > 0 {
err = json.Unmarshal([]byte(data), &raw)
if err != nil {
log.Error("unable to unmarshall github issue data", err)
return "Documize internal github json umarshall open data error: " + err.Error() + "<BR>" + data
}
}
payload.Issues = raw
if strings.TrimSpace(c.IssuesText) != "" {
payload.ShowIssueNumbers = true
payload.DateMessage = c.IssuesText
} else {
if len(c.Lists) > 0 {
for _, v := range c.Lists {
if v.Included {
payload.ShowList = true
break
}
}
payload.List = c.Lists
}
}
case tagCommitsData:
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() + "<BR>" + data
}
c.ReportInfo.ID = tagCommitsData
payload.BranchCommits = raw
for _, list := range raw {
payload.CommitCount += len(list.Commits)
}
default:
msg := "unknown data format: " + c.ReportInfo.ID
log.ErrorString(msg)
return "internal configuration error, " + msg
}
t := template.New("github")
tmpl, ok := renderTemplates[c.ReportInfo.ID]
rep, ok := reports[c.ReportInfo.ID]
if !ok {
msg := "github render template not found for: " + c.ReportInfo.ID
msg := "github report not found for: " + c.ReportInfo.ID
log.ErrorString(msg)
return "Documize internal error: " + msg
}
t, err = t.Parse(tmpl)
if err = rep.render(&c, &payload, data); err != nil {
log.Error("unable to render "+c.ReportInfo.ID, err)
return "Documize internal github render " + c.ReportInfo.ID + " error: " + err.Error() + "<BR>" + data
}
t := template.New("github")
t, err = t.Parse(rep.template)
if err != nil {
log.Error("github render template.Parse error:", err)
@ -801,57 +223,3 @@ func (p *Provider) Render(ctx *provider.Context, config, data string) string {
return buffer.String()
}
// Callback is called by a browser redirect from Github, via the validation endpoint
func Callback(res http.ResponseWriter, req *http.Request) error {
code := req.URL.Query().Get("code")
state := req.URL.Query().Get("state")
ghurl := "https://github.com/login/oauth/access_token"
vals := "client_id=" + clientID()
vals += "&client_secret=" + clientSecret()
vals += "&code=" + code
vals += "&state=" + state
req2, err := http.NewRequest("POST", ghurl+"?"+vals, strings.NewReader(vals))
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req2.Header.Set("Accept", "application/json")
res2, err := http.DefaultClient.Do(req2)
if err != nil {
return err
}
var gt githubCallbackT
err = json.NewDecoder(res2.Body).Decode(&gt)
if err != nil {
return err
}
err = res2.Body.Close()
if err != nil {
return err
}
returl, err := url.QueryUnescape(state)
if err != nil {
return err
}
up, err := url.Parse(returl)
if err != nil {
return err
}
target := up.Scheme + "://" + up.Host + up.Path + "?code=" + gt.AccessToken
http.Redirect(res, req, target, http.StatusTemporaryRedirect)
return nil
}

View file

@ -0,0 +1,217 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
package github
// THIS TO KEEP UNUSED CODE FOR THIS POSSIBLE FUTURE FUNCITON
/*
type githubIssueActivity struct {
Date string `json:"date"`
Event string `json:"event"`
Message template.HTML `json:"message"`
URL template.URL `json:"url"`
Name string `json:"name"`
Avatar string `json:"avatar"`
}
*/
// FROM renderTemplates
/* "issuenum_data": `
<div class="section-github-render">
<p>
Activity for issue #{{.IssueNum}} in repository <a href="{{ .Repo.URL }}/issues">{{.Repo.Name}}.</a>
Up to {{ .Limit }} items are shown{{ .DateMessage }}.
</p>
<div class="github-board">
<ul class="github-list">
{{range $data := .IssueNumActivity}}
<li class="github-commit-item">
<div class="github-avatar">
<img alt="@{{$data.Name}}" src="{{$data.Avatar}}" height="36" width="36">
</div>
<div class="github-commit-meta">
{{$data.Name}} <a class="link" href="{{$data.URL}}">{{$data.Event}}</a> {{$data.Date}}
</div>
<div class="github-commit-body">
<div class="github-commit-title">
{{$data.Message}}
</div>
</div>
<div class="clearfix" />
</li>
{{end}}
</ul>
</div>
</div>
`,*/
// FROM Command()
/*case "issuenum_data":
render, err := t.getIssueNum(client, config)
if err != nil {
log.Error("github getIssueNum:", err)
provider.WriteError(w, "github", err)
return
}
provider.WriteJSON(w, render)*/
// FROM Refresh()
/*case "issuenum_data":
refreshed, err := t.getIssueNum(t.githubClient(c), c)
if err != nil {
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 issue number activity", err)
return data
}
return string(j)*/
// FROM Render()
/* 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()
}
}
opt := &gogithub.MarkdownOptions{Mode: "gfm", Context: c.Owner + "/" + c.Repo}
client := p.githubClient(c)
for k, v := range raw {
if v.Event == "commented" {
output, _, err := client.Markdown(string(v.Message), opt)
if err != nil {
log.Error("convert commented text to markdown", err)
} else {
raw[k].Message = template.HTML(output)
}
}
}
payload.IssueNumActivity = raw */
/*
func (*Provider) getIssueNum(client *gogithub.Client, config githubConfig) ([]githubIssueActivity, error) {
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.Login != nil {
n = *p.Login
}
if p.AvatarURL != nil {
a = *p.AvatarURL
}
}
ret = append(ret, githubIssueActivity{
Name: n,
Event: "created",
Message: template.HTML(*issue.Title),
Date: "on " + issue.UpdatedAt.Format("January 2 2006, 15:04"),
Avatar: a,
URL: template.URL(*issue.HTMLURL),
})
ret = append(ret, githubIssueActivity{
Name: n,
Event: "described",
Message: template.HTML(*issue.Body),
Date: "on " + issue.UpdatedAt.Format("January 2 2006, 15:04"),
Avatar: a,
URL: template.URL(*issue.HTMLURL),
})
ret = append(ret, githubIssueActivity{
Name: "",
Event: "Note",
Message: template.HTML("the issue timeline below is in reverse order"),
Date: "",
Avatar: githubGravatar,
URL: template.URL(*issue.HTMLURL),
})
} else {
return ret, err
}
opts := &gogithub.ListOptions{PerPage: config.BranchLines}
guff, _, err := client.Issues.ListIssueTimeline(config.Owner, config.Repo, config.IssueNum, opts)
if err != nil {
return ret, err
}
for _, v := range guff {
if config.SincePtr == nil || v.CreatedAt.After(*config.SincePtr) {
var n, a, m, u string
p := v.Actor
if p != nil {
if p.Name != nil {
n = *p.Name
}
if p.AvatarURL != nil {
a = *p.AvatarURL
}
}
u = fmt.Sprintf("https://github.com/%s/%s/issues/%d#event-%d",
config.Owner, config.Repo, config.IssueNum, *v.ID)
switch *v.Event {
case "commented":
ic, _, err := client.Issues.GetComment(config.Owner, config.Repo, *v.ID)
if err != nil {
log.ErrorString("github error fetching issue event comment: " + err.Error())
} else {
m = *ic.Body
u = *ic.HTMLURL
p := ic.User
if p != nil {
if p.Login != nil {
n = *p.Login
}
if p.AvatarURL != nil {
a = *p.AvatarURL
}
}
}
}
ret = append(ret, githubIssueActivity{
Name: n,
Event: *v.Event,
Message: template.HTML(m),
Date: "on " + v.CreatedAt.Format("January 2 2006, 15:04"),
Avatar: a,
URL: template.URL(u),
})
}
}
return ret, nil
}
*/

View file

@ -0,0 +1,243 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
package github
import (
"encoding/json"
"html/template"
"net/http"
"strconv"
"strings"
"github.com/documize/community/core/log"
"github.com/documize/community/core/section/provider"
gogithub "github.com/google/go-github/github"
)
type githubIssue struct {
ID int `json:"id"`
Date string `json:"date"`
Updated string `json:"dated"`
Message string `json:"message"`
URL template.URL `json:"url"`
Name string `json:"name"`
Avatar string `json:"avatar"`
Labels template.HTML `json:"labels"`
IsOpen bool `json:"isopen"`
}
const tagIssuesData = "issuesData"
func init() {
reports[tagIssuesData] = report{commandIssuesData, refreshIssues, renderIssues, `
<div class="section-github-render">
<p>
{{if .ShowIssueNumbers}}
Showing Selected Issues
{{else}}
{{ .Config.IssueState.Name }}
{{end}}
for repository <a href="{{ .Repo.URL }}/issues">{{.Repo.Name}}</a>
{{if .ShowList}}
labelled
{{range $label := .List}}
{{if $label.Included}}
<span class="github-issue-label" style="background-color:#{{$label.Color}}">{{$label.Name}}</span>
{{end}}
{{end}}
{{end}}
{{if .ShowIssueNumbers}}
issue(s) {{ .DateMessage }}.
{{else}}
up to {{ .Limit }} items are shown{{ .DateMessage }}.
{{end}}
</p>
<div class="github-board">
<ul class="github-list">
{{range $data := .Issues}}
<li class="github-commit-item">
<a class="link" href="{{$data.URL}}">
<div class="issue-avatar">
{{if $data.IsOpen}}
<span title="Open issue">
<svg height="16" version="1.1" viewBox="0 0 14 16" width="14"><path d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
</span>
{{else}}
<span title="Closed issue">
<svg height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M7 10h2v2H7v-2zm2-6H7v5h2V4zm1.5 1.5l-1 1L12 9l4-4.5-1-1L12 7l-1.5-1.5zM8 13.7A5.71 5.71 0 0 1 2.3 8c0-3.14 2.56-5.7 5.7-5.7 1.83 0 3.45.88 4.5 2.2l.92-.92A6.947 6.947 0 0 0 8 1C4.14 1 1 4.14 1 8s3.14 7 7 7 7-3.14 7-7l-1.52 1.52c-.66 2.41-2.86 4.19-5.48 4.19v-.01z"></path></svg>
</span>
{{end}}
</div>
<div class="github-commit-body">
<div class="github-commit-title"><span class="label-name">{{$data.Message}}</span> {{$data.Labels}}</div>
<div class="github-commit-meta">
#{{$data.ID}} opened on {{$data.Date}} by {{$data.Name}}, last updated {{$data.Updated}}
</div>
</div>
</a>
<div class="clearfix" />
</li>
{{end}}
</ul>
</div>
</div>
`}
}
func wrapLabels(labels []gogithub.Label) string {
l := ""
for _, ll := range labels {
l += `<span class="github-issue-label" style="background-color:#` + *ll.Color + `">` + *ll.Name + `</span> `
}
return l
}
func (*Provider) getIssues(client *gogithub.Client, config githubConfig) ([]githubIssue, error) {
ret := []githubIssue{}
isRequired := make([]int, 0, 10)
for _, s := range strings.Split(strings.Replace(config.IssuesText, "#", "", -1), ",") {
i, err := strconv.Atoi(strings.TrimSpace(s))
if err == nil {
isRequired = append(isRequired, i)
}
}
if len(isRequired) > 0 {
for _, i := range isRequired {
issue, _, err := client.Issues.Get(config.Owner, config.Repo, i)
if err == nil {
n := ""
p := issue.User
if p != nil {
if p.Login != nil {
n = *p.Login
}
}
l := wrapLabels(issue.Labels)
ret = append(ret, githubIssue{
Name: n,
Message: *issue.Title,
Date: issue.CreatedAt.Format("January 2 2006, 15:04"),
Updated: issue.UpdatedAt.Format("January 2 2006, 15:04"),
URL: template.URL(*issue.HTMLURL),
Labels: template.HTML(l),
ID: *issue.Number,
IsOpen: *issue.State == "open",
})
}
}
} else {
opts := &gogithub.IssueListByRepoOptions{
Sort: "updated",
State: config.IssueState.ID,
ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}}
if config.SincePtr != nil {
opts.Since = *config.SincePtr
}
for _, lab := range config.Lists {
if lab.Included {
opts.Labels = append(opts.Labels, lab.Name)
}
}
guff, _, err := client.Issues.ListByRepo(config.Owner, config.Repo, opts)
if err != nil {
return ret, err
}
for _, v := range guff {
n := ""
ptr := v.User
if ptr != nil {
if ptr.Login != nil {
n = *ptr.Login
}
}
l := wrapLabels(v.Labels)
ret = append(ret, githubIssue{
Name: n,
Message: *v.Title,
Date: v.CreatedAt.Format("January 2 2006, 15:04"),
Updated: v.UpdatedAt.Format("January 2 2006, 15:04"),
URL: template.URL(*v.HTMLURL),
Labels: template.HTML(l),
ID: *v.Number,
IsOpen: *v.State == "open",
})
}
}
return ret, nil
}
func commandIssuesData(p *Provider, client *gogithub.Client, config githubConfig, w http.ResponseWriter) {
render, err := p.getIssues(client, config)
if err != nil {
log.Error("github getIssues:", err)
provider.WriteError(w, "github", err)
return
}
provider.WriteJSON(w, render)
}
func refreshIssues(p *Provider, c githubConfig, data string) string {
refreshed, err := p.getIssues(p.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)
}
func renderIssues(c *githubConfig, payload *githubRender, data string) error {
raw := []githubIssue{}
if len(data) > 0 {
err := json.Unmarshal([]byte(data), &raw)
if err != nil {
return err
}
}
payload.Issues = raw
if strings.TrimSpace(c.IssuesText) != "" {
payload.ShowIssueNumbers = true
payload.DateMessage = c.IssuesText
} else {
if len(c.Lists) > 0 {
for _, v := range c.Lists {
if v.Included {
payload.ShowList = true
break
}
}
payload.List = c.Lists
}
}
return nil
}

View file

@ -0,0 +1,155 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
package github
import (
"fmt"
"net/http"
"github.com/documize/community/core/log"
"github.com/documize/community/core/section/provider"
gogithub "github.com/google/go-github/github"
)
func listFailed(method string, config githubConfig, client *gogithub.Client, w http.ResponseWriter) (failed bool) {
switch method { // which list to choose?
case "owners":
me, _, err := client.Users.Get("")
if err != nil {
log.Error("github get user details:", err)
provider.WriteError(w, "github", err)
return
}
orgs, _, err := client.Organizations.List("", nil)
if err != nil {
log.Error("github get user's organisations:", err)
provider.WriteError(w, "github", err)
return
}
owners := make([]githubOwner, 1+len(orgs))
owners[0] = githubOwner{ID: *me.Login, Name: *me.Login}
for ko, vo := range orgs {
id := 1 + ko
owners[id].ID = *vo.Login
owners[id].Name = *vo.Login
}
owners = sortOwners(owners)
provider.WriteJSON(w, owners)
case "repos":
var render []githubRepo
if config.Owner != "" {
me, _, err := client.Users.Get("")
if err != nil {
log.Error("github get user details:", err)
provider.WriteError(w, "github", err)
return
}
var repos []*gogithub.Repository
if config.Owner == *me.Login {
repos, _, err = client.Repositories.List(config.Owner, nil)
} else {
opt := &gogithub.RepositoryListByOrgOptions{
ListOptions: gogithub.ListOptions{PerPage: 100},
}
repos, _, err = client.Repositories.ListByOrg(config.Owner, opt)
}
if err != nil {
log.Error("github get user/org repositories:", err)
provider.WriteError(w, "github", err)
return
}
for _, vr := range repos {
private := ""
if *vr.Private {
private = " (private)"
}
render = append(render,
githubRepo{
Name: config.Owner + "/" + *vr.Name + private,
ID: fmt.Sprintf("%s:%s", config.Owner, *vr.Name),
Owner: config.Owner,
Repo: *vr.Name,
Private: *vr.Private,
URL: *vr.HTMLURL,
})
}
}
render = sortRepos(render)
provider.WriteJSON(w, render)
case "branches":
if config.Owner == "" || config.Repo == "" {
provider.WriteJSON(w, []githubBranch{}) // we have nothing to return
return
}
branches, _, err := client.Repositories.ListBranches(config.Owner, config.Repo,
&gogithub.ListOptions{PerPage: 100})
if err != nil {
log.Error("github get branch details:", err)
provider.WriteError(w, "github", err)
return
}
render := make([]githubBranch, len(branches))
for kc, vb := range branches {
render[kc] = githubBranch{
Name: *vb.Name,
ID: fmt.Sprintf("%s:%s:%s", config.Owner, config.Repo, *vb.Name),
Included: false,
URL: "https://github.com/" + config.Owner + "/" + config.Repo + "/tree/" + *vb.Name,
}
}
provider.WriteJSON(w, render)
case "labels":
if config.Owner == "" || config.Repo == "" {
provider.WriteJSON(w, []githubBranch{}) // we have nothing to return
return
}
labels, _, err := client.Issues.ListLabels(config.Owner, config.Repo,
&gogithub.ListOptions{PerPage: 100})
if err != nil {
log.Error("github get labels:", err)
provider.WriteError(w, "github", err)
return
}
render := make([]githubBranch, len(labels))
for kc, vb := range labels {
render[kc] = githubBranch{
Name: *vb.Name,
ID: fmt.Sprintf("%s:%s:%s", config.Owner, config.Repo, *vb.Name),
Included: false,
Color: *vb.Color,
}
}
provider.WriteJSON(w, render)
default:
return true // failed to get a list
}
return
}

View file

@ -12,14 +12,13 @@
package github
import (
"html/template"
"net/http"
"time"
"github.com/documize/community/core/log"
)
const tagIssuesData = "issuesData"
const tagCommitsData = "commitsData"
gogithub "github.com/google/go-github/github"
)
type githubRender struct {
Config githubConfig
@ -36,121 +35,15 @@ type githubRender struct {
DateMessage string
}
var renderTemplates = map[string]string{
tagCommitsData: `
<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>
Showing {{ .Limit }} items {{ .DateMessage }}.
</p>
<div class="github-board">
{{range $data := .BranchCommits}}
<div class="github-group-title">
Commits on {{ $data.Day }}
</div>
<ul class="github-list">
{{range $commit := $data.Commits}}
<li class="github-commit-item">
<a class="link" href="{{$commit.URL}}">
<div class="github-avatar">
<img alt="@{{$commit.Name}}" src="{{$commit.Avatar}}" height="36" width="36">
</div>
<div class="github-commit-body">
<div class="github-commit-title">{{$commit.Message}}</div>
<div class="github-commit-meta">{{$commit.Name}} committed on {{$commit.Date}}</div>
</div>
</a>
<div class="clearfix" />
</li>
{{end}}
</ul>
{{end}}
</div>
</div>
`,
tagIssuesData: `
<div class="section-github-render">
<p>
{{if .ShowIssueNumbers}}
Showing Selected Issues
{{else}}
{{ .Config.IssueState.Name }}
{{end}}
for repository <a href="{{ .Repo.URL }}/issues">{{.Repo.Name}}</a>
{{if .ShowList}}
labelled
{{range $label := .List}}
{{if $label.Included}}
<span class="github-issue-label" style="background-color:#{{$label.Color}}">{{$label.Name}}</span>
{{end}}
{{end}}
{{end}}
{{if .ShowIssueNumbers}}
issue(s) {{ .DateMessage }}.
{{else}}
up to {{ .Limit }} items are shown{{ .DateMessage }}.
{{end}}
</p>
<div class="github-board">
<ul class="github-list">
{{range $data := .Issues}}
<li class="github-commit-item">
<a class="link" href="{{$data.URL}}">
<div class="issue-avatar">
{{if $data.IsOpen}}
<span title="Open issue">
<svg height="16" version="1.1" viewBox="0 0 14 16" width="14"><path d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
</span>
{{else}}
<span title="Closed issue">
<svg height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M7 10h2v2H7v-2zm2-6H7v5h2V4zm1.5 1.5l-1 1L12 9l4-4.5-1-1L12 7l-1.5-1.5zM8 13.7A5.71 5.71 0 0 1 2.3 8c0-3.14 2.56-5.7 5.7-5.7 1.83 0 3.45.88 4.5 2.2l.92-.92A6.947 6.947 0 0 0 8 1C4.14 1 1 4.14 1 8s3.14 7 7 7 7-3.14 7-7l-1.52 1.52c-.66 2.41-2.86 4.19-5.48 4.19v-.01z"></path></svg>
</span>
{{end}}
</div>
<div class="github-commit-body">
<div class="github-commit-title"><span class="label-name">{{$data.Message}}</span> {{$data.Labels}}</div>
<div class="github-commit-meta">
#{{$data.ID}} opened on {{$data.Date}} by {{$data.Name}}, last updated {{$data.Updated}}
</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>
Up to {{ .Limit }} items are shown{{ .DateMessage }}.
</p>
<div class="github-board">
<ul class="github-list">
{{range $data := .IssueNumActivity}}
<li class="github-commit-item">
<div class="github-avatar">
<img alt="@{{$data.Name}}" src="{{$data.Avatar}}" height="36" width="36">
</div>
<div class="github-commit-meta">
{{$data.Name}} <a class="link" href="{{$data.URL}}">{{$data.Event}}</a> {{$data.Date}}
</div>
<div class="github-commit-body">
<div class="github-commit-title">
{{$data.Message}}
</div>
</div>
<div class="clearfix" />
</li>
{{end}}
</ul>
</div>
</div>
`,*/
type report struct {
command func(*Provider, *gogithub.Client, githubConfig, http.ResponseWriter)
refresh func(*Provider, githubConfig, string) string
render func(*githubConfig, *githubRender, string) error
template string
}
var reports = make(map[string]report)
type githubReport struct {
ID string `json:"id"`
Name string `json:"name"`
@ -179,43 +72,6 @@ type githubBranch struct {
Color string `json:"color,omitempty"`
}
type githubBranchCommits struct {
Name string `json:"name"`
Day string `json:"day"`
Commits []githubCommit
}
type githubCommit struct {
Date string `json:"date"`
Message string `json:"message"`
URL template.URL `json:"url"`
Name string `json:"name"`
Avatar string `json:"avatar"`
}
type githubIssue struct {
ID int `json:"id"`
Date string `json:"date"`
Updated string `json:"dated"`
Message string `json:"message"`
URL template.URL `json:"url"`
Name string `json:"name"`
Avatar string `json:"avatar"`
Labels template.HTML `json:"labels"`
IsOpen bool `json:"isopen"`
}
/*
type githubIssueActivity struct {
Date string `json:"date"`
Event string `json:"event"`
Message template.HTML `json:"message"`
URL template.URL `json:"url"`
Name string `json:"name"`
Avatar string `json:"avatar"`
}
*/
type githubConfig struct {
Token string `json:"-"` // NOTE very important that the secret Token is not leaked to the client side, so "-"
UserID string `json:"userId"`

File diff suppressed because one or more lines are too long