Skip to content

Commit 0c759fd

Browse files
authored
feat: add DEFAULT_MERGE_STYLE to repository.pull-request section for repo init (#19751)
1 parent 808a780 commit 0c759fd

File tree

6 files changed

+15
-1
lines changed

6 files changed

+15
-1
lines changed

custom/conf/app.example.ini

+3
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,9 @@ PATH =
948948
;; List of keywords used in Pull Request comments to automatically reopen a related issue
949949
;REOPEN_KEYWORDS = reopen,reopens,reopened
950950
;;
951+
;; Set default merge style for repository creating, valid options: merge, rebase, rebase-merge, squash
952+
;DEFAULT_MERGE_STYLE = merge
953+
;;
951954
;; In the default merge message for squash commits include at most this many commits
952955
;DEFAULT_MERGE_MESSAGE_COMMITS_LIMIT = 50
953956
;;

docs/content/doc/advanced/config-cheat-sheet.en-us.md

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
9292
keywords used in Pull Request comments to automatically close a related issue
9393
- `REOPEN_KEYWORDS`: **reopen**, **reopens**, **reopened**: List of keywords used in Pull Request comments to automatically reopen
9494
a related issue
95+
- `DEFAULT_MERGE_STYLE`: **merge**: Set default merge style for repository creating, valid options: `merge`, `rebase`, `rebase-merge`, `squash`
9596
- `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
9697
- `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`.
9798
- `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

models/repo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ func CreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_
373373
units = append(units, repo_model.RepoUnit{
374374
RepoID: repo.ID,
375375
Type: tp,
376-
Config: &repo_model.PullRequestsConfig{AllowMerge: true, AllowRebase: true, AllowRebaseMerge: true, AllowSquash: true, DefaultMergeStyle: repo_model.MergeStyleMerge, AllowRebaseUpdate: true},
376+
Config: &repo_model.PullRequestsConfig{AllowMerge: true, AllowRebase: true, AllowRebaseMerge: true, AllowSquash: true, DefaultMergeStyle: repo_model.MergeStyle(setting.Repository.PullRequest.DefaultMergeStyle), AllowRebaseUpdate: true},
377377
})
378378
} else {
379379
units = append(units, repo_model.RepoUnit{

models/repo/repo_unit.go

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"code.gitea.io/gitea/models/db"
1212
"code.gitea.io/gitea/models/unit"
1313
"code.gitea.io/gitea/modules/json"
14+
"code.gitea.io/gitea/modules/setting"
1415
"code.gitea.io/gitea/modules/timeutil"
1516

1617
"xorm.io/xorm"
@@ -148,6 +149,10 @@ func (cfg *PullRequestsConfig) GetDefaultMergeStyle() MergeStyle {
148149
return cfg.DefaultMergeStyle
149150
}
150151

152+
if setting.Repository.PullRequest.DefaultMergeStyle != "" {
153+
return MergeStyle(setting.Repository.PullRequest.DefaultMergeStyle)
154+
}
155+
151156
return MergeStyleMerge
152157
}
153158

modules/setting/repository.go

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ var (
7171
WorkInProgressPrefixes []string
7272
CloseKeywords []string
7373
ReopenKeywords []string
74+
DefaultMergeStyle string
7475
DefaultMergeMessageCommitsLimit int
7576
DefaultMergeMessageSize int
7677
DefaultMergeMessageAllAuthors bool
@@ -192,6 +193,7 @@ var (
192193
WorkInProgressPrefixes []string
193194
CloseKeywords []string
194195
ReopenKeywords []string
196+
DefaultMergeStyle string
195197
DefaultMergeMessageCommitsLimit int
196198
DefaultMergeMessageSize int
197199
DefaultMergeMessageAllAuthors bool
@@ -205,6 +207,7 @@ var (
205207
// https://help.github.com/articles/closing-issues-via-commit-messages
206208
CloseKeywords: strings.Split("close,closes,closed,fix,fixes,fixed,resolve,resolves,resolved", ","),
207209
ReopenKeywords: strings.Split("reopen,reopens,reopened", ","),
210+
DefaultMergeStyle: "merge",
208211
DefaultMergeMessageCommitsLimit: 50,
209212
DefaultMergeMessageSize: 5 * 1024,
210213
DefaultMergeMessageAllAuthors: false,

routers/install/install.go

+2
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ func SubmitInstall(ctx *context.Context) {
456456
cfg.Section("log").Key("ROOT_PATH").SetValue(form.LogRootPath)
457457
cfg.Section("log").Key("ROUTER").SetValue("console")
458458

459+
cfg.Section("repository.pull-request").Key("DEFAULT_MERGE_STYLE").SetValue("merge")
460+
459461
cfg.Section("repository.signing").Key("DEFAULT_TRUST_MODEL").SetValue("committer")
460462

461463
cfg.Section("security").Key("INSTALL_LOCK").SetValue("true")

0 commit comments

Comments
 (0)