From afa93888ec4358c9ad8f05be6760c39a65f7e19b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 18 Sep 2025 14:58:14 -0700 Subject: [PATCH 1/6] Refactor `ghOptions.ts` and `githubHighlighter.ts` into `github-common.ts`. --- src/lib/enhancers/github/ghOptions.ts | 7 ------- .../github/{githubHighlighter.ts => github-common.ts} | 7 +++++++ src/lib/enhancers/github/githubEditComment.tsx | 3 +-- src/lib/enhancers/github/githubIssueAddComment.tsx | 3 +-- src/lib/enhancers/github/githubIssueNewComment.tsx | 3 +-- src/lib/enhancers/github/githubPRAddComment.tsx | 3 +-- src/lib/enhancers/github/githubPRNewComment.tsx | 3 +-- 7 files changed, 12 insertions(+), 17 deletions(-) delete mode 100644 src/lib/enhancers/github/ghOptions.ts rename src/lib/enhancers/github/{githubHighlighter.ts => github-common.ts} (76%) diff --git a/src/lib/enhancers/github/ghOptions.ts b/src/lib/enhancers/github/ghOptions.ts deleted file mode 100644 index 321389b..0000000 --- a/src/lib/enhancers/github/ghOptions.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { Options } from 'overtype' - -export const commonGithubOptions: Options = { - autoResize: true, - lineHeight: 'var(--text-body-lineHeight-medium, 1.4285)', - padding: 'var(--base-size-16)', -} diff --git a/src/lib/enhancers/github/githubHighlighter.ts b/src/lib/enhancers/github/github-common.ts similarity index 76% rename from src/lib/enhancers/github/githubHighlighter.ts rename to src/lib/enhancers/github/github-common.ts index 60f172e..f8cb833 100644 --- a/src/lib/enhancers/github/githubHighlighter.ts +++ b/src/lib/enhancers/github/github-common.ts @@ -1,7 +1,14 @@ import hljs from 'highlight.js' +import type { Options } from 'overtype' import OverType from 'overtype' import { oncePerRefresh } from '@/lib/once-per-refresh' +export const commonGithubOptions: Options = { + autoResize: true, + lineHeight: 'var(--text-body-lineHeight-medium, 1.4285)', + padding: 'var(--base-size-16)', +} + export function prepareGitHubHighlighter() { oncePerRefresh('github-highlighter', () => { OverType.setCodeHighlighter(githubHighlighter) diff --git a/src/lib/enhancers/github/githubEditComment.tsx b/src/lib/enhancers/github/githubEditComment.tsx index 6a78d37..4d7349a 100644 --- a/src/lib/enhancers/github/githubEditComment.tsx +++ b/src/lib/enhancers/github/githubEditComment.tsx @@ -3,8 +3,7 @@ import type React from 'react' import type { CommentEnhancer, CommentSpot, StrippedLocation } from '@/lib/enhancer' import { logger } from '@/lib/logger' import { modifyDOM } from '../modifyDOM' -import { commonGithubOptions } from './ghOptions' -import { prepareGitHubHighlighter } from './githubHighlighter' +import { commonGithubOptions, prepareGitHubHighlighter } from './github-common' export interface GitHubEditCommentSpot extends CommentSpot { type: 'GH_EDIT_COMMENT' diff --git a/src/lib/enhancers/github/githubIssueAddComment.tsx b/src/lib/enhancers/github/githubIssueAddComment.tsx index 2b1e1bb..6cf3e33 100644 --- a/src/lib/enhancers/github/githubIssueAddComment.tsx +++ b/src/lib/enhancers/github/githubIssueAddComment.tsx @@ -4,8 +4,7 @@ import type React from 'react' import type { CommentEnhancer, CommentSpot, StrippedLocation } from '@/lib/enhancer' import { logger } from '@/lib/logger' import { modifyDOM } from '../modifyDOM' -import { commonGithubOptions } from './ghOptions' -import { prepareGitHubHighlighter } from './githubHighlighter' +import { commonGithubOptions, prepareGitHubHighlighter } from './github-common' export interface GitHubIssueAddCommentSpot extends CommentSpot { type: 'GH_ISSUE_ADD_COMMENT' diff --git a/src/lib/enhancers/github/githubIssueNewComment.tsx b/src/lib/enhancers/github/githubIssueNewComment.tsx index cd81c09..60c9cc5 100644 --- a/src/lib/enhancers/github/githubIssueNewComment.tsx +++ b/src/lib/enhancers/github/githubIssueNewComment.tsx @@ -2,8 +2,7 @@ import OverType, { type OverTypeInstance } from 'overtype' import type { CommentEnhancer, CommentSpot, StrippedLocation } from '../../enhancer' import { logger } from '../../logger' import { modifyDOM } from '../modifyDOM' -import { commonGithubOptions } from './ghOptions' -import { prepareGitHubHighlighter } from './githubHighlighter' +import { commonGithubOptions, prepareGitHubHighlighter } from './github-common' interface GitHubIssueNewCommentSpot extends CommentSpot { type: 'GH_ISSUE_NEW_COMMENT' diff --git a/src/lib/enhancers/github/githubPRAddComment.tsx b/src/lib/enhancers/github/githubPRAddComment.tsx index 8d60641..f6ac5a4 100644 --- a/src/lib/enhancers/github/githubPRAddComment.tsx +++ b/src/lib/enhancers/github/githubPRAddComment.tsx @@ -3,8 +3,7 @@ import type React from 'react' import type { CommentEnhancer, CommentSpot, StrippedLocation } from '@/lib/enhancer' import { logger } from '@/lib/logger' import { modifyDOM } from '../modifyDOM' -import { commonGithubOptions } from './ghOptions' -import { prepareGitHubHighlighter } from './githubHighlighter' +import { commonGithubOptions, prepareGitHubHighlighter } from './github-common' export interface GitHubPRAddCommentSpot extends CommentSpot { type: 'GH_PR_ADD_COMMENT' // Override to narrow from string to specific union diff --git a/src/lib/enhancers/github/githubPRNewComment.tsx b/src/lib/enhancers/github/githubPRNewComment.tsx index 76a4a36..3588308 100644 --- a/src/lib/enhancers/github/githubPRNewComment.tsx +++ b/src/lib/enhancers/github/githubPRNewComment.tsx @@ -2,8 +2,7 @@ import OverType, { type OverTypeInstance } from 'overtype' import type { CommentEnhancer, CommentSpot, StrippedLocation } from '../../enhancer' import { logger } from '../../logger' import { modifyDOM } from '../modifyDOM' -import { commonGithubOptions } from './ghOptions' -import { prepareGitHubHighlighter } from './githubHighlighter' +import { commonGithubOptions, prepareGitHubHighlighter } from './github-common' interface GitHubPRNewCommentSpot extends CommentSpot { type: 'GH_PR_NEW_COMMENT' From 8a98d5056312c4d8e544cbeac7189e06ebbea2fc Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 18 Sep 2025 15:17:44 -0700 Subject: [PATCH 2/6] Rename all the GitHub enhancers to be a bit more consistent and less verbose. --- ...EditComment.tsx => GitHubEditEnhancer.tsx} | 23 ++++++++--------- ...AddComment.tsx => GitHubIssueEnhancer.tsx} | 23 ++++++++--------- ...Comment.tsx => GitHubIssueNewEnhancer.tsx} | 22 ++++++++-------- ...bPRAddComment.tsx => GitHubPrEnhancer.tsx} | 23 ++++++++--------- ...NewComment.tsx => GitHubPrNewEnhancer.tsx} | 25 +++++++++---------- src/lib/registries.ts | 20 +++++++-------- .../__snapshots__/gh-detection.test.ts.snap | 16 ++++++------ tests/playground/replica.tsx | 12 ++++----- tests/playground/replicaData.tsx | 20 +++++++-------- 9 files changed, 91 insertions(+), 93 deletions(-) rename src/lib/enhancers/github/{githubEditComment.tsx => GitHubEditEnhancer.tsx} (73%) rename src/lib/enhancers/github/{githubIssueAddComment.tsx => GitHubIssueEnhancer.tsx} (78%) rename src/lib/enhancers/github/{githubIssueNewComment.tsx => GitHubIssueNewEnhancer.tsx} (76%) rename src/lib/enhancers/github/{githubPRAddComment.tsx => GitHubPrEnhancer.tsx} (75%) rename src/lib/enhancers/github/{githubPRNewComment.tsx => GitHubPrNewEnhancer.tsx} (77%) diff --git a/src/lib/enhancers/github/githubEditComment.tsx b/src/lib/enhancers/github/GitHubEditEnhancer.tsx similarity index 73% rename from src/lib/enhancers/github/githubEditComment.tsx rename to src/lib/enhancers/github/GitHubEditEnhancer.tsx index 4d7349a..8aed842 100644 --- a/src/lib/enhancers/github/githubEditComment.tsx +++ b/src/lib/enhancers/github/GitHubEditEnhancer.tsx @@ -5,19 +5,18 @@ import { logger } from '@/lib/logger' import { modifyDOM } from '../modifyDOM' import { commonGithubOptions, prepareGitHubHighlighter } from './github-common' -export interface GitHubEditCommentSpot extends CommentSpot { - type: 'GH_EDIT_COMMENT' +const GH_EDIT = 'GH_EDIT' as const + +export interface GitHubEditSpot extends CommentSpot { + type: typeof GH_EDIT } -export class GitHubEditCommentEnhancer implements CommentEnhancer { +export class GitHubEditEnhancer implements CommentEnhancer { forSpotTypes(): string[] { - return ['GH_EDIT_COMMENT'] + return [GH_EDIT] } - tryToEnhance( - textarea: HTMLTextAreaElement, - location: StrippedLocation, - ): GitHubEditCommentSpot | null { + tryToEnhance(textarea: HTMLTextAreaElement, location: StrippedLocation): GitHubEditSpot | null { if (location.host !== 'github.com') { return null } @@ -43,12 +42,12 @@ export class GitHubEditCommentEnhancer implements CommentEnhancerN/A } - tableTitle(_spot: GitHubEditCommentSpot): string { + tableTitle(_spot: GitHubEditSpot): string { return 'N/A' } } diff --git a/src/lib/enhancers/github/githubIssueAddComment.tsx b/src/lib/enhancers/github/GitHubIssueEnhancer.tsx similarity index 78% rename from src/lib/enhancers/github/githubIssueAddComment.tsx rename to src/lib/enhancers/github/GitHubIssueEnhancer.tsx index 6cf3e33..168c753 100644 --- a/src/lib/enhancers/github/githubIssueAddComment.tsx +++ b/src/lib/enhancers/github/GitHubIssueEnhancer.tsx @@ -6,23 +6,22 @@ import { logger } from '@/lib/logger' import { modifyDOM } from '../modifyDOM' import { commonGithubOptions, prepareGitHubHighlighter } from './github-common' -export interface GitHubIssueAddCommentSpot extends CommentSpot { - type: 'GH_ISSUE_ADD_COMMENT' +const GH_ISSUE = 'GH_ISSUE' as const + +export interface GitHubIssueSpot extends CommentSpot { + type: typeof GH_ISSUE title: string domain: string slug: string // owner/repo number: number // issue number, undefined for new issues } -export class GitHubIssueAddCommentEnhancer implements CommentEnhancer { +export class GitHubIssueEnhancer implements CommentEnhancer { forSpotTypes(): string[] { - return ['GH_ISSUE_ADD_COMMENT'] + return [GH_ISSUE] } - tryToEnhance( - textarea: HTMLTextAreaElement, - location: StrippedLocation, - ): GitHubIssueAddCommentSpot | null { + tryToEnhance(textarea: HTMLTextAreaElement, location: StrippedLocation): GitHubIssueSpot | null { if (textarea.id === 'feedback') { return null } @@ -56,12 +55,12 @@ export class GitHubIssueAddCommentEnhancer implements CommentEnhancer @@ -85,7 +84,7 @@ export class GitHubIssueAddCommentEnhancer implements CommentEnhancer { +export class GitHubIssueNewEnhancer implements CommentEnhancer { forSpotTypes(): string[] { - return ['GH_ISSUE_NEW_COMMENT'] + return [GH_ISSUE_NEW] } tryToEnhance( textarea: HTMLTextAreaElement, location: StrippedLocation, - ): GitHubIssueNewCommentSpot | null { + ): GitHubIssueNewSpot | null { if (textarea.id === 'feedback') { return null } @@ -43,12 +45,12 @@ export class GitHubIssueNewCommentEnhancer implements CommentEnhancer @@ -68,11 +70,11 @@ export class GitHubIssueNewCommentEnhancer implements CommentEnhancer { +export class GitHubPrEnhancer implements CommentEnhancer { forSpotTypes(): string[] { - return ['GH_PR_ADD_COMMENT'] + return [GH_PR] } - tryToEnhance( - _textarea: HTMLTextAreaElement, - location: StrippedLocation, - ): GitHubPRAddCommentSpot | null { + tryToEnhance(_textarea: HTMLTextAreaElement, location: StrippedLocation): GitHubPrSpot | null { // Only handle github.com domains TODO: identify GitHub Enterprise somehow if (location.host !== 'github.com' || _textarea.id !== 'new_comment_field') { return null @@ -46,12 +45,12 @@ export class GitHubPRAddCommentEnhancer implements CommentEnhancer @@ -72,7 +71,7 @@ export class GitHubPRAddCommentEnhancer implements CommentEnhancer { +export class GitHubPRNewEnhancer implements CommentEnhancer { forSpotTypes(): string[] { - return ['GH_PR_NEW_COMMENT'] + return [GH_PR_NEW] } - tryToEnhance( - textarea: HTMLTextAreaElement, - location: StrippedLocation, - ): GitHubPRNewCommentSpot | null { + tryToEnhance(textarea: HTMLTextAreaElement, location: StrippedLocation): GitHubPRNewSpot | null { if (textarea.id === 'feedback') { return null } @@ -53,12 +52,12 @@ export class GitHubPRNewCommentEnhancer implements CommentEnhancer @@ -78,11 +77,11 @@ export class GitHubPRNewCommentEnhancer implements CommentEnhancer { textarea: HTMLTextAreaElement @@ -21,11 +21,11 @@ export class EnhancerRegistry { constructor() { // Register all available handlers - this.register(new GitHubEditCommentEnhancer()) - this.register(new GitHubIssueAddCommentEnhancer()) - this.register(new GitHubIssueNewCommentEnhancer()) - this.register(new GitHubPRAddCommentEnhancer()) - this.register(new GitHubPRNewCommentEnhancer()) + this.register(new GitHubEditEnhancer()) + this.register(new GitHubIssueEnhancer()) + this.register(new GitHubIssueNewEnhancer()) + this.register(new GitHubPrEnhancer()) + this.register(new GitHubPRNewEnhancer()) const textColor = 'rgb(31, 35, 40)' const headingColor = 'rgb(174, 52, 151)' OverType.setTheme({ diff --git a/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap b/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap index 49ccb5a..84d92fa 100644 --- a/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap +++ b/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap @@ -9,7 +9,7 @@ exports[`github detection > gh_issue:should detect correct spots 1`] = ` "number": 523, "slug": "diffplug/selfie", "title": "[jvm] docs for VCR", - "type": "GH_ISSUE_ADD_COMMENT", + "type": "GH_ISSUE", "unique_key": "github.com:diffplug/selfie:523", }, }, @@ -21,7 +21,7 @@ exports[`github detection > gh_issue_edit:should detect correct spots 1`] = ` { "for": "id=:rc3: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input", "spot": { - "type": "GH_EDIT_COMMENT", + "type": "GH_EDIT", "unique_key": "github.com:diffplug/gitcasso:56:edit-body", }, }, @@ -32,7 +32,7 @@ exports[`github detection > gh_issue_edit:should detect correct spots 1`] = ` "number": 56, "slug": "diffplug/gitcasso", "title": "what about the draft?", - "type": "GH_ISSUE_ADD_COMMENT", + "type": "GH_ISSUE", "unique_key": "github.com:diffplug/gitcasso:56", }, }, @@ -47,7 +47,7 @@ exports[`github detection > gh_issue_new:should detect correct spots 1`] = ` "domain": "github.com", "slug": "diffplug/gitcasso", "title": "New issue title", - "type": "GH_ISSUE_NEW_COMMENT", + "type": "GH_ISSUE_NEW", "unique_key": "github.com:diffplug/gitcasso:new", }, }, @@ -68,7 +68,7 @@ exports[`github detection > gh_pr:should detect correct spots 1`] = ` "slug": "diffplug/selfie", "title": "Add "VCR" functionality #517", - "type": "GH_PR_ADD_COMMENT", + "type": "GH_PR", "unique_key": "github.com:diffplug/selfie:517", }, }, @@ -80,7 +80,7 @@ exports[`github detection > gh_pr_edit:should detect correct spots 1`] = ` { "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", "spot": { - "type": "GH_EDIT_COMMENT", + "type": "GH_EDIT", "unique_key": "github.com:diffplug/gitcasso:58:edit-body", }, }, @@ -93,7 +93,7 @@ exports[`github detection > gh_pr_edit:should detect correct spots 1`] = ` "title": "Feat/expand corpus #58", - "type": "GH_PR_ADD_COMMENT", + "type": "GH_PR", "unique_key": "github.com:diffplug/gitcasso:58", }, }, @@ -114,7 +114,7 @@ exports[`github detection > gh_pr_new:should detect correct spots 1`] = ` "head": "cavia-porcellus:selfie:main", "slug": "diffplug/selfie", "title": "Update README.md", - "type": "GH_PR_NEW_COMMENT", + "type": "GH_PR_NEW", "unique_key": "github.com:diffplug/selfie:main...cavia-porcellus:selfie:main", }, }, diff --git a/tests/playground/replica.tsx b/tests/playground/replica.tsx index 71c1dfe..66fc43a 100644 --- a/tests/playground/replica.tsx +++ b/tests/playground/replica.tsx @@ -1,23 +1,23 @@ import { PopupRoot } from '@/components/PopupRoot' import type { CommentStorage, CommentTableRow } from '@/entrypoints/background' import type { CommentSpot } from '@/lib/enhancer' -import type { GitHubIssueAddCommentSpot } from '@/lib/enhancers/github/githubIssueAddComment' -import type { GitHubPRAddCommentSpot } from '@/lib/enhancers/github/githubPRAddComment' +import type { GitHubIssueSpot } from '@/lib/enhancers/github/GitHubIssueEnhancer' +import type { GitHubPrSpot } from '@/lib/enhancers/github/GitHubPrEnhancer' -const gh_pr: GitHubPRAddCommentSpot = { +const gh_pr: GitHubPrSpot = { domain: 'github.com', number: 517, slug: 'diffplug/selfie', title: 'wowza', - type: 'GH_PR_ADD_COMMENT', + type: 'GH_PR', unique_key: 'github.com:diffplug/selfie:517', } -const gh_issue: GitHubIssueAddCommentSpot = { +const gh_issue: GitHubIssueSpot = { domain: 'github.com', number: 523, slug: 'diffplug/selfie', title: 'whoa', - type: 'GH_ISSUE_ADD_COMMENT', + type: 'GH_ISSUE', unique_key: 'github.com:diffplug/selfie:523', } diff --git a/tests/playground/replicaData.tsx b/tests/playground/replicaData.tsx index 7ee7f5f..9d80879 100644 --- a/tests/playground/replicaData.tsx +++ b/tests/playground/replicaData.tsx @@ -1,7 +1,7 @@ import type { CommentTableRow } from '@/entrypoints/background' import type { CommentSpot } from '@/lib/enhancer' -import type { GitHubIssueAddCommentSpot } from '@/lib/enhancers/github/githubIssueAddComment' -import type { GitHubPRAddCommentSpot } from '@/lib/enhancers/github/githubPRAddComment' +import type { GitHubIssueSpot } from '@/lib/enhancers/github/GitHubIssueEnhancer' +import type { GitHubPrSpot } from '@/lib/enhancers/github/GitHubPrEnhancer' export interface RedditSpot extends CommentSpot { title: string @@ -42,9 +42,9 @@ export const generateMockDrafts = (): CommentTableRow[] => [ number: 1234, slug: 'microsoft/vscode', title: "Fix memory leak in extension host (why is this so hard! It's been months!)", - type: 'GH_PR_ADD_COMMENT', + type: 'GH_PR', unique_key: '1', - } satisfies GitHubPRAddCommentSpot), + } satisfies GitHubPrSpot), }, { isOpenTab: false, @@ -93,9 +93,9 @@ export const generateMockDrafts = (): CommentTableRow[] => [ number: 5678, slug: 'facebook/react', title: 'Unexpected behavior with useEffect cleanup', - type: 'GH_ISSUE_ADD_COMMENT', + type: 'GH_ISSUE', unique_key: '3', - } satisfies GitHubIssueAddCommentSpot), + } satisfies GitHubIssueSpot), }, { isOpenTab: false, @@ -129,9 +129,9 @@ export const generateMockDrafts = (): CommentTableRow[] => [ number: 9012, slug: 'vercel/next.js', title: 'Update routing documentation', - type: 'GH_PR_ADD_COMMENT', + type: 'GH_PR', unique_key: '4', - } satisfies GitHubPRAddCommentSpot), + } satisfies GitHubPrSpot), }, { isOpenTab: true, @@ -170,8 +170,8 @@ export const generateMockDrafts = (): CommentTableRow[] => [ number: 3456, slug: 'nodejs/node', title: 'Add support for ESM in worker threads', - type: 'GH_PR_ADD_COMMENT', + type: 'GH_PR', unique_key: '5', - } satisfies GitHubPRAddCommentSpot), + } satisfies GitHubPrSpot), }, ] From c2a8e80a095c8180761a84742fd135464c1d7d0a Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 18 Sep 2025 15:27:23 -0700 Subject: [PATCH 3/6] Use a clear Append/Create dichotomy on the issue enhancement. --- ...ncer.tsx => GitHubIssueAppendEnhancer.tsx} | 23 +++++++++++-------- ...ncer.tsx => GitHubIssueCreateEnhancer.tsx} | 22 +++++++++--------- src/lib/registries.ts | 8 +++---- .../__snapshots__/gh-detection.test.ts.snap | 6 ++--- tests/playground/replica.tsx | 6 ++--- tests/playground/replicaData.tsx | 6 ++--- 6 files changed, 37 insertions(+), 34 deletions(-) rename src/lib/enhancers/github/{GitHubIssueEnhancer.tsx => GitHubIssueAppendEnhancer.tsx} (78%) rename src/lib/enhancers/github/{GitHubIssueNewEnhancer.tsx => GitHubIssueCreateEnhancer.tsx} (76%) diff --git a/src/lib/enhancers/github/GitHubIssueEnhancer.tsx b/src/lib/enhancers/github/GitHubIssueAppendEnhancer.tsx similarity index 78% rename from src/lib/enhancers/github/GitHubIssueEnhancer.tsx rename to src/lib/enhancers/github/GitHubIssueAppendEnhancer.tsx index 168c753..b2fbada 100644 --- a/src/lib/enhancers/github/GitHubIssueEnhancer.tsx +++ b/src/lib/enhancers/github/GitHubIssueAppendEnhancer.tsx @@ -6,22 +6,25 @@ import { logger } from '@/lib/logger' import { modifyDOM } from '../modifyDOM' import { commonGithubOptions, prepareGitHubHighlighter } from './github-common' -const GH_ISSUE = 'GH_ISSUE' as const +const GH_ISSUE_APPEND = 'GH_ISSUE_APPEND' as const -export interface GitHubIssueSpot extends CommentSpot { - type: typeof GH_ISSUE +export interface GitHubIssueAppendSpot extends CommentSpot { + type: typeof GH_ISSUE_APPEND title: string domain: string slug: string // owner/repo number: number // issue number, undefined for new issues } -export class GitHubIssueEnhancer implements CommentEnhancer { +export class GitHubIssueAppendEnhancer implements CommentEnhancer { forSpotTypes(): string[] { - return [GH_ISSUE] + return [GH_ISSUE_APPEND] } - tryToEnhance(textarea: HTMLTextAreaElement, location: StrippedLocation): GitHubIssueSpot | null { + tryToEnhance( + textarea: HTMLTextAreaElement, + location: StrippedLocation, + ): GitHubIssueAppendSpot | null { if (textarea.id === 'feedback') { return null } @@ -55,12 +58,12 @@ export class GitHubIssueEnhancer implements CommentEnhancer { number, slug, title, - type: GH_ISSUE, + type: GH_ISSUE_APPEND, unique_key, } } - enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueSpot): OverTypeInstance { + enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueAppendSpot): OverTypeInstance { prepareGitHubHighlighter() const overtypeContainer = modifyDOM(textArea) return new OverType(overtypeContainer, { @@ -70,7 +73,7 @@ export class GitHubIssueEnhancer implements CommentEnhancer { })[0]! } - tableUpperDecoration(spot: GitHubIssueSpot): React.ReactNode { + tableUpperDecoration(spot: GitHubIssueAppendSpot): React.ReactNode { return ( <> @@ -84,7 +87,7 @@ export class GitHubIssueEnhancer implements CommentEnhancer { ) } - tableTitle(spot: GitHubIssueSpot): string { + tableTitle(spot: GitHubIssueAppendSpot): string { return spot.title } } diff --git a/src/lib/enhancers/github/GitHubIssueNewEnhancer.tsx b/src/lib/enhancers/github/GitHubIssueCreateEnhancer.tsx similarity index 76% rename from src/lib/enhancers/github/GitHubIssueNewEnhancer.tsx rename to src/lib/enhancers/github/GitHubIssueCreateEnhancer.tsx index 7cef29a..08ee18a 100644 --- a/src/lib/enhancers/github/GitHubIssueNewEnhancer.tsx +++ b/src/lib/enhancers/github/GitHubIssueCreateEnhancer.tsx @@ -4,24 +4,24 @@ import { logger } from '../../logger' import { modifyDOM } from '../modifyDOM' import { commonGithubOptions, prepareGitHubHighlighter } from './github-common' -const GH_ISSUE_NEW = 'GH_ISSUE_NEW' as const +const GH_ISSUE_CREATE = 'GH_ISSUE_CREATE' as const -interface GitHubIssueNewSpot extends CommentSpot { - type: typeof GH_ISSUE_NEW +interface GitHubIssueCreateSpot extends CommentSpot { + type: typeof GH_ISSUE_CREATE domain: string slug: string // owner/repo title: string } -export class GitHubIssueNewEnhancer implements CommentEnhancer { +export class GitHubIssueCreateEnhancer implements CommentEnhancer { forSpotTypes(): string[] { - return [GH_ISSUE_NEW] + return [GH_ISSUE_CREATE] } tryToEnhance( textarea: HTMLTextAreaElement, location: StrippedLocation, - ): GitHubIssueNewSpot | null { + ): GitHubIssueCreateSpot | null { if (textarea.id === 'feedback') { return null } @@ -45,12 +45,12 @@ export class GitHubIssueNewEnhancer implements CommentEnhancer @@ -70,11 +70,11 @@ export class GitHubIssueNewEnhancer implements CommentEnhancer gh_issue:should detect correct spots 1`] = ` "number": 523, "slug": "diffplug/selfie", "title": "[jvm] docs for VCR", - "type": "GH_ISSUE", + "type": "GH_ISSUE_APPEND", "unique_key": "github.com:diffplug/selfie:523", }, }, @@ -32,7 +32,7 @@ exports[`github detection > gh_issue_edit:should detect correct spots 1`] = ` "number": 56, "slug": "diffplug/gitcasso", "title": "what about the draft?", - "type": "GH_ISSUE", + "type": "GH_ISSUE_APPEND", "unique_key": "github.com:diffplug/gitcasso:56", }, }, @@ -47,7 +47,7 @@ exports[`github detection > gh_issue_new:should detect correct spots 1`] = ` "domain": "github.com", "slug": "diffplug/gitcasso", "title": "New issue title", - "type": "GH_ISSUE_NEW", + "type": "GH_ISSUE_CREATE", "unique_key": "github.com:diffplug/gitcasso:new", }, }, diff --git a/tests/playground/replica.tsx b/tests/playground/replica.tsx index 66fc43a..9651f13 100644 --- a/tests/playground/replica.tsx +++ b/tests/playground/replica.tsx @@ -1,7 +1,7 @@ import { PopupRoot } from '@/components/PopupRoot' import type { CommentStorage, CommentTableRow } from '@/entrypoints/background' import type { CommentSpot } from '@/lib/enhancer' -import type { GitHubIssueSpot } from '@/lib/enhancers/github/GitHubIssueEnhancer' +import type { GitHubIssueAppendSpot } from '@/lib/enhancers/github/GitHubIssueAppendEnhancer' import type { GitHubPrSpot } from '@/lib/enhancers/github/GitHubPrEnhancer' const gh_pr: GitHubPrSpot = { @@ -12,12 +12,12 @@ const gh_pr: GitHubPrSpot = { type: 'GH_PR', unique_key: 'github.com:diffplug/selfie:517', } -const gh_issue: GitHubIssueSpot = { +const gh_issue: GitHubIssueAppendSpot = { domain: 'github.com', number: 523, slug: 'diffplug/selfie', title: 'whoa', - type: 'GH_ISSUE', + type: 'GH_ISSUE_APPEND', unique_key: 'github.com:diffplug/selfie:523', } diff --git a/tests/playground/replicaData.tsx b/tests/playground/replicaData.tsx index 9d80879..fde9ec2 100644 --- a/tests/playground/replicaData.tsx +++ b/tests/playground/replicaData.tsx @@ -1,6 +1,6 @@ import type { CommentTableRow } from '@/entrypoints/background' import type { CommentSpot } from '@/lib/enhancer' -import type { GitHubIssueSpot } from '@/lib/enhancers/github/GitHubIssueEnhancer' +import type { GitHubIssueAppendSpot } from '@/lib/enhancers/github/GitHubIssueAppendEnhancer' import type { GitHubPrSpot } from '@/lib/enhancers/github/GitHubPrEnhancer' export interface RedditSpot extends CommentSpot { @@ -93,9 +93,9 @@ export const generateMockDrafts = (): CommentTableRow[] => [ number: 5678, slug: 'facebook/react', title: 'Unexpected behavior with useEffect cleanup', - type: 'GH_ISSUE', + type: 'GH_ISSUE_APPEND', unique_key: '3', - } satisfies GitHubIssueSpot), + } satisfies GitHubIssueAppendSpot), }, { isOpenTab: false, From e2d88f72a3b66aabb91df212479ac8028f9e682c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 18 Sep 2025 15:32:11 -0700 Subject: [PATCH 4/6] Same Append/Create but for prs. --- ...nhancer.tsx => GitHubPrAppendEnhancer.tsx} | 23 +++++++++-------- ...nhancer.tsx => GitHubPrCreateEnhancer.tsx} | 25 +++++++++++-------- src/lib/registries.ts | 8 +++--- .../__snapshots__/gh-detection.test.ts.snap | 6 ++--- tests/playground/replica.tsx | 6 ++--- tests/playground/replicaData.tsx | 14 +++++------ 6 files changed, 44 insertions(+), 38 deletions(-) rename src/lib/enhancers/github/{GitHubPrEnhancer.tsx => GitHubPrAppendEnhancer.tsx} (76%) rename src/lib/enhancers/github/{GitHubPrNewEnhancer.tsx => GitHubPrCreateEnhancer.tsx} (77%) diff --git a/src/lib/enhancers/github/GitHubPrEnhancer.tsx b/src/lib/enhancers/github/GitHubPrAppendEnhancer.tsx similarity index 76% rename from src/lib/enhancers/github/GitHubPrEnhancer.tsx rename to src/lib/enhancers/github/GitHubPrAppendEnhancer.tsx index eee2c8f..e868b8c 100644 --- a/src/lib/enhancers/github/GitHubPrEnhancer.tsx +++ b/src/lib/enhancers/github/GitHubPrAppendEnhancer.tsx @@ -5,22 +5,25 @@ import { logger } from '@/lib/logger' import { modifyDOM } from '../modifyDOM' import { commonGithubOptions, prepareGitHubHighlighter } from './github-common' -const GH_PR = 'GH_PR' as const +const GH_PR_APPEND = 'GH_PR_APPEND' as const -export interface GitHubPrSpot extends CommentSpot { - type: typeof GH_PR +export interface GitHubPrAppendSpot extends CommentSpot { + type: typeof GH_PR_APPEND title: string domain: string slug: string // owner/repo number: number // issue/PR number, undefined for new issues and PRs } -export class GitHubPrEnhancer implements CommentEnhancer { +export class GitHubPrAppendEnhancer implements CommentEnhancer { forSpotTypes(): string[] { - return [GH_PR] + return [GH_PR_APPEND] } - tryToEnhance(_textarea: HTMLTextAreaElement, location: StrippedLocation): GitHubPrSpot | null { + tryToEnhance( + _textarea: HTMLTextAreaElement, + location: StrippedLocation, + ): GitHubPrAppendSpot | null { // Only handle github.com domains TODO: identify GitHub Enterprise somehow if (location.host !== 'github.com' || _textarea.id !== 'new_comment_field') { return null @@ -45,12 +48,12 @@ export class GitHubPrEnhancer implements CommentEnhancer { number, slug, title, - type: GH_PR, + type: GH_PR_APPEND, unique_key, } } - enhance(textArea: HTMLTextAreaElement, _spot: GitHubPrSpot): OverTypeInstance { + enhance(textArea: HTMLTextAreaElement, _spot: GitHubPrAppendSpot): OverTypeInstance { prepareGitHubHighlighter() const overtypeContainer = modifyDOM(textArea) return new OverType(overtypeContainer, { @@ -61,7 +64,7 @@ export class GitHubPrEnhancer implements CommentEnhancer { })[0]! } - tableUpperDecoration(spot: GitHubPrSpot): React.ReactNode { + tableUpperDecoration(spot: GitHubPrAppendSpot): React.ReactNode { const { slug, number } = spot return ( <> @@ -71,7 +74,7 @@ export class GitHubPrEnhancer implements CommentEnhancer { ) } - tableTitle(spot: GitHubPrSpot): string { + tableTitle(spot: GitHubPrAppendSpot): string { return spot.title } } diff --git a/src/lib/enhancers/github/GitHubPrNewEnhancer.tsx b/src/lib/enhancers/github/GitHubPrCreateEnhancer.tsx similarity index 77% rename from src/lib/enhancers/github/GitHubPrNewEnhancer.tsx rename to src/lib/enhancers/github/GitHubPrCreateEnhancer.tsx index 73bcbb9..0855926 100644 --- a/src/lib/enhancers/github/GitHubPrNewEnhancer.tsx +++ b/src/lib/enhancers/github/GitHubPrCreateEnhancer.tsx @@ -4,10 +4,10 @@ import { logger } from '../../logger' import { modifyDOM } from '../modifyDOM' import { commonGithubOptions, prepareGitHubHighlighter } from './github-common' -const GH_PR_NEW = 'GH_PR_NEW' as const +const GH_PR_CREATE = 'GH_PR_CREATE' as const -interface GitHubPRNewSpot extends CommentSpot { - type: typeof GH_PR_NEW +interface GitHubPrCreateSpot extends CommentSpot { + type: typeof GH_PR_CREATE domain: string slug: string // owner/repo title: string @@ -15,12 +15,15 @@ interface GitHubPRNewSpot extends CommentSpot { base: string // branch you want changes pulled into } -export class GitHubPRNewEnhancer implements CommentEnhancer { +export class GitHubPrCreateEnhancer implements CommentEnhancer { forSpotTypes(): string[] { - return [GH_PR_NEW] + return [GH_PR_CREATE] } - tryToEnhance(textarea: HTMLTextAreaElement, location: StrippedLocation): GitHubPRNewSpot | null { + tryToEnhance( + textarea: HTMLTextAreaElement, + location: StrippedLocation, + ): GitHubPrCreateSpot | null { if (textarea.id === 'feedback') { return null } @@ -52,12 +55,12 @@ export class GitHubPRNewEnhancer implements CommentEnhancer { head, slug, title, - type: GH_PR_NEW, + type: GH_PR_CREATE, unique_key, } } - enhance(textArea: HTMLTextAreaElement, _spot: GitHubPRNewSpot): OverTypeInstance { + enhance(textArea: HTMLTextAreaElement, _spot: GitHubPrCreateSpot): OverTypeInstance { prepareGitHubHighlighter() const overtypeContainer = modifyDOM(textArea) return new OverType(overtypeContainer, { @@ -67,7 +70,7 @@ export class GitHubPRNewEnhancer implements CommentEnhancer { })[0]! } - tableUpperDecoration(spot: GitHubPRNewSpot): React.ReactNode { + tableUpperDecoration(spot: GitHubPrCreateSpot): React.ReactNode { const { slug } = spot return ( <> @@ -77,11 +80,11 @@ export class GitHubPRNewEnhancer implements CommentEnhancer { ) } - tableTitle(spot: GitHubPRNewSpot): string { + tableTitle(spot: GitHubPrCreateSpot): string { return spot.title || 'New Pull Request' } - buildUrl(spot: GitHubPRNewSpot): string { + buildUrl(spot: GitHubPrCreateSpot): string { return `https://${spot.domain}/${spot.slug}/issue/new` } } diff --git a/src/lib/registries.ts b/src/lib/registries.ts index 0fee86c..39d5ae5 100644 --- a/src/lib/registries.ts +++ b/src/lib/registries.ts @@ -5,8 +5,8 @@ import { CommentEnhancerMissing } from './enhancers/CommentEnhancerMissing' import { GitHubEditEnhancer } from './enhancers/github/GitHubEditEnhancer' import { GitHubIssueAppendEnhancer } from './enhancers/github/GitHubIssueAppendEnhancer' import { GitHubIssueCreateEnhancer } from './enhancers/github/GitHubIssueCreateEnhancer' -import { GitHubPrEnhancer } from './enhancers/github/GitHubPrEnhancer' -import { GitHubPRNewEnhancer } from './enhancers/github/GitHubPrNewEnhancer' +import { GitHubPrAppendEnhancer } from './enhancers/github/GitHubPrAppendEnhancer' +import { GitHubPrCreateEnhancer } from './enhancers/github/GitHubPrCreateEnhancer' export interface EnhancedTextarea { textarea: HTMLTextAreaElement @@ -24,8 +24,8 @@ export class EnhancerRegistry { this.register(new GitHubEditEnhancer()) this.register(new GitHubIssueAppendEnhancer()) this.register(new GitHubIssueCreateEnhancer()) - this.register(new GitHubPrEnhancer()) - this.register(new GitHubPRNewEnhancer()) + this.register(new GitHubPrAppendEnhancer()) + this.register(new GitHubPrCreateEnhancer()) const textColor = 'rgb(31, 35, 40)' const headingColor = 'rgb(174, 52, 151)' OverType.setTheme({ diff --git a/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap b/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap index 8170d28..0e5891a 100644 --- a/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap +++ b/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap @@ -68,7 +68,7 @@ exports[`github detection > gh_pr:should detect correct spots 1`] = ` "slug": "diffplug/selfie", "title": "Add "VCR" functionality #517", - "type": "GH_PR", + "type": "GH_PR_APPEND", "unique_key": "github.com:diffplug/selfie:517", }, }, @@ -93,7 +93,7 @@ exports[`github detection > gh_pr_edit:should detect correct spots 1`] = ` "title": "Feat/expand corpus #58", - "type": "GH_PR", + "type": "GH_PR_APPEND", "unique_key": "github.com:diffplug/gitcasso:58", }, }, @@ -114,7 +114,7 @@ exports[`github detection > gh_pr_new:should detect correct spots 1`] = ` "head": "cavia-porcellus:selfie:main", "slug": "diffplug/selfie", "title": "Update README.md", - "type": "GH_PR_NEW", + "type": "GH_PR_CREATE", "unique_key": "github.com:diffplug/selfie:main...cavia-porcellus:selfie:main", }, }, diff --git a/tests/playground/replica.tsx b/tests/playground/replica.tsx index 9651f13..5303d17 100644 --- a/tests/playground/replica.tsx +++ b/tests/playground/replica.tsx @@ -2,14 +2,14 @@ import { PopupRoot } from '@/components/PopupRoot' import type { CommentStorage, CommentTableRow } from '@/entrypoints/background' import type { CommentSpot } from '@/lib/enhancer' import type { GitHubIssueAppendSpot } from '@/lib/enhancers/github/GitHubIssueAppendEnhancer' -import type { GitHubPrSpot } from '@/lib/enhancers/github/GitHubPrEnhancer' +import type { GitHubPrAppendSpot } from '@/lib/enhancers/github/GitHubPrAppendEnhancer' -const gh_pr: GitHubPrSpot = { +const gh_pr: GitHubPrAppendSpot = { domain: 'github.com', number: 517, slug: 'diffplug/selfie', title: 'wowza', - type: 'GH_PR', + type: 'GH_PR_APPEND', unique_key: 'github.com:diffplug/selfie:517', } const gh_issue: GitHubIssueAppendSpot = { diff --git a/tests/playground/replicaData.tsx b/tests/playground/replicaData.tsx index fde9ec2..377d828 100644 --- a/tests/playground/replicaData.tsx +++ b/tests/playground/replicaData.tsx @@ -1,7 +1,7 @@ import type { CommentTableRow } from '@/entrypoints/background' import type { CommentSpot } from '@/lib/enhancer' import type { GitHubIssueAppendSpot } from '@/lib/enhancers/github/GitHubIssueAppendEnhancer' -import type { GitHubPrSpot } from '@/lib/enhancers/github/GitHubPrEnhancer' +import type { GitHubPrAppendSpot } from '@/lib/enhancers/github/GitHubPrAppendEnhancer' export interface RedditSpot extends CommentSpot { title: string @@ -42,9 +42,9 @@ export const generateMockDrafts = (): CommentTableRow[] => [ number: 1234, slug: 'microsoft/vscode', title: "Fix memory leak in extension host (why is this so hard! It's been months!)", - type: 'GH_PR', + type: 'GH_PR_APPEND', unique_key: '1', - } satisfies GitHubPrSpot), + } satisfies GitHubPrAppendSpot), }, { isOpenTab: false, @@ -129,9 +129,9 @@ export const generateMockDrafts = (): CommentTableRow[] => [ number: 9012, slug: 'vercel/next.js', title: 'Update routing documentation', - type: 'GH_PR', + type: 'GH_PR_APPEND', unique_key: '4', - } satisfies GitHubPrSpot), + } satisfies GitHubPrAppendSpot), }, { isOpenTab: true, @@ -170,8 +170,8 @@ export const generateMockDrafts = (): CommentTableRow[] => [ number: 3456, slug: 'nodejs/node', title: 'Add support for ESM in worker threads', - type: 'GH_PR', + type: 'GH_PR_APPEND', unique_key: '5', - } satisfies GitHubPrSpot), + } satisfies GitHubPrAppendSpot), }, ] From c415d43a3b5c382a56060b8ed923aef4971ef2bf Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 18 Sep 2025 15:34:37 -0700 Subject: [PATCH 5/6] Unnecessary `_` --- src/lib/enhancers/github/GitHubPrAppendEnhancer.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/enhancers/github/GitHubPrAppendEnhancer.tsx b/src/lib/enhancers/github/GitHubPrAppendEnhancer.tsx index e868b8c..575a174 100644 --- a/src/lib/enhancers/github/GitHubPrAppendEnhancer.tsx +++ b/src/lib/enhancers/github/GitHubPrAppendEnhancer.tsx @@ -21,11 +21,11 @@ export class GitHubPrAppendEnhancer implements CommentEnhancer Date: Thu, 18 Sep 2025 15:37:04 -0700 Subject: [PATCH 6/6] Little capitalization mistake. --- src/lib/enhancers/github/GitHubEditEnhancer.tsx | 4 ++-- src/lib/enhancers/github/GitHubIssueAppendEnhancer.tsx | 4 ++-- src/lib/enhancers/github/GitHubIssueCreateEnhancer.tsx | 4 ++-- src/lib/enhancers/github/GitHubPrAppendEnhancer.tsx | 4 ++-- src/lib/enhancers/github/GitHubPrCreateEnhancer.tsx | 4 ++-- src/lib/enhancers/github/github-common.ts | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/lib/enhancers/github/GitHubEditEnhancer.tsx b/src/lib/enhancers/github/GitHubEditEnhancer.tsx index 8aed842..aff5c20 100644 --- a/src/lib/enhancers/github/GitHubEditEnhancer.tsx +++ b/src/lib/enhancers/github/GitHubEditEnhancer.tsx @@ -3,7 +3,7 @@ import type React from 'react' import type { CommentEnhancer, CommentSpot, StrippedLocation } from '@/lib/enhancer' import { logger } from '@/lib/logger' import { modifyDOM } from '../modifyDOM' -import { commonGithubOptions, prepareGitHubHighlighter } from './github-common' +import { commonGitHubOptions, prepareGitHubHighlighter } from './github-common' const GH_EDIT = 'GH_EDIT' as const @@ -51,7 +51,7 @@ export class GitHubEditEnhancer implements CommentEnhancer { prepareGitHubHighlighter() const overtypeContainer = modifyDOM(textArea) return new OverType(overtypeContainer, { - ...commonGithubOptions, + ...commonGitHubOptions, minHeight: '102px', padding: 'var(--base-size-8)', placeholder: 'Add your comment here...', diff --git a/src/lib/enhancers/github/GitHubIssueAppendEnhancer.tsx b/src/lib/enhancers/github/GitHubIssueAppendEnhancer.tsx index b2fbada..0fee621 100644 --- a/src/lib/enhancers/github/GitHubIssueAppendEnhancer.tsx +++ b/src/lib/enhancers/github/GitHubIssueAppendEnhancer.tsx @@ -4,7 +4,7 @@ import type React from 'react' import type { CommentEnhancer, CommentSpot, StrippedLocation } from '@/lib/enhancer' import { logger } from '@/lib/logger' import { modifyDOM } from '../modifyDOM' -import { commonGithubOptions, prepareGitHubHighlighter } from './github-common' +import { commonGitHubOptions, prepareGitHubHighlighter } from './github-common' const GH_ISSUE_APPEND = 'GH_ISSUE_APPEND' as const @@ -67,7 +67,7 @@ export class GitHubIssueAppendEnhancer implements CommentEnhancer