-
Notifications
You must be signed in to change notification settings - Fork 0
Enhance editing comments in issues and PRs #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
browser-extension/src/lib/enhancers/github/githubEditComment.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<GitHubEditCommentSpot> { | ||
| 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 ( | ||
| <> | ||
| <span className='font-mono text-muted-foreground text-sm'>{slug}</span> | ||
| <span className='ml-2 font-medium'>PR #{number}</span> | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| tableTitle(_spot: GitHubEditCommentSpot): string { | ||
| return 'TITLE_TODO' | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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": <React.Fragment> | ||
| <span | ||
| className="flex h-4 w-4 flex-shrink-0 items-center justify-center" | ||
| > | ||
| <IssueOpenedIcon | ||
| size={16} | ||
| /> | ||
| </span> | ||
| # | ||
| 56 | ||
| <a | ||
| className="truncate hover:underline" | ||
| href="https://github.com/diffplug/gitcasso" | ||
| > | ||
| diffplug/gitcasso | ||
| </a> | ||
| </React.Fragment>, | ||
| }, | ||
| { | ||
| "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": <React.Fragment> | ||
| <span | ||
| className="flex h-4 w-4 flex-shrink-0 items-center justify-center" | ||
| > | ||
| <IssueOpenedIcon | ||
| size={16} | ||
| /> | ||
| </span> | ||
| # | ||
| 56 | ||
| <a | ||
| className="truncate hover:underline" | ||
| href="https://github.com/diffplug/gitcasso" | ||
| > | ||
| diffplug/gitcasso | ||
| </a> | ||
| </React.Fragment>, | ||
| }, | ||
| ] | ||
| `) | ||
| }) | ||
| 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": <React.Fragment> | ||
| <span | ||
| className="font-mono text-muted-foreground text-sm" | ||
| > | ||
| diffplug/gitcasso | ||
| </span> | ||
| <span | ||
| className="ml-2 font-medium" | ||
| > | ||
| PR # | ||
| NaN | ||
| </span> | ||
| </React.Fragment>, | ||
| }, | ||
| { | ||
| "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", | ||
|
Comment on lines
+252
to
+277
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for PRs, the first textarea is |
||
| "unique_key": "github.com:diffplug/gitcasso:58", | ||
| }, | ||
| "title": "TITLE_TODO", | ||
| "upperDecoration": <React.Fragment> | ||
| <span | ||
| className="font-mono text-muted-foreground text-sm" | ||
| > | ||
| diffplug/gitcasso | ||
| </span> | ||
| <span | ||
| className="ml-2 font-medium" | ||
| > | ||
| PR # | ||
| 58 | ||
| </span> | ||
| </React.Fragment>, | ||
| }, | ||
| ] | ||
| `) | ||
| }) | ||
| }) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for issues, both the top and the bottom are identified as
GH_ISSUE_ADD_COMMENT. That has to get fixed.