Skip to content

Commit 9234939

Browse files
fgLouromtsgrd
authored andcommitted
Refactor RepoInfo type to use domain instead of source and resource
1 parent 90bf797 commit 9234939

File tree

10 files changed

+29
-41
lines changed

10 files changed

+29
-41
lines changed

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ describe.concurrent('DefaultgitHostFactory', () => {
1010
expect(
1111
monitorFactory.build(
1212
{
13-
source: 'github.com',
13+
domain: 'github.com',
1414
name: 'test-repo',
15-
owner: 'test-owner',
16-
resource: 'test-resource'
15+
owner: 'test-owner'
1716
},
1817
'some-base'
1918
)
@@ -25,10 +24,9 @@ describe.concurrent('DefaultgitHostFactory', () => {
2524
expect(
2625
monitorFactory.build(
2726
{
28-
source: 'domain.com',
27+
domain: 'gitlab.domain.com',
2928
name: 'test-repo',
30-
owner: 'test-owner',
31-
resource: 'gitlab.domain.com'
29+
owner: 'test-owner'
3230
},
3331
'some-base'
3432
)
@@ -40,10 +38,9 @@ describe.concurrent('DefaultgitHostFactory', () => {
4038
expect(
4139
monitorFactory.build(
4240
{
43-
source: 'gitlab.com',
41+
domain: 'gitlab.com',
4442
name: 'test-repo',
45-
owner: 'test-owner',
46-
resource: 'test-resource'
43+
owner: 'test-owner'
4744
},
4845
'some-base'
4946
)

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ export class DefaultGitHostFactory implements GitHostFactory {
2323
fork?: RepoInfo,
2424
usePullRequestTemplate?: Persisted<boolean>
2525
) {
26-
const source = repo.source;
27-
const resource = repo.resource;
26+
const domain = repo.domain;
2827
const forkStr = fork ? `${fork.owner}:${fork.name}` : undefined;
2928

30-
if (source.includes(GITHUB_DOMAIN)) {
29+
if (domain.includes(GITHUB_DOMAIN)) {
3130
return new GitHub({
3231
repo,
3332
baseBranch,
@@ -37,13 +36,13 @@ export class DefaultGitHostFactory implements GitHostFactory {
3736
usePullRequestTemplate
3837
});
3938
}
40-
if (source === GITLAB_DOMAIN || resource.startsWith(GITLAB_SUB_DOMAIN + '.')) {
39+
if (domain === GITLAB_DOMAIN || domain.startsWith(GITLAB_SUB_DOMAIN + '.')) {
4140
return new GitLab({ repo, baseBranch, forkStr });
4241
}
43-
if (source.includes(BITBUCKET_DOMAIN)) {
42+
if (domain.includes(BITBUCKET_DOMAIN)) {
4443
return new BitBucket({ repo, baseBranch, forkStr });
4544
}
46-
if (source.includes(AZURE_DOMAIN)) {
45+
if (domain.includes(AZURE_DOMAIN)) {
4746
return new AzureDevOps({ repo, baseBranch, forkStr });
4847
}
4948
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import { expect, test, describe } from 'vitest';
44
describe.concurrent('GitHub', () => {
55
const id = 'some-branch';
66
const repo = {
7-
source: 'github.com',
7+
domain: 'github.com',
88
name: 'test-repo',
9-
owner: 'test-owner',
10-
resource: 'test-resource'
9+
owner: 'test-owner'
1110
};
1211

1312
test('commit url', async () => {

apps/desktop/src/lib/gitHost/github/githubBranch.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ describe.concurrent('GitHubBranch', () => {
66
const name = 'some-branch';
77
const baseBranch = 'some-base';
88
const repo = {
9-
source: 'github.com',
9+
domain: 'github.com',
1010
name: 'test-repo',
11-
owner: 'test-owner',
12-
resource: 'test-resource'
11+
owner: 'test-owner'
1312
};
1413

1514
test('branch compare url', async () => {

apps/desktop/src/lib/gitHost/github/githubChecksMonitor.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ describe('GitHubChecksMonitor', () => {
3131
octokit = new Octokit();
3232
gh = new GitHub({
3333
repo: {
34-
source: 'github.com',
34+
domain: 'github.com',
3535
name: 'test-repo',
36-
owner: 'test-owner',
37-
resource: 'test-resource'
36+
owner: 'test-owner'
3837
},
3938
baseBranch: 'test-branch',
4039
octokit

apps/desktop/src/lib/gitHost/github/githubListingService.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ type PrListResponse = RestEndpointMethodTypes['pulls']['list']['response'];
99

1010
describe.concurrent('GitHubListingService', () => {
1111
const repoInfo = {
12-
source: 'github.com',
12+
domain: 'github.com',
1313
name: 'test-repo',
14-
owner: 'test-owner',
15-
resource: 'test-resource'
14+
owner: 'test-owner'
1615
};
1716

1817
let octokit: Octokit;

apps/desktop/src/lib/gitHost/github/githubPrMonitor.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ describe.concurrent('GitHubPrMonitor', () => {
2323
octokit = new Octokit();
2424
gh = new GitHub({
2525
repo: {
26-
source: 'github.com',
26+
domain: 'github.com',
2727
name: 'test-repo',
28-
owner: 'test-owner',
29-
resource: 'test-resource'
28+
owner: 'test-owner'
3029
},
3130
baseBranch: 'test-branch',
3231
octokit

apps/desktop/src/lib/gitHost/github/githubPrService.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ describe.concurrent('GitHubPrService', () => {
1313
octokit = new Octokit();
1414
gh = new GitHub({
1515
repo: {
16-
source: 'github.com',
16+
domain: 'github.com',
1717
name: 'test-repo',
18-
owner: 'test-owner',
19-
resource: 'test-resource'
18+
owner: 'test-owner'
2019
},
2120
baseBranch: 'main',
2221
octokit

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { GitLabBranch } from './gitlabBranch';
12
import type { RepoInfo } from '$lib/url/gitUrl';
23
import type { GitHost } from '../interface/gitHost';
34
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 };
@@ -23,7 +23,7 @@ export class GitLab implements GitHost {
2323
private forkStr?: string;
2424

2525
constructor({ repo, baseBranch, forkStr }: GitHostArguments) {
26-
this.baseUrl = `https://${repo.resource}/${repo.owner}/${repo.name}`;
26+
this.baseUrl = `https://${repo.domain}/${repo.owner}/${repo.name}`;
2727
this.repo = repo;
2828
this.baseBranch = baseBranch;
2929
this.forkStr = forkStr;

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
import gitUrlParse from 'git-url-parse';
22

33
export type RepoInfo = {
4-
source: string;
4+
domain: string;
55
name: string;
66
owner: string;
7-
resource: string;
87
organization?: string;
98
protocol?: string;
109
};
1110

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

1615
return {
1716
protocol,
18-
source,
17+
domain: resource,
1918
name,
2019
owner,
21-
organization,
22-
resource
20+
organization
2321
};
2422
} catch {
2523
return undefined;

0 commit comments

Comments
 (0)