Skip to content

Commit 5525e27

Browse files
committed
handle base ref fetch fallback
1 parent 2901a34 commit 5525e27

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

scripts/validate_plugins/detect_changed_plugins.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ def resolve_astrbot_ref() -> str:
5555

5656

5757
def detect_pull_request_selection(*, repo_root: Path, base_ref: str) -> dict[str, object]:
58-
fetch_base_ref(base_ref)
59-
6058
try:
59+
fetch_base_ref(base_ref)
6160
base = load_plugins_map(read_base_plugins_json(base_ref), source_name=f"base ref {base_ref}")
6261
except (subprocess.CalledProcessError, ValueError):
6362
base = {}

tests/test_detect_changed_plugins.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ def test_resolve_astrbot_ref_falls_back_to_master(self):
7474

7575

7676
class PullRequestDetectionTests(unittest.TestCase):
77+
def test_detect_pull_request_selection_handles_fetch_base_ref_failure(self):
78+
module = load_detection_module()
79+
80+
with tempfile.TemporaryDirectory() as tmp_dir:
81+
repo_root = Path(tmp_dir)
82+
plugins_json = repo_root / "plugins.json"
83+
plugins_json.write_text('{"plugin-a": {"repo": "https://github.com/example/a"}}', encoding="utf-8")
84+
85+
with mock.patch.object(
86+
module,
87+
"fetch_base_ref",
88+
side_effect=module.subprocess.CalledProcessError(1, ["git", "fetch"]),
89+
):
90+
result = module.detect_pull_request_selection(repo_root=repo_root, base_ref="main")
91+
92+
self.assertEqual(result["changed"], ["plugin-a"])
93+
self.assertEqual(result["validation_note"], "")
94+
7795
def test_detect_pull_request_selection_handles_missing_base_file(self):
7896
module = load_detection_module()
7997

0 commit comments

Comments
 (0)