mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-11-28 13:26:16 +03:00
Refactor RepoInfo type to use domain instead of source and resource
This commit is contained in:
parent
90bf797ad0
commit
92349391f3
@ -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'
|
||||
)
|
||||
|
@ -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 });
|
||||
}
|
||||
}
|
||||
|
@ -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 () => {
|
||||
|
@ -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 () => {
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user