Skip to content

Commit dd4c3db

Browse files
josephperrottAndrewKushnir
authored andcommitted
refactor(dev-infra): move getRepoBaseDir() to GitClient (angular#41527)
As `getRepoBaseDir()` relies on git, it should be a method on `GitClient` for retrieval rather than its own utility outside of the common GitClient used for all git ineractions. PR Close angular#41527
1 parent 5332a4a commit dd4c3db

File tree

18 files changed

+882
-438
lines changed

18 files changed

+882
-438
lines changed

dev-infra/build-worker.js

+458-32
Large diffs are not rendered by default.

dev-infra/caretaker/check/g3.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import {SpawnSyncReturns} from 'child_process';
1010

1111
import * as console from '../../utils/console';
12-
import {GitClient} from '../../utils/git';
12+
import {GitClient} from '../../utils/git/index';
1313
import {installVirtualGitClientSpies, mockNgDevConfig} from '../../utils/testing';
1414

1515
import {G3Module, G3StatsData} from './g3';

dev-infra/caretaker/check/g3.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {existsSync, readFileSync} from 'fs';
1010
import * as multimatch from 'multimatch';
1111
import {join} from 'path';
1212
import {parse as parseYaml} from 'yaml';
13-
import {getRepoBaseDir} from '../../utils/config';
1413
import {bold, debug, error, info} from '../../utils/console';
1514

1615
import {BaseModule} from './base';
@@ -121,7 +120,7 @@ export class G3Module extends BaseModule<G3StatsData|void> {
121120

122121

123122
private getG3FileIncludeAndExcludeLists() {
124-
const angularRobotFilePath = join(getRepoBaseDir(), '.github/angular-robot.yml');
123+
const angularRobotFilePath = join(this.git.baseDir, '.github/angular-robot.yml');
125124
if (!existsSync(angularRobotFilePath)) {
126125
debug('No angular robot configuration file exists, skipping.');
127126
return null;

dev-infra/commit-message/validate-file/validate-file.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
import {readFileSync} from 'fs';
99
import {resolve} from 'path';
1010

11-
import {getRepoBaseDir} from '../../utils/config';
1211
import {error, green, info, log, red, yellow} from '../../utils/console';
12+
import {GitClient} from '../../utils/git/index';
1313

1414
import {deleteCommitMessageDraft, saveCommitMessageDraft} from '../restore-commit-message/commit-message-draft';
1515
import {printValidationErrors, validateCommitMessage} from '../validate';
1616

1717
/** Validate commit message at the provided file path. */
1818
export function validateFile(filePath: string, isErrorMode: boolean) {
19-
const commitMessage = readFileSync(resolve(getRepoBaseDir(), filePath), 'utf8');
19+
const git = GitClient.getInstance();
20+
const commitMessage = readFileSync(resolve(git.baseDir, filePath), 'utf8');
2021
const {valid, errors} = validateCommitMessage(commitMessage);
2122
if (valid) {
2223
info(`${green('√')} Valid commit message`);

dev-infra/format/cli.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import * as yargs from 'yargs';
9-
10-
import {allChangedFilesSince, allFiles, allStagedFiles} from '../utils/repo-files';
9+
import {GitClient} from '../utils/git/index';
1110

1211
import {checkFiles, formatFiles} from './format';
1312

@@ -25,21 +24,24 @@ export function buildFormatParser(localYargs: yargs.Argv) {
2524
'all', 'Run the formatter on all files in the repository', args => args,
2625
({check}) => {
2726
const executionCmd = check ? checkFiles : formatFiles;
28-
executionCmd(allFiles());
27+
const allFiles = GitClient.getInstance().allFiles();
28+
executionCmd(allFiles);
2929
})
3030
.command(
3131
'changed [shaOrRef]', 'Run the formatter on files changed since the provided sha/ref',
3232
args => args.positional('shaOrRef', {type: 'string'}),
3333
({shaOrRef, check}) => {
3434
const sha = shaOrRef || 'master';
3535
const executionCmd = check ? checkFiles : formatFiles;
36-
executionCmd(allChangedFilesSince(sha));
36+
const allChangedFilesSince = GitClient.getInstance().allChangesFilesSince(sha);
37+
executionCmd(allChangedFilesSince);
3738
})
3839
.command(
3940
'staged', 'Run the formatter on all staged files', args => args,
4041
({check}) => {
4142
const executionCmd = check ? checkFiles : formatFiles;
42-
executionCmd(allStagedFiles());
43+
const allStagedFiles = GitClient.getInstance().allStagedFiles();
44+
executionCmd(allStagedFiles);
4345
})
4446
.command(
4547
'files <files..>', 'Run the formatter on provided files',

dev-infra/format/formatters/base-formatter.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {GitClient} from '../../utils/git/index';
910
import {FormatConfig} from '../config';
1011

1112
// A callback to determine if the formatter run found a failure in formatting.
@@ -24,6 +25,7 @@ interface FormatterActionMetadata {
2425
* The base class for formatters to run against provided files.
2526
*/
2627
export abstract class Formatter {
28+
protected git = GitClient.getInstance();
2729
/**
2830
* The name of the formatter, this is used for identification in logging and for enabling and
2931
* configuring the formatter in the config.

dev-infra/format/formatters/buildifier.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import {join} from 'path';
1010

11-
import {getRepoBaseDir} from '../../utils/config';
1211
import {error} from '../../utils/console';
1312

1413
import {Formatter} from './base-formatter';
@@ -19,7 +18,7 @@ import {Formatter} from './base-formatter';
1918
export class Buildifier extends Formatter {
2019
name = 'buildifier';
2120

22-
binaryFilePath = join(getRepoBaseDir(), 'node_modules/.bin/buildifier');
21+
binaryFilePath = join(this.git.baseDir, 'node_modules/.bin/buildifier');
2322

2423
defaultFileMatcher = ['**/*.bzl', '**/BUILD.bazel', '**/WORKSPACE', '**/BUILD'];
2524

dev-infra/format/formatters/clang-format.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import {join} from 'path';
1010

11-
import {getRepoBaseDir} from '../../utils/config';
1211
import {error} from '../../utils/console';
1312

1413
import {Formatter} from './base-formatter';
@@ -19,7 +18,7 @@ import {Formatter} from './base-formatter';
1918
export class ClangFormat extends Formatter {
2019
name = 'clang-format';
2120

22-
binaryFilePath = join(getRepoBaseDir(), 'node_modules/.bin/clang-format');
21+
binaryFilePath = join(this.git.baseDir, 'node_modules/.bin/clang-format');
2322

2423
defaultFileMatcher = ['**/*.{t,j}s'];
2524

0 commit comments

Comments
 (0)