Skip to content

Searches by URL for self hosted GitHub and GitLab on Launchpad #3942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

### Added

- Adds the ability to search for GitHub Enterprise and GitLab Self-Managed pull requests by URL in the main step of Launchpad
- Adds OpenRouter support for GitLens' AI features ([#3906](https://github.com/gitkraken/vscode-gitlens/issues/3906))
- Adds OpenAI GPT-4.1, GPT-4.1 mini, GPT-4.1 nano, o4 mini, and o3 models for GitLens' AI features ([#4235](https://github.com/gitkraken/vscode-gitlens/issues/4235))
- Adds _Open File at Revision from Remote_ command to open the specific file revision from a remote file URL
Expand Down
4 changes: 2 additions & 2 deletions src/git/utils/pullRequest.utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { HostingIntegrationId } from '../../constants.integrations';
import type { HostingIntegrationId, SelfHostedIntegrationId } from '../../constants.integrations';
import type {
PullRequest,
PullRequestComparisonRefs,
Expand All @@ -9,7 +9,7 @@ import type {
import { shortenRevision } from './revision.utils';

export interface PullRequestUrlIdentity {
provider?: HostingIntegrationId;
provider?: SelfHostedIntegrationId | HostingIntegrationId;

ownerAndRepo?: string;
prNumber: string;
Expand Down
13 changes: 7 additions & 6 deletions src/plus/integrations/providers/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import { log } from '../../../system/decorators/log';
import { ensurePaidPlan } from '../../gk/utils/-webview/plus.utils';
import type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider';
import type { IntegrationAuthenticationService } from '../authentication/integrationAuthenticationService';
import type { RepositoryDescriptor, SupportedIntegrationIds } from '../integration';
import type { RepositoryDescriptor } from '../integration';
import { HostingIntegration } from '../integration';
import type { GitHubRelatedIntegrationIds } from './github/github.utils';
import { getGitHubPullRequestIdentityFromMaybeUrl } from './github/github.utils';
import { providersMetadata } from './models';
import type { ProvidersApi } from './providersApi';
Expand All @@ -38,7 +39,7 @@ const cloudEnterpriseAuthProvider: IntegrationAuthenticationProviderDescriptor =

export type GitHubRepositoryDescriptor = RepositoryDescriptor;

abstract class GitHubIntegrationBase<ID extends SupportedIntegrationIds> extends HostingIntegration<
abstract class GitHubIntegrationBase<ID extends GitHubRelatedIntegrationIds> extends HostingIntegration<
ID,
GitHubRepositoryDescriptor
> {
Expand Down Expand Up @@ -260,6 +261,10 @@ abstract class GitHubIntegrationBase<ID extends SupportedIntegrationIds> extends
baseUrl: this.apiBaseUrl,
});
}

protected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {
return getGitHubPullRequestIdentityFromMaybeUrl(search, this.id);
}
}

export class GitHubIntegration extends GitHubIntegrationBase<HostingIntegrationId.GitHub> {
Expand Down Expand Up @@ -294,10 +299,6 @@ export class GitHubIntegration extends GitHubIntegrationBase<HostingIntegrationI
super.refresh();
}
}

protected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {
return getGitHubPullRequestIdentityFromMaybeUrl(search);
}
}

export class GitHubEnterpriseIntegration extends GitHubIntegrationBase<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ suite('Test GitHub PR URL parsing to identity: getPullRequestIdentityFromMaybeUr
: {
ownerAndRepo: ownerAndRepo,
prNumber: prNumber,
provider: 'github',
provider: undefined,
},
`Parse: ${message} (${JSON.stringify(query)})`,
);
Expand Down
22 changes: 16 additions & 6 deletions src/plus/integrations/providers/github/github.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@
// That's why this file has been created that can collect more simple functions which
// don't require Container and can be tested.

import { HostingIntegrationId } from '../../../../constants.integrations';
import type { HostingIntegrationId, SelfHostedIntegrationId } from '../../../../constants.integrations';
import type { PullRequestUrlIdentity } from '../../../../git/utils/pullRequest.utils';

export type GitHubRelatedIntegrationIds =
| HostingIntegrationId.GitHub
| SelfHostedIntegrationId.GitHubEnterprise
| SelfHostedIntegrationId.CloudGitHubEnterprise;

export function isMaybeGitHubPullRequestUrl(url: string): boolean {
if (url == null) return false;

return getGitHubPullRequestIdentityFromMaybeUrl(url) != null;
}

