Skip to content

Commit bf8bf71

Browse files
committed
Adds search by URL for GitHub Enterprise to the Launchpad
(#3942)
1 parent 5592612 commit bf8bf71

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

src/git/utils/pullRequest.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { HostingIntegrationId } from '../../constants.integrations';
1+
import type { HostingIntegrationId, SelfHostedIntegrationId } from '../../constants.integrations';
22
import type {
33
PullRequest,
44
PullRequestComparisonRefs,
@@ -9,7 +9,7 @@ import type {
99
import { shortenRevision } from './revision.utils';
1010

1111
export interface PullRequestUrlIdentity {
12-
provider?: HostingIntegrationId;
12+
provider?: SelfHostedIntegrationId | HostingIntegrationId;
1313

1414
ownerAndRepo?: string;
1515
prNumber: string;

src/plus/integrations/providers/github.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import { log } from '../../../system/decorators/log';
1313
import { ensurePaidPlan } from '../../gk/utils/-webview/plus.utils';
1414
import type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider';
1515
import type { IntegrationAuthenticationService } from '../authentication/integrationAuthenticationService';
16-
import type { RepositoryDescriptor, SupportedIntegrationIds } from '../integration';
16+
import type { RepositoryDescriptor } from '../integration';
1717
import { HostingIntegration } from '../integration';
18+
import type { GitHubRelatedIntegrationIds } from './github/github.utils';
1819
import { getGitHubPullRequestIdentityFromMaybeUrl } from './github/github.utils';
1920
import { providersMetadata } from './models';
2021
import type { ProvidersApi } from './providersApi';
@@ -38,7 +39,7 @@ const cloudEnterpriseAuthProvider: IntegrationAuthenticationProviderDescriptor =
3839

3940
export type GitHubRepositoryDescriptor = RepositoryDescriptor;
4041

41-
abstract class GitHubIntegrationBase<ID extends SupportedIntegrationIds> extends HostingIntegration<
42+
abstract class GitHubIntegrationBase<ID extends GitHubRelatedIntegrationIds> extends HostingIntegration<
4243
ID,
4344
GitHubRepositoryDescriptor
4445
> {
@@ -260,6 +261,10 @@ abstract class GitHubIntegrationBase<ID extends SupportedIntegrationIds> extends
260261
baseUrl: this.apiBaseUrl,
261262
});
262263
}
264+
265+
protected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {
266+
return getGitHubPullRequestIdentityFromMaybeUrl(search, this.id);
267+
}
263268
}
264269

265270
export class GitHubIntegration extends GitHubIntegrationBase<HostingIntegrationId.GitHub> {
@@ -294,10 +299,6 @@ export class GitHubIntegration extends GitHubIntegrationBase<HostingIntegrationI
294299
super.refresh();
295300
}
296301
}
297-
298-
protected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {
299-
return getGitHubPullRequestIdentityFromMaybeUrl(search);
300-
}
301302
}
302303

303304
export class GitHubEnterpriseIntegration extends GitHubIntegrationBase<

src/plus/integrations/providers/github/__tests__/github.utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ suite('Test GitHub PR URL parsing to identity: getPullRequestIdentityFromMaybeUr
1111
: {
1212
ownerAndRepo: ownerAndRepo,
1313
prNumber: prNumber,
14-
provider: 'github',
14+
provider: undefined,
1515
},
1616
`Parse: ${message} (${JSON.stringify(query)})`,
1717
);

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,30 @@
22
// That's why this file has been created that can collect more simple functions which
33
// don't require Container and can be tested.
44

5-
import { HostingIntegrationId } from '../../../../constants.integrations';
5+
import type { HostingIntegrationId, SelfHostedIntegrationId } from '../../../../constants.integrations';
66
import type { PullRequestUrlIdentity } from '../../../../git/utils/pullRequest.utils';
77

8+
export type GitHubRelatedIntegrationIds =
9+
| HostingIntegrationId.GitHub
10+
| SelfHostedIntegrationId.GitHubEnterprise
11+
| SelfHostedIntegrationId.CloudGitHubEnterprise;
12+
813
export function isMaybeGitHubPullRequestUrl(url: string): boolean {
914
if (url == null) return false;
10-
1115
return getGitHubPullRequestIdentityFromMaybeUrl(url) != null;
1216
}
1317

1418
export function getGitHubPullRequestIdentityFromMaybeUrl(
1519
search: string,
16-
): (PullRequestUrlIdentity & { provider: HostingIntegrationId.GitHub }) | undefined {
20+
): (PullRequestUrlIdentity & { provider: undefined }) | undefined;
21+
export function getGitHubPullRequestIdentityFromMaybeUrl(
22+
search: string,
23+
id: GitHubRelatedIntegrationIds,
24+
): (PullRequestUrlIdentity & { provider: GitHubRelatedIntegrationIds }) | undefined;
25+
export function getGitHubPullRequestIdentityFromMaybeUrl(
26+
search: string,
27+
id?: GitHubRelatedIntegrationIds,
28+
): (PullRequestUrlIdentity & { provider: GitHubRelatedIntegrationIds | undefined }) | undefined {
1729
let ownerAndRepo: string | undefined = undefined;
1830
let prNumber: string | undefined = undefined;
1931

@@ -30,7 +42,5 @@ export function getGitHubPullRequestIdentityFromMaybeUrl(
3042
}
3143
}
3244

33-
return prNumber != null
34-
? { ownerAndRepo: ownerAndRepo, prNumber: prNumber, provider: HostingIntegrationId.GitHub }
35-
: undefined;
45+
return prNumber != null ? { ownerAndRepo: ownerAndRepo, prNumber: prNumber, provider: id } : undefined;
3646
}

0 commit comments

Comments
 (0)