diff --git a/.claude/commands/corpus-loop.md b/.claude/commands/corpus-loop.md index e2fdf9b..b669dcd 100644 --- a/.claude/commands/corpus-loop.md +++ b/.claude/commands/corpus-loop.md @@ -52,7 +52,7 @@ If you see `"title": "TODO_TITLE"` or similar hardcoded `TODO` values in the JSO ## Extraction code style -- Don't hedge your bets and write lots of fallback code or strings of `?.`. Have a specific piece of data you want to get, use non-null `!` assertions where necessary to be clear about getting. +- Don't hedge your bets and write lots of fallback code or strings of `?.`. Have a specific piece of data you want to get, use non-null ! assertions where necessary to be clear about getting. - If a field is empty, represent it with an empty string. Don't use placeholders when extracting data. - The pages we are scraping are going to change over time, and it's easier to fix broken ones if we know exactly what used to work. If the code has lots of branching paths, it's harder to tell what it was doing. diff --git a/src/lib/enhancers/github/GitHubEditEnhancer.tsx b/src/lib/enhancers/github/GitHubEditEnhancer.tsx index aff5c20..d571783 100644 --- a/src/lib/enhancers/github/GitHubEditEnhancer.tsx +++ b/src/lib/enhancers/github/GitHubEditEnhancer.tsx @@ -8,6 +8,7 @@ import { commonGitHubOptions, prepareGitHubHighlighter } from './github-common' const GH_EDIT = 'GH_EDIT' as const export interface GitHubEditSpot extends CommentSpot { + isIssue: boolean type: typeof GH_EDIT } @@ -21,41 +22,45 @@ export class GitHubEditEnhancer implements CommentEnhancer { return null } - // Only enhance textareas that are for editing issue/PR body - const isIssueBodyEdit = textarea.closest('.react-issue-body') - const isPRBodyEdit = - textarea.id?.match(/^issue-\d+-body$/) || textarea.name === 'pull_request[body]' - - if (!isIssueBodyEdit && !isPRBodyEdit) { - return null - } - // Parse GitHub URL structure: /owner/repo/issues/123 or /owner/repo/pull/456 const match = location.pathname.match(/^\/([^/]+)\/([^/]+)\/(?:issues|pull)\/(\d+)/) if (!match) { return null } - const [, owner, repo, numberStr] = match const number = parseInt(numberStr!, 10) const unique_key = `github.com:${owner}/${repo}:${number}:edit-body` + // Only enhance textareas that are for editing issue/PR body + const isIssueBodyRootEdit = textarea.closest('.react-issue-body') + const isIssueBodyCommentEdit = textarea.closest('[data-wrapper-timeline-id]') + const isPRBodyEdit = + textarea.name === 'pull_request[body]' || textarea.name === 'issue_comment[body]' + // ^this is the root pr comment ^this is the other pr comments (surprising!) + + if (!isIssueBodyRootEdit && !isIssueBodyCommentEdit && !isPRBodyEdit) { + return null + } + logger.debug(`${this.constructor.name} enhanced issue/PR body textarea`, unique_key) return { + isIssue: !!(isIssueBodyRootEdit || isIssueBodyCommentEdit), type: GH_EDIT, unique_key, } } - enhance(textArea: HTMLTextAreaElement, _spot: GitHubEditSpot): OverTypeInstance { + enhance(textArea: HTMLTextAreaElement, spot: GitHubEditSpot): OverTypeInstance { prepareGitHubHighlighter() const overtypeContainer = modifyDOM(textArea) - return new OverType(overtypeContainer, { + const overtype = new OverType(overtypeContainer, { ...commonGitHubOptions, - minHeight: '102px', - padding: 'var(--base-size-8)', - placeholder: 'Add your comment here...', + padding: spot.isIssue ? 'var(--base-size-16)' : 'var(--base-size-8)', })[0]! + if (!spot.isIssue) { + // TODO: autoheight not working + } + return overtype } tableUpperDecoration(_spot: GitHubEditSpot): React.ReactNode { diff --git a/tests/corpus/_corpus-index.ts b/tests/corpus/_corpus-index.ts index 156c547..592f198 100644 --- a/tests/corpus/_corpus-index.ts +++ b/tests/corpus/_corpus-index.ts @@ -14,10 +14,15 @@ export const CORPUS: Record = { }, // HAR corpus (initial page loads) gh_issue_edit: { - description: 'editing an existing comment on an issue', + description: 'edit an existing comment on an issue', type: 'html', url: 'https://github.com/diffplug/gitcasso/issues/56', }, + gh_issue_edit_multiple: { + description: 'edit an existing comment on an issue (root and appended)', + type: 'html', + url: 'https://github.com/diffplug/testing-deletable/issues/3', + }, gh_issue_new: { description: 'a new issue wiht some fields filled out', type: 'html', @@ -28,10 +33,15 @@ export const CORPUS: Record = { url: 'https://github.com/diffplug/selfie/pull/517', }, gh_pr_edit: { - description: 'editing an existing comment on a PR', + description: 'edit an existing comment on a PR', type: 'html', url: 'https://github.com/diffplug/gitcasso/pull/58', }, + gh_pr_edit_multiple: { + description: 'edit an existing comment on a PR (root and appended)', + type: 'html', + url: 'https://github.com/diffplug/testing-deletable/pull/5', + }, gh_pr_new: { type: 'har', url: 'https://github.com/diffplug/selfie/compare/main...cavia-porcellus:selfie:main?expand=1', diff --git a/tests/corpus/gh_issue_edit_multiple.html b/tests/corpus/gh_issue_edit_multiple.html new file mode 100644 index 0000000..ee1dcfc --- /dev/null +++ b/tests/corpus/gh_issue_edit_multiple.html @@ -0,0 +1,1532 @@ + + + + + + + + + + + + + + +Test 3 · Issue #3 · diffplug/testing-deletable + +
+
+ +
+ Skip to content + + + + + + + + +
+
+ + + + + + +
+
+
+ +
+ + + +
+
+
+ + + + + + + + + + + +

