Org and team charts
This commit is contained in:
+2
-2
@@ -14,12 +14,12 @@ func apiOrgsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func apiTeamsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
req, stat := parseRequest(w, r)
|
||||
teams := db.OrgTeams(stat.org)
|
||||
teams := db.OrgTeams(stat.Org)
|
||||
req.respondWith(teams)
|
||||
}
|
||||
|
||||
func apiReposHandler(w http.ResponseWriter, r *http.Request) {
|
||||
req, stat := parseRequest(w, r)
|
||||
repos := db.OrgRepos(stat.org)
|
||||
repos := db.OrgRepos(stat.Org)
|
||||
req.respondWith(repos)
|
||||
}
|
||||
|
||||
+33
-10
@@ -19,11 +19,13 @@ type (
|
||||
login string
|
||||
}
|
||||
statRequest struct {
|
||||
org string
|
||||
team string
|
||||
user string
|
||||
from int64
|
||||
to int64
|
||||
Org string `structs:"org"`
|
||||
Team string `structs:"team"`
|
||||
User string `structs:"user"`
|
||||
From int64 `structs:"from"`
|
||||
To int64 `structs:"to"`
|
||||
Item string `structs:"item"`
|
||||
Sort string `structs:"sort"`
|
||||
}
|
||||
)
|
||||
|
||||
@@ -71,12 +73,33 @@ func parseStatRequest(r *http.Request) *statRequest {
|
||||
} else {
|
||||
to = time.Now().Unix()
|
||||
}
|
||||
|
||||
var item string
|
||||
switch val := r.FormValue("item"); val {
|
||||
case "author":
|
||||
item = "c.author"
|
||||
case "team":
|
||||
item = "t.name"
|
||||
default:
|
||||
item = "c.repo"
|
||||
}
|
||||
|
||||
var sort string
|
||||
switch val := r.FormValue("sort"); val {
|
||||
case "commits", "delta":
|
||||
sort = val
|
||||
default:
|
||||
sort = "commits"
|
||||
}
|
||||
|
||||
return &statRequest{
|
||||
org: r.FormValue("org"),
|
||||
team: r.FormValue("team"),
|
||||
user: r.FormValue("user"),
|
||||
from: from,
|
||||
to: to,
|
||||
Org: r.FormValue("org"),
|
||||
Team: r.FormValue("team"),
|
||||
User: r.FormValue("user"),
|
||||
From: from,
|
||||
To: to,
|
||||
Item: item,
|
||||
Sort: sort,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-5
@@ -18,15 +18,16 @@ var (
|
||||
func init() {
|
||||
http.HandleFunc("/auth/signin", authSigninHandler)
|
||||
http.HandleFunc("/auth/callback", authCallbackHandler)
|
||||
|
||||
http.HandleFunc("/api/", authHandler)
|
||||
http.HandleFunc("/api/orgs", apiOrgsHandler)
|
||||
http.HandleFunc("/api/teams", apiTeamsHandler)
|
||||
http.HandleFunc("/api/repos", apiReposHandler)
|
||||
http.HandleFunc("/api/stat/repos/top", statOrgReposTop)
|
||||
http.HandleFunc("/api/stat/repos/activity", statOrgReposActivity)
|
||||
http.HandleFunc("/api/stat/teams/top", statOrgTeamsTop)
|
||||
http.HandleFunc("/api/stat/teams/activity", statOrgTeamsActivity)
|
||||
http.HandleFunc("/api/stat/users/top", statOrgUsersTop)
|
||||
|
||||
http.HandleFunc("/api/stat/orgs/top", statOrgTopHandler)
|
||||
http.HandleFunc("/api/stat/orgs/activity", statOrgActivityHandler)
|
||||
http.HandleFunc("/api/stat/teams/top", statTeamTopHandler)
|
||||
http.HandleFunc("/api/stat/teams/activity", statTeamActivityHandler)
|
||||
}
|
||||
|
||||
func Start() {
|
||||
|
||||
+9
-14
@@ -3,35 +3,30 @@ package server
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/fatih/structs"
|
||||
"github.com/localhots/empact/db"
|
||||
)
|
||||
|
||||
func statOrgReposTop(w http.ResponseWriter, r *http.Request) {
|
||||
func statOrgTopHandler(w http.ResponseWriter, r *http.Request) {
|
||||
req, stat := parseRequest(w, r)
|
||||
top := db.StatOrgReposTop(stat.org, stat.from, stat.to)
|
||||
top := db.StatOrgTop(structs.Map(stat))
|
||||
req.respondWith(top)
|
||||
}
|
||||
|
||||
func statOrgReposActivity(w http.ResponseWriter, r *http.Request) {
|
||||
func statOrgActivityHandler(w http.ResponseWriter, r *http.Request) {
|
||||
req, stat := parseRequest(w, r)
|
||||
activity := db.StatOrgReposActivity(stat.org, stat.from, stat.to)
|
||||
activity := db.StatOrgActivity(structs.Map(stat))
|
||||
req.respondWith(activity)
|
||||
}
|
||||
|
||||
func statOrgTeamsTop(w http.ResponseWriter, r *http.Request) {
|
||||
func statTeamTopHandler(w http.ResponseWriter, r *http.Request) {
|
||||
req, stat := parseRequest(w, r)
|
||||
top := db.StatOrgTeamsTop(stat.org, stat.from, stat.to)
|
||||
top := db.StatTeamTop(structs.Map(stat))
|
||||
req.respondWith(top)
|
||||
}
|
||||
|
||||
func statOrgTeamsActivity(w http.ResponseWriter, r *http.Request) {
|
||||
func statTeamActivityHandler(w http.ResponseWriter, r *http.Request) {
|
||||
req, stat := parseRequest(w, r)
|
||||
activity := db.StatOrgTeamsActivity(stat.org, stat.from, stat.to)
|
||||
activity := db.StatTeamActivity(structs.Map(stat))
|
||||
req.respondWith(activity)
|
||||
}
|
||||
|
||||
func statOrgUsersTop(w http.ResponseWriter, r *http.Request) {
|
||||
req, stat := parseRequest(w, r)
|
||||
top := db.StatOrgUsersTop(stat.org, stat.from, stat.to)
|
||||
req.respondWith(top)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user