diff --git a/dev-infra/build-worker.js b/dev-infra/build-worker.js index dd7ed545d4019..66a47b1fe5ab5 100644 --- a/dev-infra/build-worker.js +++ b/dev-infra/build-worker.js @@ -205,8 +205,6 @@ var GitClient = /** @class */ (function () { */ function GitClient(githubToken, config, baseDir) { this.githubToken = githubToken; - /** Whether verbose logging of Git actions should be used. */ - this.verboseLogging = true; /** The OAuth scopes available for the provided Github token. */ this._cachedOauthScopes = null; /** @@ -254,10 +252,9 @@ var GitClient = /** @class */ (function () { } GitClient.authenticated = new GitClient(token); }; - /** Set the verbose logging state of the GitClient instance. */ - GitClient.prototype.setVerboseLoggingState = function (verbose) { + /** Set the verbose logging state of the GitClient class. */ + GitClient.setVerboseLoggingState = function (verbose) { this.verboseLogging = verbose; - return this; }; /** Executes the given git command. Throws if the command fails. */ GitClient.prototype.run = function (args, options) { @@ -283,9 +280,10 @@ var GitClient = /** @class */ (function () { throw new DryRunError(); } // To improve the debugging experience in case something fails, we print all executed Git - // commands to better understand the git actions occuring. Depending on the command being - // executed, this debugging information should be logged at different logging levels. - var printFn = (!this.verboseLogging || options.stdio === 'ignore') ? debug : info; + // commands at the DEBUG level to better understand the git actions occuring. Verbose logging, + // always logging at the INFO level, can be enabled either by setting the verboseLogging + // property on the GitClient class or the options object provided to the method. + var printFn = (GitClient.verboseLogging || options.verboseLogging) ? info : debug; // Note that we do not want to print the token if it is contained in the command. It's common // to share errors with others if the tool failed, and we do not want to leak tokens. printFn('Executing: git', this.omitGithubTokenFromMessage(args.join(' '))); @@ -424,16 +422,16 @@ var GitClient = /** @class */ (function () { }); }; GitClient.prototype.determineBaseDir = function () { - this.setVerboseLoggingState(false); var _a = this.runGraceful(['rev-parse', '--show-toplevel']), stdout = _a.stdout, stderr = _a.stderr, status = _a.status; if (status !== 0) { throw Error("Unable to find the path to the base directory of the repository.\n" + "Was the command run from inside of the repo?\n\n" + ("ERROR:\n " + stderr)); } - this.setVerboseLoggingState(true); return stdout.trim(); }; + /** Whether verbose logging of Git actions should be used. */ + GitClient.verboseLogging = false; return GitClient; }()); /** diff --git a/dev-infra/caretaker/check/check.ts b/dev-infra/caretaker/check/check.ts index c16eff89fd993..d4c4396be18fe 100644 --- a/dev-infra/caretaker/check/check.ts +++ b/dev-infra/caretaker/check/check.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import {GitClient} from '../../utils/git/index'; import {getCaretakerConfig} from '../config'; import {CiModule} from './ci'; @@ -24,8 +23,6 @@ const moduleList = [ /** Check the status of services which Angular caretakers need to monitor. */ export async function checkServiceStatuses() { - // Set the verbose logging state of the GitClient. - GitClient.getAuthenticatedInstance().setVerboseLoggingState(false); /** The configuration for the caretaker commands. */ const config = getCaretakerConfig(); /** List of instances of Caretaker Check modules */ diff --git a/dev-infra/ng-dev.js b/dev-infra/ng-dev.js index 1c5024290d8c2..9a545206963c3 100755 --- a/dev-infra/ng-dev.js +++ b/dev-infra/ng-dev.js @@ -373,8 +373,6 @@ var GitClient = /** @class */ (function () { */ function GitClient(githubToken, config, baseDir) { this.githubToken = githubToken; - /** Whether verbose logging of Git actions should be used. */ - this.verboseLogging = true; /** The OAuth scopes available for the provided Github token. */ this._cachedOauthScopes = null; /** @@ -422,10 +420,9 @@ var GitClient = /** @class */ (function () { } GitClient.authenticated = new GitClient(token); }; - /** Set the verbose logging state of the GitClient instance. */ - GitClient.prototype.setVerboseLoggingState = function (verbose) { + /** Set the verbose logging state of the GitClient class. */ + GitClient.setVerboseLoggingState = function (verbose) { this.verboseLogging = verbose; - return this; }; /** Executes the given git command. Throws if the command fails. */ GitClient.prototype.run = function (args, options) { @@ -451,9 +448,10 @@ var GitClient = /** @class */ (function () { throw new DryRunError(); } // To improve the debugging experience in case something fails, we print all executed Git - // commands to better understand the git actions occuring. Depending on the command being - // executed, this debugging information should be logged at different logging levels. - var printFn = (!this.verboseLogging || options.stdio === 'ignore') ? debug : info; + // commands at the DEBUG level to better understand the git actions occuring. Verbose logging, + // always logging at the INFO level, can be enabled either by setting the verboseLogging + // property on the GitClient class or the options object provided to the method. + var printFn = (GitClient.verboseLogging || options.verboseLogging) ? info : debug; // Note that we do not want to print the token if it is contained in the command. It's common // to share errors with others if the tool failed, and we do not want to leak tokens. printFn('Executing: git', this.omitGithubTokenFromMessage(args.join(' '))); @@ -592,16 +590,16 @@ var GitClient = /** @class */ (function () { }); }; GitClient.prototype.determineBaseDir = function () { - this.setVerboseLoggingState(false); var _a = this.runGraceful(['rev-parse', '--show-toplevel']), stdout = _a.stdout, stderr = _a.stderr, status = _a.status; if (status !== 0) { throw Error("Unable to find the path to the base directory of the repository.\n" + "Was the command run from inside of the repo?\n\n" + ("ERROR:\n " + stderr)); } - this.setVerboseLoggingState(true); return stdout.trim(); }; + /** Whether verbose logging of Git actions should be used. */ + GitClient.verboseLogging = false; return GitClient; }()); /** @@ -1541,8 +1539,6 @@ const moduleList = [ /** Check the status of services which Angular caretakers need to monitor. */ function checkServiceStatuses() { return tslib.__awaiter(this, void 0, void 0, function* () { - // Set the verbose logging state of the GitClient. - GitClient.getAuthenticatedInstance().setVerboseLoggingState(false); /** The configuration for the caretaker commands. */ const config = getCaretakerConfig(); /** List of instances of Caretaker Check modules */ diff --git a/dev-infra/utils/git/index.ts b/dev-infra/utils/git/index.ts index 353f5a891e0c1..6dfb5c1cc695e 100644 --- a/dev-infra/utils/git/index.ts +++ b/dev-infra/utils/git/index.ts @@ -34,6 +34,11 @@ export class GitCommandError extends Error { } } +/** The options available for `GitClient`'s `run` and `runGraceful` methods. */ +type GitClientRunOptions = SpawnSyncOptions&{ + verboseLogging?: boolean; +}; + /** * Common client for performing Git interactions with a given remote. * @@ -83,10 +88,15 @@ export class GitClient { GitClient.authenticated = new GitClient(token); } + /** Set the verbose logging state of the GitClient class. */ + static setVerboseLoggingState(verbose: boolean) { + this.verboseLogging = verbose; + } + + /** Whether verbose logging of Git actions should be used. */ + private static verboseLogging = false; /** The configuration, containing the github specific configuration. */ private config: NgDevConfig; - /** Whether verbose logging of Git actions should be used. */ - private verboseLogging = true; /** The OAuth scopes available for the provided Github token. */ private _cachedOauthScopes: Promise|null = null; /** @@ -124,14 +134,8 @@ export class GitClient { } } - /** Set the verbose logging state of the GitClient instance. */ - setVerboseLoggingState(verbose: boolean): this { - this.verboseLogging = verbose; - return this; - } - /** Executes the given git command. Throws if the command fails. */ - run(args: string[], options?: SpawnSyncOptions): Omit, 'status'> { + run(args: string[], options?: GitClientRunOptions): Omit, 'status'> { const result = this.runGraceful(args, options); if (result.status !== 0) { throw new GitCommandError(this, args); @@ -146,7 +150,7 @@ export class GitClient { * if there is any stderr output, the output will be printed. This makes it easier to * info failed commands. */ - runGraceful(args: string[], options: SpawnSyncOptions = {}): SpawnSyncReturns { + runGraceful(args: string[], options: GitClientRunOptions = {}): SpawnSyncReturns { /** The git command to be run. */ const gitCommand = args[0]; @@ -156,9 +160,10 @@ export class GitClient { } // To improve the debugging experience in case something fails, we print all executed Git - // commands to better understand the git actions occuring. Depending on the command being - // executed, this debugging information should be logged at different logging levels. - const printFn = (!this.verboseLogging || options.stdio === 'ignore') ? debug : info; + // commands at the DEBUG level to better understand the git actions occuring. Verbose logging, + // always logging at the INFO level, can be enabled either by setting the verboseLogging + // property on the GitClient class or the options object provided to the method. + const printFn = (GitClient.verboseLogging || options.verboseLogging) ? info : debug; // Note that we do not want to print the token if it is contained in the command. It's common // to share errors with others if the tool failed, and we do not want to leak tokens. printFn('Executing: git', this.omitGithubTokenFromMessage(args.join(' '))); @@ -321,7 +326,6 @@ export class GitClient { } private determineBaseDir() { - this.setVerboseLoggingState(false); const {stdout, stderr, status} = this.runGraceful(['rev-parse', '--show-toplevel']); if (status !== 0) { throw Error( @@ -329,7 +333,6 @@ export class GitClient { `Was the command run from inside of the repo?\n\n` + `ERROR:\n ${stderr}`); } - this.setVerboseLoggingState(true); return stdout.trim(); } }