export function getGitHubPullRequestIdentityFromMaybeUrl(
search: string,
): (PullRequestUrlIdentity & { provider: HostingIntegrationId.GitHub }) | undefined {
): (PullRequestUrlIdentity & { provider: undefined }) | undefined;
export function getGitHubPullRequestIdentityFromMaybeUrl(
search: string,
id: GitHubRelatedIntegrationIds,
): (PullRequestUrlIdentity & { provider: GitHubRelatedIntegrationIds }) | undefined;
export function getGitHubPullRequestIdentityFromMaybeUrl(
search: string,
id?: GitHubRelatedIntegrationIds,
): (PullRequestUrlIdentity & { provider: GitHubRelatedIntegrationIds | undefined }) | undefined {
let ownerAndRepo: string | undefined = undefined;
let prNumber: string | undefined = undefined;

Expand All @@ -30,7 +42,5 @@ export function getGitHubPullRequestIdentityFromMaybeUrl(
}
}

return prNumber != null
? { ownerAndRepo: ownerAndRepo, prNumber: prNumber, provider: HostingIntegrationId.GitHub }
: undefined;
return prNumber != null ? { ownerAndRepo: ownerAndRepo, prNumber: prNumber, provider: id } : undefined;
}
13 changes: 6 additions & 7 deletions src/plus/integrations/providers/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type { IntegrationAuthenticationProviderDescriptor } from '../authenticat
import type { IntegrationAuthenticationService } from '../authentication/integrationAuthenticationService';
import type { RepositoryDescriptor } from '../integration';
import { HostingIntegration } from '../integration';
import type { GitLabRelatedIntegrationIds } from './gitlab/gitlab.utils';
import { getGitLabPullRequestIdentityFromMaybeUrl } from './gitlab/gitlab.utils';
import { fromGitLabMergeRequestProvidersApi } from './gitlab/models';
import type { ProviderRepository } from './models';
Expand All @@ -42,12 +43,10 @@ const cloudEnterpriseAuthProvider: IntegrationAuthenticationProviderDescriptor =

export type GitLabRepositoryDescriptor = RepositoryDescriptor;

abstract class GitLabIntegrationBase<
ID extends
| HostingIntegrationId.GitLab
| SelfHostedIntegrationId.GitLabSelfHosted
| SelfHostedIntegrationId.CloudGitLabSelfHosted,
> extends HostingIntegration<ID, GitLabRepositoryDescriptor> {
abstract class GitLabIntegrationBase<ID extends GitLabRelatedIntegrationIds> extends HostingIntegration<
ID,
GitLabRepositoryDescriptor
> {
protected abstract get apiBaseUrl(): string;

protected override async getProviderAccountForCommit(
Expand Down Expand Up @@ -409,7 +408,7 @@ abstract class GitLabIntegrationBase<
}

protected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {
return getGitLabPullRequestIdentityFromMaybeUrl(search);
return getGitLabPullRequestIdentityFromMaybeUrl(search, this.id);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ suite('Test GitLab PR URL parsing to identity: getPullRequestIdentityFromMaybeUr
: {
ownerAndRepo: ownerAndRepo,
prNumber: prNumber,
provider: 'gitlab',
provider: undefined,
},
`Parse: ${message} (${JSON.stringify(query)})`,
);
Expand Down
21 changes: 16 additions & 5 deletions src/plus/integrations/providers/gitlab/gitlab.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,29 @@
// That's why this file has been created that can collect more simple functions which
// don't require Container and can be tested.

import { HostingIntegrationId } from '../../../../constants.integrations';
import type { HostingIntegrationId, SelfHostedIntegrationId } from '../../../../constants.integrations';
import type { PullRequestUrlIdentity } from '../../../../git/utils/pullRequest.utils';

export type GitLabRelatedIntegrationIds =
| HostingIntegrationId.GitLab
| SelfHostedIntegrationId.GitLabSelfHosted
| SelfHostedIntegrationId.CloudGitLabSelfHosted;

export function isMaybeGitLabPullRequestUrl(url: string): boolean {
return getGitLabPullRequestIdentityFromMaybeUrl(url) != null;
}

export function getGitLabPullRequestIdentityFromMaybeUrl(
search: string,
): (PullRequestUrlIdentity & { provider: HostingIntegrationId.GitLab }) | undefined {
): (PullRequestUrlIdentity & { provider: undefined }) | undefined;
export function getGitLabPullRequestIdentityFromMaybeUrl(
search: string,
id: GitLabRelatedIntegrationIds,
): (PullRequestUrlIdentity & { provider: GitLabRelatedIntegrationIds }) | undefined;
export function getGitLabPullRequestIdentityFromMaybeUrl(
search: string,
id?: GitLabRelatedIntegrationIds,
): (PullRequestUrlIdentity & { provider: GitLabRelatedIntegrationIds | undefined }) | undefined {
let ownerAndRepo: string | undefined = undefined;
let prNumber: string | undefined = undefined;

Expand All @@ -28,7 +41,5 @@ export function getGitLabPullRequestIdentityFromMaybeUrl(
}
}

return prNumber != null
? { ownerAndRepo: ownerAndRepo, prNumber: prNumber, provider: HostingIntegrationId.GitLab }
: undefined;
return prNumber != null ? { ownerAndRepo: ownerAndRepo, prNumber: prNumber, provider: id } : undefined;
}