Skip to content

Commit

Permalink
fix: move getPathOrRepoUrl from ReporterUtils to GitServiceUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
adelkahomolova committed Nov 21, 2019
1 parent 4839367 commit 2198384
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/reporters/ReporterUtils.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
20 changes: 20 additions & 0 deletions src/services/git/GitServiceUtils.ts
Original file line number Diff line number Diff line change
@@ -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') => {
Expand Down Expand Up @@ -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);
};
}

0 comments on commit 2198384

Please sign in to comment.