Skip to content

Only force merge-request flow when a direct push would be rejected - #10

Merged
riki137 merged 1 commit into
mainfrom
fix-mr-flow-pr-required
Jun 30, 2026
Merged

Only force merge-request flow when a direct push would be rejected#10
riki137 merged 1 commit into
mainfrom
fix-mr-flow-pr-required

Conversation

@riki137

@riki137 riki137 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Problem

The protected-branch check forced the merge-request workflow whenever a branch was protected — but that flag flips true for plenty of rules that don't block a direct push (required status checks, signed commits, linear history, deletion protection). So releases on those branches were needlessly routed through an MR.

Confirmed against the live API: vuejs/core's main is protected: true with only deletion/non_fast_forward rules — no PR requirement — yet was being forced to MR. GitLab had the same issue: it protects the default branch with "Maintainers can push" out of the box, so protected: true even though the maintainer cutting the release can push directly.

Fix

Detect the real condition — would this push actually be rejected? — per forge:

Forge Before After
GitHub .protected (any rule) pull_request rule present (rules endpoint)
GitLab .protected (any protection) .can_push == false
  • GitHub: queries the branch rules for a pull_request rule. Covers both rulesets and classic branch protection, and needs only read access (the branch-protection endpoint is admin-only).
  • GitLab: checks .can_push (whether the current user may push) instead of .protected, so a maintainer pushing to a "Maintainers can push" branch still pushes directly.

Both undeterminable/CLI-missing fallbacks are unchanged — detection stays advisory and never blocks a release.

Tests

Unit tests updated for the new queries; full suite, typecheck, and lint pass.

The protected-branch check forced the MR workflow whenever a branch was
"protected", but that flag flips for rules that don't block a direct push
(required status checks, signed commits, linear history, deletion
protection), so releases were needlessly routed through an MR.

Detect the real condition instead:
- GitHub: query the branch rules for a `pull_request` rule (covers
  rulesets and classic protection, read access only) rather than `.protected`.
- GitLab: check `.can_push` rather than `.protected`, so a maintainer
  pushing to a "Maintainers can push" branch still pushes directly.
@sonarqubecloud

Copy link
Copy Markdown

@riki137
riki137 merged commit 75c2ee8 into main Jun 30, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant