From 58f63b946b9d5c6227db9f768b7ffc9591335554 Mon Sep 17 00:00:00 2001 From: David Svantesson Date: Mon, 5 Aug 2019 22:29:18 +0200 Subject: [PATCH] Rewrite existing repo units if setting is not included in api body Signed-off-by: David Svantesson --- routers/api/v1/repo/repo.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index db8460ac8452..7c6a24ff7f83 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -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, @@ -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, @@ -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