mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 11:33:11 -04:00
Skip quality scale review of pull requests changing only snapshots (#188897)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d4f666d42f
commit
faca49f1a5
@@ -83,8 +83,9 @@ def main(argv: list[str] | None = None) -> int:
|
||||
parser.error("GITHUB_TOKEN is unset")
|
||||
|
||||
pr = github_api.fetch_pull_request(args.repo, args.pr_number, token)
|
||||
# The diff excludes test snapshots, so they do not make a domain touched.
|
||||
domains = integrations.with_quality_scale(
|
||||
integrations.touched_domains(pr.filenames), pr.file_statuses
|
||||
integrations.touched_domains(pr.reviewed_filenames), pr.file_statuses
|
||||
)
|
||||
decision = decide_skip(
|
||||
pr,
|
||||
|
||||
@@ -31,6 +31,11 @@ class PullRequest:
|
||||
"""Return the paths of the changed files."""
|
||||
return list(self.file_statuses)
|
||||
|
||||
@property
|
||||
def reviewed_filenames(self) -> list[str]:
|
||||
"""Return the paths of the changed files that are not test snapshots."""
|
||||
return [name for name in self.file_statuses if not name.endswith(".ambr")]
|
||||
|
||||
@property
|
||||
def changed_lines(self) -> int:
|
||||
"""Return the number of added plus deleted lines."""
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""Tests for script.quality_scale_review.__main__."""
|
||||
|
||||
from dataclasses import replace
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
@@ -174,6 +175,28 @@ def test_skips_a_pull_request_without_a_quality_scale(
|
||||
assert not (tmp_path / "rules-index.txt").exists()
|
||||
|
||||
|
||||
def test_skips_a_pull_request_that_only_changes_snapshots(
|
||||
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
"""Snapshots are left out of the diff, so they do not make a domain touched."""
|
||||
pr = replace(
|
||||
_pull_request(1, 1, 1, snapshot_lines=2, snapshot_files=1),
|
||||
file_statuses={
|
||||
"tests/components/peblar/snapshots/test_sensor.ambr": "modified"
|
||||
},
|
||||
)
|
||||
monkeypatch.setattr(github_api, "fetch_pull_request", lambda *args: pr)
|
||||
monkeypatch.setattr(integrations, "with_quality_scale", lambda domains, *a: domains)
|
||||
|
||||
assert __main__.main(["--pr-number", "42", "--output", str(tmp_path)]) == 0
|
||||
|
||||
results = json.loads((tmp_path / "results.json").read_text())
|
||||
assert results["skip"] is True
|
||||
assert results["too_long"] is False
|
||||
assert results["domains"] == []
|
||||
assert not (tmp_path / "pr-diff.patch").exists()
|
||||
|
||||
|
||||
def test_skips_a_pull_request_that_is_too_long(
|
||||
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
|
||||
@@ -40,6 +40,17 @@ def test_reviewed_counts_exclude_snapshots() -> None:
|
||||
assert (pr.reviewed_lines, pr.reviewed_files) == (22, 2)
|
||||
|
||||
|
||||
def test_reviewed_filenames_exclude_snapshots() -> None:
|
||||
"""Test snapshot files are left out of the reviewed file names."""
|
||||
pr = _pull_request(
|
||||
file_statuses={
|
||||
"homeassistant/components/peblar/sensor.py": "modified",
|
||||
"tests/components/peblar/snapshots/test_sensor.ambr": "modified",
|
||||
}
|
||||
)
|
||||
assert pr.reviewed_filenames == ["homeassistant/components/peblar/sensor.py"]
|
||||
|
||||
|
||||
def test_to_meta_dict_omits_the_changed_filenames() -> None:
|
||||
"""The metadata payload holds exactly the keys the agent reads."""
|
||||
assert _pull_request().to_meta_dict() == {
|
||||
|
||||
Reference in New Issue
Block a user