From e3d3b03bb1d74e4a13312d366963ee0a371d4f47 Mon Sep 17 00:00:00 2001 From: Gavin Lucas Date: Wed, 2 Dec 2026 12:54:51 +0000 Subject: [PATCH 1/2] Stop searching for tracker keys by shape, and keep the internal-link check The key search matched any ABC-123, a shape standards, licences, Octopus tariff product codes (AGILE-24-10-01) and vendors' error codes (KT-CT-1139) all share. Each new one needed an exception, and the latest blocked a pull request whose subject is those product codes. A shape-based narrowing was tried and kept the existing tests passing, but it leaves the same trade, so the search is removed rather than tuned. The rule against tracker keys in a public repository stands; review enforces it. The search for links into the internal Atlassian site stays: a URL shape nothing else has, and the more damaging leak. It had no tests of its own, the file covering only the key search, so the file now tests it: wiki, browse and board links are reported, a hostless wiki path is reported, and a bare key shape or the hostname named as text is not. --- actions/repo-hygiene/check-repo-hygiene.py | 43 ++++++-------------- tests/test_internal_references.py | 46 +++++++++++++--------- 2 files changed, 40 insertions(+), 49 deletions(-) diff --git a/actions/repo-hygiene/check-repo-hygiene.py b/actions/repo-hygiene/check-repo-hygiene.py index 9051070..45e5f91 100755 --- a/actions/repo-hygiene/check-repo-hygiene.py +++ b/actions/repo-hygiene/check-repo-hygiene.py @@ -71,29 +71,16 @@ # --- public-repository leaks (SK.9.1) ----------------------------------------------------- # -# Matched by the tracker's key shape rather than one project's prefix, so a second project's -# keys are caught too. Letters only in the prefix, and at least two: allowing digits made an -# earlier version match `Z0-9` inside a regex character class, and a false positive is what -# gets a guard switched off wholesale. -TRACKER_KEY = re.compile(r"\b[A-Z]{2,10}-\d+\b(?!\.\d)") - -# Same shape, not tracker keys. Each is a real external standard, so this is a list of -# evidenced exceptions rather than a way to quiet a genuine hit. -NOT_A_TRACKER_KEY = re.compile(r"\b(?:ISO-\d+|RFC-\d+|SHA-\d+|UTF-\d+|AES-\d+|PEP-\d+|CVE-\d+|SMETS-\d+|FLEX-\d+|GPL-\d+|LGPL-\d+|AGPL-\d+)\b") - -# Same shape at the end of a longer standard's name, matched against the line up to the key's -# end, since the key alone cannot see what comes before it: Unicode-DFS-2016, the SPDX name of -# Unicode's data files licence, which a Debian copyright file must spell exactly. Only that name -# is let through, so a project whose keys start DFS-, or a key that follows "Unicode-", is still -# reported. -PART_OF_A_STANDARD = re.compile(r"\bUnicode-DFS-\d+$") - +# Tracker keys are not searched for by shape. `ABC-123` is too common a shape outside any +# tracker - standards, licences, product codes, vendors' error codes - and each new one needed +# an exception, so the search cost more than it caught. Links into the internal site are what +# is searched for: a URL shape nothing else has. +# # Any link into the internal Atlassian site, not only a wiki one. Review asked whether this # should require a /wiki/ path, since the name said "wiki link" while the pattern also matched a # Jira /browse/ URL. Widened the name rather than narrowing the pattern: a Jira board URL -# carrying no issue key - .../jira/software/projects/X/boards/1 - would otherwise slip past both -# this and the tracker-key check, and it is exactly as much of a leak. A /browse/ link may now -# be reported twice, once here and once as its issue key. That redundancy is the cheaper error. +# carrying no issue key - .../jira/software/projects/X/boards/1 - would otherwise slip past this +# check, and it is exactly as much of a leak. # # The URL alternative consumes the rest of the URL, so a full wiki link is reported once rather # than twice - the host branch and the /wiki/spaces/ branch would otherwise both match adjacent @@ -183,7 +170,7 @@ def tracked_paths(root): Deliberately not a filesystem walk: that would sweep in build output and a developer's own gitignored configuration, which may hold real credentials and is none of this check's business. Text is decided by sniffing rather than by a suffix allowlist, because the files - most likely to carry a leaked tracker key - maintainer scripts, CODEOWNERS - have no + most likely to carry a leaked internal link - maintainer scripts, CODEOWNERS - have no extension at all. Args: @@ -383,11 +370,11 @@ def check_the_scan_is_real(root, tracked, files): def check_no_internal_references(root, tracked, files): - """No tracker key or internal Atlassian link in a public repository (SK.9.1). + """No internal Atlassian link in a public repository (SK.9.1). - Both are leaks and both are dead references to anyone reading the repository, including - whoever reads generated release notes. Describe the work instead; the issue carries the - link in the other direction. + A leak, and a dead reference to anyone reading the repository, including whoever reads + generated release notes. Describe the work instead; the issue carries the link in the other + direction. A bare tracker key is not searched for: see the note above ``INTERNAL_LINK``. Args: root (pathlib.Path): repository root. @@ -411,12 +398,6 @@ def check_no_internal_references(root, tracked, files): except OSError as exc: raise CannotEvaluate(f"{relative} could not be read: {exc}") from exc for number, line in enumerate(text.splitlines(), 1): - for match in TRACKER_KEY.finditer(line): - span = match.group(0) - if not NOT_A_TRACKER_KEY.search(span) and not PART_OF_A_STANDARD.search( - line[: match.end()] - ): - findings.append(f"{relative}:{number}: tracker key {span}") for match in INTERNAL_LINK.finditer(line): findings.append(f"{relative}:{number}: internal Atlassian link ({match.group(0)[:48]})") return findings diff --git a/tests/test_internal_references.py b/tests/test_internal_references.py index daa7164..9028feb 100644 --- a/tests/test_internal_references.py +++ b/tests/test_internal_references.py @@ -1,36 +1,46 @@ -"""The hygiene check's search for tracker keys: what it reports, and the standards it does not. +"""The hygiene check's search for internal Atlassian links: what it reports, and what it does not. The check is loaded from the action's script, so what is tested is the script that ships. The -keys it should report are assembled at run time, so that this file holds none for the check to +links it should report are assembled at run time, so that this file holds none for the check to find. """ import pytest from conftest import load_hygiene +HOST = "example" + "." + "atlassian" + ".net" + def findings(tmp_path, line): - path = tmp_path / "copyright" + path = tmp_path / "notes.md" path.write_text(line + "\n", encoding="utf-8") return load_hygiene().check_no_internal_references(tmp_path, [path], [path]) -@pytest.mark.parametrize("line", [ - "License: Unicode-DFS-2016", - "License: GPL-3+ and Expat and Unicode-DFS-2016 and Unicode-3.0", - "Encoded as UTF-8, per RFC-3629 and ISO-8859", +@pytest.mark.parametrize("link", [ + f"https://{HOST}/wiki/spaces/XY/pages/123", + f"https://{HOST}/browse/" + "XY" + "-22", + f"https://{HOST}/jira/software/projects/XY/boards/1", ]) -def test_an_external_standard_is_not_a_tracker_key(tmp_path, line): - assert findings(tmp_path, line) == [] +def test_an_internal_link_is_reported(tmp_path, link): + (finding,) = findings(tmp_path, f"See {link} for the decision.") + assert finding.startswith("notes.md:1: internal Atlassian link (https://") + +def test_a_wiki_path_with_no_host_is_reported(tmp_path): + assert findings(tmp_path, "Moved to " + "/wiki" + "/spaces/XY") == [ + "notes.md:1: internal Atlassian link (/wiki/spaces/)" + ] -@pytest.mark.parametrize("before,key", [ - ("Fixes ", "XY" + "-22"), - ("See ", "ABC" + "-1"), - # Only the Unicode licence's name is let through, not every key ending its shape. - ("Fixes ", "DFS" + "-2016"), - ("MyUnicode-", "DFS" + "-2016"), - ("Unicode-", "XY" + "-22"), + +@pytest.mark.parametrize("line", [ + # A bare tracker-key shape is not searched for: standards, licences, product codes and + # vendors' error codes all share it. + "Fixes " + "XY" + "-22", + "License: GPL-3+ and Unicode-DFS-2016", + "Tariff E-1R-AGILE-24-10-01-C, error KT-CT-1139", + # The hostname named as text, not as a link: an instruction forbidding such links says it. + "Never put an " + "atlassian" + ".net" + "/wiki link in a commit message", ]) -def test_a_tracker_key_is_reported(tmp_path, before, key): - assert findings(tmp_path, before + key) == [f"copyright:1: tracker key {key}"] +def test_what_is_not_a_link_is_not_reported(tmp_path, line): + assert findings(tmp_path, line) == [] From a340f2e37dc6f710de2f09701cf130cf6334a919 Mon Sep 17 00:00:00 2001 From: Gavin Lucas Date: Wed, 2 Dec 2026 13:03:04 +0000 Subject: [PATCH 2/2] Catch an internal link written without its scheme, and state why the pattern matches the host With the key search gone, a link such as .atlassian.net/browse/, written without https://, was no longer reported by anything: before, its issue key caught it. Such a link is now matched by the host followed by one of the site's top-level paths (wiki, browse, jira) and a slash. The instruction-text case the pattern was built around, "an atlassian.net/wiki link", has no slash after the path, so it is still not reported. The comment above the pattern argued from the removed key search, and narrated the review that widened it. It now states the rule: any link into the site is a leak, so the pattern matches the host rather than one path. Run over the three local repositories that call this action (docker-mcp, quaffed, send-to-influx): all checks pass on each. --- actions/repo-hygiene/check-repo-hygiene.py | 14 ++++++++------ tests/test_internal_references.py | 5 ++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/actions/repo-hygiene/check-repo-hygiene.py b/actions/repo-hygiene/check-repo-hygiene.py index 45e5f91..f8d4a5b 100755 --- a/actions/repo-hygiene/check-repo-hygiene.py +++ b/actions/repo-hygiene/check-repo-hygiene.py @@ -76,23 +76,25 @@ # an exception, so the search cost more than it caught. Links into the internal site are what # is searched for: a URL shape nothing else has. # -# Any link into the internal Atlassian site, not only a wiki one. Review asked whether this -# should require a /wiki/ path, since the name said "wiki link" while the pattern also matched a -# Jira /browse/ URL. Widened the name rather than narrowing the pattern: a Jira board URL -# carrying no issue key - .../jira/software/projects/X/boards/1 - would otherwise slip past this -# check, and it is exactly as much of a leak. +# Any link into the internal site is a leak, whether a wiki page, an issue or a board, so the +# pattern matches the host rather than one path under it. # # The URL alternative consumes the rest of the URL, so a full wiki link is reported once rather # than twice - the host branch and the /wiki/spaces/ branch would otherwise both match adjacent # non-overlapping parts of the same link. The bare /wiki/spaces/ branch then only fires on a # path with no host before it. # +# A link written without its scheme is matched by its path instead: the host followed by one of +# the site's own top-level paths and a slash. +# # A URL shape is required, not the bare hostname. Matching the substring flagged a routine # prompt whose whole purpose is forbidding such links - the guard firing on the instruction not # to do the thing - and so did requiring only a slash after the host, because the same prompt # says "an atlassian.net/wiki link". INTERNAL_LINK = re.compile( - r"(?:https?://(?:[^\s)\"'/?#]*\.)?atlassian\.net(?![A-Za-z0-9-]|\.[A-Za-z])[^\s)\"\']*)|/wiki/spaces/" + r"(?:https?://(?:[^\s)\"'/?#]*\.)?atlassian\.net(?![A-Za-z0-9-]|\.[A-Za-z])[^\s)\"\']*)" + r"|(?:[^\s)\"'/?#]*\.)?atlassian\.net/(?:wiki|browse|jira)/[^\s)\"\']*" + r"|/wiki/spaces/" ) # --- CI job bounds (GB.3.5) --------------------------------------------------------------- diff --git a/tests/test_internal_references.py b/tests/test_internal_references.py index 9028feb..b42b347 100644 --- a/tests/test_internal_references.py +++ b/tests/test_internal_references.py @@ -21,10 +21,13 @@ def findings(tmp_path, line): f"https://{HOST}/wiki/spaces/XY/pages/123", f"https://{HOST}/browse/" + "XY" + "-22", f"https://{HOST}/jira/software/projects/XY/boards/1", + # Written without its scheme, as a link pasted from an address bar often is. + f"{HOST}/browse/" + "XY" + "-22", + f"{HOST}/wiki/spaces/XY/pages/123", ]) def test_an_internal_link_is_reported(tmp_path, link): (finding,) = findings(tmp_path, f"See {link} for the decision.") - assert finding.startswith("notes.md:1: internal Atlassian link (https://") + assert finding.startswith("notes.md:1: internal Atlassian link (") def test_a_wiki_path_with_no_host_is_reported(tmp_path):