Skip to content

Commit 7b8af59

Browse files
Accept branch refs in policy RoC rule URL matching
1 parent a133f0b commit 7b8af59

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

tools/check-policy-roc.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
DOCS = ROOT / "docs"
1010
RULES = ROOT / "tools" / "ci" / "policies" / "rules"
1111
LINK_RE = re.compile(r'(?<!\!)\[(?P<text>[^\]]+)\]\((?P<url>[^)\s]+)(?:\s+"[^"]*")?\)')
12-
RULE_URL_RE = re.compile(r'^https://github\.com/tomtastisch/FileClassifier/blob/[0-9a-f]{7,40}/tools/ci/policies/rules/.+\.(?:yml|yaml)(?:#[A-Za-z0-9\-_\.]+)?$')
12+
RULE_URL_RE = re.compile(
13+
r"^https://github\.com/tomtastisch/FileClassifier/blob/"
14+
r"(?P<ref>[A-Za-z0-9._-]+)/"
15+
r"(?P<path>tools/ci/policies/rules/.+\.(?:yml|yaml))"
16+
r"(?:#[A-Za-z0-9\-_\.]+)?$"
17+
)
1318

1419

1520
def main() -> int:
@@ -27,9 +32,10 @@ def main() -> int:
2732
text = policy.read_text(encoding="utf-8")
2833
for m in LINK_RE.finditer(text):
2934
url = m.group("url")
30-
if not RULE_URL_RE.match(url):
35+
rule_match = RULE_URL_RE.match(url)
36+
if not rule_match:
3137
continue
32-
path_part = url.split("/blob/", 1)[1].split("/", 1)[1].split("#", 1)[0]
38+
path_part = rule_match.group("path")
3339
rule_path = (ROOT / path_part).resolve()
3440
policy_to_rules[policy.resolve()].add(rule_path)
3541
mappings.append((str(policy.relative_to(ROOT)), str(rule_path.relative_to(ROOT))))

0 commit comments

Comments
 (0)