Skip to content

GitLab: show CI checks for MR-only pipelines and fork MRs - #15194

Open
v0id3r wants to merge 2 commits into
gitbutlerapp:masterfrom
v0id3r:gitlab-mr-pipeline-checks
Open

GitLab: show CI checks for MR-only pipelines and fork MRs#15194
v0id3r wants to merge 2 commits into
gitbutlerapp:masterfrom
v0id3r:gitlab-mr-pipeline-checks

Conversation

@v0id3r

@v0id3r v0id3r commented Aug 5, 2026

Copy link
Copy Markdown

Problem

The CI checks badge shows "No checks" for GitLab MRs in two common setups:

  1. MR-only pipelines. The backend queries GET /projects/:id/pipelines/latest?ref=<branch>, but detached / merged-results MR pipelines run on refs/merge-requests/:iid/* and are never found by branch name.
  2. MRs from forks. The badge never even created a query (enabled = !isFork && !isMerged) — a restriction motivated by the GitHub check-runs API that does not apply to GitLab. Even without the flag, jobs would be requested from the target project while fork pipelines run in the source project.

Approach

  • but-gitlab: split job pagination out of list_pipeline_jobs_for_ref (behavior unchanged) and add list_pipeline_jobs_for_open_mr: resolve the branch's open MR, re-fetch it via the single-MR endpoint for head_pipeline (list responses omit it), and list jobs from the project that owns the pipeline — by numeric id, since a fork's owner/repo path is unknown.
  • but-forge: when the ref path returns no jobs, fall back to the MR path. No open MR / no head pipeline is an authoritative empty result; MR-lookup 403/404 maps to an unresolved ref (cache preserved, "No checks"); other errors surface on the badge. head_sha is now filled from the pipeline SHA (previously always empty for GitLab).
  • Desktop: the badge's fork block now applies only where the forge cannot serve fork checks (forkBlocksChecks = isFork && !isGitLab); GitHub behavior is unchanged.

Deliberately unchanged

  • Source priority: pipelines/latest?ref= remains the primary source; the MR head pipeline is only a fallback when it is empty. Making it primary would silently change badge contents after force-pushes for branch-pipeline users.
  • Cache key: still the branch name. warm_ci_checks_cache stale cleanup and cache-only but status depend on it.

Testing

  • Unit tests for MR selection, job normalization (incl. numeric-project URL synthesis), and the head_sha mapping; cargo test -p but-gitlab -p but-forge, clippy -D warnings, desktop vitest and svelte-check all green.
  • The network path has no mock-server coverage in-repo. Manually verified against a live self-hosted GitLab: pushing to a branch with an open MR (MR-only pipelines) flips the badge to "Running" and follows the pipeline to its terminal state. Remaining scenarios (fork MRs, token without read_api) were exercised only via the unit-tested selection/error paths.

@v0id3r
v0id3r force-pushed the gitlab-mr-pipeline-checks branch 2 times, most recently from 8ef2c7b to cd4749c Compare August 5, 2026 11:52
v0id3r added 2 commits August 5, 2026 14:54
GitLab MR-only pipelines run on refs/merge-requests/* and fork MR
pipelines run in the source project, so pipelines/latest?ref= finds
neither. Split job pagination out of list_pipeline_jobs_for_ref and add
list_pipeline_jobs_for_open_mr: it resolves the branch's open MR,
re-fetches it for head_pipeline (absent from list responses), and lists
jobs from the project that owns the pipeline (numeric id for forks).
Non-success MR responses carry their HTTP status so callers can tell
missing access apart from other failures; a branch with no open MR or
head pipeline is authoritatively reported as having no checks.
When pipelines/latest?ref= returns nothing, fall back to the open MR's
head pipeline. The ref endpoint stays the primary source and the branch
name stays the cache key. MR-lookup 403/404 maps to an unresolved ref so
cached checks survive; no open MR is an authoritative empty result.
head_sha is now populated from the pipeline SHA (previously always
empty for GitLab).

The checks badge keeps its fork block only where the forge cannot serve
fork checks (GitHub); GitLab fork MRs resolve checks through the MR.
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