From faa96553d1dd5487b8d3682c8eac100580b321e3 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 1 Feb 2023 02:31:19 +0100 Subject: [PATCH] Add repository setting to enable/disable releases unit (#22671) To go along with similar settings for issues, pulls, projects, packages. --- options/locale/locale_en-US.ini | 1 + routers/web/repo/setting.go | 9 +++++++++ services/forms/repo_form.go | 1 + templates/repo/settings/options.tmpl | 13 +++++++++++++ 4 files changed, 24 insertions(+) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index f3da8dd5397..3495afe859d 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1870,6 +1870,7 @@ settings.pulls.allow_manual_merge = Enable Mark PR as manually merged settings.pulls.enable_autodetect_manual_merge = Enable autodetect manual merge (Note: In some special cases, misjudgments can occur) settings.pulls.allow_rebase_update = Enable updating pull request branch by rebase settings.pulls.default_delete_branch_after_merge = Delete pull request branch after merge by default +settings.releases_desc = Enable Repository Releases settings.packages_desc = Enable Repository Packages Registry settings.projects_desc = Enable Repository Projects settings.actions_desc = Enable Repository Actions diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index d2d15537ac7..73887195e69 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -488,6 +488,15 @@ func SettingsPost(ctx *context.Context) { deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeProjects) } + if form.EnableReleases && !unit_model.TypeReleases.UnitGlobalDisabled() { + units = append(units, repo_model.RepoUnit{ + RepoID: repo.ID, + Type: unit_model.TypeReleases, + }) + } else if !unit_model.TypeReleases.UnitGlobalDisabled() { + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeReleases) + } + if form.EnablePackages && !unit_model.TypePackages.UnitGlobalDisabled() { units = append(units, repo_model.RepoUnit{ RepoID: repo.ID, diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index c084e656008..436d79df68c 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -146,6 +146,7 @@ type RepoSettingForm struct { ExternalTrackerRegexpPattern string EnableCloseIssuesViaCommitInAnyBranch bool EnableProjects bool + EnableReleases bool EnablePackages bool EnablePulls bool EnableActions bool diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 5b7b9ec5f8d..0383364279d 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -420,6 +420,19 @@ + {{$isReleasesEnabled := .Repository.UnitEnabled $.Context $.UnitTypeReleases}} +
+ + {{if .UnitTypeReleases.UnitGlobalDisabled}} +
+ {{else}} +
+ {{end}} + + +
+
+ {{$isPackagesEnabled := .Repository.UnitEnabled $.Context $.UnitTypePackages}}