We don't need jobs!

This commit is contained in:
2015-03-06 17:01:55 +07:00
parent 3e0ac1ea2d
commit 522d53b14b
6 changed files with 13 additions and 177 deletions
+3 -12
View File
@@ -12,20 +12,11 @@ import (
"github.com/localhots/empact/db"
)
type (
FetchAccessTokenTask struct {
Code string
Result chan string
*db.Task
}
)
func FetchAccessToken(tk Tasker) {
t := tk.(*FetchAccessTokenTask)
func FetchAccessToken(code string, result chan string) {
payload := url.Values{}
payload.Set("client_id", config.C().ClientID)
payload.Set("client_secret", config.C().ClientSecret)
payload.Set("code", t.Code)
payload.Set("code", code)
payload.Set("redirect_uri", config.C().RedirectURI)
buf := bytes.NewBuffer([]byte(payload.Encode()))
@@ -72,5 +63,5 @@ func FetchAccessToken(tk Tasker) {
fmt.Println("Saving token", tok)
tok.Save()
t.Result <- user.Login
result <- user.Login
}
-7
View File
@@ -6,13 +6,6 @@ import (
"github.com/localhots/empact/db"
)
type (
Tasker interface {
Save()
T() *db.Task
}
)
func newGithubClient(token string) *github.Client {
trans := &oauth.Transport{
Token: &oauth.Token{AccessToken: token},
+5 -14
View File
@@ -4,22 +4,13 @@ import (
"github.com/localhots/empact/db"
)
type (
SyncContribTask struct {
Repo string
*db.Task
}
)
func SyncContrib(tk Tasker) {
t := tk.(*SyncContribTask)
client := newGithubClient(t.Token)
contribs, resp, err := client.Repositories.ListContributorsStats(t.Owner, t.Repo)
saveResponseMeta(t.Token, resp)
func SyncContrib(token, owner, repo string) {
client := newGithubClient(token)
contribs, resp, err := client.Repositories.ListContributorsStats(owner, repo)
saveResponseMeta(token, resp)
if err != nil {
if err.Error() == "EOF" {
// Empty repository, not an actual error
return
return // Empty repository, not an actual error
}
panic(err)
}
+5 -12
View File
@@ -5,29 +5,22 @@ import (
"github.com/localhots/empact/db"
)
type (
SyncReposTask struct {
*db.Task
}
)
func SyncRepos(tk Tasker) {
t := tk.(*SyncReposTask)
client := newGithubClient(t.Token)
func SyncRepos(token, owner string) {
client := newGithubClient(token)
opt := &github.RepositoryListByOrgOptions{
ListOptions: github.ListOptions{},
}
for {
opt.Page++
repos, resp, err := client.Repositories.ListByOrg(t.Owner, opt)
saveResponseMeta(t.Token, resp)
repos, resp, err := client.Repositories.ListByOrg(owner, opt)
saveResponseMeta(token, resp)
if err != nil {
panic(err)
}
for _, repo := range repos {
r := &db.Repo{
Owner: t.Owner,
Owner: owner,
Name: *repo.Name,
}
r.Save()