Skip to content

Commit 2f98e24

Browse files
committed
feat(issues): qualify a commit closer with its repository when it is not this one
A PR closer is written owner/name#N when it lives in another repository, but a commit closer printed its abbreviated oid alone, so a commit in another repository that closed the issue read as a commit in this one, on the line the skill calls authoritative. The query now selects the commit's repository and the line reads `by commit owner/name@<sha>` when it differs, through the same case-insensitive comparison the PR form uses, now a shared helper. A commit with no repository in the payload still reads as this one. The query shape ran once against real gh on cli/cli#13898. Finding O-Q4. Before the fix the new issue-closer-commit-crossrepo fixture rendered "closed [dana …] as completed by commit 1a2b3c4"; the golden now pins "by commit other/upstream@1a2b3c4".
1 parent d13fb91 commit 2f98e24

6 files changed

Lines changed: 94 additions & 6 deletions

‎gh-comments‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ ISSUE_FULL='number title state stateReason author{login __typename} createdAt bo
445445
nodes{
446446
__typename
447447
... on IssueComment{author{login __typename} createdAt isMinimized minimizedReason body}
448-
... on ClosedEvent{actor{login __typename} createdAt stateReason closer{__typename ... on PullRequest{number title state repository{nameWithOwner}} ... on Commit{abbreviatedOid}}}
448+
... on ClosedEvent{actor{login __typename} createdAt stateReason closer{__typename ... on PullRequest{number title state repository{nameWithOwner}} ... on Commit{abbreviatedOid repository{nameWithOwner}}}}
449449
... on ReopenedEvent{actor{login __typename} createdAt}
450450
... on CrossReferencedEvent{actor{login __typename} createdAt willCloseTarget source{__typename ... on Issue{number title state repository{nameWithOwner}} ... on PullRequest{number title state repository{nameWithOwner}}}}
451451
... on RenamedTitleEvent{actor{login __typename} createdAt previousTitle currentTitle}
@@ -918,13 +918,18 @@ def housekeeping: ["LabeledEvent","UnlabeledEvent","AssignedEvent","UnassignedEv
918918
"MilestonedEvent","DemilestonedEvent"];
919919
def ishk: .__typename as $t | (housekeeping | index($t)) != null;
920920
921+
# Whether an object with a repository is in this one. Compared
922+
# case-insensitively: GitHub names are, and -R is typed by hand. No
923+
# repository at all reads as this one, which keeps payloads captured before
924+
# the field was selected renderable.
925+
def samerepo($repo):
926+
(((.repository // {}).nameWithOwner) // "") as $r
927+
| $r == "" or ($r | ascii_downcase) == ($repo | ascii_downcase);
921928
# A reference to an issue or PR: `#N` in this repo, `owner/name#N` in another,
922929
# the way GitHub itself writes them. Shared by the xref line and the closer
923930
# on a closed line, so the two cannot drift apart.
924-
# Compared case-insensitively: GitHub names are, and -R is typed by hand.
925931
def refnum($repo):
926-
(((.repository // {}).nameWithOwner) // "") as $r
927-
| if $r == "" or ($r | ascii_downcase) == ($repo | ascii_downcase) then "#\(.number // "?")" else "\($r)#\(.number // "?")" end;
932+
if samerepo($repo) then "#\(.number // "?")" else "\(.repository.nameWithOwner)#\(.number // "?")" end;
928933
def quoted_title: ((.title // "") | gsub("\\s+"; " ")) as $t | if $t == "" then "" else " \"\($t)\"" end;
929934
930935
def r_xref($repo):
@@ -947,7 +952,8 @@ def r_closer($repo):
947952
| if $c == null then ", no closer recorded"
948953
elif $c.__typename == "PullRequest" then
949954
" by \($c | refnum($repo)) PR \($c.state // "?")" + ($c | quoted_title)
950-
elif $c.__typename == "Commit" then " by commit \($c.abbreviatedOid // "?")"
955+
elif $c.__typename == "Commit" then
956+
" by commit " + (if ($c | samerepo($repo)) then "" else "\($c.repository.nameWithOwner)@" end) + ($c.abbreviatedOid // "?")
951957
elif $c.__typename == "ProjectV2" then " by a project"
952958
else error("closer of type \($c.__typename) is not rendered") end;
953959
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
issue #48 upstream typo in the shared banner [CLOSED completed]
2+
closed [dana 2026-09-04 14:25] as completed by commit other/upstream@1a2b3c4
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
issue #48 upstream typo in the shared banner [CLOSED completed]
2+
comments: 1 · cross-refs: 0 · events: 1
3+
4+
body [carol 2026-09-04 14:00]
5+
The banner we vendor from upstream says "Instaled".
6+
7+
comment [dana 2026-09-04 14:20]
8+
Fixed upstream; the commit message closes this with owner/name#48.
9+
10+
closed [dana 2026-09-04 14:25] as completed by commit other/upstream@1a2b3c4
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
[
2+
{
3+
"data": {
4+
"repository": {
5+
"issueOrPullRequest": {
6+
"__typename": "Issue",
7+
"number": 48,
8+
"title": "upstream typo in the shared banner",
9+
"state": "CLOSED",
10+
"stateReason": "COMPLETED",
11+
"author": {
12+
"login": "carol",
13+
"__typename": "User"
14+
},
15+
"createdAt": "2026-09-04T14:00:00Z",
16+
"body": "The banner we vendor from upstream says \"Instaled\".",
17+
"labels": {
18+
"totalCount": 0,
19+
"nodes": []
20+
},
21+
"assignees": {
22+
"nodes": []
23+
},
24+
"timelineItems": {
25+
"pageInfo": {
26+
"hasNextPage": false,
27+
"endCursor": "Y3Vyc29yOnYyOpHP"
28+
},
29+
"nodes": [
30+
{
31+
"__typename": "IssueComment",
32+
"author": {
33+
"login": "dana",
34+
"__typename": "User"
35+
},
36+
"createdAt": "2026-09-04T14:20:00Z",
37+
"isMinimized": false,
38+
"minimizedReason": null,
39+
"body": "Fixed upstream; the commit message closes this with owner/name#48."
40+
},
41+
{
42+
"__typename": "ClosedEvent",
43+
"actor": {
44+
"login": "dana",
45+
"__typename": "User"
46+
},
47+
"createdAt": "2026-09-04T14:25:00Z",
48+
"stateReason": "COMPLETED",
49+
"closer": {
50+
"__typename": "Commit",
51+
"abbreviatedOid": "1a2b3c4",
52+
"repository": {
53+
"nameWithOwner": "other/upstream"
54+
}
55+
}
56+
}
57+
]
58+
}
59+
}
60+
}
61+
}
62+
}
63+
]

‎tests/fixtures/gh-comments/issue-closer-commit.tl.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@
4848
"stateReason": "COMPLETED",
4949
"closer": {
5050
"__typename": "Commit",
51-
"abbreviatedOid": "1a2b3c4"
51+
"abbreviatedOid": "1a2b3c4",
52+
"repository": {
53+
"nameWithOwner": "fixtures/fixtures"
54+
}
5255
}
5356
}
5457
]

‎tests/test-gh-comments.zsh‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
# the PR, the xref to it carries (closes); a comment and a
4343
# label event, which --closure must leave out
4444
# issue-closer-commit closed by a commit, no PR anywhere: `by commit <sha>`
45+
# issue-closer-commit-crossrepo closed by a commit in another repository:
46+
# `by commit owner/name@<sha>`, qualified like a PR closer
4547
# issue-closer-crossrepo closed by a PR in another repository: closer and
4648
# xref both written owner/name#N
4749
# issue-closer-reopened closed by a PR, reopened, closed again with no
@@ -200,6 +202,8 @@ check issue-closer-pr-toc issue-closer-pr 41 --toc
200202
check issue-closer-pr-closure issue-closer-pr 41 --closure
201203
check issue-closer-commit-full issue-closer-commit 42
202204
check issue-closer-commit-closure issue-closer-commit 42 --closure
205+
check issue-closer-commit-crossrepo-full issue-closer-commit-crossrepo 48
206+
check issue-closer-commit-crossrepo-closure issue-closer-commit-crossrepo 48 --closure
203207
check issue-closer-crossrepo-full issue-closer-crossrepo 43
204208
check issue-closer-crossrepo-closure issue-closer-crossrepo 43 --closure
205209
check issue-closer-reopened-full issue-closer-reopened 45

0 commit comments

Comments
 (0)