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

refactored smart section code

This commit is contained in:
Harvey Kandola 2017-07-21 13:39:53 +01:00
parent 5acfae3d0d
commit 3defc062bd
40 changed files with 172 additions and 306 deletions

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 + "?mode=edit&code=" + gt.AccessToken
http.Redirect(res, req, target, http.StatusTemporaryRedirect)
return nil
}

View file

@ -0,0 +1,317 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize unity 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"
"html/template"
"sort"
"time"
"github.com/documize/community/core/log"
gogithub "github.com/google/go-github/github"
)
const commitTimeFormat = "2006-01-02, 15:04"
type githubCommit struct {
Owner string `json:"owner"`
Repo string `json:"repo"`
ShowRepo bool `json:"showRepo"`
Branch string `json:"branch"`
ShowBranch bool `json:"showBranch"`
Date string `json:"date"`
BinDate time.Time `json:"-"` // only used for sorting
ShowDate bool `json:"showDate"`
Login string `json:"login"`
Name string `json:"name"`
Avatar string `json:"avatar"`
Message string `json:"message"`
URL template.URL `json:"url"`
}
type githubAuthorStats struct {
Author string `json:"author"`
Login string `json:"login"`
Avatar string `json:"avatar"`
CommitCount int `json:"commitCount"`
Repos []string `json:"repos"`
OpenIssues int `json:"openIssues"`
ClosedIssues int `json:"closedIssues"`
}
// order commits in a way that makes sense of the table
type orderCommits []githubCommit
func (s orderCommits) Len() int { return len(s) }
func (s orderCommits) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s orderCommits) Less(i, j int) bool {
if s[i].Repo == s[j].Repo {
if s[i].Branch == s[j].Branch {
if s[i].BinDate == s[j].BinDate {
return s[i].Name < s[j].Name
}
return s[i].BinDate.Before(s[j].BinDate)
}
return s[i].Branch < s[j].Branch
}
return s[i].Repo < s[j].Repo
}
// sort stats in order that that should be presented.
type asToSort []githubAuthorStats
func (s asToSort) Len() int { return len(s) }
func (s asToSort) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s asToSort) Less(i, j int) bool {
return s[i].CommitCount > s[j].CommitCount
}
// sort branches in order that that should be presented.
type branchByID []githubBranch
func (s branchByID) Len() int { return len(s) }
func (s branchByID) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s branchByID) Less(i, j int) bool {
return s[i].ID < s[j].ID
}
const tagCommitsData = "commitsData"
func getCommits(client *gogithub.Client, config *githubConfig) ([]githubCommit, []githubAuthorStats, error) {
if !config.ShowCommits {
return nil, nil, nil
}
// first make sure we've got all the branches
for _, orb := range config.Lists {
if orb.Included {
branches, _, err := client.Repositories.ListBranches(orb.Owner, orb.Repo,
&gogithub.ListOptions{PerPage: 100})
if err == nil {
render := make([]githubBranch, len(branches))
for kc, vb := range branches {
for _, existing := range config.Lists {
if orb.Owner == existing.Owner && orb.Repo == existing.Repo && orb.Name == *vb.Name {
goto found
}
}
render[kc] = githubBranch{
Owner: orb.Owner,
Repo: orb.Repo,
Name: *vb.Name,
ID: fmt.Sprintf("%s:%s:%s", orb.Owner, orb.Repo, *vb.Name),
Included: true,
URL: "https://github.com/" + orb.Owner + "/" + orb.Repo + "/tree/" + *vb.Name,
}
found:
}
config.Lists = append(config.Lists, render...)
}
}
}
sort.Sort(branchByID(config.Lists))
config.UserNames = make(map[string]string)
authorStats := make(map[string]githubAuthorStats)
contribBranch := make(map[string]map[string]struct{})
overall := []githubCommit{}
for _, orb := range config.Lists {
if orb.Included {
opts := &gogithub.CommitsListOptions{
SHA: orb.Name,
ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}}
if config.SincePtr != nil {
opts.Since = *config.SincePtr
}
guff, _, err := client.Repositories.ListCommits(orb.Owner, orb.Repo, opts)
if err != nil {
return nil, nil, err
}
thisBranch := fmt.Sprintf("%s:%s", orb.Repo, orb.Name)
for _, v := range guff {
var d, m, u string
var bd time.Time
if v.Commit != nil {
if v.Commit.Committer.Date != nil {
d = v.Commit.Committer.Date.Format(commitTimeFormat)
bd = *v.Commit.Committer.Date
}
if v.Commit.Message != nil {
m = *v.Commit.Message
}
}
if v.HTMLURL != nil {
u = *v.HTMLURL
}
// author commits
al, an, aa := "", "", githubGravatar
if v.Author != nil {
if v.Author.Login != nil {
al = *v.Author.Login
an = getUserName(client, config, al)
}
if v.Author.AvatarURL != nil {
aa = *v.Author.AvatarURL
}
}
l := al // use author login
overall = append(overall, githubCommit{
Owner: orb.Owner,
Repo: orb.Repo,
Branch: orb.Name,
Name: an,
Login: l,
Message: m,
Date: d,
BinDate: bd,
Avatar: aa,
URL: template.URL(u),
})
if _, ok := contribBranch[l]; !ok {
contribBranch[l] = make(map[string]struct{})
}
contribBranch[l][thisBranch] = struct{}{}
cum := authorStats[l]
cum.Login = l
cum.Author = an
cum.Avatar = aa
cum.CommitCount++
// TODO review, this code removed as too slow
//cmt, _, err := client.Repositories.GetCommit(orb.Owner, orb.Repo, *v.SHA)
//if err == nil {
// if cmt.Stats != nil {
// if cmt.Stats.Total != nil {
// cum.TotalChanges += (*cmt.Stats.Total)
// }
// }
//}
//
authorStats[l] = cum
}
}
}
sort.Sort(orderCommits(overall))
for k := range overall {
overall[k].ShowRepo = true
overall[k].ShowBranch = true
overall[k].ShowDate = true
if k > 0 {
if overall[k].Repo == overall[k-1].Repo {
overall[k].ShowRepo = false
if overall[k].Branch == overall[k-1].Branch {
overall[k].ShowBranch = false
if overall[k].Date == overall[k-1].Date {
overall[k].ShowDate = false
}
}
}
}
}
retStats := make([]githubAuthorStats, 0, len(authorStats))
for _, v := range authorStats {
repos := contribBranch[v.Login]
v.Repos = make([]string, 0, len(repos))
for r := range repos {
v.Repos = append(v.Repos, r)
}
sort.Strings(v.Repos)
retStats = append(retStats, v)
}
sort.Sort(asToSort(retStats))
return overall, retStats, nil
}
func refreshCommits(gr *githubRender, config *githubConfig, client *gogithub.Client) (err error) {
if !config.ShowCommits {
return nil
}
gr.BranchCommits, gr.AuthorStats, err = getCommits(client, config)
if err != nil {
log.Error("github refreshCommits:", err)
return err
}
return nil
}
func renderCommits(payload *githubRender, c *githubConfig) error {
if !c.ShowCommits {
return nil
}
payload.CommitCount = 0
for range payload.BranchCommits {
payload.CommitCount++
}
payload.HasCommits = payload.CommitCount > 0
for i := range payload.Issues {
var author int
for a := range payload.AuthorStats {
if payload.AuthorStats[a].Login == payload.Issues[i].Name ||
(payload.AuthorStats[a].Login == "" && payload.Issues[i].Name == unassignedIssue) {
author = a
goto found
}
}
// no Author found for issue, so create one
payload.AuthorStats = append(payload.AuthorStats, githubAuthorStats{
Author: payload.Issues[i].Name,
Avatar: payload.Issues[i].Avatar,
})
author = len(payload.AuthorStats) - 1
found:
if payload.Issues[i].IsOpen {
payload.AuthorStats[author].OpenIssues++
} else {
payload.AuthorStats[author].ClosedIssues++
}
}
payload.HasAuthorStats = len(payload.AuthorStats) > 0
sort.Sort(asToSort(payload.AuthorStats))
payload.NumContributors = len(payload.AuthorStats) - 1
return nil
}
func init() {
reports[tagCommitsData] = report{refreshCommits, renderCommits, commitsTemplate}
}

