Skip to content

Commit 1c39183

Browse files
committed
parse out the title and branch/repo information for new PRs.
1 parent b32f900 commit 1c39183

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

src/lib/enhancers/github/githubPRNewComment.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import { prepareGitHubHighlighter } from './githubHighlighter'
88
interface GitHubPRNewCommentSpot extends CommentSpot {
99
type: 'GH_PR_NEW_COMMENT'
1010
domain: string
11-
slug: string // owner/repo/base-branch/compare-branch
11+
slug: string // owner/repo
12+
title: string
13+
head: string // branch name where changes are implemented
14+
head_repo?: string // repository where changes were made (for cross-repo PRs)
15+
base: string // branch you want changes pulled into
1216
}
1317

1418
export class GitHubPRNewCommentEnhancer implements CommentEnhancer<GitHubPRNewCommentSpot> {
@@ -38,13 +42,25 @@ export class GitHubPRNewCommentEnhancer implements CommentEnhancer<GitHubPRNewCo
3842

3943
if (!match) return null
4044
const [, owner, repo, baseBranch, compareBranch] = match
41-
const slug = baseBranch
42-
? `${owner}/${repo}/${baseBranch}...${compareBranch}`
43-
: `${owner}/${repo}/${compareBranch}`
44-
const unique_key = `github.com:${slug}`
45+
const slug = `${owner}/${repo}`
46+
const base = baseBranch || 'main'
47+
const head = compareBranch
48+
const unique_key = `github.com:${slug}:${base}...${head}`
49+
const titleInput = document.querySelector('input[placeholder="Title"]') as HTMLInputElement
50+
const title = titleInput?.value || ''
51+
52+
// Check if this is a cross-repository PR by looking at the head repository button
53+
const headRepoButton = document.querySelector('button[aria-label*="head repository:"]')
54+
const headRepoText = headRepoButton?.textContent
55+
const headRepo = headRepoText?.includes('/') ? headRepoText.split(':')[1]?.trim() : undefined
56+
4557
return {
4658
domain: location.host,
4759
slug,
60+
title,
61+
head,
62+
head_repo: headRepo,
63+
base,
4864
type: 'GH_PR_NEW_COMMENT',
4965
unique_key,
5066
}
@@ -70,8 +86,8 @@ export class GitHubPRNewCommentEnhancer implements CommentEnhancer<GitHubPRNewCo
7086
)
7187
}
7288

73-
tableTitle(_spot: GitHubPRNewCommentSpot): string {
74-
return 'TITLE_TODO'
89+
tableTitle(spot: GitHubPRNewCommentSpot): string {
90+
return spot.title || 'New Pull Request'
7591
}
7692

7793
buildUrl(spot: GitHubPRNewCommentSpot): string {

tests/lib/enhancers/github.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,16 @@ describe('github', () => {
8282
{
8383
"for": "id=pull_request_body name=pull_request[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit FormControl-textarea CommentBox-input js-size-to-fit size-to-fit js-session-resumable js-saved-reply-shortcut-comment-field CommentBox-input--large overtype-input",
8484
"spot": {
85+
"base": "main",
8586
"domain": "github.com",
86-
"slug": "diffplug/selfie/main...cavia-porcellus:selfie:main",
87+
"head": "cavia-porcellus:selfie:main",
88+
"head_repo": undefined,
89+
"slug": "diffplug/selfie",
90+
"title": "Update README.md",
8791
"type": "GH_PR_NEW_COMMENT",
88-
"unique_key": "github.com:diffplug/selfie/main...cavia-porcellus:selfie:main",
92+
"unique_key": "github.com:diffplug/selfie:main...cavia-porcellus:selfie:main",
8993
},
90-
"title": "TITLE_TODO",
94+
"title": "Update README.md",
9195
"upperDecoration": <React.Fragment>
9296
<span>
9397
New PR
@@ -96,7 +100,7 @@ describe('github', () => {
96100
className="font-mono text-muted-foreground text-sm"
97101
>
98102
99-
diffplug/selfie/main...cavia-porcellus:selfie:main
103+
diffplug/selfie
100104
101105
</span>
102106
</React.Fragment>,

0 commit comments

Comments
 (0)