From 21606047b73069369a72dac4625ae6129c6d2d49 Mon Sep 17 00:00:00 2001 From: ttyS3 Date: Thu, 19 May 2022 14:31:05 +0800 Subject: [PATCH] feat: add DEFAULT_MERGE_STYLE to `repository.pull-request` section for repo init --- custom/conf/app.example.ini | 3 +++ docs/content/doc/advanced/config-cheat-sheet.en-us.md | 1 + models/repo.go | 2 +- models/repo/repo_unit.go | 5 +++++ modules/setting/repository.go | 3 +++ routers/install/install.go | 2 ++ 6 files changed, 15 insertions(+), 1 deletion(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 476b30502681..f02c8d058113 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -947,6 +947,9 @@ PATH = ;; List of keywords used in Pull Request comments to automatically reopen a related issue ;REOPEN_KEYWORDS = reopen,reopens,reopened ;; +;; Set default merge style for repository creating, valid options: merge, rebase, rebase-merge, squash +;DEFAULT_MERGE_STYLE = merge +;; ;; In the default merge message for squash commits include at most this many commits ;DEFAULT_MERGE_MESSAGE_COMMITS_LIMIT = 50 ;; 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 4c43ba7ddb9f..989d80c8a023 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -92,6 +92,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`. keywords used in Pull Request comments to automatically close a related issue - `REOPEN_KEYWORDS`: **reopen**, **reopens**, **reopened**: List of keywords used in Pull Request comments to automatically reopen a related issue +- `DEFAULT_MERGE_STYLE`: **merge**: Set default merge style for repository creating, valid options: `merge`, `rebase`, `rebase-merge`, `squash` - `DEFAULT_MERGE_MESSAGE_COMMITS_LIMIT`: **50**: In the default merge message for squash commits include at most this many commits. Set to `-1` to include all commits - `DEFAULT_MERGE_MESSAGE_SIZE`: **5120**: In the default merge message for squash commits limit the size of the commit messages. Set to `-1` to have no limit. Only used if `POPULATE_SQUASH_COMMENT_WITH_COMMIT_MESSAGES` is `true`. - `DEFAULT_MERGE_MESSAGE_ALL_AUTHORS`: **false**: In the default merge message for squash commits walk all commits to include all authors in the Co-authored-by otherwise just use those in the limited list diff --git a/models/repo.go b/models/repo.go index 598eec7c9e25..d170169acb7d 100644 --- a/models/repo.go +++ b/models/repo.go @@ -382,7 +382,7 @@ func CreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_ units = append(units, repo_model.RepoUnit{ RepoID: repo.ID, Type: tp, - Config: &repo_model.PullRequestsConfig{AllowMerge: true, AllowRebase: true, AllowRebaseMerge: true, AllowSquash: true, DefaultMergeStyle: repo_model.MergeStyleMerge, AllowRebaseUpdate: true}, + Config: &repo_model.PullRequestsConfig{AllowMerge: true, AllowRebase: true, AllowRebaseMerge: true, AllowSquash: true, DefaultMergeStyle: repo_model.MergeStyle(setting.Repository.PullRequest.DefaultMergeStyle), AllowRebaseUpdate: true}, }) } else { units = append(units, repo_model.RepoUnit{ diff --git a/models/repo/repo_unit.go b/models/repo/repo_unit.go index de79eb1c9f10..1d588368d792 100644 --- a/models/repo/repo_unit.go +++ b/models/repo/repo_unit.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/json" + "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" "xorm.io/xorm" @@ -147,6 +148,10 @@ func (cfg *PullRequestsConfig) GetDefaultMergeStyle() MergeStyle { return cfg.DefaultMergeStyle } + if setting.Repository.PullRequest.DefaultMergeStyle != "" { + return MergeStyle(setting.Repository.PullRequest.DefaultMergeStyle) + } + return MergeStyleMerge } diff --git a/modules/setting/repository.go b/modules/setting/repository.go index f24bc841d654..73a94f82b353 100644 --- a/modules/setting/repository.go +++ b/modules/setting/repository.go @@ -71,6 +71,7 @@ var ( WorkInProgressPrefixes []string CloseKeywords []string ReopenKeywords []string + DefaultMergeStyle string DefaultMergeMessageCommitsLimit int DefaultMergeMessageSize int DefaultMergeMessageAllAuthors bool @@ -192,6 +193,7 @@ var ( WorkInProgressPrefixes []string CloseKeywords []string ReopenKeywords []string + DefaultMergeStyle string DefaultMergeMessageCommitsLimit int DefaultMergeMessageSize int DefaultMergeMessageAllAuthors bool @@ -205,6 +207,7 @@ var ( // https://help.github.com/articles/closing-issues-via-commit-messages CloseKeywords: strings.Split("close,closes,closed,fix,fixes,fixed,resolve,resolves,resolved", ","), ReopenKeywords: strings.Split("reopen,reopens,reopened", ","), + DefaultMergeStyle: "merge", DefaultMergeMessageCommitsLimit: 50, DefaultMergeMessageSize: 5 * 1024, DefaultMergeMessageAllAuthors: false, diff --git a/routers/install/install.go b/routers/install/install.go index 41b11aef3310..7ee93050c4da 100644 --- a/routers/install/install.go +++ b/routers/install/install.go @@ -456,6 +456,8 @@ func SubmitInstall(ctx *context.Context) { cfg.Section("log").Key("ROOT_PATH").SetValue(form.LogRootPath) cfg.Section("log").Key("ROUTER").SetValue("console") + cfg.Section("repository.pull-request").Key("DEFAULT_MERGE_STYLE").SetValue("merge") + cfg.Section("repository.signing").Key("DEFAULT_TRUST_MODEL").SetValue("committer") cfg.Section("security").Key("INSTALL_LOCK").SetValue("true")