From de63ac046ed50e5ca937fb63c50df01dc285425b Mon Sep 17 00:00:00 2001 From: John Olheiser Date: Sun, 8 Mar 2020 08:34:38 -0500 Subject: [PATCH] Make PR message on pushes configurable (#10664) * Make PR message on pushes configurable * Make fmt Signed-off-by: jolheiser --- custom/conf/app.ini.sample | 4 +++- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 1 + modules/setting/git.go | 2 ++ routers/private/hook.go | 5 +++-- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index fdba955bc4d..7fd60283195 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -870,7 +870,9 @@ MAX_GIT_DIFF_FILES = 100 ; see more on http://git-scm.com/docs/git-gc/ GC_ARGS = ; If use git wire protocol version 2 when git version >= 2.18, default is true, set to false when you always want git wire protocol version 1 -EnableAutoGitWireProtocol = true +ENABLE_AUTO_GIT_WIRE_PROTOCOL = true +; Respond to pushes to a non-default branch with a URL for creating a Pull Request (if the repository has them enabled) +PULL_REQUEST_PUSH_MESSAGE = true ; Operation timeout in seconds [git.timeout] diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 45a4535c236..fa86648475e 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -541,6 +541,7 @@ NB: You must `REDIRECT_MACARON_LOG` and have `DISABLE_ROUTER_LOG` set to `false` - `MAX_GIT_DIFF_FILES`: **100**: Max number of files shown in diff view. - `GC_ARGS`: **\**: Arguments for command `git gc`, e.g. `--aggressive --auto`. See more on http://git-scm.com/docs/git-gc/ - `ENABLE_AUTO_GIT_WIRE_PROTOCOL`: **true**: If use git wire protocol version 2 when git version >= 2.18, default is true, set to false when you always want git wire protocol version 1 +- `PULL_REQUEST_PUSH_MESSAGE`: **true**: Respond to pushes to a non-default branch with a URL for creating a Pull Request (if the repository has them enabled) - `VERBOSE_PUSH`: **true**: Print status information about pushes as they are being processed. - `VERBOSE_PUSH_DELAY`: **5s**: Only print verbose information if push takes longer than this delay. diff --git a/modules/setting/git.go b/modules/setting/git.go index 8c8179cba6b..f83758f3879 100644 --- a/modules/setting/git.go +++ b/modules/setting/git.go @@ -25,6 +25,7 @@ var ( VerbosePushDelay time.Duration GCArgs []string `ini:"GC_ARGS" delim:" "` EnableAutoGitWireProtocol bool + PullRequestPushMessage bool Timeout struct { Default int Migrate int @@ -42,6 +43,7 @@ var ( VerbosePushDelay: 5 * time.Second, GCArgs: []string{}, EnableAutoGitWireProtocol: true, + PullRequestPushMessage: true, Timeout: struct { Default int Migrate int diff --git a/routers/private/hook.go b/routers/private/hook.go index 1d8cb4b48ec..6743d02e847 100644 --- a/routers/private/hook.go +++ b/routers/private/hook.go @@ -19,6 +19,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/private" "code.gitea.io/gitea/modules/repofiles" + "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" pull_service "code.gitea.io/gitea/services/pull" "gopkg.in/src-d/go-git.v4/plumbing" @@ -428,14 +429,14 @@ func HookPostReceive(ctx *macaron.Context, opts private.HookOptions) { branch = fmt.Sprintf("%s:%s", repo.OwnerName, branch) } results = append(results, private.HookPostReceiveBranchResult{ - Message: true, + Message: setting.Git.PullRequestPushMessage && repo.AllowsPulls(), Create: true, Branch: branch, URL: fmt.Sprintf("%s/compare/%s...%s", baseRepo.HTMLURL(), util.PathEscapeSegments(baseRepo.DefaultBranch), util.PathEscapeSegments(branch)), }) } else { results = append(results, private.HookPostReceiveBranchResult{ - Message: true, + Message: setting.Git.PullRequestPushMessage && repo.AllowsPulls(), Create: false, Branch: branch, URL: fmt.Sprintf("%s/pulls/%d", baseRepo.HTMLURL(), pr.Index),