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

1st cut rejigged edit page, unused code commented out for now

This commit is contained in:
Elliott Stoneham 2016-08-23 17:11:31 +01:00
parent 603db6fc15
commit b42fc1f84d
5 changed files with 221 additions and 143 deletions

View file

@ -52,9 +52,84 @@ func listFailed(method string, config githubConfig, client *gogithub.Client, w h
provider.WriteJSON(w, owners)
case "repos":
/*
case "repos":
var render []githubRepo
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{
Owner: config.Owner,
Repo: config.Repo,
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 "orgrepos":
var render []githubBranch
if config.Owner != "" {
me, _, err := client.Users.Get("")
@ -79,76 +154,48 @@ func listFailed(method string, config githubConfig, client *gogithub.Client, w h
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,
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 = sortRepos(render)
render = sortBranches(render)
provider.WriteJSON(w, render)
case "branches":
/*
case "labels":
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{
Owner: config.Owner,
Repo: config.Repo,
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,
if config.Owner == "" || config.Repo == "" {
provider.WriteJSON(w, []githubBranch{}) // we have nothing to return
return
}
}
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,
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)
provider.WriteJSON(w, render)
*/
default:
return true // failed to get a list

View file

@ -12,7 +12,6 @@
package github
import (
"fmt"
"sort"
"strings"
"time"
@ -86,6 +85,7 @@ type githubBranch struct {
URL string `json:"url"`
Color string `json:"color,omitempty"`
Comma bool `json:"comma"`
Private bool `json:"private"`
}
type githubLabel struct {
@ -155,37 +155,44 @@ func (c *githubConfig) Clean() {
c.Since = (*c.SincePtr).Format(issuesTimeFormat)
// TEST DATA INSERTION DEBUG ONLY!
debugList := map[string][]string{
"community": []string{"master"},
"enterprise": []string{"master"},
"test-data": []string{"master"},
}
c.Lists = make([]githubBranch, 0, len(debugList)*3)
for repo, branches := range debugList {
render := make([]githubBranch, len(branches))
for kc, vb := range branches {
render[kc] = githubBranch{
Owner: "documize",
Repo: repo,
Name: vb,
ID: fmt.Sprintf("%s:%s:%s", "documize", repo, vb),
Included: true,
URL: "https://github.com/" + "documize" + "/" + repo + "/tree/" + vb,
}
/*
debugList := map[string][]string{
"community": []string{"master"},
"enterprise": []string{"master"},
"test-data": []string{"master"},
}
c.Lists = append(c.Lists, render...)
}
c.Owner = "documize"
c.Lists = make([]githubBranch, 0, len(debugList)*3)
for repo, branches := range debugList {
render := make([]githubBranch, len(branches))
for kc, vb := range branches {
render[kc] = githubBranch{
Owner: "documize",
Repo: repo,
Name: vb,
ID: fmt.Sprintf("%s:%s:%s", "documize", repo, vb),
Included: true,
URL: "https://github.com/" + "documize" + "/" + repo + "/tree/" + vb,
}
}
c.Lists = append(c.Lists, render...)
}
c.Owner = "documize"
*/
c.ReportOrder = []string{tagSummaryData, tagMilestonesData, tagIssuesData /*, tagPullRequestData*/, tagCommitsData}
c.BranchLines = 100 // overide js default of 30 with maximum allowable in one call
sort.Stable(branchesToSort(c.Lists)) // get the configured branches in a sensible order for printing
lastItem := 0
for i := range c.Lists {
if i != len(c.Lists)-1 {
c.Lists[i].Comma = true // put the commas in the right places
c.Lists[i].Comma = true
if c.Lists[i].Included {
lastItem = i
}
}
if lastItem < len(c.Lists) {
c.Lists[lastItem].Comma = false
}
}
type githubCallbackT struct {

View file

@ -42,3 +42,10 @@ func sortOwners(in []githubOwner) []githubOwner {
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)
}