PATCH endpoint for branch protections does not clear contexts array #26333
Labels
modifies/api
This PR adds API routes or modifies them
type/enhancement
An improvement of existing functionality
Milestone
Uh oh!
There was an error while loading. Please reload this page.
Description
The
PATCH /api/v1/repos/<org>/<repo>/branch_protections/<branch>
API endpoint edits an existing branch protection rule for the given repo and branch.When using the web interface to disable status checks in a branch protection rule, the lists of contexts (CICD job names) is automatically cleared.
When using the API endpoint to do the same, you can pass
status_check_contexts=[]
, but this value is ignored becauseenable_status_check
is false.To clear out that array, you have to make two separate PATCH calls: once to empty the array, and once to unset the boolean flag. There is a command in the below reproducer, where it says "UNCOMMENT THIS", which demonstrates the workaround of calling PATCH twice.
Ideally the
status_check_contexts
array would be emptied automatically when theenable_status_check
boolean flag is set to false, like the UI does.Reproducer
enable_status_check=true
, and add a string to thestatus_check_contexts
array.enable_status_check=false
, andstatus_check_contexts=[]
.status_check_contexts
array was not actually emptied. It still has the value from step 1.The below shell script does this, using a try.gitea.io account. After each call, the
status_check_contexts
array from the response is printed.Expected output:
Actual output:
Output when the "UNCOMMENT THIS" line is uncommented:
Shell script:
Reproducer assumptions
~/.git-credentials
file, which have API accesstest-branch-protection-rules
Gitea Version
1.20.2, 1.21.0+dev-463-g6a7a5ea32 (the version of try.gitea.io at time of writing)
Can you reproduce the bug on the Gitea demo site?
Yes
Log Gist
No response
Screenshots
This screenshot is from loading the branch protection edit page after running the above reproducer. It shows the stale context string in the text area.
Git Version
No response
Operating System
No response
How are you running Gitea?
I was able to reproduce it using try.gitea.io.
Database
None
The text was updated successfully, but these errors were encountered: