diff --git a/README.md b/README.md index ddb19ee..fde35d5 100644 --- a/README.md +++ b/README.md @@ -43,10 +43,12 @@ Native knowledge, plan, fix and configuration commands send the selected organiz Repository commands use the checkout’s `origin` by default. Use `--remote NAME` to select another remote or `--repo URL` to supply a clone URL. The CLI sends the host and full project path to Proofline, including subgroup names. The CLI recognizes gitlab.com and otherwise looks for a GitHub repository on the exact remote host, including GitHub Enterprise Server. Use `--source-provider gitlab` for private GitLab hosts or `--source-provider git` for other Git servers. Hooks can read the same choice from `PROOFLINE_SOURCE_PROVIDER`. A connected private Git repository can use `proofline review --source-provider git --range BASE..HEAD` to request a review of two pushed commits. -`proofline review --range BASE..HEAD --fail-on serious` exits 3 when a complete review has an unresolved finding at or above the threshold. PR reviews use the server’s effective open-item counts; other reviews count unresolved findings, including those a partial code assessment recorded. Incomplete and unavailable results retain their nonzero exits. `--fail-on` cannot be combined with `--no-wait`. +`proofline review --range BASE..HEAD --fail-on serious` exits 3 when a complete review has an unresolved finding at or above the threshold. Pull-request and merge-group reviews use the server’s effective open-item counts, and a result without them is unavailable; other reviews count unresolved findings, including those a partial code assessment recorded. Incomplete and unavailable results retain their nonzero exits. `--fail-on` cannot be combined with `--no-wait`. In GitHub Actions, `proofline ci review --annotations` prints unresolved findings as workflow annotations at verified cited lines. Findings without a verified head location appear on the job. The review link contains the full result. +A repository with a GitHub merge queue adds `merge_group` to the workflow's triggers, so the queue gets the required check. On a `merge_group` event, `proofline ci review` reads the `MERGE_GROUP` review of the commit under test, not a pull-request review. That commit is the one the queue built unless `--commit` or `COMMIT_SHA` names another. The job names the queued pull requests once Proofline has read them. `--fail-on` and `--sarif` apply to it as they do to a pull-request review. `--annotations` show on the job's check run, since a merge group has no pull-request diff. The job never requests a review of that commit. + For a CodePipeline execution or Amplify job, run `proofline ci deploy --commit SHA --aws-run ID` in a later pipeline. Add `--environment-id UUID` to select its Proofline environment. The output names the AWS provider and run ID. Proofline records successful CodePipeline executions and failed, stopped or cancelled ones it ties to the ECS rollout that served the commit. A reader inside a still-running execution finds no matching deploy, waits until its timeout and exits 2. On a GitHub `workflow_run` event, an explicit `--aws-run` disables the default Actions run and attempt filters. `proofline ci deploy --until 1h` waits until Proofline has recorded the deploy checks of the job's commit through the hour check, then exits 0 when each recorded `HEALTHY` with no gap, 3 when a deploy failed or regressed, and 2 when the result is not established, including when a deploy reads a state this CLI version does not know. After a read that answered, the wait keeps reading through a read that fails in transport, times out or gets a 5xx answer, and exits 4 after five such failures in a row, naming the last error; the first read and a refusal end it at once. Without `--timeout`, a wait for `--until landing`, `--until 20m` or `--until 1h` lasts until that check is due for the selected deploys, and at least 30 minutes, so a landing check that reads the runtime again, up to 75 minutes after landing, is still read; `--until 1d` needs `--timeout`. `--environment-id` (the Proofline environment's UUID, the `environment_id` that `--json` prints for each deploy), `--environment` (the GitHub Environment name), `--task`, `--deployment` (the ID of the GitHub deployment a pipeline created), `--run` and `--attempt` select the deploy, and on a `workflow_run` event the commit, `--run` and `--attempt` default to the completed run's. When `--run` defaults to a completed run that did not succeed, the command waits at most 5 minutes for a deploy from that run, then exits 2 with a last line that names the run's conclusion and says it recorded no deploy; a deploy the run did record gets the usual wait for its check. `--json` prints the response. Each deploy prints one line per check. A deploy that rolled the environment back to an earlier commit first prints a `rollback` line with the page of the deploy it restores, when Proofline recorded one, and the pages of the deploys it rolled back. A deploy whose newest check found its service serving an earlier deploy again first prints a `rolled back` line, and stops printing it once a later check finds none; with `--json` the response carries it as `rolled_back`. A regressed deploy that a later rollback deploy of the same task rolled back within 30 days first prints a `rolled back by the deploy of ` line naming that rollback deploy's page, or its landing time when no page opens in that environment; with `--json` the response carries it as `rolled_back_by`. Any of these lines can appear together for one deploy. A rollback's exit code comes from its checks like any other deploy's; none of these lines changes it or means the rollback fixed anything. A deploy whose deploy checks ended without recording the `--until` check ends the wait at once with exit 2, and the last line names the check and the deploy's page; a check that is overdue while the checks still run keeps the wait going until the timeout. diff --git a/src/lib.rs b/src/lib.rs index 2ac4644..41865f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -190,6 +190,10 @@ enum Command { enum CiCommand { /// Wait for the pull-request review of the commit under test and report it. /// + /// On a `merge_group` event it waits for the merge-group review of the + /// commit under test instead, which is the commit GitHub's merge queue + /// built unless `--commit` or `COMMIT_SHA` names another. + /// /// The job authenticates with `PROOFLINE_TOKEN`. Without it, a GitHub Actions /// job that grants `id-token: write` exchanges its OIDC token for a one-hour /// token that reads its repository's reviews, and needs no organization ID. @@ -235,7 +239,8 @@ enum CiCommand { #[derive(Debug, Args)] struct CiReviewArgs { /// Full commit SHA under test. Defaults to `COMMIT_SHA`, then the pull - /// request's head on a GitHub Actions pull-request event, then `GITHUB_SHA`. + /// request's head on a GitHub Actions pull-request event, then `GITHUB_SHA`, + /// which on a `merge_group` event is the commit the merge queue built. #[arg(long, value_name = "SHA")] commit: Option, /// Also write the review as SARIF 2.1.0 to this file. @@ -1555,14 +1560,62 @@ async fn ci_job( } (token, _) => (connect(http, token, org).await?, None), }; - ci_review(&api, args, commit, request.as_ref()).await + let subject = CiSubject::for_event(event); + ci_review(&api, args, commit, subject, request.as_ref()).await +} + +/// The review a CI job reads. A `merge_group` job tests the commit GitHub's +/// merge queue built for a group of pull requests, which is never a pull +/// request's head, so it reads that commit's `MERGE_GROUP` review. Every +/// other job reads the pull-request review of its commit. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum CiSubject { + PullRequest, + MergeGroup, +} + +impl CiSubject { + fn for_event(event: &str) -> Self { + if event == "merge_group" { + Self::MergeGroup + } else { + Self::PullRequest + } + } + + /// The review kind as the API spells it. + const fn kind(self) -> &'static str { + match self { + Self::PullRequest => "PULL_REQUEST", + Self::MergeGroup => "MERGE_GROUP", + } + } + + const fn noun(self) -> &'static str { + match self { + Self::PullRequest => "pull-request", + Self::MergeGroup => "merge-group", + } + } + + /// Which commits get a review of this kind. + const fn reviewed(self) -> &'static str { + match self { + Self::PullRequest => { + "Proofline reviews a commit once it is the head of an open pull request." + } + Self::MergeGroup => { + "Proofline reviews the commit GitHub's merge queue builds for a group of pull requests." + } + } + } } /// How long a pull-request job waits for the App's review of its head before /// it asks for one. const REQUEST_AFTER: Duration = Duration::from_secs(120); -/// Confirms `detail` is actually the pull-request review of `commit` in +/// Confirms `detail` is actually the `subject` review of `commit` in /// `repository_id` before it is allowed to decide a CI verdict or produce a /// SARIF artifact. [`read_review`] already confirms `detail` is the review /// requested by id; a search match on `commit` against a summary row does @@ -1577,11 +1630,13 @@ const REQUEST_AFTER: Duration = Duration::from_secs(120); fn confirm_ci_subject( detail: &ReviewDetail, commit: &str, + subject: CiSubject, repository_id: Uuid, ) -> anyhow::Result<()> { - if detail.kind != "PULL_REQUEST" { + if detail.kind != subject.kind() { bail!( - "proofline asked for the pull-request review of {commit}, but the server returned a {} review", + "proofline asked for the {} review of {commit}, but the server returned a {} review", + subject.noun(), text::one_line(&detail.kind) ); } @@ -1608,15 +1663,16 @@ fn confirm_ci_subject( Ok(()) } -/// Waits for the review the App runs for the pull request whose head is -/// `commit`, then reports it. With `request`, a job that has found no review -/// after [`REQUEST_AFTER`] asks once for one and reports the review it gets; -/// a refusal is reported and the wait goes on. Without it nothing is -/// requested, so the job never starts a second review of the head. +/// Waits for the `subject` review the App runs of `commit`, then reports it. +/// With `request`, a job that has found no review after [`REQUEST_AFTER`] +/// asks once for one and reports the review it gets; a refusal is reported +/// and the wait goes on. Without it nothing is requested, so the job never +/// starts a second review of the head. async fn ci_review( api: &Api, args: &CiReviewArgs, commit: &str, + subject: CiSubject, request: Option<&github_actions::ReviewRequest>, ) -> anyhow::Result { let started = tokio::time::Instant::now(); @@ -1627,6 +1683,7 @@ async fn ci_review( &name, repository_id, commit, + subject, args.timeout, started, deadline, @@ -1643,7 +1700,7 @@ async fn ci_review( say_not_established(api, review_id, args.timeout); return Ok(Verdict::Unavailable); }; - confirm_ci_subject(&detail, commit, repository_id)?; + confirm_ci_subject(&detail, commit, subject, repository_id)?; if let Some(path) = sarif_path { write_sarif(api, review_id, &detail, path).await?; } @@ -1663,7 +1720,7 @@ async fn ci_review( Ok(verdict) } -/// Polls for the newest `PULL_REQUEST` review whose head is `commit` until +/// Polls for the newest `subject` review whose head is `commit` until /// `deadline`, asking once through `request` from [`REQUEST_AFTER`] past /// `started`. `None` means no review appeared, which it has already said. async fn wait_for_head_review( @@ -1671,6 +1728,7 @@ async fn wait_for_head_review( name: &str, repository_id: Uuid, commit: &str, + subject: CiSubject, timeout_minutes: u64, started: tokio::time::Instant, deadline: tokio::time::Instant, @@ -1680,7 +1738,7 @@ async fn wait_for_head_review( let mut delay = FIRST_POLL_SECONDS; loop { let found = latest(api, repository_id, commit, |item| { - item.kind == "PULL_REQUEST" && item.head_commit_sha.as_deref() == Some(commit) + item.kind == subject.kind() && item.head_commit_sha.as_deref() == Some(commit) }) .await?; if found.is_some() { @@ -1689,7 +1747,9 @@ async fn wait_for_head_review( let now = tokio::time::Instant::now(); if now >= deadline { say(&format!( - "No pull-request review of {name} has head commit {commit} after {timeout_minutes} minutes. Proofline reviews a commit once it is the head of an open pull request." + "No {} review of {name} has head commit {commit} after {timeout_minutes} minutes. {}", + subject.noun(), + subject.reviewed() )); return Ok(None); } @@ -1822,14 +1882,14 @@ fn ci_verdict( } } -/// How `review --fail-on` ends for a complete review. A pull request counts -/// its open items, as `ci review` does; other reviews have no finding -/// decisions, so their unresolved findings count, as in a Git hook. +/// How `review --fail-on` ends for a complete review. A pull request or a +/// merge group counts its open items, as `ci review` does; other reviews have +/// no finding decisions, so their unresolved findings count, as in a Git hook. fn review_verdict(detail: &ReviewDetail, fail_on: Option) -> Verdict { let Some(threshold) = fail_on else { return Verdict::Done; }; - if detail.kind == "PULL_REQUEST" { + if matches!(detail.kind.as_str(), "PULL_REQUEST" | "MERGE_GROUP") { return ci_verdict( Some(Outcome::Completed), detail.open_items.as_ref(), @@ -1863,7 +1923,8 @@ fn print_audit( }); writeln!(stdout, "{}", serde_json::to_string_pretty(&document)?)?; } - // `read_review` refuses SARIF for any review but a pull request's. + // `read_review` refuses SARIF for any review but a pull request's or a + // merge group's. OutputFormat::Sarif | OutputFormat::Text => { write!(stdout, "{}", render::audit(&url))?; } @@ -2491,20 +2552,24 @@ mod tests { ); assert_eq!(review_verdict(&review, None), Verdict::Done, "{kind}"); } - // The finding was dismissed. - let dismissed = detail( - "PULL_REQUEST", - json!({ "open_findings": 0, "serious_findings": 0 }), - ); - assert_eq!(review_verdict(&dismissed, serious), Verdict::Done); - let open = detail( - "PULL_REQUEST", - json!({ "open_findings": 1, "serious_findings": 1 }), - ); - assert_eq!(review_verdict(&open, serious), Verdict::ThresholdReached); - let unmeasured = detail("PULL_REQUEST", serde_json::Value::Null); - assert_eq!(review_verdict(&unmeasured, serious), Verdict::Unavailable); - assert_eq!(review_verdict(&unmeasured, None), Verdict::Done); + for kind in ["PULL_REQUEST", "MERGE_GROUP"] { + // The finding was dismissed. + let dismissed = detail(kind, json!({ "open_findings": 0, "serious_findings": 0 })); + assert_eq!(review_verdict(&dismissed, serious), Verdict::Done, "{kind}"); + let open = detail(kind, json!({ "open_findings": 1, "serious_findings": 1 })); + assert_eq!( + review_verdict(&open, serious), + Verdict::ThresholdReached, + "{kind}" + ); + let unmeasured = detail(kind, serde_json::Value::Null); + assert_eq!( + review_verdict(&unmeasured, serious), + Verdict::Unavailable, + "{kind}" + ); + assert_eq!(review_verdict(&unmeasured, None), Verdict::Done, "{kind}"); + } } #[test] @@ -2586,4 +2651,187 @@ mod tests { missing.join("\n") ); } + + /// A console that lists one completed review of `HEAD` with `listed` kind + /// and reads it back with `read` kind, its open items counting + /// `serious` serious findings. + async fn one_review_console(listed: &'static str, read: &'static str, serious: u64) -> String { + let app = Router::new() + .route( + &format!("/api/v1/organizations/{ORG}/repository-names"), + get(|| async { + Json(json!({ "repositories": [{ "id": REPOSITORY, "full_name": "acme/app" }] })) + }), + ) + .route( + &format!("/api/v1/organizations/{ORG}/reviews"), + get(move || async move { + Json(json!({ + "items": [{ + "id": REQUESTED, "kind": listed, "status": "COMPLETED", + "created_at": "2026-12-02T00:00:00Z", "head_commit_sha": HEAD, + "pull_request_number": null, "repository_id": REPOSITORY, + "run_number": 1, + }], + "next_cursor": null, "truncated": false, + "filters": { "repositories": [], "environments": [], "authors": [] }, + })) + }), + ) + .route( + &format!("/api/v1/organizations/{ORG}/reviews/{REQUESTED}"), + get(move || async move { + Json(json!({ + "id": REQUESTED, "kind": read, "status": "COMPLETED", + "head_commit_sha": HEAD, "pull_request_number": null, "run_number": 1, + "merge_group_pull_request_numbers": [12, 13], + "assessment_count": 1, + "open_items": { + "open_findings": serious, "serious_findings": serious, + "accepted_risks": 0, "not_assessed": [], + }, + "assessments": [{ + "id": "0190f3a0-0000-7000-8000-0000000000f2", + "environment_display_name": "production", + "status": "COMPLETED", "findings": [], + "checks": { "receipt_recorded": true, "status": "READY", "families": [] }, + }], + })) + }), + ); + let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); + let origin = format!("http://{}", listener.local_addr().unwrap()); + tokio::spawn(async move { axum::serve(listener, app).await.unwrap() }); + origin + } + + /// A `merge_group` job reads the `MERGE_GROUP` review of the commit the + /// queue built and gates on it as a pull-request job gates on its + /// review. Neither job takes the other kind's review of the same commit. + #[tokio::test(start_paused = true)] + async fn a_merge_group_job_reads_the_merge_group_review_of_its_commit() { + // As above, a 10 ms ticker bounds each jump of the paused clock. + let ticker = tokio::spawn(async { + for _ in 0..1_000_000 { + tokio::time::sleep(Duration::from_millis(10)).await; + } + }); + for (event, listed, read, serious, fail_on, expected) in [ + ( + "merge_group", + "MERGE_GROUP", + "MERGE_GROUP", + 0, + None, + Ok(Verdict::Done), + ), + ( + "merge_group", + "MERGE_GROUP", + "MERGE_GROUP", + 0, + Some(Severity::Serious), + Ok(Verdict::Done), + ), + ( + "merge_group", + "MERGE_GROUP", + "MERGE_GROUP", + 1, + Some(Severity::Serious), + Ok(Verdict::ThresholdReached), + ), + ( + "merge_group", + "PULL_REQUEST", + "PULL_REQUEST", + 0, + None, + Ok(Verdict::Unavailable), + ), + ( + "pull_request", + "MERGE_GROUP", + "MERGE_GROUP", + 0, + None, + Ok(Verdict::Unavailable), + ), + ( + "push", + "MERGE_GROUP", + "MERGE_GROUP", + 0, + None, + Ok(Verdict::Unavailable), + ), + ( + "pull_request", + "PULL_REQUEST", + "PULL_REQUEST", + 0, + None, + Ok(Verdict::Done), + ), + ( + "merge_group", + "MERGE_GROUP", + "PULL_REQUEST", + 0, + None, + Err("asked for the merge-group review"), + ), + ] { + let case = + format!("{event}, listed {listed}, read {read}, {serious} serious, {fail_on:?}"); + let origin = one_review_console(listed, read, serious).await; + let http = Http::new(Origin::parse(&origin).unwrap()).unwrap(); + let args = CiReviewArgs { + commit: None, + sarif: None, + annotations: false, + json: false, + timeout: 3, + fail_on, + repository: RepositoryArgs { + repo: Some("acme/app".to_owned()), + source_provider: None, + remote: "origin".to_owned(), + }, + }; + let ended = ci_job( + http, + Some(SecretString::from("plp_stored")), + None, + event, + Some(ORG.parse().unwrap()), + &args, + HEAD, + ) + .await; + match (ended, expected) { + (Ok(verdict), Ok(expected)) => assert_eq!(verdict, expected, "{case}"), + (Err(error), Err(expected)) => { + assert!(format!("{error:#}").contains(expected), "{case}: {error:#}"); + } + (ended, expected) => panic!("{case}: {ended:?}, expected {expected:?}"), + } + } + ticker.abort(); + } + + #[test] + fn only_a_merge_group_event_reads_the_merge_group_review() { + for (event, subject) in [ + ("merge_group", CiSubject::MergeGroup), + ("pull_request", CiSubject::PullRequest), + ("pull_request_target", CiSubject::PullRequest), + ("push", CiSubject::PullRequest), + ("workflow_dispatch", CiSubject::PullRequest), + ("", CiSubject::PullRequest), + ("MERGE_GROUP", CiSubject::PullRequest), + ] { + assert_eq!(CiSubject::for_event(event), subject, "{event:?}"); + } + } } diff --git a/src/model.rs b/src/model.rs index 6cbc01a..bab145e 100644 --- a/src/model.rs +++ b/src/model.rs @@ -86,6 +86,10 @@ pub struct ReviewDetail { pub head_commit_sha: Option, pub open_items: Option, pub pull_request_number: Option, + /// For a `MERGE_GROUP` review, the pull requests the merge queue grouped, + /// in number order. Absent until Proofline has read the group's members. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub merge_group_pull_request_numbers: Option>, /// The review's repository. Set only on a single-review read, and /// absent there when the review names no repository. Stable across a /// repository rename, unlike `repository_full_name`. diff --git a/src/outcome.rs b/src/outcome.rs index 0a80059..3809a7c 100644 --- a/src/outcome.rs +++ b/src/outcome.rs @@ -336,6 +336,7 @@ mod tests { head_commit_sha: None, open_items: None, pull_request_number: Some(7), + merge_group_pull_request_numbers: None, repository_id: None, repository_full_name: Some("acme/web".to_owned()), run_number: Some(1), diff --git a/src/render.rs b/src/render.rs index 44befb1..8a4e4bf 100644 --- a/src/render.rs +++ b/src/render.rs @@ -98,8 +98,12 @@ fn code_assessment(out: &mut Vec, code: &CodeAssessment) { /// `{subject}{run}{commits}: {status}`. fn headline(review: &ReviewDetail, state: Option) -> String { let subject = match (&review.repository_full_name, review.pull_request_number) { + (Some(repository), _) if review.kind == "MERGE_GROUP" => { + format!("{} {}", one_line(repository), merge_group(review)) + } (Some(repository), Some(number)) => format!("{} #{number}", one_line(repository)), (Some(repository), None) => one_line(repository), + _ if review.kind == "MERGE_GROUP" => merge_group(review), _ => one_line(&review.kind), }; let run = review @@ -113,6 +117,22 @@ fn headline(review: &ReviewDetail, state: Option) -> String { format!("{subject}{run}{}: {status}", commits(review)) } +/// A merge-group review is of the commit GitHub's merge queue built, so it +/// names the queued pull requests once Proofline has read them. +fn merge_group(review: &ReviewDetail) -> String { + match review.merge_group_pull_request_numbers.as_deref() { + Some(numbers) if !numbers.is_empty() => format!( + "merge group of {}", + numbers + .iter() + .map(|number| format!("#{number}")) + .collect::>() + .join(", ") + ), + _ => "merge group".to_owned(), + } +} + /// The reviewed commits. A patch review's head is a revision ID, not a /// commit, so it names its base; a commit review is of a range, so it names /// both ends. @@ -267,6 +287,7 @@ mod tests { head_commit_sha: Some("0123456789abcdef0123456789abcdef01234567".to_owned()), open_items: None, pull_request_number: Some(42), + merge_group_pull_request_numbers: None, repository_id: None, repository_full_name: Some("acme/web".to_owned()), run_number: Some(2), @@ -302,6 +323,44 @@ mod tests { Url::parse("https://proofline.sh/orgs/by-id/o/reviews/r").unwrap() } + #[test] + fn a_merge_group_review_names_the_queued_pull_requests() { + let mut detail = sample("COMPLETED", Vec::new()); + detail.kind = "MERGE_GROUP".to_owned(); + for (pull_request, numbers, repository, expected) in [ + ( + Some(42), + Some(vec![12, 13]), + Some("acme/web"), + "acme/web merge group of #12, #13 run 2 at 0123456789ab: COMPLETED", + ), + ( + None, + Some(Vec::new()), + Some("acme/web"), + "acme/web merge group run 2 at 0123456789ab: COMPLETED", + ), + ( + Some(42), + None, + Some("acme/web"), + "acme/web merge group run 2 at 0123456789ab: COMPLETED", + ), + ( + Some(42), + Some(vec![7]), + None, + "merge group of #7 run 2 at 0123456789ab: COMPLETED", + ), + ] { + detail.pull_request_number = pull_request; + detail.merge_group_pull_request_numbers = numbers; + detail.repository_full_name = repository.map(str::to_owned); + let text = review(&detail, outcome::terminal(&detail), &url()); + assert_eq!(text.lines().next(), Some(expected)); + } + } + #[test] fn an_incomplete_assessment_never_reads_as_clean() { let detail = sample("INCOMPLETE", Vec::new()); diff --git a/src/sarif.rs b/src/sarif.rs index 5134174..4f2439c 100644 --- a/src/sarif.rs +++ b/src/sarif.rs @@ -1,4 +1,4 @@ -//! Read-only SARIF 2.1.0 for one retained pull-request review. This closed +//! Read-only SARIF 2.1.0 for one retained pull-request or merge-group review. This closed //! projection never serializes the raw API document or World evidence values. use std::collections::BTreeSet; @@ -76,11 +76,11 @@ pub(super) enum SarifError { )] WrongReview { requested: Uuid, returned: Uuid }, #[error( - "review {review} has kind {kind}; SARIF export requires a retained pull-request review" + "review {review} has kind {kind}; SARIF export requires a retained pull-request or merge-group review" )] UnsupportedSubject { review: Uuid, kind: String }, #[error( - "review {0} does not record a full commit SHA; SARIF export requires an immutable pull-request head" + "review {0} does not record a full commit SHA; SARIF export requires an immutable head commit" )] MissingHead(Uuid), #[error("finding {finding} has unsupported severity {severity}; SARIF export refused")] @@ -326,7 +326,9 @@ pub(super) fn validate_subject(detail: &ReviewDetail, requested: Uuid) -> Result returned, }); } - if detail.kind != "PULL_REQUEST" { + // A merge-group review is of one immutable commit too: the one GitHub's + // merge queue built for its pull requests. + if !matches!(detail.kind.as_str(), "PULL_REQUEST" | "MERGE_GROUP") { return Err(SarifError::UnsupportedSubject { review: detail.id, kind: crate::text::one_line(&detail.kind), diff --git a/tests/sarif.rs b/tests/sarif.rs index 77fa843..934e383 100644 --- a/tests/sarif.rs +++ b/tests/sarif.rs @@ -952,6 +952,27 @@ async fn sarif_exports_the_four_level_severities() { assert_eq!(levels, expected); } +#[tokio::test] +async fn sarif_exports_a_merge_group_review_of_the_queued_commit() { + let mut document = review(vec![finding(1, "WARNING", Vec::new())]); + document["kind"] = json!("MERGE_GROUP"); + document["pull_request_number"] = Value::Null; + document["merge_group_pull_request_numbers"] = json!([12, 13]); + let output = export(&serve(Console::new(document)).await).await; + assert_eq!( + output.status.code(), + Some(0), + "{}", + String::from_utf8_lossy(&output.stderr) + ); + let exported = report(&output, &schema()); + assert_eq!(exported["runs"][0]["results"].as_array().unwrap().len(), 1); + assert_eq!( + exported["runs"][0]["properties"]["headCommitSha"], + json!(HEAD) + ); +} + #[tokio::test] async fn sarif_refuses_unpinned_or_unrecognized_records_before_writing_output() { let mut records = Vec::new(); @@ -965,7 +986,10 @@ async fn sarif_refuses_unpinned_or_unrecognized_records_before_writing_output() } let mut deployment = review(Vec::new()); deployment["kind"] = json!("DEPLOYMENT_GATE"); - records.push((deployment, "requires a retained pull-request review")); + records.push(( + deployment, + "requires a retained pull-request or merge-group review", + )); for (field, value, expected) in [ ("severity", "BLOCKER", "unsupported severity"), (