problem: no option to force update when posting to /contents and new_branch already exists #12600
Labels
No labels
arch
riscv64
backport/v1.19
backport/v1.20
backport/v1.21/forgejo
backport/v10.0/forgejo
backport/v11.0/forgejo
backport/v12.0/forgejo
backport/v13.0/forgejo
backport/v14.0/forgejo
backport/v15.0/forgejo
backport/v7.0/forgejo
backport/v8.0/forgejo
backport/v9.0/forgejo
breaking
bug
bug
confirmed
bug
duplicate
bug
needs-more-info
bug
new-report
bug
reported-upstream
code/actions
code/api
code/auth
code/auth/faidp
code/auth/farp
code/email
code/federation
code/git
code/migrations
code/packages
code/wiki
database
MySQL
database
PostgreSQL
database
SQLite
dependency-upgrade
dependency
Chi
dependency
Chroma
dependency
F3
dependency
ForgeFed
dependency
garage
dependency
Gitea
dependency
Golang
Discussion
duplicate
enhancement/feature
forgejo/accessibility
forgejo/branding
forgejo/ci
forgejo/commit-graph
forgejo/documentation
forgejo/furnace cleanup
forgejo/i18n
forgejo/interop
forgejo/moderation
forgejo/privacy
forgejo/release
forgejo/scaling
forgejo/security
forgejo/ui
Gain
High
Gain
Nice to have
Gain
Undefined
Gain
Very High
good first issue
i18n/backport-stable
impact
large
impact
medium
impact
small
impact
unknown
Incompatible license
issue
closed
issue
do-not-exist-yet
issue
open
manual test
Manually tested during feature freeze
OS
FreeBSD
OS
Linux
OS
macOS
OS
Windows
problem
QA
regression
release blocker
Release Cycle
Feature Freeze
release-blocker
v7.0
release-blocker
v7.0.1
release-blocker
v7.0.2
release-blocker
v7.0.3
release-blocker
v7.0.4
release-blocker
v8.0.0
release-blocker/v9.0.0
run-all-playwright-tests
run-end-to-end-tests
stage
2-research
stage
3-design
stage
4-implementation
test
manual
test
needed
test
needs-help
test
not-needed
test
present
untested
User research - time-tracker
valuable code
worth a release-note
User research - Accessibility
User research - Blocked
User research - Community
User research - Config (instance)
User research - Errors
User research - Filters
User research - Future backlog
User research - Git workflow
User research - Labels
User research - Moderation
User research - Needs input
User research - Notifications/Dashboard
User research - Rendering
User research - Repo creation
User research - Repo units
User research - Security
User research - Settings (in-app)
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
forgejo/forgejo#12600
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Does your problem still exist on the latest Forgejo version?
Yes, the problem still exists (tested locally with the latest development version)
About your usage of Forgejo
I'm working on supporting forgejo in an open-source automated release tool, https://github.com/robgonnella/releasaurus
Problem description
I am currently posting to
/api/v1/repos/{owner}/{repo}/contentsto update multiple files at once for a new branch; however, this call fails if new_branch already exists. I would love to have an option that would allow the "new" branch to be force updated if it already exists.Adding this option would allow me to better support forgejo in an automated release tool I've created, https://github.com/robgonnella/releasaurus.
I was able to land a similar patch in gitea as well https://github.com/go-gitea/gitea/issues/35538, and would be happy to post a similar PR for forgejo if you are open to accepting this change.
Potential workarounds
I'm currently able to work around the issue in two ways, but both are less than ideal.
This is problematic as any open PRs on the new branch will also be closed. The means the automated release tool will close and reopen PRs every time a commit is added to the
mainbranch resulting in an accumulation of closed / abandoned release PRs. Additionally this approach requires waiting an arbitrary amount of time for PRs to be closed after deleting the branch before the release branch can be re-created.releasaurusoffers the option to use a locally cloned repo for git operations and then only uses forge API calls to create PRs and releasesThis does fully workaround the issue but is less effective in a CI environment where
releasaurusis designed to work without any direct dependency on git. This becomes more of an issue whenreleasaurusis being used to manage multiple projects as a hosted service as it introduces additional storage requirements.Forgejo Version
image: codeberg.org/forgejo/forgejo:15
Other details about your environment (software names and versions)
Tested by running forgejo locally using docker as well as a hosted repo on codeberg.org
Solutions
Accepted solutions to address this problem will go here
If I understand https://codeberg.org/api/swagger#/repository/repoChangeFiles correctly, then by default each POST triggers a commit with the file modifications.
And what you want: that an option is added to reset the branch first? Thus, that the
new_branchwill have only the commits ofbranch+ 1?What is the option supposed to do if
new_branchis not given?As a third workaround comes to my mind:
Create a commit for each file change, by firstly getting all files https://codeberg.org/api/swagger#/repository/repoGetContentsList, create all file changes and use https://codeberg.org/api/swagger#/repository/repoChangeFiles. Maybe a bit error-prune, but doesn't have the flaws of your workarounds above.
Yes this is what I would like to have. Since the underlying operation is just a push, it amounts to adding an option for
push --force.I would expect that in all cases
forceis applied to the targeted branch, which can be eitherbranchornew_branch, and should be subject to the existing branch protection rules. If the user providesforceandbranch, but notnew_branchI believeforceultimately has no effect as it's just adding a commit on top, but might be rejected just based on branch rules. I'm not sure I really see this as a flawThe proposed 3rd workaround isn't actually a solution, it suffers from the same exact issue. Actually it is very similar to the way the release tool works currently. Instead of fetching the entire contents list, we fetch only the files we know we want to modify, create the file changes, and then use https://codeberg.org/api/swagger#/repository/repoChangeFiles - just as you have suggested. The problem is that the call to https://codeberg.org/api/swagger#/repository/repoChangeFiles will always fail if
new_branchalready exists, as I've described above. Ifnew_branchalready exists the API currently always returns a 422 status code.@mahlzahn just curious if the team might be open to this addition? If so I'm happy to put the work in and create a PR for review. I just don't want to waste anyone's time if not something the team is willing to consider. Also thank you for taking the time to review my request! Much appreciated. And thank you for all your work on forgejo as well!
Yes, you’re right. The main issue I see is that e.g., a rebase would require a very complicated and heavy call to the API. Thus, not suitable.
What about following workflow for updating a PR?
Or doesn’t that work for you? I didn’t try it, but I’d expect that you can just add more commits like that (without
new_branch). At least if you only change few files?I can’t answer you on that, yet. For me these
contentsAPI seems a bit weird (because there is Git) and I wasn’t even aware of them to exist. But, they exist and thus, maybe should cover cases like yours. I don’t know.This is an interesting approach. Thank you for the lead, somehow I missed this
/pulls/{index}/updateroute. I'll give it a try but I worry it might still fall short of the desired outcome.The idea is that the release branch only contains a single commit - something of the form
chore(<branch>): release .... In the case where users are using rebase / fast-forward / squash merge-method, the resulting single commit gets tagged. In the case where they are using merge-commit as the merge-method, the merge commit gets tagged.Branch creation, PR creation / updates, changelog updates, manifest version updates, tagging, and release creation are all fully automated. In this flow, having a release branch / PR with potentially hundreds of the same commit message is probably not going to work. FWIW github, gitlab, gitea, and azure-devops are all supported in this workflow.
I found some time to test the
/pulls/{index}/updateapproach and I was able to successfully rebase the release branch and add new changelog / manifest version update commits for each incoming commit on the base branch.However, this would accumulate potentially hundreds of commits on the release branch, all with similar titles. I could document this and instruct our users that they need to either squash the commits when merging, or use the alternate "local-path" hybrid mode offered in releasaurus. I do think offering a way to force push the target branch through API calls is a reasonable change though, and is offered in other forge APIs. I will attempt to create a PR for this functionality and see if I can get some traction.
Great that this workaround is working :)
Maybe an option
force_overwrite_new_branchcould be an option to only be used when bothbranchandnew_branchare given?