From c09656e0e0384b15405f909a0e7d7e94a373448e Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 31 Dec 2024 11:50:55 +0800 Subject: [PATCH] Make issue suggestion work for new PR page (#33035) Fix #33026 --- web_src/js/utils.test.ts | 1 + web_src/js/utils.ts | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/web_src/js/utils.test.ts b/web_src/js/utils.test.ts index ac9d4fab91..bbe328f658 100644 --- a/web_src/js/utils.test.ts +++ b/web_src/js/utils.test.ts @@ -49,6 +49,7 @@ test('parseIssueNewHref', () => { expect(parseIssueNewHref('/owner/repo/issues/new')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'issues'}); expect(parseIssueNewHref('/owner/repo/issues/new?query')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'issues'}); expect(parseIssueNewHref('/sub/owner/repo/issues/new#hash')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'issues'}); + expect(parseIssueNewHref('/sub/owner/repo/compare/feature/branch-1...fix/branch-2')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'pulls'}); }); test('parseUrl', () => { diff --git a/web_src/js/utils.ts b/web_src/js/utils.ts index 997a4d1ff3..efa144c3c7 100644 --- a/web_src/js/utils.ts +++ b/web_src/js/utils.ts @@ -39,8 +39,9 @@ export function parseIssueHref(href: string): IssuePathInfo { export function parseIssueNewHref(href: string): IssuePathInfo { const path = (href || '').replace(/[#?].*$/, ''); - const [_, ownerName, repoName, pathType, indexString] = /([^/]+)\/([^/]+)\/(issues|pulls)\/new/.exec(path) || []; - return {ownerName, repoName, pathType, indexString}; + const [_, ownerName, repoName, pathTypeField] = /([^/]+)\/([^/]+)\/(issues\/new|compare\/.+\.\.\.)/.exec(path) || []; + const pathType = pathTypeField.startsWith('issues/new') ? 'issues' : 'pulls'; + return {ownerName, repoName, pathType}; } export function parseIssuePageInfo(): IssuePageInfo {