Skip to content

Commit 6fad8f6

Browse files
committed
fix(ci): the low-risk tier takes one Dependabot commit, typed updates and no rename
Review notes of #953: a second commit on the branch, a dependency named without its update type, and a file renamed to a dependency file each refuse the tier. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_018kyZYsWnKSjpX4oNV19PCF
1 parent df05c88 commit 6fad8f6

4 files changed

Lines changed: 61 additions & 30 deletions

‎.github/workflows/pipeline-post-merge.yml‎

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -368,39 +368,52 @@ jobs:
368368
)
369369
370370
371+
def _declared_updates(commit):
372+
"""Update types of one Dependabot commit, or None when it is not one.
373+
374+
A git author is only a declared e-mail, and `verified` vouches for the
375+
committer's key. Dependabot's commits are committed and signed by GitHub
376+
itself (`web-flow`), where the author is the acting account and cannot be
377+
chosen. Every dependency the commit names must declare its update type.
378+
source: https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification
379+
"""
380+
detail = commit.get("commit") or {}
381+
signed = (detail.get("verification") or {}).get("verified") is True
382+
author = (commit.get("author") or {}).get("login")
383+
committer = (commit.get("committer") or {}).get("login")
384+
if author != "dependabot[bot]" or committer != "web-flow" or not signed:
385+
return None
386+
message = detail.get("message") or ""
387+
updates = re.findall(r"^\s*update-type: (\S+)\s*$", message, re.M)
388+
names = re.findall(r"^\s*- dependency-name: ", message, re.M)
389+
return updates if updates and len(updates) == len(names) else None
390+
391+
371392
def _is_low_risk(pr, repository, api):
372393
"""True for a Dependabot minor or patch update of the dependency files.
373394
374395
The tier comes from the change, not from a label or a title (ADR-1126): the
375-
PR and each of its commits are Dependabot's (committed and signed by GitHub),
376-
every update it declares is minor or patch, and it touches nothing outside
396+
PR is Dependabot's single commit (committed and signed by GitHub), every
397+
update it declares is minor or patch, and it touches nothing outside
377398
LOW_RISK_FILES. Such a PR merges on green required checks without a review.
378399
"""
379400
user = pr.get("user") or {}
380401
if user.get("login") != "dependabot[bot]" or user.get("type") != "Bot":
381402
return False
382403
path = f"/repos/{repository}/pulls/{pr['number']}"
383404
commits = list(api.records(path + "/commits"))
384-
updates = []
385-
for commit in commits:
386-
detail = commit.get("commit") or {}
387-
signed = (detail.get("verification") or {}).get("verified") is True
388-
author = (commit.get("author") or {}).get("login")
389-
# A git author is only a declared e-mail, and `verified` vouches for
390-
# the committer's key. Dependabot's commits are committed and signed
391-
# by GitHub itself (`web-flow`), where the author is the acting
392-
# account and cannot be chosen.
393-
# source: https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification
394-
committer = (commit.get("committer") or {}).get("login")
395-
if author != "dependabot[bot]" or committer != "web-flow" or not signed:
396-
return False
397-
updates += re.findall(
398-
r"^\s*update-type: (\S+)\s*$", detail.get("message") or "", re.M
399-
)
400-
if not updates or not set(updates) <= LOW_RISK_UPDATES:
405+
# Dependabot opens and rebases a PR as one commit; a second one is
406+
# someone else's work on its branch.
407+
if len(commits) != 1:
408+
return False
409+
updates = _declared_updates(commits[0])
410+
if updates is None or not set(updates) <= LOW_RISK_UPDATES:
401411
return False
402-
files = [row.get("filename") for row in api.records(path + "/files")]
403-
return bool(files) and set(files) <= LOW_RISK_FILES
412+
files = set()
413+
for row in api.records(path + "/files"):
414+
# A rename counts under both of its names.
415+
files |= {row.get("filename"), row.get("previous_filename")} - {None}
416+
return bool(files) and files <= LOW_RISK_FILES
404417
405418
406419
def _merge_open_pr(pr, merge_path, head, api, repository):

‎docs/adr/ADR-1126-a-dependabot-minor-or-patch-update-of-the-dependency-files-merges-without-a-review.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ Anthropic describes the same problem and its answer in "Solving code review at A
2323
## Decision
2424

