1
0
Fork 0
empact/task/sync_contrib.go

45 lines
812 B
Go
Raw Normal View History

2015-03-04 19:08:36 +00:00
package task
import (
2015-03-05 08:07:18 +00:00
"github.com/localhots/empact/db"
2015-03-04 19:08:36 +00:00
)
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
}
2015-03-05 07:32:47 +00:00
contrib := &db.Contrib{
2015-03-04 19:08:36 +00:00
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,
2015-03-05 07:32:47 +00:00
}
contrib.Save()
2015-03-04 19:08:36 +00:00
}
}
}