Skip to content

Commit 4f18cb2

Browse files
axosoft-raminteamodio
authored andcommitted
Moves util functions to better locations
1 parent 2dd7d57 commit 4f18cb2

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

src/plus/integrations/providers/github/models.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,3 +508,12 @@ export function fromCommitFileStatus(
508508
}
509509
return undefined;
510510
}
511+
512+
export function isGitHubPullRequestUrl(search: string): boolean {
513+
try {
514+
const url = new URL(search);
515+
return url.host === 'github.com' && url.pathname.includes('/pull/');
516+
} catch {
517+
return false;
518+
}
519+
}

src/plus/integrations/providers/gitlab/models.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,12 @@ export function fromGitLabMergeRequestProvidersApi(pr: ProviderPullRequest, prov
150150
};
151151
return fromProviderPullRequest(wrappedPr, provider);
152152
}
153+
154+
export function isGitLabPullRequestUrl(search: string): boolean {
155+
try {
156+
const url = new URL(search);
157+
return url.host === 'gitlab.com' && url.pathname.includes('/merge_requests/');
158+
} catch {
159+
return false;
160+
}
161+
}

src/plus/launchpad/launchpad.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import {
7373
launchpadGroups,
7474
supportedLaunchpadIntegrations,
7575
} from './launchpadProvider';
76+
import { isSupportedLaunchpadPullRequestSearchUrl } from './utils';
7677

7778
const actionGroupMap = new Map<LaunchpadActionCategory, string[]>([
7879
['mergeable', ['Ready to Merge', 'Ready to merge']],
@@ -1591,25 +1592,3 @@ function updateTelemetryContext(context: Context) {
15911592
function isLaunchpadTargetActionQuickPickItem(item: any): item is QuickPickItemOfT<LaunchpadTargetAction> {
15921593
return item?.item?.action != null && item?.item?.target != null;
15931594
}
1594-
1595-
function isGitHubPullRequestUrl(search: string) {
1596-
try {
1597-
const url = new URL(search);
1598-
return url.host === 'github.com' && url.pathname.includes('/pull/');
1599-
} catch {
1600-
return false;
1601-
}
1602-
}
1603-
1604-
function isGitLabPullRequestUrl(search: string) {
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-
}
1611-
}
1612-
1613-
function isSupportedLaunchpadPullRequestSearchUrl(search: string) {
1614-
return isGitHubPullRequestUrl(search) || isGitLabPullRequestUrl(search);
1615-
}

src/plus/launchpad/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { Container } from '../../container';
22
import { configuration } from '../../system/vscode/configuration';
3+
import { isGitHubPullRequestUrl } from '../integrations/providers/github/models';
4+
import { isGitLabPullRequestUrl } from '../integrations/providers/gitlab/models';
35
import type { LaunchpadSummaryResult } from './launchpadIndicator';
46
import { generateLaunchpadSummary } from './launchpadIndicator';
57
import type { LaunchpadGroup } from './launchpadProvider';
@@ -16,3 +18,7 @@ export async function getLaunchpadSummary(container: Container): Promise<Launchp
1618
const groups: LaunchpadGroup[] = configuration.get('launchpad.indicator.groups') ?? [];
1719
return generateLaunchpadSummary(result.items, groups);
1820
}
21+
22+
export function isSupportedLaunchpadPullRequestSearchUrl(search: string): boolean {
23+
return isGitHubPullRequestUrl(search) || isGitLabPullRequestUrl(search);
24+
}

0 commit comments

Comments
 (0)