Skip to content

feat: Add default PR branch update style setting#37410

Merged
bircni merged 18 commits into
go-gitea:mainfrom
bircni:feature/pr-default-update-style
May 16, 2026
Merged

feat: Add default PR branch update style setting#37410
bircni merged 18 commits into
go-gitea:mainfrom
bircni:feature/pr-default-update-style

Conversation

@bircni
Copy link
Copy Markdown
Member

@bircni bircni commented Apr 24, 2026

Adds repository-level settings for pull request branch updates so admins can choose the default update method and disable merge or rebase updates.

Co-Authored-By: OpenAI Codex (GPT-5) <codex@openai.com>
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 24, 2026
@bircni
Copy link
Copy Markdown
Member Author

bircni commented Apr 24, 2026

this the first one shot test with Codex 5.5

@lunny
Copy link
Copy Markdown
Member

lunny commented Apr 24, 2026

Why is this option necessary?

@silverwind
Copy link
Copy Markdown
Member

silverwind commented Apr 24, 2026

Same question. GitHub offers only merge style branch updates to my knowledge. I wonder what the benefit of other styles is exactly. New Options are good but I'm not sure we should overload users with them.

@silverwind
Copy link
Copy Markdown
Member

silverwind commented Apr 24, 2026

Actually I was wrong, Github does support rebase updates:

https://github.blog/changelog/2022-02-02-more-ways-to-keep-your-pull-request-branch-up-to-date/

So it makes sense for feature parity. Should be implemented with a dropdown-style on the "Update branch" button with similar UX than GitHub. Also I think GitHub has some condition on when they show the dropdown vs. regular button. Find out what that condition is.

@silverwind
Copy link
Copy Markdown
Member

silverwind commented Apr 24, 2026

Some more info. Dropdown UI:

image

Button only shows when "Allow rebase merging" setting is enabled, if it's disabled, the button revers to be a simple merge style update.

Gitea has a existing option "Enable updating pull request branch by rebase" which can be used to decide whether to display button or buton+dropdown.

Maybe some of that stuff is already implemented, just documenting this here.

@lunny
Copy link
Copy Markdown
Member

lunny commented Apr 24, 2026

@silverwind I think this is a bit off-topic. This PR is intended to add an option that lets users choose whether the default update action should be Update with merge commit or Update with rebase.

@silverwind
Copy link
Copy Markdown
Member

It describes the mechanism. I wasn't aware that Gitea seems to implement some of this already. A option is good to have in any case.

@wxiaoguang
Copy link
Copy Markdown
Contributor

  1. duplicate logic
  2. unmaintanable logic like (updateStyle != repo_model.UpdateStyleMerge && updateStyle != repo_model.UpdateStyleRebase) || (!allowedUpdateByMerge && !rebase) || (rebase && !allowedUpdateByRebase)
  3. default values break existing users

bircni and others added 2 commits April 26, 2026 12:06
Comment thread models/repo/repo_unit.go Outdated
Co-Authored-By: OpenAI Codex (GPT-5.5) <codex@openai.com>
@silverwind
Copy link
Copy Markdown
Member

Doing some fixups.

- API `POST /pulls/{id}/update` with no `style` continues to mean "merge"
  rather than the repo's DefaultUpdateStyle, preserving the historical
  contract for existing API clients.
- Centralize update-settings validation as
  `(*PullRequestsConfig).ValidateUpdateSettings()` with sentinel errors,
  reused by both the API and web routers.
- Inline two trivial single-caller helpers; introduce a small
  `ResolveUpdateStyle(requested, fallback)` so the API and web paths
  share the resolution shape.
- Gate API EditRepoOption update-style validation on the new fields
  being supplied, so unrelated PATCH calls don't return 422.
- Web settings handler maps the model sentinels to locale strings.
- Collapse three FromDB tests into a table-driven test and add a
  legacy-JSON regression case (pre-PR row with AllowRebaseUpdate=false
  and the new fields absent must preserve the historical setting).
- Extract setupOutdatedPRWithConfig helper for the new integration tests.
- Template: bind $isRebase once, drop redundant doc comments.

Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
@silverwind
Copy link
Copy Markdown
Member

silverwind commented Apr 26, 2026

Done, among other cleanups, it fixed an api break when no style was passed. I think this is better existing API clients but could be argued that they should also use the default style.

@silverwind silverwind marked this pull request as ready for review April 26, 2026 11:39
Comment thread routers/web/repo/setting/setting.go
@wxiaoguang wxiaoguang marked this pull request as draft April 26, 2026 11:45
Comment thread models/repo/repo_unit.go Outdated
@bircni bircni changed the title Add default PR branch update style setting feat: Add default PR branch update style setting May 11, 2026
Comment thread templates/repo/settings/options.tmpl Outdated
@bircni bircni marked this pull request as ready for review May 11, 2026 14:55
@bircni bircni requested a review from wxiaoguang May 11, 2026 14:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds repository-level configuration for “Update branch” behavior on pull requests, letting repo admins choose a default update style (merge vs rebase) and independently enable/disable each update method, while preserving API back-compat when the style parameter is omitted.

