Refactor RepoInfo type to use domain instead of source and resource

This commit is contained in:
Filipe Louro 2024-08-29 16:58:07 +02:00 committed by Mattias Granlund
parent 90bf797ad0
commit 92349391f3
10 changed files with 29 additions and 41 deletions

View File

@ -10,10 +10,9 @@ describe.concurrent('DefaultgitHostFactory', () => {
expect(
monitorFactory.build(
{
source: 'github.com',
domain: 'github.com',
name: 'test-repo',
owner: 'test-owner',
resource: 'test-resource'
owner: 'test-owner'
},
'some-base'
)
@ -25,10 +24,9 @@ describe.concurrent('DefaultgitHostFactory', () => {
expect(
monitorFactory.build(
{
source: 'domain.com',
domain: 'gitlab.domain.com',
name: 'test-repo',
owner: 'test-owner',
resource: 'gitlab.domain.com'
owner: 'test-owner'
},
'some-base'
)
@ -40,10 +38,9 @@ describe.concurrent('DefaultgitHostFactory', () => {
expect(
monitorFactory.build(
{
source: 'gitlab.com',
domain: 'gitlab.com',
name: 'test-repo',
owner: 'test-owner',
resource: 'test-resource'
owner: 'test-owner'
},
'some-base'
)

View File

@ -23,11 +23,10 @@ export class DefaultGitHostFactory implements GitHostFactory {
fork?: RepoInfo,
usePullRequestTemplate?: Persisted<boolean>
) {
const source = repo.source;
const resource = repo.resource;
const domain = repo.domain;
const forkStr = fork ? `${fork.owner}:${fork.name}` : undefined;
if (source.includes(GITHUB_DOMAIN)) {
if (domain.includes(GITHUB_DOMAIN)) {
return new GitHub({
repo,
baseBranch,
@ -37,13 +36,13 @@ export class DefaultGitHostFactory implements GitHostFactory {
usePullRequestTemplate
});
}
if (source === GITLAB_DOMAIN || resource.startsWith(GITLAB_SUB_DOMAIN + '.')) {
if (domain === GITLAB_DOMAIN || domain.startsWith(GITLAB_SUB_DOMAIN + '.')) {
return new GitLab({ repo, baseBranch, forkStr });
}
if (source.includes(BITBUCKET_DOMAIN)) {
if (domain.includes(BITBUCKET_DOMAIN)) {
return new BitBucket({ repo, baseBranch, forkStr });
}
if (source.includes(AZURE_DOMAIN)) {
if (domain.includes(AZURE_DOMAIN)) {
return new AzureDevOps({ repo, baseBranch, forkStr });
}
}

View File

@ -4,10 +4,9 @@ import { expect, test, describe } from 'vitest';
describe.concurrent('GitHub', () => {
const id = 'some-branch';
const repo = {
source: 'github.com',
domain: 'github.com',
name: 'test-repo',
owner: 'test-owner',
resource: 'test-resource'
owner: 'test-owner'
};
test('commit url', async () => {

View File

@ -6,10 +6,9 @@ describe.concurrent('GitHubBranch', () => {
const name = 'some-branch';
const baseBranch = 'some-base';
const repo = {
source: 'github.com',
domain: 'github.com',
name: 'test-repo',
owner: 'test-owner',
resource: 'test-resource'
owner: 'test-owner'
};
test('branch compare url', async () => {

View File

@ -31,10 +31,9 @@ describe('GitHubChecksMonitor', () => {
octokit = new Octokit();
gh = new GitHub({
repo: {
source: 'github.com',
domain: 'github.com',
name: 'test-repo',
owner: 'test-owner',
resource: 'test-resource'
owner: 'test-owner'
},
baseBranch: 'test-branch',
octokit

View File

@ -9,10 +9,9 @@ type PrListResponse = RestEndpointMethodTypes['pulls']['list']['response'];
describe.concurrent('GitHubListingService', () => {
const repoInfo = {
source: 'github.com',
domain: 'github.com',
name: 'test-repo',
owner: 'test-owner',
resource: 'test-resource'
owner: 'test-owner'
};
let octokit: Octokit;

View File

@ -23,10 +23,9 @@ describe.concurrent('GitHubPrMonitor', () => {
octokit = new Octokit();
gh = new GitHub({
repo: {
source: 'github.com',
domain: 'github.com',
name: 'test-repo',
owner: 'test-owner',
resource: 'test-resource'
owner: 'test-owner'
},
baseBranch: 'test-branch',
octokit

View File

@ -13,10 +13,9 @@ describe.concurrent('GitHubPrService', () => {
octokit = new Octokit();
gh = new GitHub({
repo: {
source: 'github.com',
domain: 'github.com',
name: 'test-repo',
owner: 'test-owner',
resource: 'test-resource'
owner: 'test-owner'
},
baseBranch: 'main',
octokit

View File

@ -1,7 +1,7 @@
import { GitLabBranch } from './gitlabBranch';
import type { RepoInfo } from '$lib/url/gitUrl';
import type { GitHost } from '../interface/gitHost';
import type { DetailedPullRequest, GitHostArguments } from '../interface/types';
import { GitLabBranch } from './gitlabBranch';
export type PrAction = 'creating_pr';
export type PrState = { busy: boolean; branchId: string; action?: PrAction };
@ -23,7 +23,7 @@ export class GitLab implements GitHost {
private forkStr?: string;
constructor({ repo, baseBranch, forkStr }: GitHostArguments) {
this.baseUrl = `https://${repo.resource}/${repo.owner}/${repo.name}`;
this.baseUrl = `https://${repo.domain}/${repo.owner}/${repo.name}`;
this.repo = repo;
this.baseBranch = baseBranch;
this.forkStr = forkStr;

View File

@ -1,25 +1,23 @@
import gitUrlParse from 'git-url-parse';
export type RepoInfo = {
source: string;
domain: string;
name: string;
owner: string;
resource: string;
organization?: string;
protocol?: string;
};
export function parseRemoteUrl(url: string): RepoInfo | undefined {
try {
const { protocol, source, name, owner, organization, resource } = gitUrlParse(url);
const { protocol, name, owner, organization, resource } = gitUrlParse(url);
return {
protocol,
source,
domain: resource,
name,
owner,
organization,
resource
organization
};
} catch {
return undefined;