Skip to content

Commit 3df11c0

Browse files
GiteaBotwxiaoguang
andauthored
Make issue suggestion work for new PR page (#33035) (#33056)
Backport #33035 by wxiaoguang Fix #33026 Co-authored-by: wxiaoguang <[email protected]>
1 parent 96fff86 commit 3df11c0

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Diff for: web_src/js/utils.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ test('parseIssueNewHref', () => {
4949
expect(parseIssueNewHref('/owner/repo/issues/new')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'issues'});
5050
expect(parseIssueNewHref('/owner/repo/issues/new?query')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'issues'});
5151
expect(parseIssueNewHref('/sub/owner/repo/issues/new#hash')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'issues'});
52+
expect(parseIssueNewHref('/sub/owner/repo/compare/feature/branch-1...fix/branch-2')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'pulls'});
5253
});
5354

5455
test('parseUrl', () => {

Diff for: web_src/js/utils.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ export function parseIssueHref(href: string): IssuePathInfo {
3939

4040
export function parseIssueNewHref(href: string): IssuePathInfo {
4141
const path = (href || '').replace(/[#?].*$/, '');
42-
const [_, ownerName, repoName, pathType, indexString] = /([^/]+)\/([^/]+)\/(issues|pulls)\/new/.exec(path) || [];
43-
return {ownerName, repoName, pathType, indexString};
42+
const [_, ownerName, repoName, pathTypeField] = /([^/]+)\/([^/]+)\/(issues\/new|compare\/.+\.\.\.)/.exec(path) || [];
43+
const pathType = pathTypeField.startsWith('issues/new') ? 'issues' : 'pulls';
44+
return {ownerName, repoName, pathType};
4445
}
4546

4647
export function parseIssuePageInfo(): IssuePageInfo {

0 commit comments

Comments
 (0)