@@ -15,19 +15,19 @@ const GITHUB_COMMENT_TYPES = [
1515
1616export type GitHubCommentType = ( typeof GITHUB_COMMENT_TYPES ) [ number ]
1717
18- export interface GitHubContext extends CommentSpot {
18+ export interface GitHubSpot extends CommentSpot {
1919 type : GitHubCommentType // Override to narrow from string to specific union
2020 domain : string
2121 slug : string // owner/repo
2222 number ?: number | undefined // issue/PR number, undefined for new issues and PRs
2323}
2424
25- export class GitHubHandler implements CommentEnhancer < GitHubContext > {
25+ export class GitHubHandler implements CommentEnhancer < GitHubSpot > {
2626 forCommentTypes ( ) : string [ ] {
2727 return [ ...GITHUB_COMMENT_TYPES ]
2828 }
2929
30- tryToEnhance ( textarea : HTMLTextAreaElement ) : [ OverType , GitHubContext ] | null {
30+ tryToEnhance ( textarea : HTMLTextAreaElement ) : [ OverType , GitHubSpot ] | null {
3131 // Only handle GitHub domains
3232 if ( ! window . location . hostname . includes ( 'github' ) ) {
3333 return null
@@ -46,16 +46,11 @@ export class GitHubHandler implements CommentEnhancer<GitHubContext> {
4646 // Determine comment type
4747 let type : GitHubCommentType
4848
49- // New issue
5049 if ( pathname . includes ( '/issues/new' ) ) {
5150 type = 'GH_ISSUE_NEW'
52- }
53- // New PR
54- else if ( pathname . includes ( '/compare/' ) || pathname . endsWith ( '/compare' ) ) {
51+ } else if ( pathname . includes ( '/compare/' ) || pathname . endsWith ( '/compare' ) ) {
5552 type = 'GH_PR_NEW'
56- }
57- // Existing issue or PR page
58- else if ( urlType && number ) {
53+ } else if ( urlType && number ) {
5954 if ( urlType === 'issues' ) {
6055 type = 'GH_ISSUE_ADD_COMMENT'
6156 } else {
@@ -73,30 +68,27 @@ export class GitHubHandler implements CommentEnhancer<GitHubContext> {
7368 unique_key += ':new'
7469 }
7570
76- const context : GitHubContext = {
71+ const spot : GitHubSpot = {
7772 domain : window . location . hostname ,
7873 number,
7974 slug,
8075 type,
8176 unique_key,
8277 }
83-
84- // Create OverType instance for this textarea
8578 const overtype = new OverType ( textarea )
86-
87- return [ overtype , context ]
79+ return [ overtype , spot ]
8880 }
8981
90- generateDisplayTitle ( context : GitHubContext ) : string {
91- const { slug, number } = context
82+ generateDisplayTitle ( spot : GitHubSpot ) : string {
83+ const { slug, number } = spot
9284 if ( number ) {
9385 return `Comment on ${ slug } #${ number } `
9486 }
9587 return `New ${ window . location . pathname . includes ( '/issues/' ) ? 'issue' : 'PR' } in ${ slug } `
9688 }
9789
98- generateIcon ( context : GitHubContext ) : string {
99- switch ( context . type ) {
90+ generateIcon ( spot : GitHubSpot ) : string {
91+ switch ( spot . type ) {
10092 case 'GH_ISSUE_NEW' :
10193 case 'GH_ISSUE_ADD_COMMENT' :
10294 return '🐛' // Issue icon
@@ -106,14 +98,12 @@ export class GitHubHandler implements CommentEnhancer<GitHubContext> {
10698 }
10799 }
108100
109- buildUrl ( context : GitHubContext ) : string {
110- const baseUrl = `https://${ context . domain } /${ context . slug } `
111-
112- if ( context . number ) {
113- const type = window . location . pathname . includes ( '/issues/' ) ? 'issues' : 'pull'
114- return `${ baseUrl } /${ type } /${ context . number } `
101+ buildUrl ( spot : GitHubSpot ) : string {
102+ const baseUrl = `https://${ spot . domain } /${ spot . slug } `
103+ if ( spot . number ) {
104+ const type = spot . type . indexOf ( 'ISSUE' ) ? 'issues' : 'pull'
105+ return `${ baseUrl } /${ type } /${ spot . number } `
115106 }
116-
117107 return baseUrl
118108 }
119109}
0 commit comments