// Copyright 2016 Documize Inc. . 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 . // // https://documize.com package github import ( "html/template" "time" "github.com/documize/community/core/log" ) const tagIssuesData = "issuesData" const tagCommitsData = "commitsData" type githubRender struct { Config githubConfig Repo githubRepo List []githubBranch ShowList bool ShowIssueNumbers bool BranchCommits []githubBranchCommits CommitCount int Issues []githubIssue //IssueNum int //IssueNumActivity []githubIssueActivity Limit int DateMessage string } var renderTemplates = map[string]string{ tagCommitsData: `

There are {{ .CommitCount }} commits for branch {{.Config.Branch}} of repository {{.Repo.Name}}. Showing {{ .Limit }} items {{ .DateMessage }}.

{{range $data := .BranchCommits}}
Commits on {{ $data.Day }}
{{end}}
`, tagIssuesData: `

{{if .ShowIssueNumbers}} Showing Selected Issues {{else}} {{ .Config.IssueState.Name }} {{end}} for repository {{.Repo.Name}} {{if .ShowList}} labelled {{range $label := .List}} {{if $label.Included}} {{$label.Name}} {{end}} {{end}} {{end}} {{if .ShowIssueNumbers}} issue(s) {{ .DateMessage }}. {{else}} up to {{ .Limit }} items are shown{{ .DateMessage }}. {{end}}

`, /* "issuenum_data": `

Activity for issue #{{.IssueNum}} in repository {{.Repo.Name}}. Up to {{ .Limit }} items are shown{{ .DateMessage }}.

    {{range $data := .IssueNumActivity}}
  • @{{$data.Name}}
    {{$data.Name}} {{$data.Event}} {{$data.Date}}
    {{$data.Message}}
  • {{end}}
`,*/ } type githubReport struct { ID string `json:"id"` Name string `json:"name"` } type githubOwner struct { ID string `json:"id"` Name string `json:"name"` } type githubRepo struct { ID string `json:"id"` Name string `json:"name"` Included bool `json:"included"` Owner string `json:"owner"` Repo string `json:"repo"` Private bool `json:"private"` // TODO review field use URL string `json:"url"` } type githubBranch struct { ID string `json:"id"` Name string `json:"name"` Included bool `json:"included"` URL string `json:"url"` 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"` PageID string `json:"pageId"` Owner string `json:"owner_name"` Repo string `json:"repo_name"` Branch string `json:"branch"` BranchURL string `json:"branchURL"` BranchSince string `json:"branchSince,omitempty"` SincePtr *time.Time `json:"-"` BranchLines int `json:"branchLines,omitempty,string"` OwnerInfo githubOwner `json:"owner"` RepoInfo githubRepo `json:"repo"` ReportInfo githubReport `json:"report"` ClientID string `json:"clientId"` CallbackURL string `json:"callbackUrl"` Lists []githubBranch `json:"lists,omitempty"` IssueState githubReport `json:"state,omitempty"` IssuesText string `json:"issues,omitempty"` //IssueNum int `json:"issueNum,omitempty,string"` } func (c *githubConfig) Clean() { c.Owner = c.OwnerInfo.Name c.Repo = c.RepoInfo.Repo for _, l := range c.Lists { if l.Included { c.Branch = l.Name c.BranchURL = l.URL break } } 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 } } } type githubCallbackT struct { AccessToken string `json:"access_token"` }