From 5ea4f0cfae35f7ac99b4ea46e6418d7492c08183 Mon Sep 17 00:00:00 2001 From: Jack Gleeson Date: Thu, 20 Feb 2025 12:28:28 -0500 Subject: [PATCH] Add default option for allowing pull requests on repositories (#4873) --- cmd/server/flags.go | 6 ++++++ cmd/server/setup.go | 3 +++ docs/docs/30-administration/10-server-config.md | 6 ++++++ server/api/repo.go | 2 +- server/config.go | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/server/flags.go b/cmd/server/flags.go index 7e63e7f51..2f50828d1 100644 --- a/cmd/server/flags.go +++ b/cmd/server/flags.go @@ -141,6 +141,12 @@ var flags = append([]cli.Flag{ Name: "authenticate-public-repos", Usage: "Always use authentication to clone repositories even if they are public. Needed if the SCM requires to always authenticate as used by many companies.", }, + &cli.BoolFlag{ + Sources: cli.EnvVars("WOODPECKER_DEFAULT_ALLOW_PULL_REQUESTS"), + Name: "default-allow-pull-requests", + Usage: "The default value for allowing pull requests on a repo.", + Value: true, + }, &cli.StringSliceFlag{ Sources: cli.EnvVars("WOODPECKER_DEFAULT_CANCEL_PREVIOUS_PIPELINE_EVENTS"), Name: "default-cancel-previous-pipeline-events", diff --git a/cmd/server/setup.go b/cmd/server/setup.go index b36c83dbd..bb7a575ff 100644 --- a/cmd/server/setup.go +++ b/cmd/server/setup.go @@ -173,6 +173,9 @@ func setupEvilGlobals(ctx context.Context, c *cli.Command, s store.Store) (err e // authentication server.Config.Pipeline.AuthenticatePublicRepos = c.Bool("authenticate-public-repos") + // Pull requests + server.Config.Pipeline.DefaultAllowPullRequests = c.Bool("default-allow-pull-requests") + // Cloning server.Config.Pipeline.DefaultClonePlugin = c.String("default-clone-plugin") server.Config.Pipeline.TrustedClonePlugins = c.StringSlice("plugins-trusted-clone") diff --git a/docs/docs/30-administration/10-server-config.md b/docs/docs/30-administration/10-server-config.md index a308123eb..ab345aedd 100644 --- a/docs/docs/30-administration/10-server-config.md +++ b/docs/docs/30-administration/10-server-config.md @@ -337,6 +337,12 @@ Enable to allow user registration. Always use authentication to clone repositories even if they are public. Needed if the forge requires to always authenticate as used by many companies. +### `WOODPECKER_DEFAULT_ALLOW_PULL_REQUESTS` + +> Default: `true` + +The default setting for allowing pull requests on a repo. + ### `WOODPECKER_DEFAULT_CANCEL_PREVIOUS_PIPELINE_EVENTS` > Default: `pull_request, push` diff --git a/server/api/repo.go b/server/api/repo.go index d5cf60bc5..07afd606e 100644 --- a/server/api/repo.go +++ b/server/api/repo.go @@ -92,7 +92,7 @@ func PostRepo(c *gin.Context) { } else { repo = from repo.RequireApproval = model.RequireApprovalForks - repo.AllowPull = true + repo.AllowPull = server.Config.Pipeline.DefaultAllowPullRequests repo.AllowDeploy = false repo.CancelPreviousPipelineEvents = server.Config.Pipeline.DefaultCancelPreviousPipelineEvents } diff --git a/server/config.go b/server/config.go index 7f9d51a2e..daa38c786 100644 --- a/server/config.go +++ b/server/config.go @@ -66,6 +66,7 @@ var Config = struct { } Pipeline struct { AuthenticatePublicRepos bool + DefaultAllowPullRequests bool DefaultCancelPreviousPipelineEvents []model.WebhookEvent DefaultWorkflowLabels map[string]string DefaultClonePlugin string