Update contrib model
This commit is contained in:
parent
f01da56147
commit
ede2707070
|
@ -6,21 +6,20 @@ import (
|
||||||
|
|
||||||
type Contrib struct {
|
type Contrib struct {
|
||||||
Week uint64 `json:"week"`
|
Week uint64 `json:"week"`
|
||||||
Author string `json:"author"`
|
OrgID uint64 `json:"org_id"`
|
||||||
Owner string `json:"owner"`
|
RepoID uint64 `json:"repo_id"`
|
||||||
Repo string `json:"repo"`
|
UserID uint64 `json:"user_id"`
|
||||||
Commits uint64 `json:"commits"`
|
Commits uint64 `json:"commits"`
|
||||||
Additions uint64 `json:"additions"`
|
Additions uint64 `json:"additions"`
|
||||||
Deletions uint64 `json:"deletions"`
|
Deletions uint64 `json:"deletions"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveContribQuery = `
|
|
||||||
insert into contribs (week, author, owner, repo, commits, additions, deletions)
|
|
||||||
values (:week, :author, :owner, :repo, :commits, :additions, :deletions)
|
|
||||||
on duplicate key update
|
|
||||||
commits=values(commits), additions=values(additions), deletions=values(deletions)`
|
|
||||||
|
|
||||||
func (c *Contrib) Save() {
|
func (c *Contrib) Save() {
|
||||||
defer measure("SaveContrib", time.Now())
|
defer measure("SaveContrib", time.Now())
|
||||||
mustExecN(saveContribQuery, c)
|
mustExecN(`
|
||||||
|
insert into contribs (week, org_id, repo_id, user_id, commits, additions, deletions)
|
||||||
|
values (:week, :org_id, :repo_id, :user_id, :commits, :additions, :deletions)
|
||||||
|
on duplicate key update
|
||||||
|
commits=values(commits), additions=values(additions), deletions=values(deletions)
|
||||||
|
`, c)
|
||||||
}
|
}
|
||||||
|
|
10
task/sync.go
10
task/sync.go
|
@ -39,11 +39,11 @@ func SyncRepos(token, owner string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func SyncContrib(token, owner, repo string) {
|
func SyncContrib(token, owner string, repo *db.Repo) {
|
||||||
defer report("SyncContrib", time.Now())
|
defer report("SyncContrib", time.Now())
|
||||||
client := newGithubClient(token)
|
client := newGithubClient(token)
|
||||||
|
|
||||||
contribs, resp, err := client.Repositories.ListContributorsStats(owner, repo)
|
contribs, resp, err := client.Repositories.ListContributorsStats(owner, repo.Name)
|
||||||
saveResponseMeta(token, resp)
|
saveResponseMeta(token, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == "EOF" {
|
if err.Error() == "EOF" {
|
||||||
|
@ -60,9 +60,9 @@ func SyncContrib(token, owner, repo string) {
|
||||||
|
|
||||||
c := &db.Contrib{
|
c := &db.Contrib{
|
||||||
Week: uint64(week.Week.Time.Unix()),
|
Week: uint64(week.Week.Time.Unix()),
|
||||||
Author: *contrib.Author.Login,
|
OrgID: repo.OrgID,
|
||||||
Owner: owner,
|
RepoID: repo.ID,
|
||||||
Repo: repo,
|
UserID: uint64(*contrib.Author.ID),
|
||||||
Commits: uint64(*week.Commits),
|
Commits: uint64(*week.Commits),
|
||||||
Additions: uint64(*week.Additions),
|
Additions: uint64(*week.Additions),
|
||||||
Deletions: uint64(*week.Deletions),
|
Deletions: uint64(*week.Deletions),
|
||||||
|
|
Loading…
Reference in New Issue