1
0
Fork 0
empact/task/sync_contrib.go

44 lines
803 B
Go
Raw Normal View History

2015-03-04 19:08:36 +00:00
package task
import (
"github.com/localhots/steward/db"
)
type (
SyncContribTask struct {
2015-03-04 20:51:17 +00:00
Repo string
db.Task
2015-03-04 19:08:36 +00:00
}
)
func SyncContrib(t SyncContribTask) {
2015-03-04 20:51:17 +00:00
client := newGithubClient(t.Token)
contribs, resp, err := client.Repositories.ListContributorsStats(t.Owner, t.Repo)
saveResponseMeta(t.Token, resp)
2015-03-04 19:08:36 +00:00
if err != nil {
if err.Error() == "EOF" {
// Empty repository, not an actual error
return
}
panic(err)
}
for _, c := range contribs {
for _, week := range c.Weeks {
if *week.Commits == 0 {
continue
}
res = append(res, &db.Contrib{
Week: week.Week.Time.Unix(),
Author: *c.Author.Login,
2015-03-04 20:51:17 +00:00
Owner: t.Owner,
Repo: t.Repo,
2015-03-04 19:08:36 +00:00
Commits: *week.Commits,
Additions: *week.Additions,
Deletions: *week.Deletions,
})
}
}
}