1
0
Fork 0
empact/task/sync_repos.go

40 lines
629 B
Go
Raw Normal View History

2015-03-04 19:15:05 +00:00
package task
import (
"github.com/google/go-github/github"
2015-03-05 08:07:18 +00:00
"github.com/localhots/empact/db"
2015-03-04 19:15:05 +00:00
)
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
}
}
}