2026-11-03 16:48:19 +01:00
|
|
|
"""Exercise issues.py: closing keywords, mentions, commits, branch number and linked issues."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
import subprocess
|
|
|
|
|
import sys
|
|
|
|
|
import unittest
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
SCRIPT = REPO_ROOT / "skills" / "kvb-git-close-issues" / "scripts" / "issues.py"
|
|
|
|
|
PR = {
|
2026-11-03 17:56:54 +01:00
|
|
|
"number": 40,
|
|
|
|
|
"body": (
|
|
|
|
|
"Fixes #12 and touches #13.\nCloses: other/repo#7\nSee https://github.com/a/b/issues/9\n"
|
|
|
|
|
"Rows WordPress#0 and docs#1 are not issues; this is #40."
|
|
|
|
|
),
|
2026-11-03 16:48:19 +01:00
|
|
|
"headRefName": "fix/sys-ctl-hlth-runtime/vulnerability-engines/1324",
|
|
|
|
|
"commits": [
|
|
|
|
|
{"oid": "abcdef1234567", "messageHeadline": "fix: guard", "messageBody": "Resolved #13"},
|
|
|
|
|
{"oid": "1111111111111", "messageHeadline": "chore: tidy", "messageBody": ""},
|
|
|
|
|
],
|
|
|
|
|
"closingIssuesReferences": [
|
|
|
|
|
{"number": 21, "url": "https://github.com/owner/repo/issues/21"}
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _run(payload: str) -> subprocess.CompletedProcess:
|
|
|
|
|
return subprocess.run(
|
2026-11-03 17:56:54 +01:00
|
|
|
[sys.executable, str(SCRIPT), "--repo", "Owner/repo", "--json"],
|
2026-11-03 16:48:19 +01:00
|
|
|
input=payload,
|
|
|
|
|
check=False,
|
|
|
|
|
capture_output=True,
|
|
|
|
|
text=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestIssues(unittest.TestCase):
|
|
|
|
|
def test_every_reference_is_found_with_its_kind_and_source(self):
|
|
|
|
|
result = _run(json.dumps(PR))
|
|
|
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
|
|
|
rows = {(r["repo"], r["issue"]): r for r in json.loads(result.stdout)}
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
{key: (row["closing"], row["sources"]) for key, row in rows.items()},
|
|
|
|
|
{
|
|
|
|
|
("", 12): (True, ["body"]),
|
|
|
|
|
("", 13): (True, ["body", "commit abcdef1234"]),
|
|
|
|
|
("other/repo", 7): (True, ["body"]),
|
|
|
|
|
("a/b", 9): (False, ["body"]),
|
|
|
|
|
("", 1324): (False, ["branch"]),
|
2026-11-03 17:56:54 +01:00
|
|
|
("", 21): (True, ["linked"]),
|
2026-11-03 16:48:19 +01:00
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_invalid_input_exits_2(self):
|
|
|
|
|
self.assertEqual(_run("not json").returncode, 2)
|
|
|
|
|
self.assertEqual(_run("[]").returncode, 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
unittest.main()
|