Skip to content

fix(api): preserve protected branches when refresh fails - #22655

Merged
tidy-dev merged 1 commit into
desktop:developmentfrom
agisilaos:fix/7864-protected-branches-error-handling
Aug 19, 2026
Merged

tidy-dev merged 1 commit into
desktop:developmentfrom
agisilaos:fix/7864-protected-branches-error-handling

Conversation

@agisilaos

@agisilaos agisilaos commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

Closes: #7864

Description

fetchProtectedBranches previously returned an empty array both when a request succeeded without protected branches and when the request failed. This caused temporary or ambiguous API failures to clear the last-known branch protection information.

This PR:

  • returns null when the protected branches request cannot be completed;
  • preserves existing branch protection information for inconclusive results;
  • continues treating a successful empty response as authoritative, allowing
    removed branch protections to clear the cache; and
  • adds coverage for populated, empty, network-failure, and 404 responses.

A 404 is treated as inconclusive because GitHub may return it for inaccessible private resources as well as missing repositories. Preserving the last-known state is safer than recording that the repository has no protections.

Testing

  • yarn test
  • yarn lint
  • yarn compile:dev

Release notes

Notes: [Fixed] Preserve existing branch protection information when GitHub API requests fail - #7864

What changed:
- Return null when protected branch requests fail.
- Skip cache updates for inconclusive refreshes while preserving successful empty results.
- Cover populated, empty, network failure, and not found responses.

Why:
- Prevent transient or ambiguous API failures from clearing cached branch protection state.

Alternatives considered:
- Treat 404 as no protected branches, but GitHub can use 404 for inaccessible private resources.
- Let the API throw, but the background refresh should handle inconclusive results without mutating state.
@agisilaos
agisilaos requested a review from a team as a code owner August 4, 2026 19:34
@agisilaos
agisilaos requested a review from babakks August 4, 2026 19:34
@github-actions github-actions Bot added external Pull request originating outside of the Desktop core team needs-triage labels Aug 4, 2026
@babakks babakks added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Aug 5, 2026

@tidy-dev tidy-dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ Thanks for the fix. Seems reasonable. :)

@tidy-dev
tidy-dev merged commit c956d19 into desktop:development Aug 19, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external Pull request originating outside of the Desktop core team ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

improve error handling of protected branches API call

3 participants