View file

@ -0,0 +1,99 @@
// 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
const commitsTemplate = `
<div class="section-github-render">
<!--
{{if .HasAuthorStats}}
<div class="heading">Contributors</div>
<p>
There
{{if eq 1 .NumContributors}}is{{else}}are{{end}}
{{.NumContributors}}
{{if eq 1 .NumContributors}}contributor{{else}}contributors{{end}}
across {{.RepoCount}}
{{if eq 1 .RepoCount}} repository. {{else}} repositories. {{end}}
</p>
<table class="github-table">
<thead>
<tr>
<th class="title">Contributors</th>
<th></th>
</tr>
</thead>
<tbody>
{{range $stats := .AuthorStats}}
<tr>
<td class="no-width">
<img class="github-avatar" alt="@{{$stats.Author}}" src="{{$stats.Avatar}}" />
</td>
<td>
<div class="contributor-name">{{$stats.Author}}</div>
<div class="contributor-meta">
{{if gt $stats.OpenIssues 0}}
assigned {{$stats.OpenIssues}}
{{if eq 1 $stats.OpenIssues}} issue {{else}} issues {{end}}
{{end}}
{{if gt $stats.ClosedIssues 0}}
&middot; {{$stats.ClosedIssues}} closed
{{end}}
{{if gt $stats.CommitCount 0}}
{{if gt $stats.OpenIssues 0}} &middot; {{end}}
{{if gt $stats.ClosedIssues 0}} &middot; {{end}}
made {{$stats.CommitCount}}
{{if eq 1 $stats.CommitCount}} commit {{else}} commits {{end}}
on {{len $stats.Repos}} {{if eq 1 (len $stats.Repos)}} branch {{else}} branches {{end}}
{{range $repo := $stats.Repos}} &middot; {{$repo}} {{end}}
{{end}}
</div>
</td>
</tr>
{{end}}
</tbody>
</table>
{{end}}
-->
{{if .HasCommits}}
<table class="github-table" style="width: 100%;">
<thead>
<tr>
<th class="title">Commits <span>&middot; {{len .BranchCommits}} commits</span>
</th>
<th></th>
</tr>
</thead>
<tbody>
{{range $commit := .BranchCommits}}
<tr>
<td>
<a href="{{$commit.URL}}">{{$commit.Message}}</a>
<span class="data"> {{$commit.Branch}}</span>
</td>
<td class="right-column">
<div class="contributor-meta">
{{$commit.Date}}
<img class="github-avatar" title="@{{$commit.Name}}" alt="@{{$commit.Name}}" src="{{$commit.Avatar}}" />
</div>
</td>
</tr>
{{end}}
</tbody>
</table>
{{end}}
</div>
`

