diff --git a/src/lib/enhancers/github/githubEditComment.tsx b/src/lib/enhancers/github/GitHubEditEnhancer.tsx similarity index 67% rename from src/lib/enhancers/github/githubEditComment.tsx rename to src/lib/enhancers/github/GitHubEditEnhancer.tsx index 6a78d37..aff5c20 100644 --- a/src/lib/enhancers/github/githubEditComment.tsx +++ b/src/lib/enhancers/github/GitHubEditEnhancer.tsx @@ -3,22 +3,20 @@ 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' +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 } @@ -44,27 +42,27 @@ 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/GitHubIssueAppendEnhancer.tsx similarity index 76% rename from src/lib/enhancers/github/githubIssueAddComment.tsx rename to src/lib/enhancers/github/GitHubIssueAppendEnhancer.tsx index 2b1e1bb..0fee621 100644 --- a/src/lib/enhancers/github/githubIssueAddComment.tsx +++ b/src/lib/enhancers/github/GitHubIssueAppendEnhancer.tsx @@ -4,26 +4,27 @@ 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' +const GH_ISSUE_APPEND = 'GH_ISSUE_APPEND' as const + +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 GitHubIssueAddCommentEnhancer implements CommentEnhancer { +export class GitHubIssueAppendEnhancer implements CommentEnhancer { forSpotTypes(): string[] { - return ['GH_ISSUE_ADD_COMMENT'] + return [GH_ISSUE_APPEND] } tryToEnhance( textarea: HTMLTextAreaElement, location: StrippedLocation, - ): GitHubIssueAddCommentSpot | null { + ): GitHubIssueAppendSpot | null { if (textarea.id === 'feedback') { return null } @@ -57,22 +58,22 @@ export class GitHubIssueAddCommentEnhancer implements CommentEnhancer @@ -86,7 +87,7 @@ export class GitHubIssueAddCommentEnhancer implements CommentEnhancer { +export class GitHubIssueCreateEnhancer implements CommentEnhancer { forSpotTypes(): string[] { - return ['GH_ISSUE_NEW_COMMENT'] + return [GH_ISSUE_CREATE] } tryToEnhance( textarea: HTMLTextAreaElement, location: StrippedLocation, - ): GitHubIssueNewCommentSpot | null { + ): GitHubIssueCreateSpot | null { if (textarea.id === 'feedback') { return null } @@ -44,22 +45,22 @@ export class GitHubIssueNewCommentEnhancer implements CommentEnhancer @@ -69,11 +70,11 @@ export class GitHubIssueNewCommentEnhancer implements CommentEnhancer { +export class GitHubPrAppendEnhancer implements CommentEnhancer { forSpotTypes(): string[] { - return ['GH_PR_ADD_COMMENT'] + return [GH_PR_APPEND] } tryToEnhance( - _textarea: HTMLTextAreaElement, + textarea: HTMLTextAreaElement, location: StrippedLocation, - ): GitHubPRAddCommentSpot | null { + ): GitHubPrAppendSpot | null { // Only handle github.com domains TODO: identify GitHub Enterprise somehow - if (location.host !== 'github.com' || _textarea.id !== 'new_comment_field') { + if (location.host !== 'github.com' || textarea.id !== 'new_comment_field') { return null } @@ -47,23 +48,23 @@ export class GitHubPRAddCommentEnhancer implements CommentEnhancer @@ -73,7 +74,7 @@ export class GitHubPRAddCommentEnhancer implements CommentEnhancer { +export class GitHubPrCreateEnhancer implements CommentEnhancer { forSpotTypes(): string[] { - return ['GH_PR_NEW_COMMENT'] + return [GH_PR_CREATE] } tryToEnhance( textarea: HTMLTextAreaElement, location: StrippedLocation, - ): GitHubPRNewCommentSpot | null { + ): GitHubPrCreateSpot | null { if (textarea.id === 'feedback') { return null } @@ -54,22 +55,22 @@ export class GitHubPRNewCommentEnhancer implements CommentEnhancer @@ -79,11 +80,11 @@ export class GitHubPRNewCommentEnhancer implements CommentEnhancer { OverType.setCodeHighlighter(githubHighlighter) diff --git a/src/lib/registries.ts b/src/lib/registries.ts index 3a08e98..39d5ae5 100644 --- a/src/lib/registries.ts +++ b/src/lib/registries.ts @@ -2,11 +2,11 @@ import type { OverTypeInstance } from 'overtype' import OverType from 'overtype' import type { CommentEnhancer, CommentSpot, StrippedLocation } from './enhancer' import { CommentEnhancerMissing } from './enhancers/CommentEnhancerMissing' -import { GitHubEditCommentEnhancer } from './enhancers/github/githubEditComment' -import { GitHubIssueAddCommentEnhancer } from './enhancers/github/githubIssueAddComment' -import { GitHubIssueNewCommentEnhancer } from './enhancers/github/githubIssueNewComment' -import { GitHubPRAddCommentEnhancer } from './enhancers/github/githubPRAddComment' -import { GitHubPRNewCommentEnhancer } from './enhancers/github/githubPRNewComment' +import { GitHubEditEnhancer } from './enhancers/github/GitHubEditEnhancer' +import { GitHubIssueAppendEnhancer } from './enhancers/github/GitHubIssueAppendEnhancer' +import { GitHubIssueCreateEnhancer } from './enhancers/github/GitHubIssueCreateEnhancer' +import { GitHubPrAppendEnhancer } from './enhancers/github/GitHubPrAppendEnhancer' +import { GitHubPrCreateEnhancer } from './enhancers/github/GitHubPrCreateEnhancer' export interface EnhancedTextarea { 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 GitHubIssueAppendEnhancer()) + this.register(new GitHubIssueCreateEnhancer()) + 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 49ccb5a..0e5891a 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_APPEND", "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_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_COMMENT", + "type": "GH_ISSUE_CREATE", "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_APPEND", "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_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_COMMENT", + "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 71c1dfe..5303d17 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 { GitHubIssueAppendSpot } from '@/lib/enhancers/github/GitHubIssueAppendEnhancer' +import type { GitHubPrAppendSpot } from '@/lib/enhancers/github/GitHubPrAppendEnhancer' -const gh_pr: GitHubPRAddCommentSpot = { +const gh_pr: GitHubPrAppendSpot = { domain: 'github.com', number: 517, slug: 'diffplug/selfie', title: 'wowza', - type: 'GH_PR_ADD_COMMENT', + type: 'GH_PR_APPEND', unique_key: 'github.com:diffplug/selfie:517', } -const gh_issue: GitHubIssueAddCommentSpot = { +const gh_issue: GitHubIssueAppendSpot = { domain: 'github.com', number: 523, slug: 'diffplug/selfie', title: 'whoa', - type: 'GH_ISSUE_ADD_COMMENT', + type: 'GH_ISSUE_APPEND', unique_key: 'github.com:diffplug/selfie:523', } diff --git a/tests/playground/replicaData.tsx b/tests/playground/replicaData.tsx index 7ee7f5f..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 { GitHubIssueAddCommentSpot } from '@/lib/enhancers/github/githubIssueAddComment' -import type { GitHubPRAddCommentSpot } from '@/lib/enhancers/github/githubPRAddComment' +import type { GitHubIssueAppendSpot } from '@/lib/enhancers/github/GitHubIssueAppendEnhancer' +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_ADD_COMMENT', + type: 'GH_PR_APPEND', unique_key: '1', - } satisfies GitHubPRAddCommentSpot), + } satisfies GitHubPrAppendSpot), }, { 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_APPEND', unique_key: '3', - } satisfies GitHubIssueAddCommentSpot), + } satisfies GitHubIssueAppendSpot), }, { 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_APPEND', unique_key: '4', - } satisfies GitHubPRAddCommentSpot), + } 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_ADD_COMMENT', + type: 'GH_PR_APPEND', unique_key: '5', - } satisfies GitHubPRAddCommentSpot), + } satisfies GitHubPrAppendSpot), }, ]