Skip to content

Commit 2dd7d57

Browse files
axosoft-raminteamodio
authored andcommitted
Improves PR url checks
1 parent 609ce3a commit 2dd7d57

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/plus/launchpad/launchpad.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
682682
quickpick.items = getLaunchpadQuickPickItems(context.result.items, true);
683683

684684
// Show just the option to toggle search on if nothing found
685-
if (quickpick.activeItems.length === 0 && !isSupportedLaunchpadPullRequestUrl(value)) {
685+
if (quickpick.activeItems.length === 0 && !isSupportedLaunchpadPullRequestSearchUrl(value)) {
686686
quickpick.items = [toggleSearchOnItem];
687687
return true;
688688
}
@@ -721,7 +721,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
721721
}
722722

723723
// If a supported PR URL was entered but no existing items match outside of search mode, turn on search mode and search the API.
724-
if (isSupportedLaunchpadPullRequestUrl(value)) {
724+
if (isSupportedLaunchpadPullRequestSearchUrl(value)) {
725725
context.isSearching = true;
726726
await updateItems(quickpick, true);
727727
} else if (quickpick.activeItems.length === 0 || quickpick.activeItems[0] === toggleSearchOnItem) {
@@ -1593,13 +1593,23 @@ function isLaunchpadTargetActionQuickPickItem(item: any): item is QuickPickItemO
15931593
}
15941594

15951595
function isGitHubPullRequestUrl(search: string) {
1596-
return search.includes('github.com') && search.includes('/pull/');
1596+
try {
1597+
const url = new URL(search);
1598+
return url.host === 'github.com' && url.pathname.includes('/pull/');
1599+
} catch {
1600+
return false;
1601+
}
15971602
}
15981603

15991604
function isGitLabPullRequestUrl(search: string) {
1600-
return search.includes('gitlab.com') && search.includes('/merge_requests/');
1605+
try {
1606+
const url = new URL(search);
1607+
return url.host === 'gitlab.com' && url.pathname.includes('/merge_requests/');
1608+
} catch {
1609+
return false;
1610+
}
16011611
}
16021612

1603-
function isSupportedLaunchpadPullRequestUrl(search: string) {
1613+
function isSupportedLaunchpadPullRequestSearchUrl(search: string) {
16041614
return isGitHubPullRequestUrl(search) || isGitLabPullRequestUrl(search);
16051615
}

0 commit comments

Comments
 (0)