Skip to content

Commit bce5f38

Browse files
committed
fix conflict between issueAdd and Edit
1 parent b25cb3d commit bce5f38

File tree

3 files changed

+33
-50
lines changed

3 files changed

+33
-50
lines changed

src/lib/enhancers/github/githubEditComment.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,33 @@ export class GitHubEditCommentEnhancer implements CommentEnhancer<GitHubEditComm
1616
}
1717

1818
tryToEnhance(
19-
_textarea: HTMLTextAreaElement,
19+
textarea: HTMLTextAreaElement,
2020
location: StrippedLocation,
2121
): GitHubEditCommentSpot | null {
2222
if (location.host !== 'github.com') {
2323
return null
2424
}
25+
26+
// Only enhance textareas that are within the issue/PR body editing container
27+
const bodyContainer = textarea.closest('.react-issue-body')
28+
if (!bodyContainer) {
29+
return null
30+
}
31+
2532
// Parse GitHub URL structure: /owner/repo/issues/123 or /owner/repo/pull/456
26-
logger.info(`${this.constructor.name} examing url`, window.location.pathname)
33+
const match = location.pathname.match(/^\/([^/]+)\/([^/]+)\/(?:issues|pull)\/(\d+)/)
34+
if (!match) {
35+
return null
36+
}
37+
38+
const [, owner, repo, numberStr] = match
39+
const number = parseInt(numberStr!, 10)
40+
const unique_key = `github.com:${owner}/${repo}:${number}:edit-body`
41+
42+
logger.debug(`${this.constructor.name} enhanced issue/PR body textarea`, unique_key)
2743
return {
2844
type: 'GH_EDIT_COMMENT',
29-
unique_key: '<not unique>',
45+
unique_key,
3046
}
3147
}
3248

src/lib/enhancers/github/githubIssueAddComment.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ export class GitHubIssueAddCommentEnhancer implements CommentEnhancer<GitHubIssu
3131
return null
3232
}
3333

34+
// Don't enhance textareas that are within the issue/PR body editing container
35+
const bodyContainer = textarea.closest('.react-issue-body')
36+
if (bodyContainer) {
37+
return null
38+
}
39+
3440
// Parse GitHub URL structure: /owner/repo/issues/123 or /owner/repo/pull/456
3541
logger.debug(`${this.constructor.name} examing url`, location.pathname)
3642

tests/lib/enhancers/github.test.ts

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -197,31 +197,13 @@ describe('github', () => {
197197
{
198198
"for": "id=:rc3: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input",
199199
"spot": {
200-
"domain": "github.com",
201-
"number": 56,
202-
"slug": "diffplug/gitcasso",
203-
"title": "what about the draft?",
204-
"type": "GH_ISSUE_ADD_COMMENT",
205-
"unique_key": "github.com:diffplug/gitcasso:56",
200+
"type": "GH_EDIT_COMMENT",
201+
"unique_key": "github.com:diffplug/gitcasso:56:edit-body",
206202
},
207-
"title": "what about the draft?",
208-
"upperDecoration": <React.Fragment>
209-
<span
210-
className="flex h-4 w-4 flex-shrink-0 items-center justify-center"
211-
>
212-
<IssueOpenedIcon
213-
size={16}
214-
/>
215-
</span>
216-
#
217-
56
218-
<a
219-
className="truncate hover:underline"
220-
href="https://github.com/diffplug/gitcasso"
221-
>
222-
diffplug/gitcasso
223-
</a>
224-
</React.Fragment>,
203+
"title": "N/A",
204+
"upperDecoration": <span>
205+
N/A
206+
</span>,
225207
},
226208
{
227209
"for": "id=:ra7: name=null className=prc-Textarea-TextArea-13q4j overtype-input",
@@ -259,29 +241,8 @@ describe('github', () => {
259241
expect(enhancements(document, window)).toMatchInlineSnapshot(`
260242
[
261243
{
262-
"for": "id=issue-3429313834-body name=pull_request[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit js-size-to-fit size-to-fit js-session-resumable CommentBox-input FormControl-textarea js-saved-reply-shortcut-comment-field focus-visible overtype-input",
263-
"spot": {
264-
"domain": "github.com",
265-
"number": NaN,
266-
"slug": "diffplug/gitcasso",
267-
"title": "TODO_TITLE",
268-
"type": "GH_EDIT_COMMENT",
269-
"unique_key": "github.com:diffplug/gitcasso:NaN",
270-
},
271-
"title": "TITLE_TODO",
272-
"upperDecoration": <React.Fragment>
273-
<span
274-
className="font-mono text-muted-foreground text-sm"
275-
>
276-
diffplug/gitcasso
277-
</span>
278-
<span
279-
className="ml-2 font-medium"
280-
>
281-
PR #
282-
NaN
283-
</span>
284-
</React.Fragment>,
244+
"for": "id=issue-3429313834-body name=pull_request[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit js-size-to-fit size-to-fit js-session-resumable CommentBox-input FormControl-textarea js-saved-reply-shortcut-comment-field focus-visible",
245+
"spot": "NO_SPOT",
285246
},
286247
{
287248
"for": "id=new_comment_field name=comment[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit FormControl-textarea CommentBox-input js-size-to-fit size-to-fit js-session-resumable js-saved-reply-shortcut-comment-field overtype-input",

0 commit comments

Comments
 (0)