Skip to content

Commit ea81553

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

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-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: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import type {
2020
IntegrationAuthenticationProviderDescriptor,
2121
IntegrationAuthenticationService,
2222
} from '../authentication/integrationAuthentication';
23-
import type { RepositoryDescriptor, SupportedIntegrationIds } from '../integration';
23+
import type { RepositoryDescriptor } from '../integration';
2424
import { HostingIntegration } from '../integration';
25+
import type { GitHubRelatedIntegrationIds } from './github/github.utils';
2526
import { getGitHubPullRequestIdentityFromMaybeUrl } from './github/github.utils';
2627
import { providersMetadata } from './models';
2728
import type { ProvidersApi } from './providersApi';
@@ -45,7 +46,7 @@ const cloudEnterpriseAuthProvider: IntegrationAuthenticationProviderDescriptor =
4546

4647
export type GitHubRepositoryDescriptor = RepositoryDescriptor;
4748

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

272283
export class GitHubIntegration extends GitHubIntegrationBase<HostingIntegrationId.GitHub> {
@@ -301,10 +312,6 @@ export class GitHubIntegration extends GitHubIntegrationBase<HostingIntegrationI
301312
super.refresh();
302313
}
303314
}
304-
305-
protected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {
306-
return getGitHubPullRequestIdentityFromMaybeUrl(search);
307-
}
308315
}
309316

310317
export class GitHubEnterpriseIntegration extends GitHubIntegrationBase<

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

Lines changed: 0 additions & 1 deletion
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
);

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

Lines changed: 8 additions & 6 deletions
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)