From c3732041d532142ad84126576eaa09098547facb Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Fri, 21 Jul 2017 11:53:11 -0400 Subject: [PATCH] refresh repo info on activation --- model/repo.go | 21 +++++++++++++++++++-- server/repo.go | 5 +++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/model/repo.go b/model/repo.go index a59239a1..4b1d1ef5 100644 --- a/model/repo.go +++ b/model/repo.go @@ -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"` diff --git a/server/repo.go b/server/repo.go index 6f9966bf..8873729c 100644 --- a/server/repo.go +++ b/server/repo.go @@ -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())