View file

@ -0,0 +1,253 @@
// 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 (
"bytes"
"encoding/json"
"errors"
"html/template"
"io/ioutil"
"net/http"
"strings"
"github.com/documize/community/core/env"
"github.com/documize/community/domain/section/provider"
gogithub "github.com/google/go-github/github"
)
// TODO find a smaller image than the one below
const githubGravatar = "https://i2.wp.com/assets-cdn.github.com/images/gravatars/gravatar-user-420.png"
var meta provider.TypeMeta
func init() {
meta = provider.TypeMeta{}
meta.ID = "38c0e4c5-291c-415e-8a4d-262ee80ba5df"
meta.Title = "GitHub"
meta.Description = "Link code commits and issues"
meta.ContentType = "github"
meta.PageType = "tab"
meta.Callback = Callback
}
// Provider represents GitHub
type Provider struct {
Runtime env.Runtime
}
// Meta describes us.
func (*Provider) Meta() provider.TypeMeta {
return meta
}
// Command to run the various functions required...
func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
method := query.Get("method")
if len(method) == 0 {
msg := "missing method name"
provider.WriteMessage(w, "gitub", msg)
return
}
if method == "config" {
var ret struct {
CID string `json:"clientID"`
URL string `json:"authorizationCallbackURL"`
}
ret.CID = clientID()
ret.URL = authorizationCallbackURL()
provider.WriteJSON(w, ret)
return
}
defer r.Body.Close() // ignore error
body, err := ioutil.ReadAll(r.Body)
if err != nil {
p.Runtime.Log.Error("bad body", errors.New("Missing body"))
provider.WriteMessage(w, "github", "bad body")
return
}
if method == "saveSecret" { // secret Token update code
// write the new one, direct from JS
if err = ctx.SaveSecrets(string(body)); err != nil {
p.Runtime.Log.Error("github settoken configuration", err)
provider.WriteError(w, "github", err)
return
}
provider.WriteEmpty(w)
return
}
// load the config from the client-side
config := githubConfig{}
err = json.Unmarshal(body, &config)
if err != nil {
p.Runtime.Log.Error("github Command Unmarshal", err)
provider.WriteError(w, "github", err)
return
}
config.Clean()
// always use DB version of the token
config.Token = ctx.GetSecrets("token") // get the secret token in the database
client := p.githubClient(&config)
switch method {
case "checkAuth":
if len(config.Token) == 0 {
err = errors.New("empty github token")
} else {
err = validateToken(config.Token)
}
if err != nil {
// token now invalid, so wipe it
ctx.SaveSecrets("") // ignore error, already in an error state
p.Runtime.Log.Error("github check token validation", err)
provider.WriteError(w, "github", err)
return
}
provider.WriteEmpty(w)
default:
if listFailed(p.Runtime, method, config, client, w) {
gr := githubRender{}
for _, rep := range reports {
rep.refresh(&gr, &config, client)
}
provider.WriteJSON(w, &gr)
}
}
}
// Refresh ... gets the latest version
func (p *Provider) Refresh(ctx *provider.Context, configJSON, data string) string {
var c = githubConfig{}
err := json.Unmarshal([]byte(configJSON), &c)
if err != nil {
p.Runtime.Log.Error("unable to unmarshall github config", err)
return "internal configuration error '" + err.Error() + "'"
}
c.Clean()
c.Token = ctx.GetSecrets("token")
client := p.githubClient(&c)
byts, err := json.Marshal(refreshReportData(&c, client))
if err != nil {
p.Runtime.Log.Error("unable to marshall github data", err)
return "internal configuration error '" + err.Error() + "'"
}
return string(byts)
}
func refreshReportData(c *githubConfig, client *gogithub.Client) *githubRender {
var gr = githubRender{}
for _, rep := range reports {
rep.refresh(&gr, c, client)
}
return &gr
}
// Render ... just returns the data given, suitably formatted
func (p *Provider) Render(ctx *provider.Context, config, data string) string {
var err error
payload := githubRender{}
var c = githubConfig{}
err = json.Unmarshal([]byte(config), &c)
if err != nil {
p.Runtime.Log.Error("unable to unmarshall github config", err)
return "Please delete and recreate this Github section."
}
c.Clean()
c.Token = ctx.GetSecrets("token")
data = strings.TrimSpace(data)
if len(data) == 0 {
// TODO review why this error occurs & if it should be reported - seems to occur for new sections
// log.ErrorString(fmt.Sprintf("Rendered empty github JSON payload as '' for owner %s repos %#v", c.Owner, c.Lists))
return ""
}
err = json.Unmarshal([]byte(data), &payload)
if err != nil {
p.Runtime.Log.Error("unable to unmarshall github data", err)
return "Please delete and recreate this Github section."
}
payload.Config = c
payload.Limit = c.BranchLines
payload.List = c.Lists
ret := ""
for _, repID := range c.ReportOrder {
rep, ok := reports[repID]
if !ok {
msg := "github report not found for: " + repID
p.Runtime.Log.Info(msg)
return "Documize internal error: " + msg
}
if err = rep.render(&payload, &c); err != nil {
p.Runtime.Log.Error("unable to render "+repID, err)
return "Documize internal github render " + repID + " error: " + err.Error() + "<BR>" + data
}
t := template.New("github")
t, err = t.Parse(rep.template)
if err != nil {
p.Runtime.Log.Error("github render template.Parse error:", err)
//for k, v := range strings.Split(rep.template, "\n") {
// fmt.Println("DEBUG", k+1, v)
//}
return "Documize internal github template.Parse error: " + err.Error()
}
buffer := new(bytes.Buffer)
err = t.Execute(buffer, payload)
if err != nil {
p.Runtime.Log.Error("github render template.Execute error:", err)
return "Documize internal github template.Execute error: " + err.Error()
}
ret += buffer.String()
}
return ret
}

