refresh repo info on activation

This commit is contained in:
Brad Rydzewski 2017-07-21 11:53:11 -04:00
parent 0eb09cf2b1
commit c3732041d5
2 changed files with 24 additions and 2 deletions

View file

@ -23,11 +23,11 @@ type Repo struct {
Branch string `json:"default_branch,omitempty" meddler:"repo_branch"`
Timeout int64 `json:"timeout,omitempty" meddler:"repo_timeout"`
Visibility string `json:"visibility" meddler:"repo_visibility"`
IsPrivate bool `json:"private,omitempty" meddler:"repo_private"`
IsPrivate bool `json:"private" meddler:"repo_private"`
IsTrusted bool `json:"trusted" meddler:"repo_trusted"`
IsStarred bool `json:"starred,omitempty" meddler:"-"`
IsGated bool `json:"gated" meddler:"repo_gated"`
IsActive bool `json:"active,omitempty" meddler:"repo_active"`
IsActive bool `json:"active" meddler:"repo_active"`
AllowPull bool `json:"allow_pr" meddler:"repo_allow_pr"`
AllowPush bool `json:"allow_push" meddler:"repo_allow_push"`
AllowDeploy bool `json:"allow_deploys" meddler:"repo_allow_deploys"`
@ -38,6 +38,23 @@ type Repo struct {
Perm *Perm `json:"-" meddler:"-"`
}
// Update updates the repository with values from the given Repo.
func (r *Repo) Update(from *Repo) {
r.Avatar = from.Avatar
r.Link = from.Link
r.Kind = from.Kind
r.Clone = from.Clone
r.Branch = from.Branch
if from.IsPrivate != r.IsPrivate {
if from.IsPrivate {
r.Visibility = VisibilityPrivate
} else {
r.Visibility = VisibilityPublic
}
}
r.IsPrivate = from.IsPrivate
}
// RepoPatch represents a repository patch object.
type RepoPatch struct {
Config *string `json:"config_file,omitempty"`

View file

@ -71,6 +71,11 @@ func PostRepo(c *gin.Context) {
return
}
from, err := remote.Repo(user, repo.Owner, repo.Name)
if err == nil {
repo.Update(from)
}
err = store.UpdateRepo(c, repo)
if err != nil {
c.String(500, err.Error())