mirror of
https://github.com/documize/community.git
synced 2025-07-21 06:09:42 +02:00
parameterise reports
This commit is contained in:
parent
7d38102eb6
commit
18b61e4ad2
8 changed files with 1530 additions and 1503 deletions
|
@ -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"`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue