Switch to a manual check status for dependent PRs (#7117)

The labeling script will now directly set a check status for the PR as
`pending` when it marks something as dependent, and clear it when it no
longer is. This emulates a check that starts when marked as dependent
and runs until the last dependency lands, allowing automerge and other
workflows to work cleanly.

The branch protection rule will have to be updated to the new spelling.

This should do the same key thing as #7113, but integrated to the new
script.

Assisted-by: Antigravity with Gemini
This commit is contained in:
Chandler Carruth
2026-04-28 02:01:57 +00:00
committed by GitHub
parent 9480c10ecf
commit 0e308e0739
5 changed files with 173 additions and 56 deletions
+55 -6
View File
@@ -24,6 +24,7 @@ import json
import re
import os
import sys
import requests
from typing import Any, Optional
# Do some extra work to support direct runs.
@@ -238,13 +239,50 @@ def _parse_and_validate_state(
return parsed_open, parsed_merged, first_commit
def _set_commit_status(
sha: str,
state: str,
description: str,
token: str,
dry_run: bool,
) -> None:
"""Sets the commit status via the GitHub REST API."""
url = (
"https://api.github.com/repos/carbon-language/carbon-lang/"
f"statuses/{sha}"
)
headers = {
"Authorization": f"bearer {token}",
"Accept": "application/vnd.github.v3+json",
}
payload = {
"state": state,
"description": description,
"context": "PR dependencies check",
}
if dry_run:
_print_err(
f"[Dry-run] Would set commit status on {sha[:8]} to {state} "
f"({description})"
)
return
try:
response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
_print_err(f"Set commit status on {sha[:8]} to {state}")
except Exception as e:
_print_err(f"Error setting commit status on {sha[:8]}: {e}")
def _process_pr(
client: github_helpers.Client,
pr_number: int,
pr_to_commits: dict[int, list[str]],
open_pr_numbers: set[int],
label_id: str,
dry_run: bool,
token: str,
dry_run: bool = False,
scanning: bool = False,
max_merged_pr: int = 10000,
) -> None:
@@ -322,9 +360,6 @@ def _process_pr(
)
)
if not open_deps and not existing_comment_id:
return
# Keep tracking previously identified dependencies if they are still open,
# even if they no longer pass the subset check (e.g. they got new commits).
for pr in parsed_open_deps:
@@ -339,6 +374,18 @@ def _process_pr(
merged_deps = list(set(parsed_merged_deps + newly_merged_deps))
if open_deps:
state = "pending"
pr_list_str = ", ".join([f"#{num}" for num in open_deps])
description = f"This PR has open dependencies: {pr_list_str}"
else:
state = "success"
description = "This PR has no open dependencies"
_set_commit_status(
pr_node["headRefOid"], state, description, token, dry_run
)
first_independent_commit_oid = None
if open_deps:
dependent_oids = set()
@@ -527,7 +574,8 @@ def main() -> None:
pr_to_commits,
open_pr_numbers,
label_id,
parsed_args.dry_run,
parsed_args.access_token,
dry_run=parsed_args.dry_run,
max_merged_pr=max_merged_pr,
)
elif parsed_args.scan:
@@ -540,7 +588,8 @@ def main() -> None:
pr_to_commits,
open_pr_numbers,
label_id,
parsed_args.dry_run,
parsed_args.access_token,
dry_run=parsed_args.dry_run,
scanning=True,
max_merged_pr=max_merged_pr,
)