@@ -4,36 +4,41 @@ import { logger } from '../../logger'
44import { modifyDOM } from '../modifyDOM'
55import { githubHighlighter } from './githubHighlighter'
66
7- interface GitHubIssueAddCommentSpot extends CommentSpot {
8- type : 'GH_ISSUE_NEW_COMMENT '
7+ interface GitHubPRNewCommentSpot extends CommentSpot {
8+ type : 'GH_PR_NEW_COMMENT '
99 domain : string
10- slug : string // owner/repo
10+ slug : string // owner/repo/base-branch/compare-branch
1111}
1212
13- export class GitHubIssueNewCommentEnhancer implements CommentEnhancer < GitHubIssueAddCommentSpot > {
13+ export class GitHubPRNewCommentEnhancer implements CommentEnhancer < GitHubPRNewCommentSpot > {
1414 forSpotTypes ( ) : string [ ] {
15- return [ 'GH_ISSUE_NEW_COMMENT ' ]
15+ return [ 'GH_PR_NEW_COMMENT ' ]
1616 }
1717
18- tryToEnhance ( _textarea : HTMLTextAreaElement ) : GitHubIssueAddCommentSpot | null {
18+ tryToEnhance ( _textarea : HTMLTextAreaElement ) : GitHubPRNewCommentSpot | null {
1919 if ( document . querySelector ( 'meta[name="hostname"]' ) ?. getAttribute ( 'content' ) !== 'github.com' ) {
2020 return null
2121 }
2222
23- // Parse GitHub URL structure: /owner/repo/issues/123 or /owner/repo/pull/456
23+ // /owner/repo/compare/feature/more-enhancers?expand=1
24+ // or /owner/repo/compare/feat/issue-static-and-dynamic...feature/more-enhancers?expand=1
2425 logger . info ( `${ this . constructor . name } examing url` , window . location . pathname )
2526
26- const match = window . location . pathname . match ( / ^ \/ ( [ ^ / ] + ) \/ ( [ ^ / ] + ) (?: \/ i s s u e s \/ n e w ) / )
27- logger . info ( `${ this . constructor . name } found match` , window . location . pathname )
27+ const match = window . location . pathname . match (
28+ / ^ \/ ( [ ^ / ] + ) \/ ( [ ^ / ] + ) \/ c o m p a r e \/ (?: ( [ ^ . ? ] + ) \. \. \. ) ? ( [ ^ ? ] + ) / ,
29+ )
30+ logger . info ( `${ this . constructor . name } found match` , window . location . pathname , match )
2831
2932 if ( ! match ) return null
30- const [ , owner , repo ] = match
31- const slug = `${ owner } /${ repo } `
32- const unique_key = `github.com:${ slug } :new`
33+ const [ , owner , repo , baseBranch , compareBranch ] = match
34+ const slug = baseBranch
35+ ? `${ owner } /${ repo } /${ baseBranch } ...${ compareBranch } `
36+ : `${ owner } /${ repo } /${ compareBranch } `
37+ const unique_key = `github.com:${ slug } `
3338 return {
3439 domain : 'github.com' ,
3540 slug,
36- type : 'GH_ISSUE_NEW_COMMENT ' ,
41+ type : 'GH_PR_NEW_COMMENT ' ,
3742 unique_key,
3843 }
3944 }
@@ -42,26 +47,26 @@ export class GitHubIssueNewCommentEnhancer implements CommentEnhancer<GitHubIssu
4247 OverType . setCodeHighlighter ( githubHighlighter )
4348 }
4449
45- enhance ( textArea : HTMLTextAreaElement , _spot : GitHubIssueAddCommentSpot ) : OverTypeInstance {
50+ enhance ( textArea : HTMLTextAreaElement , _spot : GitHubPRNewCommentSpot ) : OverTypeInstance {
4651 const overtypeContainer = modifyDOM ( textArea )
4752 return new OverType ( overtypeContainer , {
4853 autoResize : true ,
49- minHeight : '400px ' ,
54+ minHeight : '250px ' ,
5055 padding : 'var(--base-size-16)' ,
5156 placeholder : 'Type your description here...' ,
5257 } ) [ 0 ] !
5358 }
5459
55- tableTitle ( spot : GitHubIssueAddCommentSpot ) : string {
60+ tableTitle ( spot : GitHubPRNewCommentSpot ) : string {
5661 const { slug } = spot
5762 return `${ slug } New Issue`
5863 }
5964
60- tableIcon ( _ : GitHubIssueAddCommentSpot ) : string {
65+ tableIcon ( _ : GitHubPRNewCommentSpot ) : string {
6166 return '🔄' // PR icon TODO: icon urls in /public
6267 }
6368
64- buildUrl ( spot : GitHubIssueAddCommentSpot ) : string {
69+ buildUrl ( spot : GitHubPRNewCommentSpot ) : string {
6570 return `https://${ spot . domain } /${ spot . slug } /issue/new`
6671 }
6772}
0 commit comments