View file

@ -0,0 +1,244 @@
// 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 (
"html/template"
"sort"
"time"
"github.com/documize/community/core/log"
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"`
Creator string `json:"creator"`
Avatar string `json:"avatar"`
Labels template.HTML `json:"labels"`
LabelNames []string `json:"labelNames"`
LabelColors []string `json:"labelColors"`
IsOpen bool `json:"isopen"`
Repo string `json:"repo"`
Private bool `json:"private"`
Milestone string `json:"milestone"`
}
type githubSharedLabel struct {
Name string `json:"name"`
Count int `json:"count"`
Color string `json:"color"`
Repos template.HTML `json:"Repos"`
}
// sort issues in order that that should be presented - by date updated.
type issuesToSort []githubIssue
func (s issuesToSort) Len() int { return len(s) }
func (s issuesToSort) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s issuesToSort) Less(i, j int) bool {
if s[i].Milestone != noMilestone && s[j].Milestone == noMilestone {
return true
}
if s[i].Milestone == noMilestone && s[j].Milestone != noMilestone {
return false
}
if s[i].Milestone != s[j].Milestone {
// TODO should this order be by milestone completion?
return s[i].Milestone < s[j].Milestone
}
if !s[i].IsOpen && s[j].IsOpen {
return true
}
if s[i].IsOpen && !s[j].IsOpen {
return false
}
// TODO this seems a very slow approach
iDate, iErr := time.Parse(issuesTimeFormat, s[i].Updated)
log.IfErr(iErr)
jDate, jErr := time.Parse(issuesTimeFormat, s[j].Updated)
log.IfErr(jErr)
return iDate.Before(jDate)
}
// sort shared labels alphabetically
type sharedLabelsSort []githubSharedLabel
func (s sharedLabelsSort) Len() int { return len(s) }
func (s sharedLabelsSort) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s sharedLabelsSort) Less(i, j int) bool { return s[i].Name < s[j].Name }
const (
tagIssuesData = "issuesData"
issuesTimeFormat = "January 2 2006, 15:04"
unassignedIssue = "(unassigned)"
)
func init() {
reports[tagIssuesData] = report{refreshIssues, renderIssues, issuesTemplate}
}
func wrapLabels(labels []gogithub.Label) (l string, labelNames []string, labelColors []string) {
labelNames = make([]string, 0, len(labels))
labelColors = make([]string, 0, len(labels))
for _, ll := range labels {
labelNames = append(labelNames, *ll.Name)
labelColors = append(labelColors, *ll.Color)
l += `<span class="issue-label" style="background-color:#` + *ll.Color + `">` + *ll.Name + `</span> `
}
return l, labelNames, labelColors
}
func getIssues(client *gogithub.Client, config *githubConfig) ([]githubIssue, error) {
if !config.ShowIssues {
return nil, nil
}
ret := []githubIssue{}
hadRepo := make(map[string]bool)
for _, orb := range config.Lists {
if orb.Included {
rName := orb.Owner + "/" + orb.Repo
if !hadRepo[rName] {
for _, state := range []string{"open", "closed"} {
opts := &gogithub.IssueListByRepoOptions{
Sort: "updated",
State: state,
ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}}
if config.SincePtr != nil && state == "closed" /* we want all the open ones */ {
opts.Since = *config.SincePtr
}
guff, _, err := client.Issues.ListByRepo(orb.Owner, orb.Repo, opts)
if err != nil {
return ret, err
}
for _, v := range guff {
n := unassignedIssue
av := githubGravatar
ptr := v.Assignee
if ptr != nil {
if ptr.Login != nil {
n = *ptr.Login
av = *ptr.AvatarURL
}
}
ms := noMilestone
if v.Milestone != nil {
if v.Milestone.Title != nil {
ms = *v.Milestone.Title
}
}
l, ln, lc := wrapLabels(v.Labels)
ret = append(ret, githubIssue{
Name: n,
Creator: getUserName(client, config, *v.User.Login),
Avatar: av,
Message: *v.Title,
Date: v.CreatedAt.Format(issuesTimeFormat),
Updated: v.UpdatedAt.Format(issuesTimeFormat),
URL: template.URL(*v.HTMLURL),
Labels: template.HTML(l),
LabelNames: ln,
LabelColors: lc,
ID: *v.Number,
IsOpen: *v.State == "open",
Repo: repoName(rName),
Private: orb.Private,
Milestone: ms,
})
}
}
}
hadRepo[rName] = true
}
}
sort.Sort(issuesToSort(ret))
return ret, nil
}
func refreshIssues(gr *githubRender, config *githubConfig, client *gogithub.Client) (err error) {
if !config.ShowIssues {
return nil
}
gr.Issues, err = getIssues(client, config)
if err != nil {
log.Error("unable to get github issues (cmd)", err)
return err
}
gr.OpenIssues = 0
gr.ClosedIssues = 0
sharedLabels := make(map[string][]string)
sharedLabelColors := make(map[string]string)
for _, v := range gr.Issues {
if v.IsOpen {
gr.OpenIssues++
} else {
gr.ClosedIssues++
}
for i, lab := range v.LabelNames {
sharedLabels[lab] = append(sharedLabels[lab], v.Repo)
if _, exists := sharedLabelColors[lab]; !exists { // use the first one we see
sharedLabelColors[lab] = v.LabelColors[i]
}
}
}
gr.HasIssues = (gr.OpenIssues + gr.ClosedIssues) > 0
gr.SharedLabels = make([]githubSharedLabel, 0, len(sharedLabels)) // will usually be too big
for name, repos := range sharedLabels {
if len(repos) > 1 {
thisLab := githubSharedLabel{Name: name, Count: len(repos), Color: sharedLabelColors[name]}
show := ""
for i, r := range repos {
if i > 0 {
show += ", "
}
show += "<a href='https://github.com/" + config.Owner + "/" + r +
"/issues?q=is%3Aissue+label%3A" + name + "'>" + r + "</a>"
}
thisLab.Repos = template.HTML(show)
gr.SharedLabels = append(gr.SharedLabels, thisLab)
}
}
sort.Sort(sharedLabelsSort(gr.SharedLabels))
gr.HasSharedLabels = len(gr.SharedLabels) > 0
return nil
}
func renderIssues(payload *githubRender, c *githubConfig) error {
return nil
}

