Skip to content

Commit c2a8e80

Browse files
committed
Use a clear Append/Create dichotomy on the issue enhancement.
1 parent 8a98d50 commit c2a8e80

File tree

6 files changed

+37
-34
lines changed

6 files changed

+37
-34
lines changed

src/lib/enhancers/github/GitHubIssueEnhancer.tsx renamed to src/lib/enhancers/github/GitHubIssueAppendEnhancer.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@ import { logger } from '@/lib/logger'
66
import { modifyDOM } from '../modifyDOM'
77
import { commonGithubOptions, prepareGitHubHighlighter } from './github-common'
88

9-
const GH_ISSUE = 'GH_ISSUE' as const
9+
const GH_ISSUE_APPEND = 'GH_ISSUE_APPEND' as const
1010

11-
export interface GitHubIssueSpot extends CommentSpot {
12-
type: typeof GH_ISSUE
11+
export interface GitHubIssueAppendSpot extends CommentSpot {
12+
type: typeof GH_ISSUE_APPEND
1313
title: string
1414
domain: string
1515
slug: string // owner/repo
1616
number: number // issue number, undefined for new issues
1717
}
1818

19-
export class GitHubIssueEnhancer implements CommentEnhancer<GitHubIssueSpot> {
19+
export class GitHubIssueAppendEnhancer implements CommentEnhancer<GitHubIssueAppendSpot> {
2020
forSpotTypes(): string[] {
21-
return [GH_ISSUE]
21+
return [GH_ISSUE_APPEND]
2222
}
2323

24-
tryToEnhance(textarea: HTMLTextAreaElement, location: StrippedLocation): GitHubIssueSpot | null {
24+
tryToEnhance(
25+
textarea: HTMLTextAreaElement,
26+
location: StrippedLocation,
27+
): GitHubIssueAppendSpot | null {
2528
if (textarea.id === 'feedback') {
2629
return null
2730
}
@@ -55,12 +58,12 @@ export class GitHubIssueEnhancer implements CommentEnhancer<GitHubIssueSpot> {
5558
number,
5659
slug,
5760
title,
58-
type: GH_ISSUE,
61+
type: GH_ISSUE_APPEND,
5962
unique_key,
6063
}
6164
}
6265

63-
enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueSpot): OverTypeInstance {
66+
enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueAppendSpot): OverTypeInstance {
6467
prepareGitHubHighlighter()
6568
const overtypeContainer = modifyDOM(textArea)
6669
return new OverType(overtypeContainer, {
@@ -70,7 +73,7 @@ export class GitHubIssueEnhancer implements CommentEnhancer<GitHubIssueSpot> {
7073
})[0]!
7174
}
7275

73-
tableUpperDecoration(spot: GitHubIssueSpot): React.ReactNode {
76+
tableUpperDecoration(spot: GitHubIssueAppendSpot): React.ReactNode {
7477
return (
7578
<>
7679
<span className='flex h-4 w-4 flex-shrink-0 items-center justify-center'>
@@ -84,7 +87,7 @@ export class GitHubIssueEnhancer implements CommentEnhancer<GitHubIssueSpot> {
8487
)
8588
}
8689

87-
tableTitle(spot: GitHubIssueSpot): string {
90+
tableTitle(spot: GitHubIssueAppendSpot): string {
8891
return spot.title
8992
}
9093
}

src/lib/enhancers/github/GitHubIssueNewEnhancer.tsx renamed to src/lib/enhancers/github/GitHubIssueCreateEnhancer.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ import { logger } from '../../logger'
44
import { modifyDOM } from '../modifyDOM'
55
import { commonGithubOptions, prepareGitHubHighlighter } from './github-common'
66

7-
const GH_ISSUE_NEW = 'GH_ISSUE_NEW' as const
7+
const GH_ISSUE_CREATE = 'GH_ISSUE_CREATE' as const
88

9-
interface GitHubIssueNewSpot extends CommentSpot {
10-
type: typeof GH_ISSUE_NEW
9+
interface GitHubIssueCreateSpot extends CommentSpot {
10+
type: typeof GH_ISSUE_CREATE
1111
domain: string
1212
slug: string // owner/repo
1313
title: string
1414
}
1515

16-
export class GitHubIssueNewEnhancer implements CommentEnhancer<GitHubIssueNewSpot> {
16+
export class GitHubIssueCreateEnhancer implements CommentEnhancer<GitHubIssueCreateSpot> {
1717
forSpotTypes(): string[] {
18-
return [GH_ISSUE_NEW]
18+
return [GH_ISSUE_CREATE]
1919
}
2020

2121
tryToEnhance(
2222
textarea: HTMLTextAreaElement,
2323
location: StrippedLocation,
24-
): GitHubIssueNewSpot | null {
24+
): GitHubIssueCreateSpot | null {
2525
if (textarea.id === 'feedback') {
2626
return null
2727
}
@@ -45,12 +45,12 @@ export class GitHubIssueNewEnhancer implements CommentEnhancer<GitHubIssueNewSpo
4545
domain: location.host,
4646
slug,
4747
title,
48-
type: GH_ISSUE_NEW,
48+
type: GH_ISSUE_CREATE,
4949
unique_key,
5050
}
5151
}
5252

53-
enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueNewSpot): OverTypeInstance {
53+
enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueCreateSpot): OverTypeInstance {
5454
prepareGitHubHighlighter()
5555
const overtypeContainer = modifyDOM(textArea)
5656
return new OverType(overtypeContainer, {
@@ -60,7 +60,7 @@ export class GitHubIssueNewEnhancer implements CommentEnhancer<GitHubIssueNewSpo
6060
})[0]!
6161
}
6262

63-
tableUpperDecoration(spot: GitHubIssueNewSpot): React.ReactNode {
63+
tableUpperDecoration(spot: GitHubIssueCreateSpot): React.ReactNode {
6464
const { slug } = spot
6565
return (
6666
<>
@@ -70,11 +70,11 @@ export class GitHubIssueNewEnhancer implements CommentEnhancer<GitHubIssueNewSpo
7070
)
7171
}
7272

73-
tableTitle(spot: GitHubIssueNewSpot): string {
73+
tableTitle(spot: GitHubIssueCreateSpot): string {
7474
return spot.title || 'New Issue'
7575
}
7676

77-
buildUrl(spot: GitHubIssueNewSpot): string {
77+
buildUrl(spot: GitHubIssueCreateSpot): string {
7878
return `https://${spot.domain}/${spot.slug}/issue/new`
7979
}
8080
}

src/lib/registries.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import OverType from 'overtype'
33
import type { CommentEnhancer, CommentSpot, StrippedLocation } from './enhancer'
44
import { CommentEnhancerMissing } from './enhancers/CommentEnhancerMissing'
55
import { GitHubEditEnhancer } from './enhancers/github/GitHubEditEnhancer'
6-
import { GitHubIssueEnhancer } from './enhancers/github/GitHubIssueEnhancer'
7-
import { GitHubIssueNewEnhancer } from './enhancers/github/GitHubIssueNewEnhancer'
6+
import { GitHubIssueAppendEnhancer } from './enhancers/github/GitHubIssueAppendEnhancer'
7+
import { GitHubIssueCreateEnhancer } from './enhancers/github/GitHubIssueCreateEnhancer'
88
import { GitHubPrEnhancer } from './enhancers/github/GitHubPrEnhancer'
99
import { GitHubPRNewEnhancer } from './enhancers/github/GitHubPrNewEnhancer'
1010

@@ -22,8 +22,8 @@ export class EnhancerRegistry {
2222
constructor() {
2323
// Register all available handlers
2424
this.register(new GitHubEditEnhancer())
25-
this.register(new GitHubIssueEnhancer())
26-
this.register(new GitHubIssueNewEnhancer())
25+
this.register(new GitHubIssueAppendEnhancer())
26+
this.register(new GitHubIssueCreateEnhancer())
2727
this.register(new GitHubPrEnhancer())
2828
this.register(new GitHubPRNewEnhancer())
2929
const textColor = 'rgb(31, 35, 40)'

tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ exports[`github detection > gh_issue:should detect correct spots 1`] = `
99
"number": 523,
1010
"slug": "diffplug/selfie",
1111
"title": "[jvm] docs for VCR",
12-
"type": "GH_ISSUE",
12+
"type": "GH_ISSUE_APPEND",
1313
"unique_key": "github.com:diffplug/selfie:523",
1414
},
1515
},
@@ -32,7 +32,7 @@ exports[`github detection > gh_issue_edit:should detect correct spots 1`] = `
3232
"number": 56,
3333
"slug": "diffplug/gitcasso",
3434
"title": "what about the draft?",
35-
"type": "GH_ISSUE",
35+
"type": "GH_ISSUE_APPEND",
3636
"unique_key": "github.com:diffplug/gitcasso:56",
3737
},
3838
},
@@ -47,7 +47,7 @@ exports[`github detection > gh_issue_new:should detect correct spots 1`] = `
4747
"domain": "github.com",
4848
"slug": "diffplug/gitcasso",
4949
"title": "New issue title",
50-
"type": "GH_ISSUE_NEW",
50+
"type": "GH_ISSUE_CREATE",
5151
"unique_key": "github.com:diffplug/gitcasso:new",
5252
},
5353
},

tests/playground/replica.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { PopupRoot } from '@/components/PopupRoot'
22
import type { CommentStorage, CommentTableRow } from '@/entrypoints/background'
33
import type { CommentSpot } from '@/lib/enhancer'
4-
import type { GitHubIssueSpot } from '@/lib/enhancers/github/GitHubIssueEnhancer'
4+
import type { GitHubIssueAppendSpot } from '@/lib/enhancers/github/GitHubIssueAppendEnhancer'
55
import type { GitHubPrSpot } from '@/lib/enhancers/github/GitHubPrEnhancer'
66

77
const gh_pr: GitHubPrSpot = {
@@ -12,12 +12,12 @@ const gh_pr: GitHubPrSpot = {
1212
type: 'GH_PR',
1313
unique_key: 'github.com:diffplug/selfie:517',
1414
}
15-
const gh_issue: GitHubIssueSpot = {
15+
const gh_issue: GitHubIssueAppendSpot = {
1616
domain: 'github.com',
1717
number: 523,
1818
slug: 'diffplug/selfie',
1919
title: 'whoa',
20-
type: 'GH_ISSUE',
20+
type: 'GH_ISSUE_APPEND',
2121
unique_key: 'github.com:diffplug/selfie:523',
2222
}
2323

tests/playground/replicaData.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { CommentTableRow } from '@/entrypoints/background'
22
import type { CommentSpot } from '@/lib/enhancer'
3-
import type { GitHubIssueSpot } from '@/lib/enhancers/github/GitHubIssueEnhancer'
3+
import type { GitHubIssueAppendSpot } from '@/lib/enhancers/github/GitHubIssueAppendEnhancer'
44
import type { GitHubPrSpot } from '@/lib/enhancers/github/GitHubPrEnhancer'
55

66
export interface RedditSpot extends CommentSpot {
@@ -93,9 +93,9 @@ export const generateMockDrafts = (): CommentTableRow[] => [
9393
number: 5678,
9494
slug: 'facebook/react',
9595
title: 'Unexpected behavior with useEffect cleanup',
96-
type: 'GH_ISSUE',
96+
type: 'GH_ISSUE_APPEND',
9797
unique_key: '3',
98-
} satisfies GitHubIssueSpot),
98+
} satisfies GitHubIssueAppendSpot),
9999
},
100100
{
101101
isOpenTab: false,

0 commit comments

Comments
 (0)