Changes:

  • Introduce UpdateStyle and new PR unit config fields: AllowMergeUpdate, AllowRebaseUpdate, DefaultUpdateStyle, plus validation helpers.
  • Wire the new settings through web UI, API edit-repo endpoints, API/struct conversion, and swagger docs.
  • Update PR “outdated” UI and add/extend unit + integration tests (including API back-compat/validation cases).

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/integration/pull_update_test.go Adds integration coverage for API update behavior (no-style back-compat; disabled style forbidden) and shared setup helpers.
tests/integration/api_repo_edit_test.go Extends repo edit test helpers to include new fields and adds validation tests for invalid combinations.
templates/swagger/v1_openapi3_json.tmpl Documents new allow_merge_update and default_update_style fields in OpenAPI v3 template.
templates/swagger/v1_json.tmpl Documents new allow_merge_update and default_update_style fields in swagger v1 template.
templates/repo/settings/options.tmpl Adds repo settings controls for merge-update enablement and default update style selection.
templates/repo/issue/view_content/update_branch_by_merge.tmpl Switches outdated-PR update UI to data-driven primary action + optional style dropdown.
services/pull/update.go Adds helpers to resolve requested vs default style and applies new repo config gates for merge/rebase update permissions.
services/pull/update_test.go Adds unit test for default update style retrieval and extends permission tests for merge-update disablement.
services/forms/repo_form.go Extends repo settings form with new update settings fields.
services/convert/repository.go Exposes new update settings fields in API repository conversion output.
routers/web/repo/setting/setting.go Prepares template data for default update style dropdown and validates new settings on save.
routers/web/repo/pull.go Makes web “Update branch” route respect repo default style when style is omitted.
routers/web/repo/issue_view.go Builds primary update action + dropdown options based on repo default and allowed styles.
routers/api/v1/repo/repo.go Applies and validates new update settings fields in repo PATCH endpoint (422 on invalid combos).
routers/api/v1/repo/pull.go Preserves API back-compat: no style parameter continues to mean merge update.
options/locale/locale_en-US.json Adds English strings for the new repo settings UI labels.
modules/structs/repo.go Adds new fields to API structs (Repository, EditRepoOption).
models/repo/repo_unit.go Extends PullRequestsConfig with new update settings + validation methods and DB defaulting behavior.
models/repo/pull_request_default_test.go Adds unit tests for config DB unmarshalling defaults and validation failures.
models/repo/git.go Introduces UpdateStyle type and constants (merge, rebase).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels May 13, 2026
@lunny lunny added the type/enhancement An improvement of existing functionality label May 13, 2026
@lunny lunny added this to the 1.27.0 milestone May 13, 2026
Comment thread tests/integration/api_repo_edit_test.go Outdated
Comment thread tests/integration/pull_update_test.go Outdated
Comment thread templates/repo/settings/options.tmpl
Comment thread templates/repo/issue/view_content/update_branch_by_merge.tmpl Outdated
@bircni bircni requested a review from wxiaoguang May 13, 2026 16:44
Comment thread routers/api/v1/repo/pull.go Outdated
Comment thread services/pull/update.go Outdated
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels May 16, 2026
@bircni bircni added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label May 16, 2026
@bircni bircni enabled auto-merge (squash) May 16, 2026 09:38
@bircni bircni merged commit 34fd3c9 into go-gitea:main May 16, 2026
21 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label May 16, 2026
silverwind added a commit to silverwind/gitea that referenced this pull request May 18, 2026
* origin/main: (39 commits)
  fix: Add missed token scope checking (go-gitea#37735)
  chore: Use giteabot instead of backporter (go-gitea#37422)
  fix: Allow direct commits for unprotected files with push restrictions (go-gitea#37657)
  chore: Conventional adjustments (go-gitea#37677)
  chore(db): introduce db.Session and db.EngineMigration interfaces (go-gitea#37746)
  fix(migrations): preserve unique constraints in v334 sync (go-gitea#37743)
  feat(web): also display PR counts in repo list (go-gitea#37739)
  feat: execute post run cleanup when workflow is cancelled (go-gitea#37275)
  fix(actions): wrong assumption that run id always >= job id (go-gitea#37737)
  fix(icon): use repo-forked icon to display forks count (go-gitea#37731)
  fix(oauth): strengthen PKCE validation and refresh token replay protection (go-gitea#37706)
  fix(web): enforce token scopes on raw, media, and attachment downloads (go-gitea#37698)
  feat: Add bypass allowlist for branch protection (go-gitea#36514)
  refactor(glob): use strings.Builder for regexp compilation (go-gitea#37730)
  feat(oauth): Support AWS Cognito OAuth2 provider (go-gitea#37607)
  feat: Add default PR branch update style setting (go-gitea#37410)
  refactor: move `workflowpattern` into `modules/actions` (go-gitea#37717)
  ci: add `zizmor` to `lint-actions` (go-gitea#37720)
  chore(doctor): remove four obsolete doctor check implementations (go-gitea#37728)
  chore(renovate): enable dockerfile manager (go-gitea#37719)
  ...

# Conflicts:
#	modules/globallock/locker_test.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants