Skip to content

Commit 8a98d50

Browse files
committed
Rename all the GitHub enhancers to be a bit more consistent and less verbose.
1 parent afa9388 commit 8a98d50

File tree

9 files changed

+91
-93
lines changed

9 files changed

+91
-93
lines changed

src/lib/enhancers/github/githubEditComment.tsx renamed to src/lib/enhancers/github/GitHubEditEnhancer.tsx

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

8-
export interface GitHubEditCommentSpot extends CommentSpot {
9-
type: 'GH_EDIT_COMMENT'
8+
const GH_EDIT = 'GH_EDIT' as const
9+
10+
export interface GitHubEditSpot extends CommentSpot {
11+
type: typeof GH_EDIT
1012
}
1113

12-
export class GitHubEditCommentEnhancer implements CommentEnhancer<GitHubEditCommentSpot> {
14+
export class GitHubEditEnhancer implements CommentEnhancer<GitHubEditSpot> {
1315
forSpotTypes(): string[] {
14-
return ['GH_EDIT_COMMENT']
16+
return [GH_EDIT]
1517
}
1618

17-
tryToEnhance(
18-
textarea: HTMLTextAreaElement,
19-
location: StrippedLocation,
20-
): GitHubEditCommentSpot | null {
19+
tryToEnhance(textarea: HTMLTextAreaElement, location: StrippedLocation): GitHubEditSpot | null {
2120
if (location.host !== 'github.com') {
2221
return null
2322
}
@@ -43,12 +42,12 @@ export class GitHubEditCommentEnhancer implements CommentEnhancer<GitHubEditComm
4342

4443
logger.debug(`${this.constructor.name} enhanced issue/PR body textarea`, unique_key)
4544
return {
46-
type: 'GH_EDIT_COMMENT',
45+
type: GH_EDIT,
4746
unique_key,
4847
}
4948
}
5049

51-
enhance(textArea: HTMLTextAreaElement, _spot: GitHubEditCommentSpot): OverTypeInstance {
50+
enhance(textArea: HTMLTextAreaElement, _spot: GitHubEditSpot): OverTypeInstance {
5251
prepareGitHubHighlighter()
5352
const overtypeContainer = modifyDOM(textArea)
5453
return new OverType(overtypeContainer, {
@@ -59,11 +58,11 @@ export class GitHubEditCommentEnhancer implements CommentEnhancer<GitHubEditComm
5958
})[0]!
6059
}
6160

62-
tableUpperDecoration(_spot: GitHubEditCommentSpot): React.ReactNode {
61+
tableUpperDecoration(_spot: GitHubEditSpot): React.ReactNode {
6362
return <span>N/A</span>
6463
}
6564

66-
tableTitle(_spot: GitHubEditCommentSpot): string {
65+
tableTitle(_spot: GitHubEditSpot): string {
6766
return 'N/A'
6867
}
6968
}

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

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

9-
export interface GitHubIssueAddCommentSpot extends CommentSpot {
10-
type: 'GH_ISSUE_ADD_COMMENT'
9+
const GH_ISSUE = 'GH_ISSUE' as const
10+
11+
export interface GitHubIssueSpot extends CommentSpot {
12+
type: typeof GH_ISSUE
1113
title: string
1214
domain: string
1315
slug: string // owner/repo
1416
number: number // issue number, undefined for new issues
1517
}
1618

17-
export class GitHubIssueAddCommentEnhancer implements CommentEnhancer<GitHubIssueAddCommentSpot> {
19+
export class GitHubIssueEnhancer implements CommentEnhancer<GitHubIssueSpot> {
1820
forSpotTypes(): string[] {
19-
return ['GH_ISSUE_ADD_COMMENT']
21+
return [GH_ISSUE]
2022
}
2123

22-
tryToEnhance(
23-
textarea: HTMLTextAreaElement,
24-
location: StrippedLocation,
25-
): GitHubIssueAddCommentSpot | null {
24+
tryToEnhance(textarea: HTMLTextAreaElement, location: StrippedLocation): GitHubIssueSpot | null {
2625
if (textarea.id === 'feedback') {
2726
return null
2827
}
@@ -56,12 +55,12 @@ export class GitHubIssueAddCommentEnhancer implements CommentEnhancer<GitHubIssu
5655
number,
5756
slug,
5857
title,
59-
type: 'GH_ISSUE_ADD_COMMENT',
58+
type: GH_ISSUE,
6059
unique_key,
6160
}
6261
}
6362

64-
enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueAddCommentSpot): OverTypeInstance {
63+
enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueSpot): OverTypeInstance {
6564
prepareGitHubHighlighter()
6665
const overtypeContainer = modifyDOM(textArea)
6766
return new OverType(overtypeContainer, {
@@ -71,7 +70,7 @@ export class GitHubIssueAddCommentEnhancer implements CommentEnhancer<GitHubIssu
7170
})[0]!
7271
}
7372

74-
tableUpperDecoration(spot: GitHubIssueAddCommentSpot): React.ReactNode {
73+
tableUpperDecoration(spot: GitHubIssueSpot): React.ReactNode {
7574
return (
7675
<>
7776
<span className='flex h-4 w-4 flex-shrink-0 items-center justify-center'>
@@ -85,7 +84,7 @@ export class GitHubIssueAddCommentEnhancer implements CommentEnhancer<GitHubIssu
8584
)
8685
}
8786

88-
tableTitle(spot: GitHubIssueAddCommentSpot): string {
87+
tableTitle(spot: GitHubIssueSpot): string {
8988
return spot.title
9089
}
9190
}

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

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

7-
interface GitHubIssueNewCommentSpot extends CommentSpot {
8-
type: 'GH_ISSUE_NEW_COMMENT'
7+
const GH_ISSUE_NEW = 'GH_ISSUE_NEW' as const
8+
9+
interface GitHubIssueNewSpot extends CommentSpot {
10+
type: typeof GH_ISSUE_NEW
911
domain: string
1012
slug: string // owner/repo
1113
title: string
1214
}
1315

14-
export class GitHubIssueNewCommentEnhancer implements CommentEnhancer<GitHubIssueNewCommentSpot> {
16+
export class GitHubIssueNewEnhancer implements CommentEnhancer<GitHubIssueNewSpot> {
1517
forSpotTypes(): string[] {
16-
return ['GH_ISSUE_NEW_COMMENT']
18+
return [GH_ISSUE_NEW]
1719
}
1820

1921
tryToEnhance(
2022
textarea: HTMLTextAreaElement,
2123
location: StrippedLocation,
22-
): GitHubIssueNewCommentSpot | null {
24+
): GitHubIssueNewSpot | null {
2325
if (textarea.id === 'feedback') {
2426
return null
2527
}
@@ -43,12 +45,12 @@ export class GitHubIssueNewCommentEnhancer implements CommentEnhancer<GitHubIssu
4345
domain: location.host,
4446
slug,
4547
title,
46-
type: 'GH_ISSUE_NEW_COMMENT',
48+
type: GH_ISSUE_NEW,
4749
unique_key,
4850
}
4951
}
5052

51-
enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueNewCommentSpot): OverTypeInstance {
53+
enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueNewSpot): OverTypeInstance {
5254
prepareGitHubHighlighter()
5355
const overtypeContainer = modifyDOM(textArea)
5456
return new OverType(overtypeContainer, {
@@ -58,7 +60,7 @@ export class GitHubIssueNewCommentEnhancer implements CommentEnhancer<GitHubIssu
5860
})[0]!
5961
}
6062

61-
tableUpperDecoration(spot: GitHubIssueNewCommentSpot): React.ReactNode {
63+
tableUpperDecoration(spot: GitHubIssueNewSpot): React.ReactNode {
6264
const { slug } = spot
6365
return (
6466
<>
@@ -68,11 +70,11 @@ export class GitHubIssueNewCommentEnhancer implements CommentEnhancer<GitHubIssu
6870
)
6971
}
7072

71-
tableTitle(spot: GitHubIssueNewCommentSpot): string {
73+
tableTitle(spot: GitHubIssueNewSpot): string {
7274
return spot.title || 'New Issue'
7375
}
7476

75-
buildUrl(spot: GitHubIssueNewCommentSpot): string {
77+
buildUrl(spot: GitHubIssueNewSpot): string {
7678
return `https://${spot.domain}/${spot.slug}/issue/new`
7779
}
7880
}

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

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

8-
export interface GitHubPRAddCommentSpot extends CommentSpot {
9-
type: 'GH_PR_ADD_COMMENT' // Override to narrow from string to specific union
8+
const GH_PR = 'GH_PR' as const
9+
10+
export interface GitHubPrSpot extends CommentSpot {
11+
type: typeof GH_PR
1012
title: string
1113
domain: string
1214
slug: string // owner/repo
1315
number: number // issue/PR number, undefined for new issues and PRs
1416
}
1517

16-
export class GitHubPRAddCommentEnhancer implements CommentEnhancer<GitHubPRAddCommentSpot> {
18+
export class GitHubPrEnhancer implements CommentEnhancer<GitHubPrSpot> {
1719
forSpotTypes(): string[] {
18-
return ['GH_PR_ADD_COMMENT']
20+
return [GH_PR]
1921
}
2022

21-
tryToEnhance(
22-
_textarea: HTMLTextAreaElement,
23-
location: StrippedLocation,
24-
): GitHubPRAddCommentSpot | null {
23+
tryToEnhance(_textarea: HTMLTextAreaElement, location: StrippedLocation): GitHubPrSpot | null {
2524
// Only handle github.com domains TODO: identify GitHub Enterprise somehow
2625
if (location.host !== 'github.com' || _textarea.id !== 'new_comment_field') {
2726
return null
@@ -46,12 +45,12 @@ export class GitHubPRAddCommentEnhancer implements CommentEnhancer<GitHubPRAddCo
4645
number,
4746
slug,
4847
title,
49-
type: 'GH_PR_ADD_COMMENT',
48+
type: GH_PR,
5049
unique_key,
5150
}
5251
}
5352

54-
enhance(textArea: HTMLTextAreaElement, _spot: GitHubPRAddCommentSpot): OverTypeInstance {
53+
enhance(textArea: HTMLTextAreaElement, _spot: GitHubPrSpot): OverTypeInstance {
5554
prepareGitHubHighlighter()
5655
const overtypeContainer = modifyDOM(textArea)
5756
return new OverType(overtypeContainer, {
@@ -62,7 +61,7 @@ export class GitHubPRAddCommentEnhancer implements CommentEnhancer<GitHubPRAddCo
6261
})[0]!
6362
}
6463

65-
tableUpperDecoration(spot: GitHubPRAddCommentSpot): React.ReactNode {
64+
tableUpperDecoration(spot: GitHubPrSpot): React.ReactNode {
6665
const { slug, number } = spot
6766
return (
6867
<>
@@ -72,7 +71,7 @@ export class GitHubPRAddCommentEnhancer implements CommentEnhancer<GitHubPRAddCo
7271
)
7372
}
7473

75-
tableTitle(spot: GitHubPRAddCommentSpot): string {
74+
tableTitle(spot: GitHubPrSpot): string {
7675
return spot.title
7776
}
7877
}

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

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

7-
interface GitHubPRNewCommentSpot extends CommentSpot {
8-
type: 'GH_PR_NEW_COMMENT'
7+
const GH_PR_NEW = 'GH_PR_NEW' as const
8+
9+
interface GitHubPRNewSpot extends CommentSpot {
10+
type: typeof GH_PR_NEW
911
domain: string
1012
slug: string // owner/repo
1113
title: string
1214
head: string // `user:repo:branch` where changes are implemented
1315
base: string // branch you want changes pulled into
1416
}
1517

16-
export class GitHubPRNewCommentEnhancer implements CommentEnhancer<GitHubPRNewCommentSpot> {
18+
export class GitHubPRNewEnhancer implements CommentEnhancer<GitHubPRNewSpot> {
1719
forSpotTypes(): string[] {
18-
return ['GH_PR_NEW_COMMENT']
20+
return [GH_PR_NEW]
1921
}
2022

21-
tryToEnhance(
22-
textarea: HTMLTextAreaElement,
23-
location: StrippedLocation,
24-
): GitHubPRNewCommentSpot | null {
23+
tryToEnhance(textarea: HTMLTextAreaElement, location: StrippedLocation): GitHubPRNewSpot | null {
2524
if (textarea.id === 'feedback') {
2625
return null
2726
}
@@ -53,12 +52,12 @@ export class GitHubPRNewCommentEnhancer implements CommentEnhancer<GitHubPRNewCo
5352
head,
5453
slug,
5554
title,
56-
type: 'GH_PR_NEW_COMMENT',
55+
type: GH_PR_NEW,
5756
unique_key,
5857
}
5958
}
6059

61-
enhance(textArea: HTMLTextAreaElement, _spot: GitHubPRNewCommentSpot): OverTypeInstance {
60+
enhance(textArea: HTMLTextAreaElement, _spot: GitHubPRNewSpot): OverTypeInstance {
6261
prepareGitHubHighlighter()
6362
const overtypeContainer = modifyDOM(textArea)
6463
return new OverType(overtypeContainer, {
@@ -68,7 +67,7 @@ export class GitHubPRNewCommentEnhancer implements CommentEnhancer<GitHubPRNewCo
6867
})[0]!
6968
}
7069

71-
tableUpperDecoration(spot: GitHubPRNewCommentSpot): React.ReactNode {
70+
tableUpperDecoration(spot: GitHubPRNewSpot): React.ReactNode {
7271
const { slug } = spot
7372
return (
7473
<>
@@ -78,11 +77,11 @@ export class GitHubPRNewCommentEnhancer implements CommentEnhancer<GitHubPRNewCo
7877
)
7978
}
8079

81-
tableTitle(spot: GitHubPRNewCommentSpot): string {
80+
tableTitle(spot: GitHubPRNewSpot): string {
8281
return spot.title || 'New Pull Request'
8382
}
8483

85-
buildUrl(spot: GitHubPRNewCommentSpot): string {
84+
buildUrl(spot: GitHubPRNewSpot): string {
8685
return `https://${spot.domain}/${spot.slug}/issue/new`
8786
}
8887
}

src/lib/registries.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import type { OverTypeInstance } from 'overtype'
22
import OverType from 'overtype'
33
import type { CommentEnhancer, CommentSpot, StrippedLocation } from './enhancer'
44
import { CommentEnhancerMissing } from './enhancers/CommentEnhancerMissing'
5-
import { GitHubEditCommentEnhancer } from './enhancers/github/githubEditComment'
6-
import { GitHubIssueAddCommentEnhancer } from './enhancers/github/githubIssueAddComment'
7-
import { GitHubIssueNewCommentEnhancer } from './enhancers/github/githubIssueNewComment'
8-
import { GitHubPRAddCommentEnhancer } from './enhancers/github/githubPRAddComment'
9-
import { GitHubPRNewCommentEnhancer } from './enhancers/github/githubPRNewComment'
5+
import { GitHubEditEnhancer } from './enhancers/github/GitHubEditEnhancer'
6+
import { GitHubIssueEnhancer } from './enhancers/github/GitHubIssueEnhancer'
7+
import { GitHubIssueNewEnhancer } from './enhancers/github/GitHubIssueNewEnhancer'
8+
import { GitHubPrEnhancer } from './enhancers/github/GitHubPrEnhancer'
9+
import { GitHubPRNewEnhancer } from './enhancers/github/GitHubPrNewEnhancer'
1010

1111
export interface EnhancedTextarea<T extends CommentSpot = CommentSpot> {
1212
textarea: HTMLTextAreaElement
@@ -21,11 +21,11 @@ export class EnhancerRegistry {
2121

2222
constructor() {
2323
// Register all available handlers
24-
this.register(new GitHubEditCommentEnhancer())
25-
this.register(new GitHubIssueAddCommentEnhancer())
26-
this.register(new GitHubIssueNewCommentEnhancer())
27-
this.register(new GitHubPRAddCommentEnhancer())
28-
this.register(new GitHubPRNewCommentEnhancer())
24+
this.register(new GitHubEditEnhancer())
25+
this.register(new GitHubIssueEnhancer())
26+
this.register(new GitHubIssueNewEnhancer())
27+
this.register(new GitHubPrEnhancer())
28+
this.register(new GitHubPRNewEnhancer())
2929
const textColor = 'rgb(31, 35, 40)'
3030
const headingColor = 'rgb(174, 52, 151)'
3131
OverType.setTheme({

0 commit comments

Comments
 (0)