Task reports

This commit is contained in:
2015-03-05 03:51:17 +07:00
parent 8ac16bb695
commit ed666552ef
8 changed files with 80 additions and 86 deletions
+7 -19
View File
@@ -2,29 +2,19 @@ package task
import (
"github.com/localhots/steward/db"
"github.com/localhots/steward/job"
)
type (
SyncContribTask struct {
Owner string
Repo string
Token string
job.Task
Repo string
db.Task
}
)
func SyncContrib(t SyncContribTask) {
contribs := fetchContrib(t.Token, t.Owner, t.Repo)
for _, c := range contribs {
db.ImportRepo(c)
}
}
func fetchContrib(token, owner, repo string) (res []*db.Contrib) {
client := newGithubClient(token)
contribs, resp, err := client.Repositories.ListContributorsStats(owner, repo)
saveResponseMeta(token, resp)
client := newGithubClient(t.Token)
contribs, resp, err := client.Repositories.ListContributorsStats(t.Owner, t.Repo)
saveResponseMeta(t.Token, resp)
if err != nil {
if err.Error() == "EOF" {
// Empty repository, not an actual error
@@ -42,14 +32,12 @@ func fetchContrib(token, owner, repo string) (res []*db.Contrib) {
res = append(res, &db.Contrib{
Week: week.Week.Time.Unix(),
Author: *c.Author.Login,
Owner: owner,
Repo: repo,
Owner: t.Owner,
Repo: t.Repo,
Commits: *week.Commits,
Additions: *week.Additions,
Deletions: *week.Deletions,
})
}
}
return
}
+12 -25
View File
@@ -3,50 +3,37 @@ package task
import (
"github.com/google/go-github/github"
"github.com/localhots/steward/db"
"github.com/localhots/steward/job"
)
type (
SyncReposTask struct {
Owner string
Token string
job.Task
db.Task
}
)
func SyncRepos(t SyncReposTask) {
repos := fetchRepos(t.Token, t.Owner)
for _, repo := range repos {
db.ImportRepo(&db.Repo{
Owner: t.Owner,
Name: repo,
})
client := newGithubClient(token)
names := []string{}
opt := &github.RepositoryListByOrgOptions{
ListOptions: github.ListOptions{},
}
}
func fetchRepos(token, owner string) {
var (
client = newGithubClient(token)
names = []string{}
opt = &github.RepositoryListByOrgOptions{
ListOptions: github.ListOptions{},
}
)
for {
opt.Page++
repos, resp, err := client.Repositories.ListByOrg(owner, opt)
saveResponseMeta(token, resp)
repos, resp, err := client.Repositories.ListByOrg(t.Owner, opt)
saveResponseMeta(t.Token, resp)
if err != nil {
panic(err)
}
for _, repo := range repos {
names = append(names, *repo.Name)
r := &db.Repo{
Owner: t.Owner,
Name: *repo.Name,
}
r.Save()
}
if len(repos) < 30 {
break
}
}
return names
}