From 219838495437cbc4eadb6c01f704940c5ae8e55f Mon Sep 17 00:00:00 2001 From: Adela Homolova Date: Thu, 21 Nov 2019 14:05:13 +0100 Subject: [PATCH] fix: move getPathOrRepoUrl from ReporterUtils to GitServiceUtils --- src/reporters/ReporterUtils.ts | 18 +++--------------- src/services/git/GitServiceUtils.ts | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/reporters/ReporterUtils.ts b/src/reporters/ReporterUtils.ts index 760bb1ac7..22aeaba94 100644 --- a/src/reporters/ReporterUtils.ts +++ b/src/reporters/ReporterUtils.ts @@ -1,22 +1,10 @@ -import { PracticeWithContextForReporter } from './IReporter'; import _ from 'lodash'; -import { ProjectComponent, PracticeEvaluationResult, PracticeImpact, PracticeMetadata } from '../model'; -import { DXScoreResult, DXScoreOverallResult } from './model'; import { assertNever } from '../lib/assertNever'; -import { GitServiceUtils } from '../services/git/GitServiceUtils'; -import gitUrlParse from 'git-url-parse'; +import { PracticeEvaluationResult, PracticeImpact, PracticeMetadata, ProjectComponent } from '../model'; +import { PracticeWithContextForReporter } from './IReporter'; +import { DXScoreOverallResult, DXScoreResult } from './model'; export class ReporterUtils { - static getPathOrRepoUrl = (url: string, path?: string | undefined, branch = 'master') => { - const parsedUrl = gitUrlParse(url); - - if (parsedUrl.protocol === 'file') { - return url; - } - - return GitServiceUtils.getUrlToRepo(url, path, branch); - }; - static getComponentsWithPractices(practicesAndComponents: PracticeWithContextForReporter[]) { const result: { component: ProjectComponent; diff --git a/src/services/git/GitServiceUtils.ts b/src/services/git/GitServiceUtils.ts index fdc3f7138..2b94bf5c3 100644 --- a/src/services/git/GitServiceUtils.ts +++ b/src/services/git/GitServiceUtils.ts @@ -1,6 +1,8 @@ import gitUrlParse from 'git-url-parse'; import { GitService } from './model'; import { assertNever } from '../../lib/assertNever'; +import { ReporterUtils } from '../../reporters/ReporterUtils'; +import { sharedSubpath } from '../../detectors/utils'; export class GitServiceUtils { static getUrlToRepo = (url: string, path?: string | undefined, branch = 'master') => { @@ -36,4 +38,22 @@ export class GitServiceUtils { return assertNever(service); } }; + + static getRepoName = (repositoryPath: string | undefined, path: string): string => { + if (repositoryPath) { + return GitServiceUtils.getPathOrRepoUrl(repositoryPath); + } else { + return path; + } + }; + + static getPathOrRepoUrl = (url: string, path?: string | undefined, branch = 'master') => { + const parsedUrl = gitUrlParse(url); + + if (parsedUrl.protocol === 'file') { + return url; + } + + return GitServiceUtils.getUrlToRepo(url, path, branch); + }; }