View file

@ -0,0 +1,68 @@
// 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
const (
openIsvg = `
<span class="issue-state" title="Open Issue">
<svg height="16" version="1.1" viewBox="0 0 14 16" width="14" class="color:#6cc644;">
<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>
`
closedIsvg = `
<span class="issue-state" title="Closed Issue">
<svg height="16" version="1.1" viewBox="0 0 16 16" width="16" class="color:#bd2c00;">
<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>
`
issuesTemplate = `
<div class="section-github-render">
{{if .HasIssues}}
<table class="github-table" style="width: 100%;">
<thead>
<tr>
<th class="title">
Issues <span>&middot; {{.ClosedIssues}} closed {{if eq 1 .ClosedIssues}}{{else}}issues{{end}} and {{.OpenIssues}} open
{{if eq 1 .OpenIssues}}issue{{else}}{{end}}</span>
</th>
<th></th>
</tr>
</thead>
<tbody>
{{range $data := .Issues}}
<tr>
<td>
{{if $data.IsOpen}}
` + openIsvg + `
{{else}}
` + closedIsvg + `
{{end}}
<a href="{{$data.URL}}">{{$data.Message}}</a> <span class="data">#{{$data.ID}}</span>
{{$data.Labels}}
</td>
<td class="right-column">
<div class="milestone-meta">
<span class="meta-milestone">{{$data.Milestone}}</span> &middot;
<span class="meta-creator">{{$data.Creator}}</span> &middot; <span class="meta-date">{{$data.Date}}</span>
</div>
</td>
</tr>
{{end}}
</tbody>
</table>
{{end}}
</div>
`
)

View file

