From e60d10c8effe0159f3f98c809c11e0bda4dda579 Mon Sep 17 00:00:00 2001 From: Todd Riley Date: Wed, 17 Sep 2025 12:34:11 -0400 Subject: [PATCH 1/2] Enhance editing comments in issues and PRs. --- .../enhancers/github/githubEditComment.tsx | 78 +++++++++++++++++++ .../enhancers/github/githubPRNewComment.tsx | 4 +- browser-extension/src/lib/registries.ts | 2 + 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 browser-extension/src/lib/enhancers/github/githubEditComment.tsx diff --git a/browser-extension/src/lib/enhancers/github/githubEditComment.tsx b/browser-extension/src/lib/enhancers/github/githubEditComment.tsx new file mode 100644 index 0000000..a457ae6 --- /dev/null +++ b/browser-extension/src/lib/enhancers/github/githubEditComment.tsx @@ -0,0 +1,78 @@ +import OverType, { type OverTypeInstance } from 'overtype' +import type React from 'react' +import type { CommentEnhancer, CommentSpot } from '@/lib/enhancer' +import { logger } from '@/lib/logger' +import { modifyDOM } from '../modifyDOM' +import { commonGithubOptions } from './ghOptions' +import { githubHighlighter } from './githubHighlighter' + +export interface GitHubEditCommentSpot extends CommentSpot { + type: 'GH_EDIT_COMMENT' + title: string + domain: string + slug: string + number: number +} + +export class GitHubEditCommentEnhancer implements CommentEnhancer { + forSpotTypes(): string[] { + return ['GH_EDIT_COMMENT'] + } + + tryToEnhance(_textarea: HTMLTextAreaElement): GitHubEditCommentSpot | null { + if ( + document.querySelector('meta[name="hostname"]')?.getAttribute('content') !== 'github.com' || + !_textarea.matches('.TimelineItem textarea') + ) { + return null + } + + // Parse GitHub URL structure: /owner/repo/issues/123 or /owner/repo/pull/456 + logger.info(`${this.constructor.name} examing url`, window.location.pathname) + + const match = window.location.pathname.match(/^\/([^/]+)\/([^/]+)(?:\/(pull|issues)\/(\d+))/) + logger.info(`${this.constructor.name} found match`, window.location.pathname) + if (!match) return null + const [, owner, repo, numberStr] = match + const slug = `${owner}/${repo}` + const number = parseInt(numberStr!, 10) + const unique_key = `github.com:${slug}:${number}` + const title = 'TODO_TITLE' + return { + domain: 'github.com', + number, + slug, + title, + type: 'GH_EDIT_COMMENT', + unique_key, + } + } + + prepareForFirstEnhancement(): void { + OverType.setCodeHighlighter(githubHighlighter) + } + + enhance(textArea: HTMLTextAreaElement, _spot: GitHubEditCommentSpot): OverTypeInstance { + const overtypeContainer = modifyDOM(textArea) + return new OverType(overtypeContainer, { + ...commonGithubOptions, + minHeight: '102px', + padding: 'var(--base-size-8)', + placeholder: 'Add your comment here...', + })[0]! + } + + tableUpperDecoration(spot: GitHubEditCommentSpot): React.ReactNode { + const { slug, number } = spot + return ( + <> + {slug} + PR #{number} + + ) + } + + tableTitle(_spot: GitHubEditCommentSpot): string { + return 'TITLE_TODO' + } +} diff --git a/browser-extension/src/lib/enhancers/github/githubPRNewComment.tsx b/browser-extension/src/lib/enhancers/github/githubPRNewComment.tsx index 4996f6d..20a0542 100644 --- a/browser-extension/src/lib/enhancers/github/githubPRNewComment.tsx +++ b/browser-extension/src/lib/enhancers/github/githubPRNewComment.tsx @@ -23,12 +23,12 @@ export class GitHubPRNewCommentEnhancer implements CommentEnhancer Date: Thu, 18 Sep 2025 01:46:40 -0700 Subject: [PATCH 2/2] Add tests for the editing case. --- .../tests/lib/enhancers/github.test.ts | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/browser-extension/tests/lib/enhancers/github.test.ts b/browser-extension/tests/lib/enhancers/github.test.ts index 7e47a14..d4fc82c 100644 --- a/browser-extension/tests/lib/enhancers/github.test.ts +++ b/browser-extension/tests/lib/enhancers/github.test.ts @@ -175,4 +175,124 @@ describe('github', () => { ] `) }) + withCorpus('gh_issue_edit').it('should create the correct spot object', async () => { + expect(enhancements(document, window)).toMatchInlineSnapshot(` + [ + { + "for": "id=:rc3: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input", + "spot": { + "domain": "github.com", + "number": 56, + "slug": "diffplug/gitcasso", + "title": "TODO_TITLE", + "type": "GH_ISSUE_ADD_COMMENT", + "unique_key": "github.com:diffplug/gitcasso:56", + }, + "title": "TITLE_TODO", + "upperDecoration": + + + + # + 56 + + diffplug/gitcasso + + , + }, + { + "for": "id=:ra7: name=null className=prc-Textarea-TextArea-13q4j overtype-input", + "spot": { + "domain": "github.com", + "number": 56, + "slug": "diffplug/gitcasso", + "title": "TODO_TITLE", + "type": "GH_ISSUE_ADD_COMMENT", + "unique_key": "github.com:diffplug/gitcasso:56", + }, + "title": "TITLE_TODO", + "upperDecoration": + + + + # + 56 + + diffplug/gitcasso + + , + }, + ] + `) + }) + withCorpus('gh_pr_edit').it('should create the correct spot object', async () => { + expect(enhancements(document, window)).toMatchInlineSnapshot(` + [ + { + "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": { + "domain": "github.com", + "number": NaN, + "slug": "diffplug/gitcasso", + "title": "TODO_TITLE", + "type": "GH_EDIT_COMMENT", + "unique_key": "github.com:diffplug/gitcasso:NaN", + }, + "title": "TITLE_TODO", + "upperDecoration": + + diffplug/gitcasso + + + PR # + NaN + + , + }, + { + "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", + "spot": { + "domain": "github.com", + "number": 58, + "slug": "diffplug/gitcasso", + "title": "TODO_TITLE", + "type": "GH_PR_ADD_COMMENT", + "unique_key": "github.com:diffplug/gitcasso:58", + }, + "title": "TITLE_TODO", + "upperDecoration": + + diffplug/gitcasso + + + PR # + 58 + + , + }, + ] + `) + }) })