Fix API not persisting pull request unit config when has_pull_requests is not set#36718
Fix API not persisting pull request unit config when has_pull_requests is not set#36718silverwind merged 9 commits intogo-gitea:mainfrom
Conversation
There was a problem hiding this comment.
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.SetPtrTohelper 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>
cf71560 to
580c9f2
Compare
…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>
|
AI only knows copying-pasting code. It will cause inconsistency and even bugs in the future. gitea/services/repository/create.go Lines 385 to 394 in 427954b |
|
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. |
acbded5 to
262ef7f
Compare
|
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. |
|
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. |
|
So I understand that new repos will now have |
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. |
|
Ah, you meant the description. Yeah I will do that via AI to summarize this PR's content. |
|
description updated, merging. |
* 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)
* 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

The
PATCH /api/v1/repos/{owner}/{repo}endpoint silently ignores pullrequest config fields (like
default_delete_branch_after_merge,allow_squash_merge, etc.) unlesshas_pull_requests: trueis alsoincluded 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_requeststo be explicitly set. A new unit is onlycreated when
has_pull_requests: trueis explicitly sent.Fixes #36466