Skip to content

Fix API not persisting pull request unit config when has_pull_requests is not set#36718

Merged
silverwind merged 9 commits intogo-gitea:mainfrom
silverwind:api-persist
Mar 2, 2026
Merged

Fix API not persisting pull request unit config when has_pull_requests is not set#36718
silverwind merged 9 commits intogo-gitea:mainfrom
silverwind:api-persist

Conversation

@silverwind
Copy link
Copy Markdown
Member

@silverwind silverwind commented Feb 23, 2026

The PATCH /api/v1/repos/{owner}/{repo} endpoint silently ignores pull
request config fields (like default_delete_branch_after_merge,
allow_squash_merge, etc.) unless has_pull_requests: true is also
included in the request body. This is because the entire PR unit config
block was gated behind if opts.HasPullRequests != nil.

This PR restructures the logic so that PR config options are applied
whenever the pull request unit already exists on the repo, without
requiring has_pull_requests to be explicitly set. A new unit is only
created when has_pull_requests: true is explicitly sent.

Fixes #36466

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 23, 2026
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels Feb 23, 2026
@silverwind silverwind requested a review from Copilot February 23, 2026 04:09
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

This PR fixes PATCH /api/v1/repos/{owner}/{repo} so pull request unit configuration updates (e.g. default_delete_branch_after_merge) persist even when has_pull_requests is omitted, aligning API behavior with the Web UI and addressing #36466.

Changes:

  • Update API repo edit logic to apply PR unit config changes when the PR unit already exists, and refactor pointer-to-value assignments via optional.SetPtrTo.
  • Add an integration test ensuring PR settings can be updated without sending has_pull_requests.
  • Add optional.SetPtrTo helper to reduce boilerplate in pointer-field updates.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/integration/api_repo_edit_test.go Adds regression coverage for updating PR settings without has_pull_requests.
routers/api/v1/repo/repo.go Adjusts PR unit update logic and refactors assignments using optional.SetPtrTo.
modules/optional/option.go Introduces SetPtrTo helper for conditional pointer-based assignments.

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

…s is not set

Previously, updating PR settings like `default_delete_branch_after_merge`
via `PATCH /api/v1/repos/{owner}/{repo}` required also sending
`has_pull_requests: true`. Without it, all PR config changes were silently
ignored. Now PR settings are updated whenever the unit already exists.

Also add `optional.SetPtrTo` helper and use it to reduce boilerplate.

Fixes go-gitea#36466

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…s is not set

Previously, updating PR settings like `default_delete_branch_after_merge`
via `PATCH /api/v1/repos/{owner}/{repo}` required also sending
`has_pull_requests: true`. Without it, all PR config changes were silently
ignored. Now PR settings are updated whenever the unit already exists.

Also add `optional.SetPtrTo` helper and use it to reduce boilerplate.

Fixes go-gitea#36466

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@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 Feb 23, 2026
@wxiaoguang
Copy link
Copy Markdown
Contributor

AI only knows copying-pasting code.

It will cause inconsistency and even bugs in the future.

case unit.TypePullRequests:
units = append(units, repo_model.RepoUnit{
RepoID: repo.ID,
Type: tp,
Config: &repo_model.PullRequestsConfig{
AllowMerge: true, AllowRebase: true, AllowRebaseMerge: true, AllowSquash: true, AllowFastForwardOnly: true,
DefaultMergeStyle: repo_model.MergeStyle(setting.Repository.PullRequest.DefaultMergeStyle),
AllowRebaseUpdate: true,
},
})

@wxiaoguang wxiaoguang marked this pull request as draft February 23, 2026 12:48
@wxiaoguang
Copy link
Copy Markdown
Contributor

wxiaoguang commented Feb 23, 2026

And you always blindly use AI, you know nothing about the code base and don't know what is the right thing to do. For example: Change default "allow edits from maintainers" to true #36709 , it is also related.

If you ever have some basic sense, you should know that the "default unit settings" should be handled in the same way.

@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Feb 23, 2026

The code might be bad but it's proven to work so it can't be completely wrong. I think the reason why AI can't produce good code is that the code base ist just too convoluted. In other code bases I have AI produce beautiful code.

@wxiaoguang wxiaoguang marked this pull request as ready for review February 23, 2026 14:41
@wxiaoguang
Copy link
Copy Markdown
Contributor

Because the rubberstamp approvals only make the code base more and more messy.

Although I do refactoring works, it never catches the new messy code growing faster and faster.

Actually I should leave the messy code to other maintainers, and save my time to play games.

@wxiaoguang
Copy link
Copy Markdown
Contributor

wxiaoguang commented Feb 23, 2026

By the way, DefaultAllowMaintainerEdit=true by default is there.

CI failure is caused by the changed default value:

