Skip to content

fix(bin): allow GitLab merges only when CI is confirmed unable to run at all - #18

Merged
alandomio merged 2 commits into
mainfrom
fm/fm-merge-no-ci
Sep 10, 2026
Merged

alandomio merged 2 commits into
mainfrom
fm/fm-merge-no-ci

Conversation

@alandomio

Copy link
Copy Markdown
Owner

Intent

Fix bin/fm-pr-merge.sh so it can distinguish "no automated checks exist at all" from "checks could run but didn't or failed" when merging a GitLab merge request.

Concrete failure: fm-pr-merge.sh refuses a GitLab merge unless head_pipeline.status == "success" at the exact current head. On a project where CI is switched off at the project level (e.g. jobs_enabled=false / builds_access_level=disabled), head_pipeline is always null, so status reads "none" and every merge is refused forever, with no way to proceed except bypassing the tool. This blocked captain-authorized merges on real GitLab projects (GOPlannerWeb has jobs_enabled=false and a .gitlab-ci.yml it can never run; the Android project has no pipeline configured either).

Requirements:

  • Allow a merge on a project where automated checks genuinely cannot run at all, and say loudly in the output that it did so and why.
  • Do NOT allow a merge where checks could run but did not or failed: a failed/cancelled/still-running pipeline, a pipeline that succeeded at a different commit than head, no pipeline at this head because job rules skipped it or it hasn't started yet, or a project with CI enabled but no pipeline on this particular merge request. None of those count as "no checks exist".
  • The signal is the project's own live-read capability (jobs_enabled / builds_access_level from the forge), not the absence of a pipeline on this one merge request, and not the presence/absence of a .gitlab-ci.yml file (GOPlannerWeb has one and still can't run it).
  • Decide whether the relaxed state additionally requires an explicit caller opt-in flag, and justify the choice either way in the PR description.
  • Keep every other pre-merge condition unchanged: open, mergeable, no conflicts, blocking discussions resolved, verified head passed as --sha.
  • Refusal messages must keep naming every failing condition, not just the first.
  • Add tests colocated in tests/, extending the existing fm-pr-merge.test.sh runner and conventions, covering at minimum: CI disabled at project level (allowed); CI enabled but no pipeline on this MR (refused); pipeline failed (refused); pipeline succeeded at a stale commit (refused); pipeline succeeded at head (allowed, unchanged).
  • Tests must exercise behavior through the script's interface, never assert source bytes.
  • GitHub path is out of scope; do not change it.
  • bin/fm-lint.sh must be clean.
  • Loaded firstmate-coding-guidelines before editing, since this is firstmate's own shared tracked material.

What Changed

  • bin/fm-pr-merge.sh: added gitlab_ci_disabled_at_project_level(), which live-reads a GitLab project's jobs_enabled/builds_access_level via glab api projects/<encoded> and returns success only when CI is structurally incapable of running there.
  • The pre-merge pipeline check now skips the "pipeline succeeded at head" requirement only when the merge request has no head pipeline and that project-level check confirms CI can never run; a failed, canceled, still-running, or stale-commit pipeline is always refused regardless of project capability, and a project that can run CI but simply has no pipeline yet is still refused. Refusal messages continue to list every failing condition, not just the first.
  • Success output distinguishes the two allowed outcomes: a normal "successful pipeline at head" message, or a "merging with no pipeline check" message paired with a loud notice: line naming the project and its jobs_enabled/builds_access_level values.
  • Updated docs/architecture.md and docs/gitlab-merge-watch.md to describe the new exception and point to the script header as the source of truth for its exact conditions.
  • Extended tests/fm-pr-merge.test.sh with cases for: CI disabled at the project level (allowed), CI enabled but no pipeline on the MR (refused), a failed pipeline (refused), a pipeline succeeded at a stale commit (refused), and a pipeline succeeded at head (allowed, unchanged) — all exercised through the script's interface rather than by asserting source bytes.

No caller-facing opt-in flag was added: the relaxation is gated purely on a fresh, per-call live read of the project's own forge-reported capability, which cannot go stale the way a passed-in or remembered flag could, so there's no separate flag to keep in sync with reality. The GitHub merge path is unchanged.

Risk Assessment

✅ Low: The change is narrowly scoped to the GitLab pipeline-refusal path, correctly reads live project capability (jobs_enabled/builds_access_level) only when no head pipeline exists, never relaxes a failed/stale/running pipeline, preserves all other pre-merge conditions and multi-condition refusal reporting, leaves GitHub untouched, is covered by thorough behavior-driven tests for every required scenario in the intent, and passes fm-lint.sh.

Testing

Ran the colocated fm-pr-merge.test.sh suite (30 cases including 6 new ones added by this change) and all pass, verified the new tests are non-vacuous by confirming they fail against the pre-fix script, and confirmed fm-lint.sh reports no ShellCheck issues; no UI surface exists for this CLI script change so the test transcript is the product-level evidence.

Evidence: fm-pr-merge.test.sh full run (target commit) — 6 new GitLab CI-capability tests all pass
ok - fm-pr-merge merges a GitLab merge request with no pipeline when jobs_enabled is false
ok - fm-pr-merge treats builds_access_level=disabled the same as jobs_enabled=false
ok - fm-pr-merge still refuses a pipeline-less GitLab merge request when the project can run CI
ok - fm-pr-merge never relaxes a pipeline that ran and failed, even on a CI-disabled project
ok - fm-pr-merge never relaxes a pipeline that succeeded at a stale commit, even on a CI-disabled project
ok - fm-pr-merge does not query project capability when the head pipeline already succeeded
Evidence: Regression check: same test against base commit (55db226) bin/fm-pr-merge.sh fails as expected
not ok - gitlab-ci-disabled-jobs: a project with jobs disabled should merge with no pipeline: expected exit 0, got 1

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ bin/fm-pr-merge.sh:172 - gitlab_ci_disabled_at_project_level() prints its 'merging with no pipeline check' notice as soon as project settings confirm CI is disabled, before the other pre-merge conditions (state, mergeable, conflicts, discussions) are evaluated. If one of those unrelated conditions also fails, stderr will show both the 'merging because none can ever run' notice and a subsequent 'error: refusing to merge' block for a different reason, which reads as contradictory even though the final refusal is correct. Purely a message-ordering nit; no functional impact since the merge is still correctly refused.
✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-pr-merge.test.sh (full targeted suite for this script, 30/30 passing on target commit)
  • Reverted bin/fm-pr-merge.sh to base commit 55db226 content and reran tests/fm-pr-merge.test.sh to confirm the new 'gitlab-ci-disabled-jobs' case fails (exit 1 vs expected 0), proving it's a real regression test, then restored the target commit's file via git checkout
  • bash bin/fm-lint.sh bin/fm-pr-merge.sh (ShellCheck 0.11.0, clean, exit 0)
  • git status --short (confirmed no leftover artifacts in the worktree after testing)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Alan Domio and others added 2 commits September 7, 2026 23:46
…nes in fm-pr-merge.sh

A GitLab merge request with no head pipeline was always refused, whether the
project genuinely cannot run CI or a pipeline simply has not run yet on this
one request. fm-pr-merge.sh now reads the project's own jobs_enabled and
builds_access_level, live, only when the head pipeline is absent, and relaxes
the pipeline check only when those confirm CI can never run there. A pipeline
that ran and failed, is still running, or ran at a stale commit is always
refused regardless of that project setting.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018Muwy5vLvuiW4qDadEFUtA
@alandomio
alandomio merged commit 36a3b66 into main Sep 10, 2026
13 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