-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithubIssueNewComment.tsx
More file actions
75 lines (64 loc) · 2.23 KB
/
githubIssueNewComment.tsx
File metadata and controls
75 lines (64 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import OverType, { type OverTypeInstance } from 'overtype'
import type { CommentEnhancer, CommentSpot, StrippedLocation } from '../../enhancer'
import { logger } from '../../logger'
import { modifyDOM } from '../modifyDOM'
import { commonGithubOptions } from './ghOptions'
import { githubHighlighter } from './githubHighlighter'
interface GitHubIssueNewCommentSpot extends CommentSpot {
type: 'GH_ISSUE_NEW_COMMENT'
domain: string
slug: string // owner/repo
}
export class GitHubIssueNewCommentEnhancer implements CommentEnhancer<GitHubIssueNewCommentSpot> {
forSpotTypes(): string[] {
return ['GH_ISSUE_NEW_COMMENT']
}
tryToEnhance(
_textarea: HTMLTextAreaElement,
location: StrippedLocation,
): GitHubIssueNewCommentSpot | null {
if (location.host !== 'github.com') {
return null
}
// Parse GitHub URL structure: /owner/repo/issues/123 or /owner/repo/pull/456
logger.debug(`${this.constructor.name} examing url`, location.pathname)
const match = location.pathname.match(/^\/([^/]+)\/([^/]+)(?:\/issues\/new)/)
logger.debug(`${this.constructor.name} found match`, location.pathname)
if (!match) return null
const [, owner, repo] = match
const slug = `${owner}/${repo}`
const unique_key = `github.com:${slug}:new`
return {
domain: location.host,
slug,
type: 'GH_ISSUE_NEW_COMMENT',
unique_key,
}
}
prepareForFirstEnhancement(): void {
OverType.setCodeHighlighter(githubHighlighter)
}
enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueNewCommentSpot): OverTypeInstance {
const overtypeContainer = modifyDOM(textArea)
return new OverType(overtypeContainer, {
...commonGithubOptions,
minHeight: '400px',
placeholder: 'Type your description here...',
})[0]!
}
tableUpperDecoration(spot: GitHubIssueNewCommentSpot): React.ReactNode {
const { slug } = spot
return (
<>
<span>New Issue</span>
<span className='font-mono text-muted-foreground text-sm'> {slug} </span>
</>
)
}
tableTitle(_spot: GitHubIssueNewCommentSpot): string {
return 'New Issue'
}
buildUrl(spot: GitHubIssueNewCommentSpot): string {
return `https://${spot.domain}/${spot.slug}/issue/new`
}
}