-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithubIssueNewComment.ts
More file actions
67 lines (56 loc) · 2.12 KB
/
githubIssueNewComment.ts
File metadata and controls
67 lines (56 loc) · 2.12 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
import OverType, { type OverTypeInstance } from 'overtype'
import type { CommentEnhancer, CommentSpot } from '../../enhancer'
import { logger } from '../../logger'
import { modifyDOM } from '../modifyDOM'
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): GitHubIssueNewCommentSpot | null {
if (document.querySelector('meta[name="hostname"]')?.getAttribute('content') !== 'github.com') {
return null
}
// Parse GitHub URL structure: /owner/repo/issues/123 or /owner/repo/pull/456
logger.debug(`${this.constructor.name} examing url`, window.location.pathname)
const match = window.location.pathname.match(/^\/([^/]+)\/([^/]+)(?:\/issues\/new)/)
logger.debug(`${this.constructor.name} found match`, window.location.pathname)
if (!match) return null
const [, owner, repo] = match
const slug = `${owner}/${repo}`
const unique_key = `github.com:${slug}:new`
return {
domain: 'github.com',
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, {
autoResize: true,
minHeight: '400px',
padding: 'var(--base-size-16)',
placeholder: 'Type your description here...',
})[0]!
}
tableTitle(spot: GitHubIssueNewCommentSpot): string {
const { slug } = spot
return `${slug} New Issue`
}
tableIcon(_: GitHubIssueNewCommentSpot): string {
return '🔄' // PR icon TODO: icon urls in /public
}
buildUrl(spot: GitHubIssueNewCommentSpot): string {
return `https://${spot.domain}/${spot.slug}/issue/new`
}
}