Skip to content

Commit 2967a4a

Browse files
committed
Adds search by URL for GitLab Self Managed to the Launchpad
(#3942)
1 parent bf8bf71 commit 2967a4a

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

src/plus/integrations/providers/gitlab.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type { IntegrationAuthenticationProviderDescriptor } from '../authenticat
1717
import type { IntegrationAuthenticationService } from '../authentication/integrationAuthenticationService';
1818
import type { RepositoryDescriptor } from '../integration';
1919
import { HostingIntegration } from '../integration';
20+
import type { GitLabRelatedIntegrationIds } from './gitlab/gitlab.utils';
2021
import { getGitLabPullRequestIdentityFromMaybeUrl } from './gitlab/gitlab.utils';
2122
import { fromGitLabMergeRequestProvidersApi } from './gitlab/models';
2223
import type { ProviderRepository } from './models';
@@ -42,12 +43,10 @@ const cloudEnterpriseAuthProvider: IntegrationAuthenticationProviderDescriptor =
4243

4344
export type GitLabRepositoryDescriptor = RepositoryDescriptor;
4445

45-
abstract class GitLabIntegrationBase<
46-
ID extends
47-
| HostingIntegrationId.GitLab
48-
| SelfHostedIntegrationId.GitLabSelfHosted
49-
| SelfHostedIntegrationId.CloudGitLabSelfHosted,
50-
> extends HostingIntegration<ID, GitLabRepositoryDescriptor> {
46+
abstract class GitLabIntegrationBase<ID extends GitLabRelatedIntegrationIds> extends HostingIntegration<
47+
ID,
48+
GitLabRepositoryDescriptor
49+
> {
5150
protected abstract get apiBaseUrl(): string;
5251

5352
protected override async getProviderAccountForCommit(
@@ -409,7 +408,7 @@ abstract class GitLabIntegrationBase<
409408
}
410409

411410
protected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {
412-
return getGitLabPullRequestIdentityFromMaybeUrl(search);
411+
return getGitLabPullRequestIdentityFromMaybeUrl(search, this.id);
413412
}
414413
}
415414

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ suite('Test GitLab PR URL parsing to identity: getPullRequestIdentityFromMaybeUr
1010
: {
1111
ownerAndRepo: ownerAndRepo,
1212
prNumber: prNumber,
13-
provider: 'gitlab',
13+
provider: undefined,
1414
},
1515
`Parse: ${message} (${JSON.stringify(query)})`,
1616
);

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

+16-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,29 @@
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 GitLabRelatedIntegrationIds =
9+
| HostingIntegrationId.GitLab
10+
| SelfHostedIntegrationId.GitLabSelfHosted
11+
| SelfHostedIntegrationId.CloudGitLabSelfHosted;
12+
813
export function isMaybeGitLabPullRequestUrl(url: string): boolean {
914
return getGitLabPullRequestIdentityFromMaybeUrl(url) != null;
1015
}
1116

1217
export function getGitLabPullRequestIdentityFromMaybeUrl(
1318
search: string,
14-
): (PullRequestUrlIdentity & { provider: HostingIntegrationId.GitLab }) | undefined {
19+
): (PullRequestUrlIdentity & { provider: undefined }) | undefined;
20+
export function getGitLabPullRequestIdentityFromMaybeUrl(
21+
search: string,
22+
id: GitLabRelatedIntegrationIds,
23+
): (PullRequestUrlIdentity & { provider: GitLabRelatedIntegrationIds }) | undefined;
24+
export function getGitLabPullRequestIdentityFromMaybeUrl(
25+
search: string,
26+
id?: GitLabRelatedIntegrationIds,
27+
): (PullRequestUrlIdentity & { provider: GitLabRelatedIntegrationIds | undefined }) | undefined {
1528
let ownerAndRepo: string | undefined = undefined;
1629
let prNumber: string | undefined = undefined;
1730

@@ -28,7 +41,5 @@ export function getGitLabPullRequestIdentityFromMaybeUrl(
2841
}
2942
}
3043

31-
return prNumber != null
32-
? { ownerAndRepo: ownerAndRepo, prNumber: prNumber, provider: HostingIntegrationId.GitLab }
33-
: undefined;
44+
return prNumber != null ? { ownerAndRepo: ownerAndRepo, prNumber: prNumber, provider: id } : undefined;
3445
}

0 commit comments

Comments
 (0)