From 711b2b7d826dc606df651e36d9b3ed338b190f81 Mon Sep 17 00:00:00 2001 From: Sergei Shmakov Date: Fri, 17 Jan 2025 03:09:29 +0100 Subject: [PATCH 1/3] Adds search by URL for GitHub Enterprise to the Launchpad (#3942) --- src/git/utils/pullRequest.utils.ts | 4 ++-- src/plus/integrations/providers/github.ts | 13 ++++++----- .../github/__tests__/github.utils.test.ts | 2 +- .../providers/github/github.utils.ts | 22 ++++++++++++++----- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/git/utils/pullRequest.utils.ts b/src/git/utils/pullRequest.utils.ts index 5eaae38f5ce0d..9ef568c1e5dd4 100644 --- a/src/git/utils/pullRequest.utils.ts +++ b/src/git/utils/pullRequest.utils.ts @@ -1,4 +1,4 @@ -import type { HostingIntegrationId } from '../../constants.integrations'; +import type { HostingIntegrationId, SelfHostedIntegrationId } from '../../constants.integrations'; import type { PullRequest, PullRequestComparisonRefs, @@ -9,7 +9,7 @@ import type { import { shortenRevision } from './revision.utils'; export interface PullRequestUrlIdentity { - provider?: HostingIntegrationId; + provider?: SelfHostedIntegrationId | HostingIntegrationId; ownerAndRepo?: string; prNumber: string; diff --git a/src/plus/integrations/providers/github.ts b/src/plus/integrations/providers/github.ts index 097f30fc2f28a..054a15693357a 100644 --- a/src/plus/integrations/providers/github.ts +++ b/src/plus/integrations/providers/github.ts @@ -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'; @@ -38,7 +39,7 @@ const cloudEnterpriseAuthProvider: IntegrationAuthenticationProviderDescriptor = export type GitHubRepositoryDescriptor = RepositoryDescriptor; -abstract class GitHubIntegrationBase extends HostingIntegration< +abstract class GitHubIntegrationBase extends HostingIntegration< ID, GitHubRepositoryDescriptor > { @@ -260,6 +261,10 @@ abstract class GitHubIntegrationBase extends baseUrl: this.apiBaseUrl, }); } + + protected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined { + return getGitHubPullRequestIdentityFromMaybeUrl(search, this.id); + } } export class GitHubIntegration extends GitHubIntegrationBase { @@ -294,10 +299,6 @@ export class GitHubIntegration extends GitHubIntegrationBase Date: Fri, 17 Jan 2025 03:29:47 +0100 Subject: [PATCH 2/3] Adds search by URL for GitLab Self Managed to the Launchpad (#3942) --- src/plus/integrations/providers/gitlab.ts | 13 ++++++------ .../gitlab/__tests__/gitlab.utils.test.ts | 2 +- .../providers/gitlab/gitlab.utils.ts | 21 ++++++++++++++----- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/plus/integrations/providers/gitlab.ts b/src/plus/integrations/providers/gitlab.ts index 0f60ba43dec44..cb6ff2968b812 100644 --- a/src/plus/integrations/providers/gitlab.ts +++ b/src/plus/integrations/providers/gitlab.ts @@ -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'; @@ -42,12 +43,10 @@ const cloudEnterpriseAuthProvider: IntegrationAuthenticationProviderDescriptor = export type GitLabRepositoryDescriptor = RepositoryDescriptor; -abstract class GitLabIntegrationBase< - ID extends - | HostingIntegrationId.GitLab - | SelfHostedIntegrationId.GitLabSelfHosted - | SelfHostedIntegrationId.CloudGitLabSelfHosted, -> extends HostingIntegration { +abstract class GitLabIntegrationBase extends HostingIntegration< + ID, + GitLabRepositoryDescriptor +> { protected abstract get apiBaseUrl(): string; protected override async getProviderAccountForCommit( @@ -409,7 +408,7 @@ abstract class GitLabIntegrationBase< } protected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined { - return getGitLabPullRequestIdentityFromMaybeUrl(search); + return getGitLabPullRequestIdentityFromMaybeUrl(search, this.id); } } diff --git a/src/plus/integrations/providers/gitlab/__tests__/gitlab.utils.test.ts b/src/plus/integrations/providers/gitlab/__tests__/gitlab.utils.test.ts index 9e6699586080c..45b17593b483b 100644 --- a/src/plus/integrations/providers/gitlab/__tests__/gitlab.utils.test.ts +++ b/src/plus/integrations/providers/gitlab/__tests__/gitlab.utils.test.ts @@ -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)})`, ); diff --git a/src/plus/integrations/providers/gitlab/gitlab.utils.ts b/src/plus/integrations/providers/gitlab/gitlab.utils.ts index e3757895d664b..ef4a37a40b29e 100644 --- a/src/plus/integrations/providers/gitlab/gitlab.utils.ts +++ b/src/plus/integrations/providers/gitlab/gitlab.utils.ts @@ -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; @@ -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; } From 2148232aea76f54c335e4ad250eb9aa60e571a74 Mon Sep 17 00:00:00 2001 From: Sergei Shmakov Date: Thu, 23 Jan 2025 12:23:01 +0100 Subject: [PATCH 3/3] Mentions search by URL in changelog (#3942) --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78ecc96659f2d..8514f386772d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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