2525
1. The resolver computes a tier from the change itself. A pull request is low risk when all of these hold:
26-
- its author is `dependabot[bot]`, and every commit is authored by `dependabot[bot]`, committed by GitHub (`web-flow`) and carries a verified signature. The author alone is a declared e-mail and `verified` vouches for the committer's key, so a commit a person signs under Dependabot's name is refused;
27-
- every `update-type` its commit messages declare is `version-update:semver-minor` or `version-update:semver-patch`, and there is at least one;
28-
- every file it changes is `uv.lock` or `pyproject.toml`.
26+
- its author is `dependabot[bot]`, it has exactly one commit, and every commit is authored by `dependabot[bot]`, committed by GitHub (`web-flow`) and carries a verified signature. The author alone is a declared e-mail and `verified` vouches for the committer's key, so a commit a person signs under Dependabot's name is refused;
27+
- every `update-type` its commit messages declare is `version-update:semver-minor` or `version-update:semver-patch`, and every dependency the commit names declares one;
28+
- every file it changes is `uv.lock` or `pyproject.toml`, a renamed file counting under both of its names.
2929
2. A low-risk pull request merges without a Claude verdict. Everything else of the merge path is unchanged: the `Pipeline` run of the head succeeded, the branch protection still requires `merge` and `CodeQL`, and a `hold` or `do-not-merge` label or a "do not merge" title still holds it.
3030
3. Any other pull request keeps ADR-1121. That includes a Dependabot major update, a Dependabot update of a workflow or a Dockerfile, and a Dependabot branch someone else pushed to.
3131
4. The rule lives in the resolver, which runs from `main` through `workflow_run`: a pull request cannot change its own tier.

‎tests_py/scripts/test_ci_low_risk_tier.py‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ def records(self, path, key=None):
5656
if path.endswith("/commits"):
5757
return self.commits
5858
if path.endswith("/files"):
59-
return [{"filename": name} for name in self.files]
59+
return [
60+
name if isinstance(name, dict) else {"filename": name}
61+
for name in self.files
62+
]
6063
return [] # no review run, no comment: the reviewed path holds
6164

6265
def request(self, method, path, body=None):
@@ -93,14 +96,29 @@ def test_a_workflow_or_any_other_file_is_not(self):
9396
def test_another_author_or_an_unsigned_commit_is_not(self):
9497
self.assertFalse(self.low(pr=pull(login="cdeust", kind="User")))
9598
self.assertFalse(self.low(pr=pull(kind="User")))
96-
self.assertFalse(self.low([commit(), commit(author="cdeust")]))
99+
self.assertFalse(self.low([commit(author="cdeust")]))
97100
self.assertFalse(self.low([commit(verified=False)]))
98101

99102
def test_a_bot_attributed_commit_signed_by_a_person_is_not(self):
100103
# Dependabot's e-mail as author, a contributor's own verified key.
101-
self.assertFalse(self.low([commit(), commit(committer="cdeust")]))
104+
self.assertFalse(self.low([commit(committer="cdeust")]))
102105
self.assertFalse(self.low([commit(committer=None)]))
103106

107+
def test_a_second_commit_on_the_branch_is_not(self):
108+
self.assertFalse(self.low([commit(), commit()]))
109+
110+
def test_a_dependency_without_its_update_type_is_not(self):
111+
untyped = commit()
112+
untyped["commit"]["message"] += "- dependency-name: y\n"
113+
self.assertFalse(self.low([untyped]))
114+
115+
def test_a_file_renamed_to_a_dependency_file_is_not(self):
116+
renamed = {
117+
"filename": "uv.lock",
118+
"previous_filename": ".github/workflows/pipeline.yml",
119+
}
120+
self.assertFalse(self.low(files=(renamed,)))
121+
104122
def test_a_low_risk_pr_merges_without_a_review(self):
105123
api = FakeApi([commit()], ("uv.lock",))
106124
merge = resolver()["_merge_open_pr"]

‎wiki/adr/cortex/1126-a-dependabot-minor-or-patch-update-of-the-dependency-files-merges-without-a-review.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ Anthropic describes the same problem and its answer in "Solving code review at A
2121
## Decision
2222

2323
1. The resolver computes a tier from the change itself. A pull request is low risk when all of these hold:
24-
- its author is `dependabot[bot]`, and every commit is authored by `dependabot[bot]`, committed by GitHub (`web-flow`) and carries a verified signature. The author alone is a declared e-mail and `verified` vouches for the committer's key, so a commit a person signs under Dependabot's name is refused;
25-
- every `update-type` its commit messages declare is `version-update:semver-minor` or `version-update:semver-patch`, and there is at least one;
26-
- every file it changes is `uv.lock` or `pyproject.toml`.
24+
- its author is `dependabot[bot]`, it has exactly one commit, and every commit is authored by `dependabot[bot]`, committed by GitHub (`web-flow`) and carries a verified signature. The author alone is a declared e-mail and `verified` vouches for the committer's key, so a commit a person signs under Dependabot's name is refused;
25+
- every `update-type` its commit messages declare is `version-update:semver-minor` or `version-update:semver-patch`, and every dependency the commit names declares one;
26+
- every file it changes is `uv.lock` or `pyproject.toml`, a renamed file counting under both of its names.
2727
2. A low-risk pull request merges without a Claude verdict. Everything else of the merge path is unchanged: the `Pipeline` run of the head succeeded, the branch protection still requires `merge` and `CodeQL`, and a `hold` or `do-not-merge` label or a "do not merge" title still holds it.
2828
3. Any other pull request keeps ADR-1121. That includes a Dependabot major update, a Dependabot update of a workflow or a Dockerfile, and a Dependabot branch someone else pushed to.
2929
4. The rule lives in the resolver, which runs from `main` through `workflow_run`: a pull request cannot change its own tier.

0 commit comments

Comments
 (0)