Skip to content

Commit

Permalink
Shows the item that matches the entered URL (if exists)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeibbb committed Sep 20, 2024
1 parent 2cc08bd commit fb0ff8a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/plus/integrations/providers/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,23 @@ export class GitHubEnterpriseIntegration extends GitHubIntegrationBase<SelfHoste
return super.connect(source);
}
}

const GitHubPullRequestUrlRegex = /github\.com\/([^/]+\/[^/]+)\/pull\/(\d+)/;
export function getPullRequestIdentityValuesFromSearch(search: string): { ownerAndRepo?: string; prNumber?: string } {
let match = search.match(GitHubPullRequestUrlRegex);
let ownerAndRepo: string | undefined = undefined;
let prNumber: string | undefined = undefined;
if (match != null) {
ownerAndRepo = match[1];
prNumber = match[2];
}

if (prNumber == null) {
match = search.match(/(?:#|\/)(\d+)/);
if (match != null) {
prNumber = match[1];
}
}

return { ownerAndRepo: ownerAndRepo, prNumber: prNumber };
}
20 changes: 20 additions & 0 deletions src/plus/launchpad/launchpad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { executeCommand } from '../../system/vscode/command';
import { configuration } from '../../system/vscode/configuration';
import { openUrl } from '../../system/vscode/utils';
import { getApplicablePromo } from '../gk/account/promos';
import { getPullRequestIdentityValuesFromSearch } from '../integrations/providers/github';
import type { IntegrationId } from '../integrations/providers/models';
import {
HostingIntegrationId,
Expand Down Expand Up @@ -561,6 +562,25 @@ export class LaunchpadCommand extends QuickCommand<State> {
if (groupsHidden != hideGroups) {
groupsHidden = hideGroups;
quickpick.items = hideGroups ? items.filter(i => !isDirectiveQuickPickItem(i)) : items;
const { value } = quickpick;
const activeLaunchpadItems = quickpick.activeItems.filter(
(i): i is LaunchpadItemQuickPickItem => 'item' in i,
);
if (value?.length && !activeLaunchpadItems.length) {
const { prNumber } = getPullRequestIdentityValuesFromSearch(value);
if (prNumber != null) {
const launchpadItems = quickpick.items.filter(
(i): i is LaunchpadItemQuickPickItem => 'item' in i,
);
const item = launchpadItems.find(i => i.item.id === prNumber);
if (item != null) {
if (!item.alwaysShow) {
item.alwaysShow = true;
// This is a hack because the quickpick doesn't update until you change the items
quickpick.items = [...quickpick.items];
}
}
}
}

return true;
Expand Down

0 comments on commit fb0ff8a

Please sign in to comment.