diff --git a/dev-infra/utils/git.ts b/dev-infra/utils/git.ts index 1330ac158c..d234c1d570 100644 --- a/dev-infra/utils/git.ts +++ b/dev-infra/utils/git.ts @@ -61,11 +61,21 @@ export class GitClient { private _projectRoot = getRepoBaseDir(); /** The OAuth scopes available for the provided Github token. */ private _oauthScopes: Promise|null = null; - /** Regular expression that matches the provided Github token. */ - private _tokenRegex = new RegExp(this._githubToken, 'g'); + /** + * Regular expression that matches the provided Github token. Used for + * sanitizing the token from Git child process output. + */ + private _githubTokenRegex: RegExp|null = null; constructor( - private _githubToken = '', private _config: Pick = getConfig()) { + private _githubToken?: string, private _config: Pick = getConfig()) { + // If a token has been specified (and is not empty), pass it to the Octokit API and + // also create a regular expression that can be used for sanitizing Git command output + // so that it does not print the token accidentally. + if (_githubToken != null) { + this._githubTokenRegex = new RegExp(_githubToken, 'g'); + } + this.api = new Octokit({auth: _githubToken}); this.api.hook.error('request', error => { // Wrap API errors in a known error class. This allows us to @@ -137,7 +147,12 @@ export class GitClient { /** Sanitizes a given message by omitting the provided Github token if present. */ omitGithubTokenFromMessage(value: string): string { - return value.replace(this._tokenRegex, ''); + // If no token has been defined (i.e. no token regex), we just return the + // value as is. There is no secret value that needs to be omitted. + if (this._githubTokenRegex === null) { + return value; + } + return value.replace(this._githubTokenRegex, ''); } /** diff --git a/dev-infra/utils/shelljs.ts b/dev-infra/utils/shelljs.ts index 831dea9291..0040b4135b 100644 --- a/dev-infra/utils/shelljs.ts +++ b/dev-infra/utils/shelljs.ts @@ -8,7 +8,10 @@ import {exec as _exec, ExecOptions, ShellString} from 'shelljs'; -/* Run an exec command as silent. */ -export function exec(cmd: string, opts?: ExecOptions&{async?: false}): ShellString { - return _exec(cmd, {silent: true, ...opts}); +/** + * Runs an given command as child process. By default, child process + * output will not be printed. + */ +export function exec(cmd: string, opts?: Omit): ShellString { + return _exec(cmd, {silent: true, ...opts, async: false}); }