API: Patching branch_protection always clears status_check_contexts #6379

Open
opened 2025-11-02 06:54:07 -06:00 by GiteaMirror · 6 comments
Owner

Originally created by @ChristophGr on GitHub (Nov 24, 2020).

  • Gitea version (or commit ref): 1.12.5
  • Git version: git version 2.24.3
  • Operating system: Debian 9 - official docker image
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
  • Log gist:

Description

cat << EOF | curl -X PATCH https://my.gitea/api/v1/repos/${org}/${repo_id}/branch_protections/master" -H "Content-Type: application/json" -f -d @-                                                                                                     
{
  "enable_status_check": true,
  "status_check_contexts": [
    "my-status-check"
  ]
}
EOF

[...]
"enable_status_check": true,
"status_check_contexts": [
"my-status-check"
],
[...]

cat << EOF | curl -X PATCH https://my.gitea/api/v1/repos/${org}/${repo_id}/branch_protections/master" -H "Content-Type: application/json" -f -d @-                                                                                                     
{
  "dismiss_stale_approvals": true
}
EOF

-->

[...]
  "status_check_contexts": null,
[...]

Screenshots

Originally created by @ChristophGr on GitHub (Nov 24, 2020). <!-- NOTE: If your issue is a security concern, please send an email to security@gitea.io instead of opening a public issue --> <!-- 1. Please speak English, this is the language all maintainers can speak and write. 2. Please ask questions or configuration/deploy problems on our Discord server (https://discord.gg/gitea) or forum (https://discourse.gitea.io). 3. Please take a moment to check that your issue doesn't already exist. 4. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> - Gitea version (or commit ref): 1.12.5 - Git version: git version 2.24.3 - Operating system: Debian 9 - official docker image - Database (use `[x]`): - [ ] PostgreSQL - [x] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [x] No - Log gist: ## Description ``` cat << EOF | curl -X PATCH https://my.gitea/api/v1/repos/${org}/${repo_id}/branch_protections/master" -H "Content-Type: application/json" -f -d @- { "enable_status_check": true, "status_check_contexts": [ "my-status-check" ] } EOF ``` [...] "enable_status_check": true, "status_check_contexts": [ "my-status-check" ], [...] ``` cat << EOF | curl -X PATCH https://my.gitea/api/v1/repos/${org}/${repo_id}/branch_protections/master" -H "Content-Type: application/json" -f -d @- { "dismiss_stale_approvals": true } EOF ``` --> ``` [...] "status_check_contexts": null, [...] ``` ## Screenshots <!-- **If this issue involves the Web Interface, please include a screenshot** -->
GiteaMirror added the type/proposalmodifies/api labels 2025-11-02 06:54:07 -06:00
Author
Owner

@6543 commented on GitHub (Nov 24, 2020):

look's like status_check_contexts is required at the moment - so this issue is a proposal ...

API: Patching branch_protection: make status_check_contexts optional

@6543 commented on GitHub (Nov 24, 2020): look's like `status_check_contexts` is required at the moment - so this issue is a proposal ... **API: Patching branch_protection: make status_check_contexts optional**
Author
Owner

@ChristophGr commented on GitHub (Dec 1, 2020):

Then the documentation is wrong.
It says

Edit a branch protections for a repository. Only fields that are set will be changed
@ChristophGr commented on GitHub (Dec 1, 2020): Then the documentation is wrong. It says ``` Edit a branch protections for a repository. Only fields that are set will be changed ```
Author
Owner

@jolheiser commented on GitHub (Dec 1, 2020):

This is the same type of issue described in #13622 (but different route)
Our API has pseudo-required parameters which can be confusing since their description doesn't match what the code does.

Apologies, I wrongly assumed this was a similar issue.

This is the code responsible.
b1cf7f4df1/routers/api/v1/repo/branch.go (L640-L642)

We should also be checking to see if form.StatusCheckContexts actually contains anything.

@jolheiser commented on GitHub (Dec 1, 2020): ~~This is the same type of issue described in #13622 (but different route)~~ ~~Our API has pseudo-required parameters which can be confusing since their description doesn't match what the code does.~~ Apologies, I wrongly assumed this was a similar issue. This is the code responsible. https://github.com/go-gitea/gitea/blob/b1cf7f4df11dfac879d65125880d18a03fef22c0/routers/api/v1/repo/branch.go#L640-L642 We should also be checking to see if `form.StatusCheckContexts` actually contains anything.
Author
Owner

@ChristophGr commented on GitHub (Dec 1, 2020):

I don't get what the "dependency" between dismiss_stale_approvals and status_check_contexts should be.

It appears to me, that detecting missing attributes does not work properly for arrays (just a wild guess)

@ChristophGr commented on GitHub (Dec 1, 2020): I don't get what the "dependency" between `dismiss_stale_approvals` and `status_check_contexts` should be. It appears to me, that detecting missing attributes does not work properly for arrays (just a wild guess)
Author
Owner

@jolheiser commented on GitHub (Dec 1, 2020):

I've edited my above comment. This is caused because we don't check whether status_check_contexts is valid or not before updating the branch protection.

@jolheiser commented on GitHub (Dec 1, 2020): I've edited my above comment. This is caused because we don't check whether `status_check_contexts` is valid or not before updating the branch protection.
Author
Owner

@jpraet commented on GitHub (Jun 28, 2023):

look's like status_check_contexts is required at the moment - so this issue is a proposal ...

API: Patching branch_protection: make status_check_contexts optional

status_check_contexts is not required in EditBranchProtectionOption. So it's a bug? I've been bitten by it as well today.

@jpraet commented on GitHub (Jun 28, 2023): > look's like `status_check_contexts` is required at the moment - so this issue is a proposal ... > > **API: Patching branch_protection: make status_check_contexts optional** status_check_contexts is not required in EditBranchProtectionOption. So it's a bug? I've been bitten by it as well today.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#6379