Skip to content

Commit 9c5d99b

Browse files
authored
Merge pull request #761 from OptimumCode/annotation-script-rfc-support
Correct annotation python script to correctly work with rfc and iso links
2 parents e524505 + 9563ce7 commit 9c5d99b

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

bin/annotate-specification-links

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ def line_number_of(path: Path, case: dict[str, Any]) -> int:
6161
1,
6262
)
6363

64+
def extract_kind_and_spec(key: str) -> (str, str):
65+
"""
66+
Extracts specification number and kind from the defined key
67+
"""
68+
can_have_spec = ["rfc", "iso"]
69+
if not any(key.startswith(el) for el in can_have_spec):
70+
return key, ""
71+
number = re.search(r"\d+", key)
72+
spec = "" if number is None else number.group(0)
73+
kind = key.removesuffix(spec)
74+
return kind, spec
75+
6476

6577
def main():
6678
# Clear annotations which may have been emitted by a previous run.
@@ -82,20 +94,33 @@ def main():
8294
line=error.lineno,
8395
col=error.pos + 1,
8496
title=str(error),
97+
message=f"cannot load {path}"
8598
)
8699
sys.stdout.write(error)
100+
continue
87101

88102
for test_case in contents:
89103
specifications = test_case.get("specification")
90104
if specifications is not None:
91105
for each in specifications:
92106
quote = each.pop("quote", "")
93-
(kind, section), = each.items()
107+
(key, section), = each.items()
94108

95-
number = re.search(r"\d+", kind)
96-
spec = "" if number is None else number.group(0)
109+
(kind, spec) = extract_kind_and_spec(key)
110+
111+
url_template = version_urls[kind]
112+
if url_template is None:
113+
error = annotation(
114+
level="error",
115+
path=path,
116+
line=line_number_of(path, test_case),
117+
title=f"unsupported template '{kind}'",
118+
message=f"cannot find a URL template for '{kind}'"
119+
)
120+
sys.stdout.write(error)
121+
continue
97122

98-
url = version_urls[kind].expand(
123+
url = url_template.expand(
99124
spec=spec,
100125
section=section,
101126
)

bin/specification_urls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"external": {
2929
"ecma262": "https://262.ecma-international.org/{section}",
3030
"perl5": "https://perldoc.perl.org/perlre#{section}",
31-
"rfc": "https://www.rfc-editor.org/rfc/{spec}.txt#{section}",
31+
"rfc": "https://www.rfc-editor.org/rfc/rfc{spec}.txt#{section}",
3232
"iso": "https://www.iso.org/obp/ui"
3333
}
3434
}

0 commit comments

Comments
 (0)