Skip to content

Commit 49919c6

Browse files
brechtvllunny
andauthored
Pull Requests: setting to allow edits by maintainers by default, tweak UI (#22862)
Add setting to allow edits by maintainers by default, to avoid having to often ask contributors to enable this. This also reorganizes the pull request settings UI to improve clarity. It was unclear which checkbox options were there to control available merge styles and which merge styles they correspond to. Now there is a "Merge Styles" label followed by the merge style options with the same name as in other menus. The remaining checkboxes were moved to the bottom, ordered rougly by typical order of operations. --------- Co-authored-by: Lunny Xiao <[email protected]>
1 parent b6d7722 commit 49919c6

File tree

11 files changed

+72
-34
lines changed

11 files changed

+72
-34
lines changed

models/repo/repo_unit.go

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ type PullRequestsConfig struct {
125125
AllowRebaseUpdate bool
126126
DefaultDeleteBranchAfterMerge bool
127127
DefaultMergeStyle MergeStyle
128+
DefaultAllowMaintainerEdit bool
128129
}
129130

130131
// FromDB fills up a PullRequestsConfig from serialized format.

modules/structs/repo.go

+3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ type Repository struct {
9696
AllowRebaseUpdate bool `json:"allow_rebase_update"`
9797
DefaultDeleteBranchAfterMerge bool `json:"default_delete_branch_after_merge"`
9898
DefaultMergeStyle string `json:"default_merge_style"`
99+
DefaultAllowMaintainerEdit bool `json:"default_allow_maintainer_edit"`
99100
AvatarURL string `json:"avatar_url"`
100101
Internal bool `json:"internal"`
101102
MirrorInterval string `json:"mirror_interval"`
@@ -187,6 +188,8 @@ type EditRepoOption struct {
187188
DefaultDeleteBranchAfterMerge *bool `json:"default_delete_branch_after_merge,omitempty"`
188189
// set to a merge style to be used by this repository: "merge", "rebase", "rebase-merge", or "squash".
189190
DefaultMergeStyle *string `json:"default_merge_style,omitempty"`
191+
// set to `true` to allow edits from maintainers by default
192+
DefaultAllowMaintainerEdit *bool `json:"default_allow_maintainer_edit,omitempty"`
190193
// set to `true` to archive this repository.
191194
Archived *bool `json:"archived,omitempty"`
192195
// set to a string like `8h30m0s` to set the mirror interval time

options/locale/locale_en-US.ini

+3-6
Original file line numberDiff line numberDiff line change
@@ -1871,14 +1871,10 @@ settings.enable_timetracker = Enable Time Tracking
18711871
settings.allow_only_contributors_to_track_time = Let Only Contributors Track Time
18721872
settings.pulls_desc = Enable Repository Pull Requests
18731873
settings.pulls.ignore_whitespace = Ignore Whitespace for Conflicts
1874-
settings.pulls.allow_merge_commits = Enable Commit Merging
1875-
settings.pulls.allow_rebase_merge = Enable Rebasing to Merge Commits
1876-
settings.pulls.allow_rebase_merge_commit = Enable Rebasing with explicit merge commits (--no-ff)
1877-
settings.pulls.allow_squash_commits = Enable Squashing to Merge Commits
1878-
settings.pulls.allow_manual_merge = Enable Mark PR as manually merged
18791874
settings.pulls.enable_autodetect_manual_merge = Enable autodetect manual merge (Note: In some special cases, misjudgments can occur)
18801875
settings.pulls.allow_rebase_update = Enable updating pull request branch by rebase
18811876
settings.pulls.default_delete_branch_after_merge = Delete pull request branch after merge by default
1877+
settings.pulls.default_allow_edits_from_maintainers = Allow edits from maintainers by default
18821878
settings.releases_desc = Enable Repository Releases
18831879
settings.packages_desc = Enable Repository Packages Registry
18841880
settings.projects_desc = Enable Repository Projects
@@ -2147,7 +2143,8 @@ settings.block_on_official_review_requests_desc = Merging will not be possible w
21472143
settings.block_outdated_branch = Block merge if pull request is outdated
21482144
settings.block_outdated_branch_desc = Merging will not be possible when head branch is behind base branch.
21492145
settings.default_branch_desc = Select a default repository branch for pull requests and code commits:
2150-
settings.default_merge_style_desc = Default merge style for pull requests:
2146+
settings.merge_style_desc = Merge Styles
2147+
settings.default_merge_style_desc = Default Merge Style
21512148
settings.choose_branch = Choose a branch…
21522149
settings.no_protected_branch = There are no protected branches.
21532150
settings.edit_protected_branch = Edit

routers/api/v1/repo/repo.go

+4
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
863863
AllowRebaseUpdate: true,
864864
DefaultDeleteBranchAfterMerge: false,
865865
DefaultMergeStyle: repo_model.MergeStyleMerge,
866+
DefaultAllowMaintainerEdit: false,
866867
}
867868
} else {
868869
config = unit.PullRequestsConfig()
@@ -898,6 +899,9 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
898899
if opts.DefaultMergeStyle != nil {
899900
config.DefaultMergeStyle = repo_model.MergeStyle(*opts.DefaultMergeStyle)
900901
}
902+
if opts.DefaultAllowMaintainerEdit != nil {
903+
config.DefaultAllowMaintainerEdit = *opts.DefaultAllowMaintainerEdit
904+
}
901905

902906
units = append(units, repo_model.RepoUnit{
903907
RepoID: repo.ID,

routers/web/repo/compare.go

+7
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,13 @@ func CompareDiff(ctx *context.Context) {
820820

821821
ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWrite(unit.TypePullRequests)
822822

823+
if unit, err := ctx.Repo.Repository.GetUnit(ctx, unit.TypePullRequests); err == nil {
824+
config := unit.PullRequestsConfig()
825+
ctx.Data["AllowMaintainerEdit"] = config.DefaultAllowMaintainerEdit
826+
} else {
827+
ctx.Data["AllowMaintainerEdit"] = false
828+
}
829+
823830
ctx.HTML(http.StatusOK, tplCompare)
824831
}
825832

routers/web/repo/setting.go

+1
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ func SettingsPost(ctx *context.Context) {
529529
AllowRebaseUpdate: form.PullsAllowRebaseUpdate,
530530
DefaultDeleteBranchAfterMerge: form.DefaultDeleteBranchAfterMerge,
531531
DefaultMergeStyle: repo_model.MergeStyle(form.PullsDefaultMergeStyle),
532+
DefaultAllowMaintainerEdit: form.DefaultAllowMaintainerEdit,
532533
},
533534
})
534535
} else if !unit_model.TypePullRequests.UnitGlobalDisabled() {

services/convert/repository.go

+3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.Acc
8181
allowRebaseUpdate := false
8282
defaultDeleteBranchAfterMerge := false
8383
defaultMergeStyle := repo_model.MergeStyleMerge
84+
defaultAllowMaintainerEdit := false
8485
if unit, err := repo.GetUnit(ctx, unit_model.TypePullRequests); err == nil {
8586
config := unit.PullRequestsConfig()
8687
hasPullRequests = true
@@ -92,6 +93,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.Acc
9293
allowRebaseUpdate = config.AllowRebaseUpdate
9394
defaultDeleteBranchAfterMerge = config.DefaultDeleteBranchAfterMerge
9495
defaultMergeStyle = config.GetDefaultMergeStyle()
96+
defaultAllowMaintainerEdit = config.DefaultAllowMaintainerEdit
9597
}
9698
hasProjects := false
9799
if _, err := repo.GetUnit(ctx, unit_model.TypeProjects); err == nil {
@@ -182,6 +184,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.Acc
182184
AllowRebaseUpdate: allowRebaseUpdate,
183185
DefaultDeleteBranchAfterMerge: defaultDeleteBranchAfterMerge,
184186
DefaultMergeStyle: string(defaultMergeStyle),
187+
DefaultAllowMaintainerEdit: defaultAllowMaintainerEdit,
185188
AvatarURL: repo.AvatarLink(),
186189
Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate,
187190
MirrorInterval: mirrorInterval,

services/forms/repo_form.go

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ type RepoSettingForm struct {
160160
EnableAutodetectManualMerge bool
161161
PullsAllowRebaseUpdate bool
162162
DefaultDeleteBranchAfterMerge bool
163+
DefaultAllowMaintainerEdit bool
163164
EnableTimetracker bool
164165
AllowOnlyContributorsToTrackTime bool
165166
EnableIssueDependencies bool

templates/repo/issue/new_form.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238
<div class="inline field">
239239
<div class="ui checkbox">
240240
<label class="tooltip" data-content="{{.locale.Tr "repo.pulls.allow_edits_from_maintainers_desc"}}"><strong>{{.locale.Tr "repo.pulls.allow_edits_from_maintainers"}}</strong></label>
241-
<input name="allow_maintainer_edit" type="checkbox">
241+
<input name="allow_maintainer_edit" type="checkbox" {{if .AllowMaintainerEdit}}checked{{end}}>
242242
</div>
243243
</div>
244244
{{end}}

templates/repo/settings/options.tmpl

+39-27
Original file line numberDiff line numberDiff line change
@@ -478,59 +478,41 @@
478478
</div>
479479
<div class="field{{if not $pullRequestEnabled}} disabled{{end}}" id="pull_box">
480480
<div class="field">
481-
<div class="ui checkbox">
482-
<input name="pulls_ignore_whitespace" type="checkbox" {{if and $pullRequestEnabled ($prUnit.PullRequestsConfig.IgnoreWhitespaceConflicts)}}checked{{end}}>
483-
<label>{{.locale.Tr "repo.settings.pulls.ignore_whitespace"}}</label>
484-
</div>
481+
<p>
482+
{{.locale.Tr "repo.settings.merge_style_desc"}}
483+
</p>
485484
</div>
486485
<div class="field">
487486
<div class="ui checkbox">
488487
<input name="pulls_allow_merge" type="checkbox" {{if or (not $pullRequestEnabled) ($prUnit.PullRequestsConfig.AllowMerge)}}checked{{end}}>
489-
<label>{{.locale.Tr "repo.settings.pulls.allow_merge_commits"}}</label>
488+
<label>{{.locale.Tr "repo.pulls.merge_pull_request"}}</label>
490489
</div>
491490
</div>
492491
<div class="field">
493492
<div class="ui checkbox">
494493
<input name="pulls_allow_rebase" type="checkbox" {{if or (not $pullRequestEnabled) ($prUnit.PullRequestsConfig.AllowRebase)}}checked{{end}}>
495-
<label>{{.locale.Tr "repo.settings.pulls.allow_rebase_merge"}}</label>
494+
<label>{{.locale.Tr "repo.pulls.rebase_merge_pull_request"}}</label>
496495
</div>
497496
</div>
498497
<div class="field">
499498
<div class="ui checkbox">
500499
<input name="pulls_allow_rebase_merge" type="checkbox" {{if or (not $pullRequestEnabled) ($prUnit.PullRequestsConfig.AllowRebaseMerge)}}checked{{end}}>
501-
<label>{{.locale.Tr "repo.settings.pulls.allow_rebase_merge_commit"}}</label>
500+
<label>{{.locale.Tr "repo.pulls.rebase_merge_commit_pull_request"}}</label>
502501
</div>
503502
</div>
504503
<div class="field">
505504
<div class="ui checkbox">
506505
<input name="pulls_allow_squash" type="checkbox" {{if or (not $pullRequestEnabled) ($prUnit.PullRequestsConfig.AllowSquash)}}checked{{end}}>
507-
<label>{{.locale.Tr "repo.settings.pulls.allow_squash_commits"}}</label>
506+
<label>{{.locale.Tr "repo.pulls.squash_merge_pull_request"}}</label>
508507
</div>
509508
</div>
510509
<div class="field">
511510
<div class="ui checkbox">
512511
<input name="pulls_allow_manual_merge" type="checkbox" {{if or (not $pullRequestEnabled) ($prUnit.PullRequestsConfig.AllowManualMerge)}}checked{{end}}>
513-
<label>{{.locale.Tr "repo.settings.pulls.allow_manual_merge"}}</label>
514-
</div>
515-
</div>
516-
<div class="field">
517-
<div class="ui checkbox">
518-
<input name="enable_autodetect_manual_merge" type="checkbox" {{if or (not $pullRequestEnabled) ($prUnit.PullRequestsConfig.AutodetectManualMerge)}}checked{{end}}>
519-
<label>{{.locale.Tr "repo.settings.pulls.enable_autodetect_manual_merge"}}</label>
520-
</div>
521-
</div>
522-
<div class="field">
523-
<div class="ui checkbox">
524-
<input name="pulls_allow_rebase_update" type="checkbox" {{if or (not $pullRequestEnabled) ($prUnit.PullRequestsConfig.AllowRebaseUpdate)}}checked{{end}}>
525-
<label>{{.locale.Tr "repo.settings.pulls.allow_rebase_update"}}</label>
526-
</div>
527-
</div>
528-
<div class="field">
529-
<div class="ui checkbox">
530-
<input name="default_delete_branch_after_merge" type="checkbox" {{if or (not $pullRequestEnabled) ($prUnit.PullRequestsConfig.DefaultDeleteBranchAfterMerge)}}checked{{end}}>
531-
<label>{{.locale.Tr "repo.settings.pulls.default_delete_branch_after_merge"}}</label>
512+
<label>{{.locale.Tr "repo.pulls.merge_manually"}}</label>
532513
</div>
533514
</div>
515+
534516
<div class="field">
535517
<p>
536518
{{.locale.Tr "repo.settings.default_merge_style_desc"}}
@@ -564,6 +546,36 @@
564546
</div>
565547
</div>
566548
</div>
549+
<div class="field">
550+
<div class="ui checkbox">
551+
<input name="default_allow_maintainer_edit" type="checkbox" {{if or (not $pullRequestEnabled) ($prUnit.PullRequestsConfig.DefaultAllowMaintainerEdit)}}checked{{end}}>
552+
<label>{{.locale.Tr "repo.settings.pulls.default_allow_edits_from_maintainers"}}</label>
553+
</div>
554+
</div>
555+
<div class="field">
556+
<div class="ui checkbox">
557+
<input name="pulls_allow_rebase_update" type="checkbox" {{if or (not $pullRequestEnabled) ($prUnit.PullRequestsConfig.AllowRebaseUpdate)}}checked{{end}}>
558+
<label>{{.locale.Tr "repo.settings.pulls.allow_rebase_update"}}</label>
559+
</div>
560+
</div>
561+
<div class="field">
562+
<div class="ui checkbox">
563+
<input name="default_delete_branch_after_merge" type="checkbox" {{if or (not $pullRequestEnabled) ($prUnit.PullRequestsConfig.DefaultDeleteBranchAfterMerge)}}checked{{end}}>
564+
<label>{{.locale.Tr "repo.settings.pulls.default_delete_branch_after_merge"}}</label>
565+
</div>
566+
</div>
567+
<div class="field">
568+
<div class="ui checkbox">
569+
<input name="enable_autodetect_manual_merge" type="checkbox" {{if or (not $pullRequestEnabled) ($prUnit.PullRequestsConfig.AutodetectManualMerge)}}checked{{end}}>
570+
<label>{{.locale.Tr "repo.settings.pulls.enable_autodetect_manual_merge"}}</label>
571+
</div>
572+
</div>
573+
<div class="field">
574+
<div class="ui checkbox">
575+
<input name="pulls_ignore_whitespace" type="checkbox" {{if and $pullRequestEnabled ($prUnit.PullRequestsConfig.IgnoreWhitespaceConflicts)}}checked{{end}}>
576+
<label>{{.locale.Tr "repo.settings.pulls.ignore_whitespace"}}</label>
577+
</div>
578+
</div>
567579
</div>
568580
{{end}}
569581

templates/swagger/v1_json.tmpl

+9
Original file line numberDiff line numberDiff line change
@@ -16497,6 +16497,11 @@
1649716497
"type": "boolean",
1649816498
"x-go-name": "AutodetectManualMerge"
1649916499
},
16500+
"default_allow_maintainer_edit": {
16501+
"description": "set to `true` to allow edits from maintainers by default",
16502+
"type": "boolean",
16503+
"x-go-name": "DefaultAllowMaintainerEdit"
16504+
},
1650016505
"default_branch": {
1650116506
"description": "sets the default branch for this repository.",
1650216507
"type": "string",
@@ -19015,6 +19020,10 @@
1901519020
"format": "date-time",
1901619021
"x-go-name": "Created"
1901719022
},
19023+
"default_allow_maintainer_edit": {
19024+
"type": "boolean",
19025+
"x-go-name": "DefaultAllowMaintainerEdit"
19026+
},
1901819027
"default_branch": {
1901919028
"type": "string",
1902019029
"x-go-name": "DefaultBranch"

0 commit comments

Comments
 (0)