empact/task/sync_repos.go

40 lines
631 B
Go
Raw Normal View History

2015-03-05 02:15:05 +07:00
package task
import (
"github.com/google/go-github/github"
2015-03-05 15:07:18 +07:00
"github.com/localhots/empact/db"
2015-03-05 02:15:05 +07:00
)
type (
SyncReposTask struct {
2015-03-05 19:57:36 +07:00
*db.Task
2015-03-05 02:15:05 +07:00
}
)
2015-03-05 19:57:36 +07:00
func SyncRepos(tk Tasker) {
t := tk.(*SyncReposTask)
client := newGithubClient(t.Token)
2015-03-05 03:51:17 +07:00
opt := &github.RepositoryListByOrgOptions{
ListOptions: github.ListOptions{},
2015-03-05 02:15:05 +07:00
}
for {
opt.Page++
2015-03-05 03:51:17 +07:00
repos, resp, err := client.Repositories.ListByOrg(t.Owner, opt)
saveResponseMeta(t.Token, resp)
2015-03-05 02:15:05 +07:00
if err != nil {
panic(err)
}
for _, repo := range repos {
2015-03-05 03:51:17 +07:00
r := &db.Repo{
Owner: t.Owner,
Name: *repo.Name,
}
r.Save()
2015-03-05 02:15:05 +07:00
}
if len(repos) < 30 {
break
}
}
}