@ -0,0 +1,105 @@
// 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/env"
"github.com/documize/community/domain/section/provider"
gogithub "github.com/google/go-github/github"
)
func listFailed(rt env.Runtime, 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 {
rt.Log.Error("github get user details:", err)
provider.WriteError(w, "github", err)
return
}
orgs, _, err := client.Organizations.List("", nil)
if err != nil {
rt.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 "orgrepos":
var render []githubBranch
if config.Owner != "" {
me, _, err := client.Users.Get("")
if err != nil {
rt.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 {
rt.Log.Error("github get user/org repositories:", err)
provider.WriteError(w, "github", err)
return
}
for _, vr := range repos {
render = append(render,
githubBranch{
Name: "master",
ID: fmt.Sprintf("%s:%s", config.Owner, *vr.Name),
Owner: config.Owner,
Repo: *vr.Name,
Private: *vr.Private,
Included: false,
URL: *vr.HTMLURL,
})
}
}
render = sortBranches(render)
provider.WriteJSON(w, render)
case "content":
provider.WriteJSON(w, refreshReportData(&config, client))
default:
return true // failed to get a list
}
return
}

View file

@ -0,0 +1,227 @@
// 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"
"html/template"
"sort"
"github.com/documize/community/core/log"
gogithub "github.com/google/go-github/github"
)
type githubMilestone struct {
Repo string `json:"repo"`
Private bool `json:"private"`
Name string `json:"name"`
URL template.URL `json:"url"`
IsOpen bool `json:"isopen"`
OpenIssues int `json:"openIssues"`
ClosedIssues int `json:"closedIssues"`
CompleteMsg string `json:"completeMsg"`
DueDate string `json:"dueDate"`
UpdatedAt string `json:"updatedAt"`
Progress uint `json:"progress"`
IsMilestone bool `json:"isMilestone"`
}
// sort milestones in order that that should be presented.
type milestonesToSort []githubMilestone
func (s milestonesToSort) Len() int { return len(s) }
func (s milestonesToSort) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s milestonesToSort) Less(i, j int) bool {
if s[i].Repo < s[j].Repo {
return true
}
if s[i].Repo > s[j].Repo {
return false
}
if !s[i].IsOpen && s[j].IsOpen {
return true
}
if s[i].IsOpen && !s[j].IsOpen {
return false
}
if s[i].Name != noMilestone && s[j].Name == noMilestone {
return true
}
if s[i].Name == noMilestone && s[j].Name != noMilestone {
return false
}
if s[i].Progress == s[j].Progress { // order equal progress milestones
return s[i].Name < s[j].Name
}
return s[i].Progress >= s[j].Progress // put more complete milestones first
}
const (
tagMilestonesData = "milestonesData"
milestonesTimeFormat = "January 2 2006"
noMilestone = "no milestone"
)
func init() {
reports[tagMilestonesData] = report{refreshMilestones, renderMilestones, milestonesTemplate}
}
func getMilestones(client *gogithub.Client, config *githubConfig) ([]githubMilestone, error) {
if !config.ShowMilestones {
return nil, nil
}
ret := []githubMilestone{}
hadRepo := make(map[string]bool)
for _, orb := range config.Lists {
if orb.Included {
rName := orb.Owner + "/" + orb.Repo
if !hadRepo[rName] {
for _, state := range []string{"open", "closed"} {
opts := &gogithub.MilestoneListOptions{
Sort: "updated",
State: state,
ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}}
guff, _, err := client.Issues.ListMilestones(orb.Owner, orb.Repo, opts)
if err != nil {
return ret, err
}
for _, v := range guff {
include := true
if state == "closed" {
if config.SincePtr != nil {
if (*config.SincePtr).After(*v.ClosedAt) {
include = false
}
}
}
if include {
dd := "no due date"
if v.DueOn != nil {
// TODO refactor to add message in red if the milestone is overdue
dd = "due " + (*v.DueOn).Format(milestonesTimeFormat) + ""
}
up := ""
if v.UpdatedAt != nil {
up = (*v.UpdatedAt).Format(milestonesTimeFormat)
}
progress := float64(*v.ClosedIssues*100) / float64(*v.OpenIssues+*v.ClosedIssues)
ret = append(ret, githubMilestone{
Repo: repoName(rName),
Private: orb.Private,
Name: *v.Title,
URL: template.URL(fmt.Sprintf(
"https://github.com/%s/%s/milestone/%d",
orb.Owner, orb.Repo, *v.Number)), // *v.HTMLURL does not give the correct value
IsOpen: *v.State == "open",
OpenIssues: *v.OpenIssues,
ClosedIssues: *v.ClosedIssues,
CompleteMsg: fmt.Sprintf("%2.0f%%", progress),
DueDate: dd,
UpdatedAt: up,
Progress: uint(progress),
IsMilestone: true,
})
}
}
}
}
hadRepo[rName] = true
}
}
return ret, nil
}
func refreshMilestones(gr *githubRender, config *githubConfig, client *gogithub.Client) (err error) {
if !config.ShowMilestones {
return nil
}
gr.Milestones, err = getMilestones(client, config)
if err != nil {
log.Error("unable to get github milestones", err)
return err
}
gr.OpenMS = 0
gr.ClosedMS = 0
for _, v := range gr.Milestones {
if v.IsOpen {
gr.OpenMS++
} else {
gr.ClosedMS++
}
}
gr.HasMilestones = (gr.OpenMS + gr.ClosedMS) > 0
return nil
}
func renderMilestones(payload *githubRender, c *githubConfig) error {
if !c.ShowMilestones {
return nil
}
hadRepo := make(map[string]bool)
payload.RepoCount = 0
for _, orb := range payload.List {
rName := orb.Owner + "/" + orb.Repo
if !hadRepo[rName] {
if orb.Included {
payload.RepoCount++
issuesOpen, issuesClosed := 0, 0
for _, iss := range payload.Issues {
if iss.Repo == repoName(rName) {
if iss.Milestone == noMilestone {
if iss.IsOpen {
issuesOpen++
} else {
issuesClosed++
}
}
}
}
if issuesClosed+issuesOpen > 0 {
//payload.Milestones = append(payload.Milestones, githubMilestone{
// Repo: orb.Repo, Private: orb.Private, Name: noMilestone, IsOpen: true,
// OpenIssues: issuesOpen, ClosedIssues: issuesClosed, URL: template.URL(orb.URL),
//})
}
hadRepo[rName] = true
}
}
}
sort.Sort(milestonesToSort(payload.Milestones))
return nil
}

