Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/scripts/test_text_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ def test_ulid_run_ids(self):
self.assertEqual(rules("a 26-digit number 12345678901234567890123456"), set())
self.assertEqual(rules("too long 01JD8ZQ4M3T7KXW2B9RVNHC6PAX"), set())

def test_coderhelm_ci_and_run_urls_are_ignored(self):
actions = (
"- [`Lint & Build`]"
"(https://github.com/CoderHelm/coderhelm/actions/runs/46580354258/job/142414691790): running"
)
self.assertEqual(rules(actions), set())
run_page = "The rest of the notes are on the [run page](https://app.coderhelm.ai/runs/01JD8ZQ4M3T7KXW2B9RVNHC6PA)."
self.assertEqual(rules(run_page), set())
built = "Plan, steps and logs: [the run page](https://app.coderhelm.com/runs/detail?id=01M8QY2KBNKJ7H0259BEYP5SRV)."
self.assertEqual(rules(built), set())
footer = "Opened by CoderHelm \u00b7 [run log](https://app.coderhelm.com/runs/detail?id=01M8QY2KBNKJ7H0259BEYP5SRV)"
self.assertEqual(rules(footer), set())
# A bare 12-digit number or ULID, outside such a URL, still trips.
self.assertEqual(rules("job 142414691790 ran"), {"12-digit number"})
self.assertEqual(rules("run 01JD8ZQ4M3T7KXW2B9RVNHC6PA failed"), {"ULID run id"})
# Another host's URL is not excused.
self.assertIn("AWS account id", rules("https://418273645091.dkr.ecr.us-east-1.amazonaws.com/x"))

def test_jira_keys_and_allowlist(self):
self.assertEqual(rules("Closes QXZ-4821"), {"Jira-style key"})
self.assertEqual(rules("branch coderhelm/QXZ-48"), {"Jira-style key"})
Expand Down
18 changes: 18 additions & 0 deletions .github/scripts/text_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@
RE_TEAM = re.compile(r"TEAM#[0-9A-Za-z][0-9A-Za-z_-]*")
RE_ULID = re.compile(r"(?<![0-9A-Za-z])[0-7][0-9A-HJKMNP-TV-Z]{25}(?![0-9A-Za-z])", re.IGNORECASE)
RE_JIRA = re.compile(r"(?<![A-Za-z0-9-])([A-Z]{2,6})-(\d{2,6})(?![0-9])")

# References CoderHelm writes into its own pull-request body for this repository:
# GitHub Actions run/job links for CoderHelm/coderhelm (whose run and job ids are
# plain 12-digit numbers) and CoderHelm run-page links (on coderhelm.ai or
# coderhelm.com, whose run id is a ULID). These are references to this repository's
# CI and to the run, not details carried from a customer install, so their ids are
# not read as account ids or run ids.
RE_CODERHELM_URL = re.compile(
r"https?://(?:github\.com/CoderHelm/coderhelm|(?:[a-z0-9-]+\.)*coderhelm\.(?:ai|com))/\S*",
re.IGNORECASE,
)


def _without_self_urls(line):
"""The line with CoderHelm's own CI and run-page URLs removed."""
return RE_CODERHELM_URL.sub(" ", line)
RE_EMAIL = re.compile(r"[A-Za-z0-9._%+-]+@((?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,})(?![A-Za-z0-9-])")


Expand All @@ -71,6 +87,7 @@ def _account(line):


def _twelve(line):
line = _without_self_urls(line)
return any(m.group(1).replace("-", "") not in PLACEHOLDER_ACCOUNTS for m in RE_TWELVE.finditer(line))


Expand All @@ -79,6 +96,7 @@ def _team(line):


def _ulid(line):
line = _without_self_urls(line)
return any(re.search(r"[A-Za-z]", m.group(0)) and m.group(0).upper() not in ULID_ALLOW
for m in RE_ULID.finditer(line))

Expand Down
Loading
Loading