Test 3 #3

@cavia-porcellus

Description

Body input
Markdown input: edit mode selected.

Activity

cavia-porcellus

cavia-porcellus commented on Sep 24, 2025

Author

Okay, here is a comment that I will post for you

cavia-porcellus

cavia-porcellus commented on Sep 24, 2025

Author
Markdown Editor
Markdown input: edit mode selected.
cavia-porcellus

cavia-porcellus commented on Sep 24, 2025

Author

Let's try it.

cavia-porcellus

Add a comment

new Comment
Markdown input: edit mode selected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Notifications

        You're receiving notifications because you're subscribed to this thread.

        Participants

        @cavia-porcellus

        Issue actions

          +
          +
          +
          +
          +
          + + + + + + + + +
          +
          Test 3 · Issue #3 · diffplug/testing-deletable
          +
          4 results
          + + \ No newline at end of file diff --git a/tests/corpus/gh_pr_edit_multiple.html b/tests/corpus/gh_pr_edit_multiple.html new file mode 100644 index 0000000..3275532 --- /dev/null +++ b/tests/corpus/gh_pr_edit_multiple.html @@ -0,0 +1,7501 @@ + + + + + + + + + + +Update README.md by cavia-porcellus · Pull Request #5 · diffplug/testing-deletable + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          +
          + +
          + Skip to content + + + + + + + + +
          +
          + + + + + + +
          +
          +
          + +
          + + + +
          +
          +
          + + + + + + + + +
          + Open in github.dev + Open in a new github.dev tab + Open in codespace + + +
          +
          + +
          + + +
          + +
          + + +
          +
          +

          Conversation

          +
          + + +
          +
          +
          + cavia-porcellus + + +
          +
          +
          +
          +
          + + + + + + + + + + + + Copy link +
          +
          + + + + +
          +
          +
          +
          + + +
          +

          +
          + @cavia-porcellus + + cavia-porcellus + + + + commented + Sep 25, 2025 + +
          +

          +
          +
          +
          + + + +
          +
          +
          +
          +
          + + +
          +
          + + +
          + + +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          + +
          +
          +
          +
          +
          +
          + +
          +
          +
          +
          +
          +
          +
          +
          + + +
          + + + + + + +
          +
          +

          + The content you are editing has changed. + Please copy your edits and refresh the page. +

          + +
          + + + + + + +
          + +
          +
          + +
          + +
          + +
          +
          +
          + +
          + + + + + + + + + + + + +
          +
          +
          +
          + +
          +
          +
          +
          + +
          + +
          + + +
          +
          + +
          +
          +
          + +
          +
          +
          +
          + + +
          +
          + +
          +
          +
          + +
          +
          +
          +
          + +
          +
          + + @cavia-porcellus +
          +
          + +
          + + + + + + + + +
          +
          +
          + +
          +
          +
          + + 45bc218 + +
          +
          +
          +
          +
          +
          +
          +
          +
          + + +
          +
          + @cavia-porcellus +
          + +
          +
          +
          +
          +
          + + + + + + + + + + + + Copy link +
          +
          + + +
          + + Reference in new issue + + +
          + +

          Reference in new issue

          +
          + +
          + +
          +
          +
          +
          +
          + + + testing-deletable + + + +
          + Repositories +
          +
          +
          + + + +
          +
          + + + Loading + + + +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          + +
          + + + + + + +
          +
          +
          +
          + +
          +
          +
          +
          +
          + + + +
          + + +
          + +
          +
          +
          +
          + + + + Author + +
          +

          +
          + + + cavia-porcellus + + + + commented + Sep 25, 2025 + +
          +

          +
          +
          + + +
          + + +
          + +
          +
          +
          +
          +
          +
          + + +
          +
          + + +
          + + +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          + +
          +
          +
          +
          +
          +
          + +
          +
          +
          +
          +
          +
          +
          +
          + + +
          + + + + + + +
          +
          +

          + The content you are editing has changed. + Please copy your edits and refresh the page. +

          + +
          + + + + + + +
          + +
          +
          + +
          + +
          + +
          +
          +
          + +
          + + + + + + + + + + + + +
          +
          +
          +
          + +
          +
          +
          +
          + +
          + +
          + + +
          +
          + +
          +
          +
          +
          +
          + +
          +
          + +
          +
          +
          +
          +
          + + + + + +

          Merge info

          No conflicts with base branch

          Changes can be cleanly merged.

          +
          +
          +
          + + +
          +
          + @cavia-porcellus +
          +
          +
          + + +
          + +

          Add a comment

          + + + +
          +
          + + +
          + + +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          + +
          +
          +
          +
          +
          +
          + +
          +
          +
          +
          +
          +
          +
          +
          + + +
          + + + + + + +
          + + +
          + + + +
          + +
          +
          + +
          + +
          + + +
          +
          +
          + +
          + + + + + + + + + + + + +
          +
          +
          + +
          +
          + + +
          +
          +
          + +
          +
          +
          +
          +
          +
          + + +
          +
          +
          +
          +
          +
          +
          +
          + Remember, contributions to this repository should follow + our + GitHub Community Guidelines. +
          +
          + + ProTip! + Add .patch or .diff to the end of URLs for Git’s plaintext views. +
          +
          +
          +
          +
          +
          +
          +
          + + + +
          + +
          + Labels +
          +
          + None yet +
          +
          + +
          +
          +
          + Projects +
          +
          +
          + + None yet + +
          + + + + + +
          +
          +
          + +
          + +
          + Development +
          + +

          Successfully merging this pull request may close these issues.

          +
          +

          None yet

          +
          +
          +
          +
          +
          +
          + + +
          +
          +
          + 1 participant +
          +
          + + @cavia-porcellus +
          +
          +
          + + + +
          + +
          +
          + + + + + + + + + + + + + +
          +
          +
          +
          +
          + +
          +
          + +
          +
          +
          +
          +
          +
          + + + + + + + + +
          +
          +
          + + \ No newline at end of file diff --git a/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap b/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap index 0e5891a..b5b8f6c 100644 --- a/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap +++ b/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap @@ -21,6 +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": { + "isIssue": true, "type": "GH_EDIT", "unique_key": "github.com:diffplug/gitcasso:56:edit-body", }, @@ -39,6 +40,38 @@ exports[`github detection > gh_issue_edit:should detect correct spots 1`] = ` ] `; +exports[`github detection > gh_issue_edit_multiple:should detect correct spots 1`] = ` +[ + { + "for": "id=:r76: name=null className=prc-Textarea-TextArea-13q4j overtype-input", + "spot": { + "isIssue": true, + "type": "GH_EDIT", + "unique_key": "github.com:diffplug/testing-deletable:3:edit-body", + }, + }, + { + "for": "id=:r8k: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input", + "spot": { + "isIssue": true, + "type": "GH_EDIT", + "unique_key": "github.com:diffplug/testing-deletable:3:edit-body", + }, + }, + { + "for": "id=:r5b: name=null className=prc-Textarea-TextArea-13q4j overtype-input", + "spot": { + "domain": "github.com", + "number": 3, + "slug": "diffplug/testing-deletable", + "title": "Test 3", + "type": "GH_ISSUE_APPEND", + "unique_key": "github.com:diffplug/testing-deletable:3", + }, + }, +] +`; + exports[`github detection > gh_issue_new:should detect correct spots 1`] = ` [ { @@ -80,6 +113,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": { + "isIssue": false, "type": "GH_EDIT", "unique_key": "github.com:diffplug/gitcasso:58:edit-body", }, @@ -100,6 +134,43 @@ exports[`github detection > gh_pr_edit:should detect correct spots 1`] = ` ] `; +exports[`github detection > gh_pr_edit_multiple:should detect correct spots 1`] = ` +[ + { + "for": "id=issue-3454672384-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 overtype-input", + "spot": { + "isIssue": false, + "type": "GH_EDIT", + "unique_key": "github.com:diffplug/testing-deletable:5:edit-body", + }, + }, + { + "for": "id=convert-to-issue-body-3335416053 name=issue[body] className=form-control input-contrast comment-form-textarea js-comment-field js-paste-markdown js-task-list-field js-quick-submit js-size-to-fit size-to-fit js-session-resumable", + "spot": "NO_SPOT", + }, + { + "for": "id=issuecomment-3335416053-body name=issue_comment[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": { + "isIssue": false, + "type": "GH_EDIT", + "unique_key": "github.com:diffplug/testing-deletable:5:edit-body", + }, + }, + { + "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": 5, + "slug": "diffplug/testing-deletable", + "title": "Update README.md + #5", + "type": "GH_PR_APPEND", + "unique_key": "github.com:diffplug/testing-deletable:5", + }, + }, +] +`; + exports[`github detection > gh_pr_new:should detect correct spots 1`] = ` [ { diff --git a/tests/lib/enhancers/__snapshots__/gh-ui.test.ts.snap b/tests/lib/enhancers/__snapshots__/gh-ui.test.ts.snap index 5122750..74331a9 100644 --- a/tests/lib/enhancers/__snapshots__/gh-ui.test.ts.snap +++ b/tests/lib/enhancers/__snapshots__/gh-ui.test.ts.snap @@ -59,6 +59,46 @@ exports[`github ui > gh_issue_edit:should render correct UI elements 1`] = ` ] `; +exports[`github ui > gh_issue_edit_multiple:should render correct UI elements 1`] = ` +[ + { + "for": "id=:r76: name=null className=prc-Textarea-TextArea-13q4j overtype-input", + "title": "N/A", + "upperDecoration": + N/A + , + }, + { + "for": "id=:r8k: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input", + "title": "N/A", + "upperDecoration": + N/A + , + }, + { + "for": "id=:r5b: name=null className=prc-Textarea-TextArea-13q4j overtype-input", + "title": "Test 3", + "upperDecoration": + + + + # + 3 + + diffplug/testing-deletable + + , + }, +] +`; + exports[`github ui > gh_issue_new:should render correct UI elements 1`] = ` [ { @@ -134,6 +174,43 @@ exports[`github ui > gh_pr_edit:should render correct UI elements 1`] = ` ] `; +exports[`github ui > gh_pr_edit_multiple:should render correct UI elements 1`] = ` +[ + { + "for": "id=issue-3454672384-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 overtype-input", + "title": "N/A", + "upperDecoration": + N/A + , + }, + { + "for": "id=issuecomment-3335416053-body name=issue_comment[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", + "title": "N/A", + "upperDecoration": + N/A + , + }, + { + "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", + "title": "Update README.md + #5", + "upperDecoration": + + diffplug/testing-deletable + + + PR # + 5 + + , + }, +] +`; + exports[`github ui > gh_pr_new:should render correct UI elements 1`] = ` [ {