feat(dev-infra): allow suppression of `GitClient`s verbose logging (#39474)
Some usages of the `GitClient` are better served by suppressing the logging of lines that express what commands are being run. Many usages of `GitClient` are contained within tools which are best served by keeping the output clean as mostly read actions are occurring. PR Close #39474
This commit is contained in:
parent
059b1ca322
commit
af8e547d86
|
@ -647,12 +647,11 @@ var GitClient = /** @class */ (function () {
|
||||||
GitClient.prototype.runGraceful = function (args, options) {
|
GitClient.prototype.runGraceful = function (args, options) {
|
||||||
if (options === void 0) { options = {}; }
|
if (options === void 0) { options = {}; }
|
||||||
// To improve the debugging experience in case something fails, we print all executed Git
|
// To improve the debugging experience in case something fails, we print all executed Git
|
||||||
// commands unless the `stdio` is explicitly set to `ignore` (which is equivalent to silent).
|
// 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 = (!GitClient.LOG_COMMANDS || options.stdio === 'ignore') ? debug : info;
|
||||||
// Note that we do not want to print the token if it is contained in the command. It's common
|
// 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.
|
// to share errors with others if the tool failed, and we do not want to leak tokens.
|
||||||
// TODO: Add support for configuring this on a per-client basis. Some tools do not want
|
|
||||||
// to print the Git command messages to the console at all (e.g. to maintain clean output).
|
|
||||||
var printFn = options.stdio !== 'ignore' ? info : debug;
|
|
||||||
printFn('Executing: git', this.omitGithubTokenFromMessage(args.join(' ')));
|
printFn('Executing: git', this.omitGithubTokenFromMessage(args.join(' ')));
|
||||||
var result = child_process.spawnSync('git', args, tslib.__assign(tslib.__assign({ cwd: this._projectRoot, stdio: 'pipe' }, options), {
|
var result = child_process.spawnSync('git', args, tslib.__assign(tslib.__assign({ cwd: this._projectRoot, stdio: 'pipe' }, options), {
|
||||||
// Encoding is always `utf8` and not overridable. This ensures that this method
|
// Encoding is always `utf8` and not overridable. This ensures that this method
|
||||||
|
|
|
@ -42,6 +42,8 @@ export class GitCommandError extends Error {
|
||||||
* the dev-infra configuration is loaded with its Github configuration.
|
* the dev-infra configuration is loaded with its Github configuration.
|
||||||
**/
|
**/
|
||||||
export class GitClient {
|
export class GitClient {
|
||||||
|
/** Whether verbose logging of Git actions should be used. */
|
||||||
|
static LOG_COMMANDS = true;
|
||||||
/** Short-hand for accessing the default remote configuration. */
|
/** Short-hand for accessing the default remote configuration. */
|
||||||
remoteConfig = this._config.github;
|
remoteConfig = this._config.github;
|
||||||
/** Octokit request parameters object for targeting the configured remote. */
|
/** Octokit request parameters object for targeting the configured remote. */
|
||||||
|
@ -88,12 +90,11 @@ export class GitClient {
|
||||||
*/
|
*/
|
||||||
runGraceful(args: string[], options: SpawnSyncOptions = {}): SpawnSyncReturns<string> {
|
runGraceful(args: string[], options: SpawnSyncOptions = {}): SpawnSyncReturns<string> {
|
||||||
// To improve the debugging experience in case something fails, we print all executed Git
|
// To improve the debugging experience in case something fails, we print all executed Git
|
||||||
// commands unless the `stdio` is explicitly set to `ignore` (which is equivalent to silent).
|
// 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 = (!GitClient.LOG_COMMANDS || options.stdio === 'ignore') ? debug : info;
|
||||||
// Note that we do not want to print the token if it is contained in the command. It's common
|
// 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.
|
// to share errors with others if the tool failed, and we do not want to leak tokens.
|
||||||
// TODO: Add support for configuring this on a per-client basis. Some tools do not want
|
|
||||||
// to print the Git command messages to the console at all (e.g. to maintain clean output).
|
|
||||||
const printFn = options.stdio !== 'ignore' ? info : debug;
|
|
||||||
printFn('Executing: git', this.omitGithubTokenFromMessage(args.join(' ')));
|
printFn('Executing: git', this.omitGithubTokenFromMessage(args.join(' ')));
|
||||||
|
|
||||||
const result = spawnSync('git', args, {
|
const result = spawnSync('git', args, {
|
||||||
|
|
Loading…
Reference in New Issue