Skip to content

Commit 1c83093

Browse files
committed
closes-issue hook: accept full Forgejo URLs as same-repo close refs
The hook already accepts bare #N and qualified owner/repo#N. Add a third alternation that matches the full Forgejo issue URL and applies the same same-repo check (URLs to other repos are still rejected). Lets contributors land commits that reference Forgejo issues with a clickable URL, which is the canonical form during the GitHub->Forgejo transition (parent tracker at the Forgejo URL below). closes https://forgejo.coilysiren.me/coilysiren/agentic-os/issues/17
1 parent af6f53b commit 1c83093

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repos:
1616
# on this repo. README + docs/FEATURES still need See-also sections;
1717
# fix in a follow-up before enabling.
1818
- id: closes-issue
19-
name: commit closes a GitHub issue
19+
name: commit closes a Forgejo issue
2020
entry: python -m agentic_os.check_commit_closes_issue
2121
language: python
2222
stages: [commit-msg]

agentic_os/check_commit_closes_issue.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
fixes #N | fix #N | fixed #N
1111
resolves #N | resolve #N | resolved #N
1212
<this-owner>/<this-repo>#N with any of the above keywords
13+
https://forgejo.coilysiren.me/<this-owner>/<this-repo>/issues/N
14+
with any of the above keywords (full URL form for unambiguous
15+
clickable references; same-repo check still applied)
1316
14-
Rejected: cross-repo refs (`owner/other-repo#N`). The issue must live
15-
in the repo the commit lands in. If the rule needs to span repos,
16-
file the issue locally and link out from there instead.
17+
Rejected: cross-repo refs (`owner/other-repo#N` or a Forgejo URL
18+
pointing at a different repo). The issue must live in the repo the
19+
commit lands in. If the rule needs to span repos, file the issue
20+
locally and link out from there instead.
1721
1822
Exempt: Merge / Revert / fixup! / squash! commits.
1923
@@ -27,15 +31,23 @@
2731
import subprocess
2832
import sys
2933

34+
KEYWORD = r"close[sd]?|fix(?:e[sd])?|resolve[sd]?"
3035
KEYWORD_RE = re.compile(
31-
r"\b(close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s+([\w.-]+/[\w.-]+)?#\d+",
36+
rf"\b(?:{KEYWORD})\s+"
37+
r"(?:"
38+
r"https?://forgejo\.coilysiren\.me/(?P<fj_owner>[\w.-]+)/(?P<fj_repo>[\w.-]+)/issues/\d+"
39+
r"|"
40+
r"(?P<qualifier>[\w.-]+/[\w.-]+)?#\d+"
41+
r")",
3242
re.IGNORECASE,
3343
)
3444
EXEMPT_PREFIXES = ("Merge ", "Revert ", "fixup! ", "squash! ")
3545
ERROR = (
3646
"ERROR: commit message must close an issue in this repo.\n"
37-
" Add 'closes #N' (or fixes #N / resolves #N) to the message.\n"
38-
" Cross-repo refs (owner/other-repo#N) are rejected.\n"
47+
" Add 'closes #N' (or fixes #N / resolves #N) to the message,\n"
48+
" or 'closes https://forgejo.coilysiren.me/<owner>/<repo>/issues/N'.\n"
49+
" Cross-repo refs (owner/other-repo#N or a Forgejo URL pointing at\n"
50+
" another repo) are rejected.\n"
3951
" File the issue in this repo first if one does not exist:\n"
4052
" https://forgejo.coilysiren.me/coilysiren/<repo>/issues/new\n"
4153
)
@@ -60,7 +72,15 @@ def this_repo() -> tuple[str, str] | None:
6072

6173
def has_same_repo_ref(body: str, this: tuple[str, str] | None) -> bool:
6274
for match in KEYWORD_RE.finditer(body):
63-
qualifier = match.group(2)
75+
fj_owner = match.group("fj_owner")
76+
fj_repo = match.group("fj_repo")
77+
if fj_owner is not None and fj_repo is not None:
78+
if this is None:
79+
continue
80+
if (fj_owner.lower(), fj_repo.lower()) == this:
81+
return True
82+
continue
83+
qualifier = match.group("qualifier")
6484
if qualifier is None:
6585
return True
6686
if this is None:

0 commit comments

Comments
 (0)