Skip to content
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

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

- Fixes [#3938](https://github.com/gitkraken/vscode-gitlens/issues/3938) - GitLens automatically initiating an external sign-in after install on vscode.dev

#### Added

- Searches by URL for self hosted GitHub and GitLab on Launchpad

## [16.2.1] - 2025-01-21

### Fixed
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
19 changes: 13 additions & 6 deletions src/plus/integrations/providers/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import type {
IntegrationAuthenticationProviderDescriptor,
IntegrationAuthenticationService,
} from '../authentication/integrationAuthentication';
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 @@ -45,7 +46,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 @@ -267,6 +268,16 @@ abstract class GitHubIntegrationBase<ID extends SupportedIntegrationIds> extends
baseUrl: this.apiBaseUrl,
});
}

protected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {
const identity = getGitHubPullRequestIdentityFromMaybeUrl(search);
if (identity == null) return undefined;

return {
...identity,
provider: this.id,
};
}
}

export class GitHubIntegration extends GitHubIntegrationBase<HostingIntegrationId.GitHub> {
Expand Down Expand Up @@ -301,10 +312,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 @@ -12,7 +12,6 @@ suite('Test GitHub PR URL parsing to identity: getPullRequestIdentityFromMaybeUr
: {
ownerAndRepo: ownerAndRepo,
prNumber: prNumber,
provider: 'github',
},
`Parse: ${message} (${JSON.stringify(query)})`,
);
Expand Down
14 changes: 8 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,22 @@
// 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 {
): Omit<PullRequestUrlIdentity, 'provider'> | undefined {
let ownerAndRepo: string | undefined = undefined;
let prNumber: string | undefined = undefined;

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

return prNumber != null
? { ownerAndRepo: ownerAndRepo, prNumber: prNumber, provider: HostingIntegrationId.GitHub }
: undefined;
return prNumber != null ? { ownerAndRepo: ownerAndRepo, prNumber: prNumber } : undefined;
}
8 changes: 7 additions & 1 deletion src/plus/integrations/providers/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,13 @@ abstract class GitLabIntegrationBase<
}

protected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {
return getGitLabPullRequestIdentityFromMaybeUrl(search);
const identity = getGitLabPullRequestIdentityFromMaybeUrl(search);
if (identity == null) return undefined;

return {
...identity,
provider: this.id,
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ suite('Test GitLab PR URL parsing to identity: getPullRequestIdentityFromMaybeUr
: {
ownerAndRepo: ownerAndRepo,
prNumber: prNumber,
provider: 'gitlab',
},
`Parse: ${message} (${JSON.stringify(query)})`,
);
Expand Down
7 changes: 2 additions & 5 deletions src/plus/integrations/providers/gitlab/gitlab.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// 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 { PullRequestUrlIdentity } from '../../../../git/utils/pullRequest.utils';

export function isMaybeGitLabPullRequestUrl(url: string): boolean {
Expand All @@ -11,7 +10,7 @@ export function isMaybeGitLabPullRequestUrl(url: string): boolean {

export function getGitLabPullRequestIdentityFromMaybeUrl(
search: string,
): (PullRequestUrlIdentity & { provider: HostingIntegrationId.GitLab }) | undefined {
): Omit<PullRequestUrlIdentity, 'provider'> | undefined {
let ownerAndRepo: string | undefined = undefined;
let prNumber: string | undefined = undefined;

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

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