Skip to content

Commit 7134b9c

Browse files
committed
Adds search by URL for GitHub Enterprise to the Launchpad
(#3901)
1 parent c1e45f8 commit 7134b9c

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

Diff for: src/git/models/pullRequest.utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// To avoid this file has been created that can collect more simple functions which
33
// don't require Container and can be tested.
44

5-
import type { HostingIntegrationId } from '../../constants.integrations';
5+
import type { HostingIntegrationId, SelfHostedIntegrationId } from '../../constants.integrations';
66

77
export interface PullRequestUrlIdentity {
8-
provider?: HostingIntegrationId;
8+
provider?: SelfHostedIntegrationId | HostingIntegrationId;
99

1010
ownerAndRepo?: string;
1111
prNumber: string;

Diff for: src/plus/integrations/providers/github.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import type {
1919
IntegrationAuthenticationProviderDescriptor,
2020
IntegrationAuthenticationService,
2121
} from '../authentication/integrationAuthentication';
22-
import type { RepositoryDescriptor, SupportedIntegrationIds } from '../integration';
22+
import type { RepositoryDescriptor } from '../integration';
2323
import { HostingIntegration } from '../integration';
24+
import type { GitHubRelatedIntegrationIds } from './github/github.utils';
2425
import { getGitHubPullRequestIdentityFromMaybeUrl } from './github/github.utils';
2526
import { providersMetadata } from './models';
2627
import type { ProvidersApi } from './providersApi';
@@ -44,7 +45,7 @@ const cloudEnterpriseAuthProvider: IntegrationAuthenticationProviderDescriptor =
4445

4546
export type GitHubRepositoryDescriptor = RepositoryDescriptor;
4647

47-
abstract class GitHubIntegrationBase<ID extends SupportedIntegrationIds> extends HostingIntegration<
48+
abstract class GitHubIntegrationBase<ID extends GitHubRelatedIntegrationIds> extends HostingIntegration<
4849
ID,
4950
GitHubRepositoryDescriptor
5051
> {
@@ -266,6 +267,16 @@ abstract class GitHubIntegrationBase<ID extends SupportedIntegrationIds> extends
266267
baseUrl: this.apiBaseUrl,
267268
});
268269
}
270+
271+
protected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {
272+
const identity = getGitHubPullRequestIdentityFromMaybeUrl(search);
273+
if (identity == null) return undefined;
274+
275+
return {
276+
...identity,
277+
provider: this.id,
278+
};
279+
}
269280
}
270281

271282
export class GitHubIntegration extends GitHubIntegrationBase<HostingIntegrationId.GitHub> {
@@ -300,10 +311,6 @@ export class GitHubIntegration extends GitHubIntegrationBase<HostingIntegrationI
300311
super.refresh();
301312
}
302313
}
303-
304-
protected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {
305-
return getGitHubPullRequestIdentityFromMaybeUrl(search);
306-
}
307314
}
308315

309316
export class GitHubEnterpriseIntegration extends GitHubIntegrationBase<

Diff for: src/plus/integrations/providers/github/__tests__/github.utils.test.ts

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

Diff for: 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/models/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)