1
0
Fork 0
empact/task/sync_repos.go

40 lines
630 B
Go
Raw Normal View History

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