Details image

Fixed.

@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 Mar 2, 2026
@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Mar 2, 2026

So I understand that new repos will now have DefaultAllowMaintainerEdit=true while existing ones remain at their stored setting? I can live with that personally.

@lunny
Copy link
Copy Markdown
Member

lunny commented Mar 2, 2026

So I understand that new repos will now have DefaultAllowMaintainerEdit=true while existing ones remain at their stored setting? I can live with that personally.

Yes. The pull request content needs to be updated.

@lunny lunny added type/bug type/enhancement An improvement of existing functionality reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. labels Mar 2, 2026
@silverwind
Copy link
Copy Markdown
Member Author

So I understand that new repos will now have DefaultAllowMaintainerEdit=true while existing ones remain at their stored setting? I can live with that personally.

Yes. The pull request content needs to be updated.

Pull request? I thought it's a per-repo setting, set only during repo creation or when manually updated in the repo settings.

@lunny
Copy link
Copy Markdown
Member

lunny commented Mar 2, 2026

So I understand that new repos will now have DefaultAllowMaintainerEdit=true while existing ones remain at their stored setting? I can live with that personally.

Yes. The pull request content needs to be updated.

Pull request? I thought it's a per-repo setting, set only during repo creation or when manually updated in the repo settings.

I mean since more codes changed since you first post this pull request, the content of this pull request should be updated before merging.

@silverwind
Copy link
Copy Markdown
Member Author

Ah, you meant the description. Yeah I will do that via AI to summarize this PR's content.

@silverwind
Copy link
Copy Markdown
Member Author

description updated, merging.

@silverwind silverwind enabled auto-merge (squash) March 2, 2026 21:20
@silverwind silverwind merged commit 761b9d4 into go-gitea:main Mar 2, 2026
26 checks passed
@silverwind silverwind deleted the api-persist branch March 2, 2026 22:08
@GiteaBot GiteaBot added this to the 1.26.0 milestone Mar 2, 2026
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 2, 2026
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 4, 2026
* giteaofficial/main:
  [skip ci] Updated translations via Crowdin
  fix: /repos/{owner}/{repo}/actions/{runs,jobs} requiring owner permissions (go-gitea#36818)
  Fix CRAN package version validation to allow more than 4 version components (go-gitea#36813)
  Fix API not persisting pull request unit config when has_pull_requests is not set (go-gitea#36718)
  feat: Add Actions API rerun endpoints for runs and jobs (go-gitea#36768)
  Fix bug when pushing mirror with wiki (go-gitea#36795)
  Pull Request Pusher should be the author of the merge (go-gitea#36581)
  Delete non-exist branch should return 404 (go-gitea#36694)
  Remove API registration-token (go-gitea#36801)
  Add background and run count to actions list page (go-gitea#36707)
silverwind added a commit to silverwind/gitea that referenced this pull request Mar 6, 2026
* origin/main: (27 commits)
  Fix OAuth2 authorization code expiry and reuse handling (go-gitea#36797)
  Fix org permission API visibility checks for hidden members and private orgs (go-gitea#36798)
  Fix non-admins unable to automerge PRs from forks (go-gitea#36833)
  upgrade to github.com/cloudflare/circl 1.6.3, svgo 4.0.1, markdownlint-cli 0.48.0 (go-gitea#36837)
  Fix dump release asset bug (go-gitea#36799)
  build(deps): update material-icon-theme v5.32.0 (go-gitea#36832)
  Fix bug to check whether user can update pull request branch or rebase branch (go-gitea#36465)
  Fix forwarded proto handling for public URL detection (go-gitea#36810)
  Fix artifacts v4 backend upload problems (go-gitea#36805)
  Add a git grep search timeout (go-gitea#36809)
  fix(repo): unify DEFAULT_SHOW_FULL_NAME output in templates and dropdown (go-gitea#36597)
  Harden render iframe open-link handling (go-gitea#36811)
  [skip ci] Updated translations via Crowdin
  fix: /repos/{owner}/{repo}/actions/{runs,jobs} requiring owner permissions (go-gitea#36818)
  Fix CRAN package version validation to allow more than 4 version components (go-gitea#36813)
  Fix API not persisting pull request unit config when has_pull_requests is not set (go-gitea#36718)
  feat: Add Actions API rerun endpoints for runs and jobs (go-gitea#36768)
  Fix bug when pushing mirror with wiki (go-gitea#36795)
  Pull Request Pusher should be the author of the merge (go-gitea#36581)
  Delete non-exist branch should return 404 (go-gitea#36694)
  ...

# Conflicts:
#	routers/web/repo/issue_view.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. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code type/bug type/enhancement An improvement of existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"default_delete_branch_after_merge"cannot be updated via API

5 participants