empact/task/sync_contrib.go

46 lines
833 B
Go
Raw Normal View History

2015-03-05 02:08:36 +07:00
package task
import (
2015-03-05 15:07:18 +07:00
"github.com/localhots/empact/db"
2015-03-05 02:08:36 +07:00
)
type (
SyncContribTask struct {
2015-03-05 03:51:17 +07:00
Repo string
2015-03-05 19:57:36 +07:00
*db.Task
2015-03-05 02:08:36 +07:00
}
)
2015-03-05 19:57:36 +07:00
func SyncContrib(tk Tasker) {
t := tk.(*SyncContribTask)
2015-03-05 03:51:17 +07:00
client := newGithubClient(t.Token)
contribs, resp, err := client.Repositories.ListContributorsStats(t.Owner, t.Repo)
saveResponseMeta(t.Token, resp)
2015-03-05 02:08:36 +07: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 14:32:47 +07:00
contrib := &db.Contrib{
2015-03-05 02:08:36 +07:00
Week: week.Week.Time.Unix(),
Author: *c.Author.Login,
2015-03-05 03:51:17 +07:00
Owner: t.Owner,
Repo: t.Repo,
2015-03-05 02:08:36 +07:00
Commits: *week.Commits,
Additions: *week.Additions,
Deletions: *week.Deletions,
2015-03-05 14:32:47 +07:00
}
contrib.Save()
2015-03-05 02:08:36 +07:00
}
}
}