Skip to content

Commit 597f6e5

Browse files
committed
PR new
1 parent f6dfe03 commit 597f6e5

File tree

4 files changed

+39
-28
lines changed

4 files changed

+39
-28
lines changed

browser-extension/src/lib/enhancers/github/githubIssueNewComment.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@ import { logger } from '../../logger'
44
import { modifyDOM } from '../modifyDOM'
55
import { githubHighlighter } from './githubHighlighter'
66

7-
interface GitHubIssueAddCommentSpot extends CommentSpot {
7+
interface GitHubIssueNewCommentSpot extends CommentSpot {
88
type: 'GH_ISSUE_NEW_COMMENT'
99
domain: string
1010
slug: string // owner/repo
1111
}
1212

13-
export class GitHubIssueNewCommentEnhancer implements CommentEnhancer<GitHubIssueAddCommentSpot> {
13+
export class GitHubIssueNewCommentEnhancer implements CommentEnhancer<GitHubIssueNewCommentSpot> {
1414
forSpotTypes(): string[] {
1515
return ['GH_ISSUE_NEW_COMMENT']
1616
}
1717

18-
tryToEnhance(_textarea: HTMLTextAreaElement): GitHubIssueAddCommentSpot | null {
18+
tryToEnhance(_textarea: HTMLTextAreaElement): GitHubIssueNewCommentSpot | null {
1919
if (document.querySelector('meta[name="hostname"]')?.getAttribute('content') !== 'github.com') {
2020
return null
2121
}
2222

2323
// Parse GitHub URL structure: /owner/repo/issues/123 or /owner/repo/pull/456
24-
logger.info(`${this.constructor.name} examing url`, window.location.pathname)
24+
logger.debug(`${this.constructor.name} examing url`, window.location.pathname)
2525

2626
const match = window.location.pathname.match(/^\/([^/]+)\/([^/]+)(?:\/issues\/new)/)
27-
logger.info(`${this.constructor.name} found match`, window.location.pathname)
27+
logger.debug(`${this.constructor.name} found match`, window.location.pathname)
2828

2929
if (!match) return null
3030
const [, owner, repo] = match
@@ -42,7 +42,7 @@ export class GitHubIssueNewCommentEnhancer implements CommentEnhancer<GitHubIssu
4242
OverType.setCodeHighlighter(githubHighlighter)
4343
}
4444

45-
enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueAddCommentSpot): OverTypeInstance {
45+
enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueNewCommentSpot): OverTypeInstance {
4646
const overtypeContainer = modifyDOM(textArea)
4747
return new OverType(overtypeContainer, {
4848
autoResize: true,
@@ -52,16 +52,16 @@ export class GitHubIssueNewCommentEnhancer implements CommentEnhancer<GitHubIssu
5252
})[0]!
5353
}
5454

55-
tableTitle(spot: GitHubIssueAddCommentSpot): string {
55+
tableTitle(spot: GitHubIssueNewCommentSpot): string {
5656
const { slug } = spot
5757
return `${slug} New Issue`
5858
}
5959

60-
tableIcon(_: GitHubIssueAddCommentSpot): string {
60+
tableIcon(_: GitHubIssueNewCommentSpot): string {
6161
return '🔄' // PR icon TODO: icon urls in /public
6262
}
6363

64-
buildUrl(spot: GitHubIssueAddCommentSpot): string {
64+
buildUrl(spot: GitHubIssueNewCommentSpot): string {
6565
return `https://${spot.domain}/${spot.slug}/issue/new`
6666
}
6767
}

browser-extension/src/lib/enhancers/github/githubIssuePRNewComment.ts renamed to browser-extension/src/lib/enhancers/github/githubPRNewComment.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,41 @@ import { logger } from '../../logger'
44
import { modifyDOM } from '../modifyDOM'
55
import { 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(/^\/([^/]+)\/([^/]+)(?:\/issues\/new)/)
27-
logger.info(`${this.constructor.name} found match`, window.location.pathname)
27+
const match = window.location.pathname.match(
28+
/^\/([^/]+)\/([^/]+)\/compare\/(?:([^.?]+)\.\.\.)?([^?]+)/,
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
}

browser-extension/src/lib/logger.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const LOG_LEVEL_PRIORITY: Record<LogLevel, number> = {
1919

2020
// Helper function to check if a log level is enabled
2121
const shouldLog = (level: LogLevel): boolean => {
22+
// Don't log anything in production mode
23+
if (CONFIG.MODE === 'PROD') {
24+
return false
25+
}
2226
return LOG_LEVEL_PRIORITY[level] >= LOG_LEVEL_PRIORITY[CONFIG.LOG_LEVEL]
2327
}
2428

browser-extension/src/lib/registries.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { CommentEnhancer, CommentSpot } from './enhancer'
33
import { GitHubIssueAddCommentEnhancer } from './enhancers/github/githubIssueAddComment'
44
import { GitHubIssueNewCommentEnhancer } from './enhancers/github/githubIssueNewComment'
55
import { GitHubPRAddCommentEnhancer } from './enhancers/github/githubPRAddComment'
6+
import { GitHubPRNewCommentEnhancer } from './enhancers/github/githubPRNewComment'
67

78
export interface EnhancedTextarea<T extends CommentSpot = CommentSpot> {
89
textarea: HTMLTextAreaElement
@@ -19,8 +20,9 @@ export class EnhancerRegistry {
1920
constructor() {
2021
// Register all available handlers
2122
this.register(new GitHubIssueAddCommentEnhancer())
22-
this.register(new GitHubPRAddCommentEnhancer())
2323
this.register(new GitHubIssueNewCommentEnhancer())
24+
this.register(new GitHubPRAddCommentEnhancer())
25+
this.register(new GitHubPRNewCommentEnhancer())
2426
}
2527

2628
private register<T extends CommentSpot>(enhancer: CommentEnhancer<T>): void {

0 commit comments

Comments
 (0)