Skip to content

Commit a7420f4

Browse files
author
ntwigg
committed
Simplify github-handler down to only the things which are likely to make it into v1
1 parent fe74e99 commit a7420f4

File tree

1 file changed

+8
-56
lines changed

1 file changed

+8
-56
lines changed

browser-extension/src/datamodel/handlers/github-handler.ts

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ const GITHUB_COMMENT_TYPES = [
55
'GH_ISSUE_NEW',
66
'GH_PR_NEW',
77
'GH_ISSUE_ADD_COMMENT',
8-
'GH_ISSUE_EDIT_COMMENT',
98
'GH_PR_ADD_COMMENT',
9+
/* TODO
10+
'GH_ISSUE_EDIT_COMMENT',
1011
'GH_PR_EDIT_COMMENT',
1112
'GH_PR_CODE_COMMENT',
13+
*/
1214
] as const
1315

1416
export type GitHubCommentType = (typeof GITHUB_COMMENT_TYPES)[number]
@@ -17,8 +19,7 @@ export interface GitHubContext extends CommentSpot {
1719
type: GitHubCommentType // Override to narrow from string to specific union
1820
domain: string
1921
slug: string // owner/repo
20-
number?: number | undefined // issue/PR number
21-
commentId?: string | undefined // for editing existing comments
22+
number?: number | undefined // issue/PR number, undefined for new issues and PRs
2223
}
2324

2425
export class GitHubHandler implements CommentEnhancer<GitHubContext> {
@@ -42,9 +43,6 @@ export class GitHubHandler implements CommentEnhancer<GitHubContext> {
4243
const slug = `${owner}/${repo}`
4344
const number = numberStr ? parseInt(numberStr, 10) : undefined
4445

45-
// Check if editing existing comment
46-
const commentId = this.getCommentId(textarea)
47-
4846
// Determine comment type
4947
let type: GitHubCommentType
5048

@@ -58,21 +56,10 @@ export class GitHubHandler implements CommentEnhancer<GitHubContext> {
5856
}
5957
// Existing issue or PR page
6058
else if (urlType && number) {
61-
const isEditingComment = commentId !== null
62-
6359
if (urlType === 'issues') {
64-
type = isEditingComment ? 'GH_ISSUE_EDIT_COMMENT' : 'GH_ISSUE_ADD_COMMENT'
60+
type = 'GH_ISSUE_ADD_COMMENT'
6561
} else {
66-
// Check if it's a code comment (in Files Changed tab)
67-
const isCodeComment =
68-
textarea.closest('.js-inline-comment-form') !== null ||
69-
textarea.closest('[data-path]') !== null
70-
71-
if (isCodeComment) {
72-
type = 'GH_PR_CODE_COMMENT'
73-
} else {
74-
type = isEditingComment ? 'GH_PR_EDIT_COMMENT' : 'GH_PR_ADD_COMMENT'
75-
}
62+
type = 'GH_PR_ADD_COMMENT'
7663
}
7764
} else {
7865
return null
@@ -86,12 +73,8 @@ export class GitHubHandler implements CommentEnhancer<GitHubContext> {
8673
unique_key += ':new'
8774
}
8875

89-
if (commentId) {
90-
unique_key += `:edit:${commentId}`
91-
}
9276

9377
const context: GitHubContext = {
94-
commentId: commentId || undefined,
9578
domain: window.location.hostname,
9679
number,
9780
slug,
@@ -106,33 +89,21 @@ export class GitHubHandler implements CommentEnhancer<GitHubContext> {
10689
}
10790

10891
generateDisplayTitle(context: GitHubContext): string {
109-
const { slug, number, commentId } = context
110-
111-
if (commentId) {
112-
return `Edit comment in ${slug}${number ? ` #${number}` : ''}`
113-
}
114-
92+
const { slug, number } = context
11593
if (number) {
11694
return `Comment on ${slug} #${number}`
11795
}
118-
11996
return `New ${window.location.pathname.includes('/issues/') ? 'issue' : 'PR'} in ${slug}`
12097
}
12198

12299
generateIcon(context: GitHubContext): string {
123100
switch (context.type) {
124101
case 'GH_ISSUE_NEW':
125102
case 'GH_ISSUE_ADD_COMMENT':
126-
case 'GH_ISSUE_EDIT_COMMENT':
127103
return '🐛' // Issue icon
128104
case 'GH_PR_NEW':
129105
case 'GH_PR_ADD_COMMENT':
130-
case 'GH_PR_EDIT_COMMENT':
131106
return '🔄' // PR icon
132-
case 'GH_PR_CODE_COMMENT':
133-
return '💬' // Code comment icon
134-
default:
135-
return '📝' // Generic comment icon
136107
}
137108
}
138109

@@ -141,28 +112,9 @@ export class GitHubHandler implements CommentEnhancer<GitHubContext> {
141112

142113
if (context.number) {
143114
const type = window.location.pathname.includes('/issues/') ? 'issues' : 'pull'
144-
return `${baseUrl}/${type}/${context.number}${context.commentId ? `#issuecomment-${context.commentId}` : ''}`
115+
return `${baseUrl}/${type}/${context.number}`
145116
}
146117

147118
return baseUrl
148119
}
149-
150-
private getCommentId(textarea: HTMLTextAreaElement): string | null {
151-
// Look for edit comment form indicators
152-
const commentForm = textarea.closest('[data-comment-id]')
153-
if (commentForm) {
154-
return commentForm.getAttribute('data-comment-id')
155-
}
156-
157-
const editForm = textarea.closest('.js-comment-edit-form')
158-
if (editForm) {
159-
const commentContainer = editForm.closest('.js-comment-container')
160-
if (commentContainer) {
161-
const id = commentContainer.getAttribute('data-gid') || commentContainer.getAttribute('id')
162-
return id ? id.replace('issuecomment-', '') : null
163-
}
164-
}
165-
166-
return null
167-
}
168120
}

0 commit comments

Comments
 (0)