Skip to content

Commit 3cc2edd

Browse files
fgLouromtsgrd
authored andcommitted
Set gitHostFactory for gitlab self hosted instances
1 parent 0f48b53 commit 3cc2edd

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

apps/desktop/src/lib/gitHost/gitHostFactory.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { DefaultGitHostFactory } from './gitHostFactory';
22
import { GitHub } from './github/github';
3+
import { GitLab } from './gitlab/gitlab';
34
import { Octokit } from '@octokit/rest';
45
import { expect, test, describe } from 'vitest';
56

@@ -17,4 +18,33 @@ describe.concurrent('DefaultgitHostFactory', () => {
1718
)
1819
).instanceOf(GitHub);
1920
});
21+
22+
test('Create self hosted Gitlab service', async () => {
23+
const monitorFactory = new DefaultGitHostFactory(new Octokit());
24+
expect(
25+
monitorFactory.build(
26+
{
27+
source: 'domain.com',
28+
name: 'test-repo',
29+
owner: 'test-owner',
30+
resource: 'gitlab.domain.com'
31+
},
32+
'some-base'
33+
)
34+
).instanceOf(GitLab);
35+
});
36+
37+
test('Create Gitlab service', async () => {
38+
const monitorFactory = new DefaultGitHostFactory(new Octokit());
39+
expect(
40+
monitorFactory.build(
41+
{
42+
source: 'gitlab.com',
43+
name: 'test-repo',
44+
owner: 'test-owner'
45+
},
46+
'some-base'
47+
)
48+
).instanceOf(GitLab);
49+
});
2050
});

apps/desktop/src/lib/gitHost/gitHostFactory.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AZURE_DOMAIN, AzureDevOps } from './azure/azure';
22
import { BitBucket, BITBUCKET_DOMAIN } from './bitbucket/bitbucket';
33
import { GitHub, GITHUB_DOMAIN } from './github/github';
4-
import { GitLab, GITLAB_DOMAIN } from './gitlab/gitlab';
4+
import { GitLab, GITLAB_DOMAIN, GITLAB_SUB_DOMAIN } from './gitlab/gitlab';
55
import { ProjectMetrics } from '$lib/metrics/projectMetrics';
66
import type { Persisted } from '$lib/persisted/persisted';
77
import type { RepoInfo } from '$lib/url/gitUrl';
@@ -24,6 +24,7 @@ export class DefaultGitHostFactory implements GitHostFactory {
2424
usePullRequestTemplate?: Persisted<boolean>
2525
) {
2626
const source = repo.source;
27+
const resource = repo.resource;
2728
const forkStr = fork ? `${fork.owner}:${fork.name}` : undefined;
2829

2930
if (source.includes(GITHUB_DOMAIN)) {
@@ -36,7 +37,7 @@ export class DefaultGitHostFactory implements GitHostFactory {
3637
usePullRequestTemplate
3738
});
3839
}
39-
if (source.includes(GITLAB_DOMAIN)) {
40+
if (source.includes(GITLAB_DOMAIN) || resource.includes(GITLAB_SUB_DOMAIN)) {
4041
return new GitLab({ repo, baseBranch, forkStr });
4142
}
4243
if (source.includes(BITBUCKET_DOMAIN)) {

apps/desktop/src/lib/gitHost/gitlab/gitlab.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { GitLabBranch } from './gitlabBranch';
21
import type { RepoInfo } from '$lib/url/gitUrl';
32
import type { GitHost } from '../interface/gitHost';
43
import type { DetailedPullRequest, GitHostArguments } from '../interface/types';
4+
import { GitLabBranch } from './gitlabBranch';
55

66
export type PrAction = 'creating_pr';
77
export type PrState = { busy: boolean; branchId: string; action?: PrAction };
88
export type PrCacheKey = { value: DetailedPullRequest | undefined; fetchedAt: Date };
99

1010
export const GITLAB_DOMAIN = 'gitlab.com';
11+
export const GITLAB_SUB_DOMAIN = 'gitlab'; // For self hosted instance of Gitlab
1112

1213
/**
1314
* PR support is pending OAuth support in the rust code.
@@ -22,7 +23,7 @@ export class GitLab implements GitHost {
2223
private forkStr?: string;
2324

2425
constructor({ repo, baseBranch, forkStr }: GitHostArguments) {
25-
this.baseUrl = `https://${GITLAB_DOMAIN}/${repo.owner}/${repo.name}`;
26+
this.baseUrl = `https://${repo.resource}/${repo.owner}/${repo.name}`;
2627
this.repo = repo;
2728
this.baseBranch = baseBranch;
2829
this.forkStr = forkStr;

apps/desktop/src/lib/url/gitUrl.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@ export type RepoInfo = {
44
source: string;
55
name: string;
66
owner: string;
7+
resource: string;
78
organization?: string;
89
protocol?: string;
910
};
1011

1112
export function parseRemoteUrl(url: string): RepoInfo | undefined {
1213
try {
13-
const { protocol, source, name, owner, organization } = gitUrlParse(url);
14+
const { protocol, source, name, owner, organization, resource } = gitUrlParse(url);
1415

1516
return {
1617
protocol,
1718
source,
1819
name,
1920
owner,
20-
organization
21+
organization,
22+
resource
2123
};
2224
} catch {
2325
return undefined;

0 commit comments

Comments
 (0)