View file

@ -0,0 +1,75 @@
// 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
const (
rawMSsvg = `<path d="M8 2H6V0h2v2zm4 5H2c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h10l2 2-2 2zM8 4H6v2h2V4zM6 16h2V8H6v8z"></path>`
openMSsvg = `
<span class="issue-state" title="Open Milestone">
<svg height="16" width="14" version="1.1" viewBox="0 0 14 16">
` + rawMSsvg + `
</svg>
</span>
`
closedMSsvg = `
<span class="issue-state" title="Closed Milestone">
<svg aria-hidden="true" class="octicon octicon-check" height="16" height="14" version="1.1" viewBox="0 0 12 16">
<path d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5z"></path>
</svg>
</span>
`
milestonesTemplate = `
<div class="section-github-render">
{{if .HasMilestones}}
<table class="github-table" style="width: 100%;">
<thead>
<tr>
<th class="title">Milestones <span>&middot; {{.ClosedMS}} closed and {{.OpenMS}} open</span>
</th>
<th></th>
</tr>
</thead>
<tbody>
{{range $data := .Milestones}}
<tr>
<td>
{{if $data.IsMilestone}}
{{if $data.IsOpen}}
` + openMSsvg + `
{{else}}
` + closedMSsvg + `
{{end}}
{{end}}
<a class="link" href="{{$data.URL}}">{{$data.Name}}</a>
<span class="data"> &middot; {{if $data.IsMilestone}} {{$data.DueDate}}{{end}} </span>
</td>
<td class="right-column">
{{if $data.IsMilestone}}
<span class="bold color-off-black">{{$data.CompleteMsg}}</span> complete
<span class="bold color-off-black">{{$data.OpenIssues}}</span> open
<span class="bold color-off-black">{{$data.ClosedIssues}}</span> closed
{{else}}
<span class="bold color-off-black">{{$data.OpenIssues}}</span> open <span class="bold color-off-black">{{$data.ClosedIssues}}</span> closed
{{end}}
<div class="progress-bar">
<div class="progress" style="width:{{$data.Progress}}%;"></div>
</div>
</td>
</tr>
{{end}}
</tbody>
</table>
{{end}}
</div>
`
)

View file

@ -0,0 +1,200 @@
// 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 (
"sort"
"strings"
"time"
"github.com/documize/community/core/log"
gogithub "github.com/google/go-github/github"
)
type githubRender struct {
Config githubConfig `json:"config"`
List []githubBranch `json:"list"`
RepoCount int `json:"repoCount"`
ShowList bool `json:"showList"`
ShowIssueNumbers bool `json:"showIssueNumbers"`
BranchCommits []githubCommit `json:"branchCommits"`
HasCommits bool `json:"hasCommits"`
CommitCount int `json:"commitCount"`
Issues []githubIssue `json:"issues"`
HasIssues bool `json:"hasIssues"`
SharedLabels []githubSharedLabel `json:"sharedLabels"`
HasSharedLabels bool `json:"hasSharedLabels"`
OpenIssues int `json:"openIssues"`
ClosedIssues int `json:"closedIssues"`
Limit int `json:"limit"`
Milestones []githubMilestone `json:"milestones"`
HasMilestones bool `json:"hasMilestones"`
OpenMS int `json:"openMS"`
ClosedMS int `json:"closedMS"`
OpenPRs int `json:"openPRs"`
ClosedPRs int `json:"closedPRs"`
AuthorStats []githubAuthorStats `json:"authorStats"`
HasAuthorStats bool `json:"hasAuthorStats"`
NumContributors int `json:"numContributors"`
}
type report struct {
refresh func(*githubRender, *githubConfig, *gogithub.Client) error
render func(*githubRender, *githubConfig) error
template string
}
var reports = make(map[string]report)
type githubOwner struct {
ID string `json:"id"`
Name string `json:"name"`
}
type githubBranch struct {
ID string `json:"id"`
Owner string `json:"owner"`
Repo string `json:"repo"`
Name string `json:"name"`
Included bool `json:"included"`
URL string `json:"url"`
Color string `json:"color,omitempty"`
Comma bool `json:"comma"`
Private bool `json:"private"`
}
type githubLabel struct {
ID string `json:"id"`
Owner string `json:"owner"`
Repo string `json:"repo"`
Name string `json:"name"`
Included bool `json:"included"`
URL string `json:"url"`
Color string `json:"color,omitempty"`
}
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"`
PageID string `json:"pageId"`
Owner string `json:"owner_name"`
BranchSince string `json:"branchSince,omitempty"`
SincePtr *time.Time `json:"-"`
Since string `json:"-"`
BranchLines int `json:"branchLines,omitempty,string"`
OwnerInfo githubOwner `json:"owner"`
ClientID string `json:"clientId"`
CallbackURL string `json:"callbackUrl"`
Lists []githubBranch `json:"lists,omitempty"`
ReportOrder []string `json:"-"`
DateMessage string `json:"-"`
UserNames map[string]string `json:"UserNames"`
ShowMilestones bool `json:"showMilestones,omitempty"`
ShowIssues bool `json:"showIssues,omitempty"`
ShowCommits bool `json:"showCommits,omitempty"`
}
func (c *githubConfig) Clean() {
c.Owner = c.OwnerInfo.Name
if len(c.BranchSince) >= len("yyyy/mm/dd hh:ss") {
var since time.Time
tt := []byte("yyyy-mm-ddThh:mm:00Z")
for _, i := range []int{0, 1, 2, 3, 5, 6, 8, 9, 11, 12, 14, 15} {
tt[i] = c.BranchSince[i]
}
err := since.UnmarshalText(tt)
if err != nil {
log.ErrorString("Date unmarshall '" + c.BranchSince + "'->'" + string(tt) + "' error: " + err.Error())
} else {
c.SincePtr = &since
}
}
if c.SincePtr == nil {
c.DateMessage = " (the last 7 days)"
since := time.Now().AddDate(0, 0, -7)
c.SincePtr = &since
} else {
c.DateMessage = ""
}
c.Since = (*c.SincePtr).Format(issuesTimeFormat)
c.ReportOrder = []string{tagSummaryData}
if c.ShowMilestones {
c.ReportOrder = append(c.ReportOrder, tagMilestonesData)
}
if c.ShowIssues {
c.ReportOrder = append(c.ReportOrder, tagIssuesData)
}
if c.ShowCommits {
c.ReportOrder = append(c.ReportOrder, tagCommitsData)
}
c.BranchLines = 100 // overide any existing value with maximum allowable in one call
sort.Sort(branchesToSort(c.Lists)) // get the configured branches in a sensible order for display
lastItem := 0
for i := range c.Lists {
c.Lists[i].Comma = true
if c.Lists[i].Included {
lastItem = i
}
}
if lastItem < len(c.Lists) {
c.Lists[lastItem].Comma = false
}
if c.UserNames == nil {
c.UserNames = make(map[string]string)
}
}
type githubCallbackT struct {
AccessToken string `json:"access_token"`
}
func repoName(branchName string) string {
bits := strings.Split(branchName, "/")
if len(bits) != 2 {
return branchName + "?repo"
}
pieces := strings.Split(bits[1], ":")
if len(pieces) == 0 {
return branchName + "?repo:?branch"
}
return pieces[0]
}
func getUserName(client *gogithub.Client, config *githubConfig, login string) (fullName string) {
an := login
if content, found := config.UserNames[login]; found {
if len(content) > 0 {
an = content
}
} else {
usr, _, err := client.Users.Get(login)
if err == nil {
if usr.Name != nil {
if len(*usr.Name) > 0 {
config.UserNames[login] = *usr.Name
an = *usr.Name
}
}
} else {
config.UserNames[login] = login // don't look again for a missing name
}
}
return an
}

