1
0
Fork 0
empact/task/sync_repos.go

40 lines
630 B
Go

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