1
0
Fork 0

Update repo model

This commit is contained in:
Gregory Eremin 2015-03-20 18:43:58 +07:00
parent 6e498953bd
commit f01da56147
2 changed files with 29 additions and 17 deletions

View File

@ -5,28 +5,33 @@ import (
) )
type Repo struct { type Repo struct {
ID uint64 `json:"id"` ID uint64 `json:"id"`
Owner string `json:"owner"` OrgID uint64 `json:"org_id"`
Name string `json:"name"` Name string `json:"name"`
UpdatedAt time.Time `json:"updated_at"` Description string `json:"description"`
IsPrivate bool `json:"is_private"` IsPrivate bool `json:"is_private"`
IsForm bool `json:"is_fork"` IsFork bool `json:"is_fork"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
} }
const orgReposQuery = `select * from repos where owner = ?`
const saveRepoQuery = `
insert into repos (owner, name, updated_at)
values (:owner, :name, now())
on duplicate key update
updated_at=now()`
func (r *Repo) Save() { func (r *Repo) Save() {
defer measure("SaveRepo", time.Now()) defer measure("SaveRepo", time.Now())
mustExecN(saveRepoQuery, r) mustExecN(`
insert into repos (owner, name, updated_at)
values (:owner, :name, now())
on duplicate key update
updated_at=now()
`, r)
} }
func OrgRepos(login string) (repos []*Repo) { func OrgRepos(login string) (repos []*Repo) {
defer measure("OrgRepos", time.Now()) defer measure("OrgRepos", time.Now())
mustSelect(&repos, orgReposQuery, login) mustSelect(&repos, `
select *
from repos r
left join orgs o on r.org_id = o.id
where o.login = ?
`, login)
return return
} }

View File

@ -20,9 +20,16 @@ func SyncRepos(token, owner string) {
panic(err) panic(err)
} }
for _, repo := range repos { for _, repo := range repos {
var descr string
if repo.Description != nil {
descr = *repo.Description
}
r := &db.Repo{ r := &db.Repo{
Owner: owner, OrgID: uint64(*repo.Organization.ID),
Name: *repo.Name, Name: *repo.Name,
Description: descr,
IsPrivate: *repo.Private,
IsFork: *repo.Fork,
} }
r.Save() r.Save()
} }