View file

@ -0,0 +1,36 @@
// 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 "sort"
// sort owners in order that that should be presented.
type ownersToSort []githubOwner
func (s ownersToSort) Len() int { return len(s) }
func (s ownersToSort) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s ownersToSort) Less(i, j int) bool {
return s[i].Name < s[j].Name
}
func sortOwners(in []githubOwner) []githubOwner {
sts := ownersToSort(in)
sort.Sort(sts)
return []githubOwner(sts)
}
// sort branches in order that that should be presented.
func sortBranches(in []githubBranch) []githubBranch {
sts := branchesToSort(in)
sort.Sort(sts)
return []githubBranch(sts)
}

View file

@ -0,0 +1,42 @@
// 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 (
gogithub "github.com/google/go-github/github"
)
const (
tagSummaryData = "summaryData"
)
// sort branches in order that that should be presented.
type branchesToSort []githubBranch
func (s branchesToSort) Len() int { return len(s) }
func (s branchesToSort) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s branchesToSort) Less(i, j int) bool {
return s[i].URL < s[j].URL
}
func init() {
reports[tagSummaryData] = report{refreshSummary, renderSummary, summaryTemplate}
}
func refreshSummary(gr *githubRender, config *githubConfig, client *gogithub.Client) (err error) {
return nil
}
func renderSummary(payload *githubRender, c *githubConfig) error {
return nil
}

View file

@ -0,0 +1,48 @@
// 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
const summaryTemplate = `
<div class="section-github-render">
<p>Activity since {{.Config.Since}}{{.Config.DateMessage}} for {{.Config.Owner}} repository
{{range $data := .Config.Lists}}
{{if $data.Included}}
<a class="link" href="{{$data.URL}}">
{{$data.Repo}}{{if $data.Comma}},{{end}}
</a>
{{end}}
{{end}}
</p>
<!--
{{if .HasSharedLabels}}
<div class="heading">Labels</div>
<p>There
{{if eq 1 (len .SharedLabels)}} is {{else}} are {{end}}
{{len .SharedLabels}}
shared
{{if eq 1 (len .SharedLabels)}} label {{else}} labels {{end}}
across the repositories.</p>
<table class="github-table">
<tbody>
{{range $slabel := .SharedLabels}}
<tr>
<td class="no-width"><span class="issue-label" style="background-color:#{{$slabel.Color}}">{{$slabel.Name}} ({{$slabel.Count}})</span></td>
<td>{{$slabel.Repos}}</td>
</tr>
{{end}}
</tbody>
</table>
{{end}}
-->
</div>
`