Skip to content

Commit d68ef97

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

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

src/git/utils/pullRequest.utils.ts

+2-2
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

+13-6
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,16 @@ abstract class GitHubIntegrationBase<ID extends SupportedIntegrationIds> extends
260261
baseUrl: this.apiBaseUrl,
261262
});
262263
}
264+
265+
protected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {
266+
const identity = getGitHubPullRequestIdentityFromMaybeUrl(search);
267+
if (identity == null) return undefined;
268+
269+
return {
270+
...identity,
271+
provider: this.id,
272+
};
273+
}
263274
}
264275

265276
export class GitHubIntegration extends GitHubIntegrationBase<HostingIntegrationId.GitHub> {
@@ -294,10 +305,6 @@ export class GitHubIntegration extends GitHubIntegrationBase<HostingIntegrationI
294305
super.refresh();
295306
}
296307
}
297-
298-
protected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {
299-
return getGitHubPullRequestIdentityFromMaybeUrl(search);
300-
}
301308
}
302309

303310
export class GitHubEnterpriseIntegration extends GitHubIntegrationBase<

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

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ suite('Test GitHub PR URL parsing to identity: getPullRequestIdentityFromMaybeUr
1111
: {
1212
ownerAndRepo: ownerAndRepo,
1313
prNumber: prNumber,
14-
provider: 'github',
1514
},
1615
`Parse: ${message} (${JSON.stringify(query)})`,
1716
);

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
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+
): Omit<PullRequestUrlIdentity, 'provider'> | undefined {
1721
let ownerAndRepo: string | undefined = undefined;
1822
let prNumber: string | undefined = undefined;
1923

@@ -30,7 +34,5 @@ export function getGitHubPullRequestIdentityFromMaybeUrl(
3034
}
3135
}
3236

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

0 commit comments

Comments
 (0)