Skip to content

Commit e2d88f7

Browse files
committed
Same Append/Create but for prs.
1 parent c2a8e80 commit e2d88f7

File tree

6 files changed

+44
-38
lines changed

6 files changed

+44
-38
lines changed

src/lib/enhancers/github/GitHubPrEnhancer.tsx renamed to src/lib/enhancers/github/GitHubPrAppendEnhancer.tsx

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

8-
const GH_PR = 'GH_PR' as const
8+
const GH_PR_APPEND = 'GH_PR_APPEND' as const
99

10-
export interface GitHubPrSpot extends CommentSpot {
11-
type: typeof GH_PR
10+
export interface GitHubPrAppendSpot extends CommentSpot {
11+
type: typeof GH_PR_APPEND
1212
title: string
1313
domain: string
1414
slug: string // owner/repo
1515
number: number // issue/PR number, undefined for new issues and PRs
1616
}
1717

18-
export class GitHubPrEnhancer implements CommentEnhancer<GitHubPrSpot> {
18+
export class GitHubPrAppendEnhancer implements CommentEnhancer<GitHubPrAppendSpot> {
1919
forSpotTypes(): string[] {
20-
return [GH_PR]
20+
return [GH_PR_APPEND]
2121
}
2222

23-
tryToEnhance(_textarea: HTMLTextAreaElement, location: StrippedLocation): GitHubPrSpot | null {
23+
tryToEnhance(
24+
_textarea: HTMLTextAreaElement,
25+
location: StrippedLocation,
26+
): GitHubPrAppendSpot | null {
2427
// Only handle github.com domains TODO: identify GitHub Enterprise somehow
2528
if (location.host !== 'github.com' || _textarea.id !== 'new_comment_field') {
2629
return null
@@ -45,12 +48,12 @@ export class GitHubPrEnhancer implements CommentEnhancer<GitHubPrSpot> {
4548
number,
4649
slug,
4750
title,
48-
type: GH_PR,
51+
type: GH_PR_APPEND,
4952
unique_key,
5053
}
5154
}
5255

53-
enhance(textArea: HTMLTextAreaElement, _spot: GitHubPrSpot): OverTypeInstance {
56+
enhance(textArea: HTMLTextAreaElement, _spot: GitHubPrAppendSpot): OverTypeInstance {
5457
prepareGitHubHighlighter()
5558
const overtypeContainer = modifyDOM(textArea)
5659
return new OverType(overtypeContainer, {
@@ -61,7 +64,7 @@ export class GitHubPrEnhancer implements CommentEnhancer<GitHubPrSpot> {
6164
})[0]!
6265
}
6366

64-
tableUpperDecoration(spot: GitHubPrSpot): React.ReactNode {
67+
tableUpperDecoration(spot: GitHubPrAppendSpot): React.ReactNode {
6568
const { slug, number } = spot
6669
return (
6770
<>
@@ -71,7 +74,7 @@ export class GitHubPrEnhancer implements CommentEnhancer<GitHubPrSpot> {
7174
)
7275
}
7376

74-
tableTitle(spot: GitHubPrSpot): string {
77+
tableTitle(spot: GitHubPrAppendSpot): string {
7578
return spot.title
7679
}
7780
}

src/lib/enhancers/github/GitHubPrNewEnhancer.tsx renamed to src/lib/enhancers/github/GitHubPrCreateEnhancer.tsx

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

7-
const GH_PR_NEW = 'GH_PR_NEW' as const
7+
const GH_PR_CREATE = 'GH_PR_CREATE' as const
88

9-
interface GitHubPRNewSpot extends CommentSpot {
10-
type: typeof GH_PR_NEW
9+
interface GitHubPrCreateSpot extends CommentSpot {
10+
type: typeof GH_PR_CREATE
1111
domain: string
1212
slug: string // owner/repo
1313
title: string
1414
head: string // `user:repo:branch` where changes are implemented
1515
base: string // branch you want changes pulled into
1616
}
1717

18-
export class GitHubPRNewEnhancer implements CommentEnhancer<GitHubPRNewSpot> {
18+
export class GitHubPrCreateEnhancer implements CommentEnhancer<GitHubPrCreateSpot> {
1919
forSpotTypes(): string[] {
20-
return [GH_PR_NEW]
20+
return [GH_PR_CREATE]
2121
}
2222

23-
tryToEnhance(textarea: HTMLTextAreaElement, location: StrippedLocation): GitHubPRNewSpot | null {
23+
tryToEnhance(
24+
textarea: HTMLTextAreaElement,
25+
location: StrippedLocation,
26+
): GitHubPrCreateSpot | null {
2427
if (textarea.id === 'feedback') {
2528
return null
2629
}
@@ -52,12 +55,12 @@ export class GitHubPRNewEnhancer implements CommentEnhancer<GitHubPRNewSpot> {
5255
head,
5356
slug,
5457
title,
55-
type: GH_PR_NEW,
58+
type: GH_PR_CREATE,
5659
unique_key,
5760
}
5861
}
5962

60-
enhance(textArea: HTMLTextAreaElement, _spot: GitHubPRNewSpot): OverTypeInstance {
63+
enhance(textArea: HTMLTextAreaElement, _spot: GitHubPrCreateSpot): OverTypeInstance {
6164
prepareGitHubHighlighter()
6265
const overtypeContainer = modifyDOM(textArea)
6366
return new OverType(overtypeContainer, {
@@ -67,7 +70,7 @@ export class GitHubPRNewEnhancer implements CommentEnhancer<GitHubPRNewSpot> {
6770
})[0]!
6871
}
6972

70-
tableUpperDecoration(spot: GitHubPRNewSpot): React.ReactNode {
73+
tableUpperDecoration(spot: GitHubPrCreateSpot): React.ReactNode {
7174
const { slug } = spot
7275
return (
7376
<>
@@ -77,11 +80,11 @@ export class GitHubPRNewEnhancer implements CommentEnhancer<GitHubPRNewSpot> {
7780
)
7881
}
7982

80-
tableTitle(spot: GitHubPRNewSpot): string {
83+
tableTitle(spot: GitHubPrCreateSpot): string {
8184
return spot.title || 'New Pull Request'
8285
}
8386

84-
buildUrl(spot: GitHubPRNewSpot): string {
87+
buildUrl(spot: GitHubPrCreateSpot): string {
8588
return `https://${spot.domain}/${spot.slug}/issue/new`
8689
}
8790
}

src/lib/registries.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { CommentEnhancerMissing } from './enhancers/CommentEnhancerMissing'
55
import { GitHubEditEnhancer } from './enhancers/github/GitHubEditEnhancer'
66
import { GitHubIssueAppendEnhancer } from './enhancers/github/GitHubIssueAppendEnhancer'
77
import { GitHubIssueCreateEnhancer } from './enhancers/github/GitHubIssueCreateEnhancer'
8-
import { GitHubPrEnhancer } from './enhancers/github/GitHubPrEnhancer'
9-
import { GitHubPRNewEnhancer } from './enhancers/github/GitHubPrNewEnhancer'
8+
import { GitHubPrAppendEnhancer } from './enhancers/github/GitHubPrAppendEnhancer'
9+
import { GitHubPrCreateEnhancer } from './enhancers/github/GitHubPrCreateEnhancer'
1010

1111
export interface EnhancedTextarea<T extends CommentSpot = CommentSpot> {
1212
textarea: HTMLTextAreaElement
@@ -24,8 +24,8 @@ export class EnhancerRegistry {
2424
this.register(new GitHubEditEnhancer())
2525
this.register(new GitHubIssueAppendEnhancer())
2626
this.register(new GitHubIssueCreateEnhancer())
27-
this.register(new GitHubPrEnhancer())
28-
this.register(new GitHubPRNewEnhancer())
27+
this.register(new GitHubPrAppendEnhancer())
28+
this.register(new GitHubPrCreateEnhancer())
2929
const textColor = 'rgb(31, 35, 40)'
3030
const headingColor = 'rgb(174, 52, 151)'
3131
OverType.setTheme({

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ exports[`github detection > gh_pr:should detect correct spots 1`] = `
6868
"slug": "diffplug/selfie",
6969
"title": "Add "VCR" functionality
7070
#517",
71-
"type": "GH_PR",
71+
"type": "GH_PR_APPEND",
7272
"unique_key": "github.com:diffplug/selfie:517",
7373
},
7474
},
@@ -93,7 +93,7 @@ exports[`github detection > gh_pr_edit:should detect correct spots 1`] = `
9393
"title": "Feat/expand corpus
9494
9595
#58",
96-
"type": "GH_PR",
96+
"type": "GH_PR_APPEND",
9797
"unique_key": "github.com:diffplug/gitcasso:58",
9898
},
9999
},
@@ -114,7 +114,7 @@ exports[`github detection > gh_pr_new:should detect correct spots 1`] = `
114114
"head": "cavia-porcellus:selfie:main",
115115
"slug": "diffplug/selfie",
116116
"title": "Update README.md",
117-
"type": "GH_PR_NEW",
117+
"type": "GH_PR_CREATE",
118118
"unique_key": "github.com:diffplug/selfie:main...cavia-porcellus:selfie:main",
119119
},
120120
},

tests/playground/replica.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { PopupRoot } from '@/components/PopupRoot'
22
import type { CommentStorage, CommentTableRow } from '@/entrypoints/background'
33
import type { CommentSpot } from '@/lib/enhancer'
44
import type { GitHubIssueAppendSpot } from '@/lib/enhancers/github/GitHubIssueAppendEnhancer'
5-
import type { GitHubPrSpot } from '@/lib/enhancers/github/GitHubPrEnhancer'
5+
import type { GitHubPrAppendSpot } from '@/lib/enhancers/github/GitHubPrAppendEnhancer'
66

7-
const gh_pr: GitHubPrSpot = {
7+
const gh_pr: GitHubPrAppendSpot = {
88
domain: 'github.com',
99
number: 517,
1010
slug: 'diffplug/selfie',
1111
title: 'wowza',
12-
type: 'GH_PR',
12+
type: 'GH_PR_APPEND',
1313
unique_key: 'github.com:diffplug/selfie:517',
1414
}
1515
const gh_issue: GitHubIssueAppendSpot = {

tests/playground/replicaData.tsx

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

66
export interface RedditSpot extends CommentSpot {
77
title: string
@@ -42,9 +42,9 @@ export const generateMockDrafts = (): CommentTableRow[] => [
4242
number: 1234,
4343
slug: 'microsoft/vscode',
4444
title: "Fix memory leak in extension host (why is this so hard! It's been months!)",
45-
type: 'GH_PR',
45+
type: 'GH_PR_APPEND',
4646
unique_key: '1',
47-
} satisfies GitHubPrSpot),
47+
} satisfies GitHubPrAppendSpot),
4848
},
4949
{
5050
isOpenTab: false,
@@ -129,9 +129,9 @@ export const generateMockDrafts = (): CommentTableRow[] => [
129129
number: 9012,
130130
slug: 'vercel/next.js',
131131
title: 'Update routing documentation',
132-
type: 'GH_PR',
132+
type: 'GH_PR_APPEND',
133133
unique_key: '4',
134-
} satisfies GitHubPrSpot),
134+
} satisfies GitHubPrAppendSpot),
135135
},
136136
{
137137
isOpenTab: true,
@@ -170,8 +170,8 @@ export const generateMockDrafts = (): CommentTableRow[] => [
170170
number: 3456,
171171
slug: 'nodejs/node',
172172
title: 'Add support for ESM in worker threads',
173-
type: 'GH_PR',
173+
type: 'GH_PR_APPEND',
174174
unique_key: '5',
175-
} satisfies GitHubPrSpot),
175+
} satisfies GitHubPrAppendSpot),
176176
},
177177
]

0 commit comments

Comments
 (0)