Skip to content

Commit

Permalink
Rewrite existing repo units if setting is not included in api body
Browse files Browse the repository at this point in the history
Signed-off-by: David Svantesson <davidsvantesson@gmail.com>
  • Loading branch information
davidsvantesson committed Aug 5, 2019
1 parent 7b2a39c commit 58f63b9
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions routers/api/v1/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,14 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
})
}

if opts.HasIssues != nil {
if opts.HasIssues == nil {
// If HasIssues setting not touched, rewrite existing repo unit
if unit, err := repo.GetUnit(models.UnitTypeIssues); err == nil {
units = append(units, *unit)
} else if unit, err := repo.GetUnit(models.UnitTypeExternalTracker); err == nil {
units = append(units, *unit)
}
} else {
if *opts.HasIssues {
// We don't currently allow setting individual issue settings through the API,
// only can enable/disable issues, so when enabling issues,
Expand All @@ -677,7 +684,14 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
}
}

if opts.HasWiki != nil {
if opts.HasWiki == nil {
// If HasWiki setting not touched, rewrite existing repo unit
if unit, err := repo.GetUnit(models.UnitTypeWiki); err == nil {
units = append(units, *unit)
} else if unit, err := repo.GetUnit(models.UnitTypeExternalWiki); err == nil {
units = append(units, *unit)
}
} else {
if *opts.HasWiki {
// We don't currently allow setting individual wiki settings through the API,
// only can enable/disable the wiki, so when enabling the wiki,
Expand All @@ -692,7 +706,12 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
}
}

if opts.HasPullRequests != nil {
if opts.HasPullRequests == nil {
// If HasPullRequest setting not touched, rewrite existing repo unit
if unit, err := repo.GetUnit(models.UnitTypePullRequests); err == nil {
units = append(units, *unit)
}
} else {
if *opts.HasPullRequests {
// We do allow setting individual PR settings through the API, so
// we get the config settings and then set them
Expand Down

0 comments on commit 58f63b9

Please sign in to comment.