githaven/routers/api/v1/repo
Henry Goodman 12cb1d2998
Allow force push to protected branches (#28086)
Fixes #22722 

### Problem
Currently, it is not possible to force push to a branch with branch
protection rules in place. There are often times where this is necessary
(CI workflows/administrative tasks etc).

The current workaround is to rename/remove the branch protection,
perform the force push, and then reinstate the protections.

### Solution
Provide an additional section in the branch protection rules to allow
users to specify which users with push access can also force push to the
branch. The default value of the rule will be set to `Disabled`, and the
UI is intuitive and very similar to the `Push` section.

It is worth noting in this implementation that allowing force push does
not override regular push access, and both will need to be enabled for a
user to force push.

This applies to manual force push to a remote, and also in Gitea UI
updating a PR by rebase (which requires force push)

This modifies the `BranchProtection` API structs to add:
- `enable_force_push bool`
- `enable_force_push_whitelist bool`
- `force_push_whitelist_usernames string[]`
- `force_push_whitelist_teams string[]`
- `force_push_whitelist_deploy_keys bool`

### Updated Branch Protection UI:

<img width="943" alt="image"
src="https://github.com/go-gitea/gitea/assets/79623665/7491899c-d816-45d5-be84-8512abd156bf">

### Pull Request `Update branch by Rebase` option enabled with source
branch `test` being a protected branch:


![image](https://github.com/go-gitea/gitea/assets/79623665/e018e6e9-b7b2-4bd3-808e-4947d7da35cc)
<img width="1038" alt="image"
src="https://github.com/go-gitea/gitea/assets/79623665/57ead13e-9006-459f-b83c-7079e6f4c654">

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2024-07-05 18:21:56 +00:00
..
action.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
avatar.go Move context from modules to services (#29440) 2024-02-27 08:12:22 +01:00
blob.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
branch.go Allow force push to protected branches (#28086) 2024-07-05 18:21:56 +00:00
collaborators.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
commits.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
compare.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
file.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
fork.go Add user blocking (#29028) 2024-03-04 08:16:03 +00:00
git_hook.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
git_ref.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
hook_test.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
hook.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
issue_attachment.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
issue_comment_attachment.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
issue_comment.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
issue_dependency.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
issue_label.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
issue_pin.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
issue_reaction.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
issue_stopwatch.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
issue_subscription.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
issue_tracked_time.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
issue.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
key.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
label.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
language.go Move context from modules to services (#29440) 2024-02-27 08:12:22 +01:00
main_test.go make writing main test easier (#27270) 2023-09-28 01:38:53 +00:00
migrate.go Fix "force private" logic (#31012) 2024-05-20 00:56:45 +00:00
milestone.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
mirror.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
notes.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
patch.go Move context from modules to services (#29440) 2024-02-27 08:12:22 +01:00
pull_review.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
pull.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
release_attachment.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
release_tags.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
release.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
repo_test.go Move context from modules to services (#29440) 2024-02-27 08:12:22 +01:00
repo.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
star.go Move context from modules to services (#29440) 2024-02-27 08:12:22 +01:00
status.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
subscriber.go Move context from modules to services (#29440) 2024-02-27 08:12:22 +01:00
tag.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
teams.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
topic.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
transfer.go Add user blocking (#29028) 2024-03-04 08:16:03 +00:00
tree.go Refactor names (#31405) 2024-06-19 06:32:45 +08:00
wiki.go Enable more revive linter rules (#30608) 2024-04-22 11:48:42 +00:00