Adding the ability to update the repo owner and name via patch with the owner and name props

This commit is contained in:
Joachim Hill-Grannec 2017-08-16 16:21:13 -07:00
parent d6e18e6dba
commit 4fab997871
2 changed files with 17 additions and 1 deletions

View file

@ -67,4 +67,6 @@ type RepoPatch struct {
AllowDeploy *bool `json:"allow_deploy,omitempty"`
AllowTag *bool `json:"allow_tag,omitempty"`
BuildCounter *int `json:"build_counter,omitempty"`
Name *string `json:"name",omitempty`
Owner *string `json:"owner,omitempty"`
}

View file

@ -88,6 +88,7 @@ func PostRepo(c *gin.Context) {
func PatchRepo(c *gin.Context) {
repo := session.Repo(c)
user := session.User(c)
remote := remote.FromContext(c)
in := new(model.RepoPatch)
if err := c.Bind(in); err != nil {
@ -95,7 +96,7 @@ func PatchRepo(c *gin.Context) {
return
}
if (in.IsTrusted != nil || in.Timeout != nil || in.BuildCounter != nil) && !user.Admin {
if (in.IsTrusted != nil || in.Timeout != nil || in.BuildCounter != nil || in.Owner != nil || in.Name != nil) && !user.Admin {
c.String(403, "Insufficient privileges")
return
}
@ -137,6 +138,19 @@ func PatchRepo(c *gin.Context) {
repo.Counter = *in.BuildCounter
}
if in.Name != nil && in.Owner != nil {
from, err := remote.Repo(user, *in.Owner, *in.Name)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
}
repo.Name = from.Name
repo.Owner = from.Owner
repo.FullName = from.FullName
repo.Avatar = from.Avatar
repo.Link = from.Link
repo.Clone = from.Clone
}
err := store.UpdateRepo(c, repo)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)