Skip to content

Commit 7c9636e

Browse files
committed
Appending comments to issues within a project are now handled correctly.
1 parent 15c9171 commit 7c9636e

File tree

4 files changed

+94
-15
lines changed

4 files changed

+94
-15
lines changed

src/lib/enhancers/github/GitHubEditEnhancer.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ export class GitHubEditEnhancer implements CommentEnhancer<GitHubEditSpot> {
3636
if (isProjectDraftEdit) {
3737
const params = new URLSearchParams(location.search)
3838
const itemId = params.get("itemId")
39-
if (itemId && textarea.closest("[role='dialog']")) {
39+
// Exclude textareas within Shared-module__CommentBox (those are for adding new comments, not editing)
40+
const isInCommentBox = textarea.closest(
41+
'[class*="Shared-module__CommentBox"]'
42+
)
43+
if (itemId && textarea.closest("[role='dialog']") && !isInCommentBox) {
4044
const unique_key = `github.com:project-draft:${itemId}:edit-body`
4145
logger.debug(
4246
`${this.constructor.name} enhanced project draft body textarea`,

src/lib/enhancers/github/GitHubIssueAppendEnhancer.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,43 @@ export class GitHubIssueAppendEnhancer
4545
return null
4646
}
4747

48+
// Check for project URLs with issue parameter first
49+
const isProjectView = location.pathname.match(
50+
/^\/(?:orgs|users)\/[^/]+\/projects\/\d+\/views\/\d+/
51+
)
52+
if (isProjectView) {
53+
const params = new URLSearchParams(location.search)
54+
const issueParam = params.get("issue")
55+
// Only match textareas within Shared-module__CommentBox (those are for adding new comments)
56+
const isInCommentBox = textarea.closest(
57+
'[class*="Shared-module__CommentBox"]'
58+
)
59+
if (issueParam && isInCommentBox) {
60+
// Parse issue parameter: "owner|repo|number" (URL encoded as owner%7Crepo%7Cnumber)
61+
const parts = issueParam.split("|")
62+
if (parts.length === 3) {
63+
const [owner, repo, numberStr] = parts
64+
const slug = `${owner}/${repo}`
65+
const number = parseInt(numberStr!, 10)
66+
const unique_key = `github.com:${slug}:${number}`
67+
// For project views, the title is in the side panel dialog
68+
const title =
69+
document
70+
.querySelector('[data-testid="issue-title"]')
71+
?.textContent?.trim() || ""
72+
return {
73+
domain: location.host,
74+
number,
75+
slug,
76+
title,
77+
type: GH_ISSUE_APPEND,
78+
unique_key,
79+
}
80+
}
81+
}
82+
return null
83+
}
84+
4885
// Parse GitHub URL structure: /owner/repo/issues/123 or /owner/repo/pull/456
4986
logger.debug(`${this.constructor.name} examing url`, location.pathname)
5087

tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,12 @@ exports[`github detection > gh_project_issue:should detect correct spots 1`] = `
239239
{
240240
"for": "id=:rbs: name=null className=prc-Textarea-TextArea-13q4j overtype-input",
241241
"spot": {
242-
"isIssue": true,
243-
"type": "GH_EDIT",
244-
"unique_key": "github.com:project-draft:129503239:edit-body",
242+
"domain": "github.com",
243+
"number": 57,
244+
"slug": "diffplug/gitcasso",
245+
"title": "what about drafts?",
246+
"type": "GH_ISSUE_APPEND",
247+
"unique_key": "github.com:diffplug/gitcasso:57",
245248
},
246249
},
247250
]
@@ -260,9 +263,12 @@ exports[`github detection > gh_project_issue_edit:should detect correct spots 1`
260263
{
261264
"for": "id=:rbs: name=null className=prc-Textarea-TextArea-13q4j overtype-input",
262265
"spot": {
263-
"isIssue": true,
264-
"type": "GH_EDIT",
265-
"unique_key": "github.com:project-draft:129503239:edit-body",
266+
"domain": "github.com",
267+
"number": 57,
268+
"slug": "diffplug/gitcasso",
269+
"title": "what about drafts?",
270+
"type": "GH_ISSUE_APPEND",
271+
"unique_key": "github.com:diffplug/gitcasso:57",
266272
},
267273
},
268274
]

tests/lib/enhancers/__snapshots__/gh-ui.test.ts.snap

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,26 @@ exports[`github ui > gh_project_issue:should render correct UI elements 1`] = `
290290
[
291291
{
292292
"for": "id=:rbs: name=null className=prc-Textarea-TextArea-13q4j overtype-input",
293-
"title": "N/A",
294-
"upperDecoration": <span>
295-
N/A
296-
</span>,
293+
"title": "what about drafts?",
294+
"upperDecoration": <React.Fragment>
295+
<span
296+
className="flex h-4 w-4 flex-shrink-0 items-center justify-center"
297+
>
298+
<IssueOpenedIcon
299+
size={16}
300+
/>
301+
</span>
302+
<span>
303+
#
304+
57
305+
306+
<LinkOutOfPopup
307+
href="https://github.com/diffplug/gitcasso"
308+
>
309+
diffplug/gitcasso
310+
</LinkOutOfPopup>
311+
</span>
312+
</React.Fragment>,
297313
},
298314
]
299315
`;
@@ -309,10 +325,26 @@ exports[`github ui > gh_project_issue_edit:should render correct UI elements 1`]
309325
},
310326
{
311327
"for": "id=:rbs: name=null className=prc-Textarea-TextArea-13q4j overtype-input",
312-
"title": "N/A",
313-
"upperDecoration": <span>
314-
N/A
315-
</span>,
328+
"title": "what about drafts?",
329+
"upperDecoration": <React.Fragment>
330+
<span
331+
className="flex h-4 w-4 flex-shrink-0 items-center justify-center"
332+
>
333+
<IssueOpenedIcon
334+
size={16}
335+
/>
336+
</span>
337+
<span>
338+
#
339+
57
340+
341+
<LinkOutOfPopup
342+
href="https://github.com/diffplug/gitcasso"
343+
>
344+
diffplug/gitcasso
345+
</LinkOutOfPopup>
346+
</span>
347+
</React.Fragment>,
316348
},
317349
]
318350
`;

0 commit comments

Comments
 (0)