Skip to content

Commit

Permalink
fix(ng-dev): do not print git client command stderr on success
Browse files Browse the repository at this point in the history
The comment and the logic seem to contradict a little. This commit
fixes this, allowing for cleaner console output unless explicitly
printed through e.g. `stdio: 'inherit'
  • Loading branch information
devversion committed Mar 27, 2022
1 parent 87e5ec9 commit 72fcac4
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 84 deletions.
6 changes: 3 additions & 3 deletions github-actions/commit-message-based-labels/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48660,10 +48660,10 @@ var require_git_client = __commonJS({
"use strict";
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.GitClient = exports2.GitCommandError = void 0;
var child_process_1 = require("child_process");
var dry_run_1 = require_dry_run();
var config_12 = require_config2();
var child_process_1 = require("child_process");
var console_1 = require_console();
var dry_run_1 = require_dry_run();
var github_12 = require_github2();
var github_urls_1 = require_github_urls();
var GitCommandError = class extends Error {
Expand Down Expand Up @@ -48704,7 +48704,7 @@ var require_git_client = __commonJS({
}, options), {
encoding: "utf8"
}));
if (result.stderr !== null) {
if (result.status !== 0 && result.stderr !== null) {
process.stderr.write(this.sanitizeConsoleOutput(result.stderr));
}
if (result.error !== void 0) {
Expand Down
76 changes: 38 additions & 38 deletions github-actions/slash-commands/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -53842,6 +53842,39 @@ var require_inquirer = __commonJS({
}
});

//
var require_dry_run = __commonJS({
""(exports2) {
"use strict";
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.DryRunError = exports2.isDryRun = exports2.addDryRunFlag = void 0;
function addDryRunFlag(args) {
return args.option("dry-run", {
type: "boolean",
default: false,
description: "Whether to do a dry run",
coerce: (dryRun) => {
if (dryRun) {
process.env["DRY_RUN"] = "1";
}
return dryRun;
}
});
}
exports2.addDryRunFlag = addDryRunFlag;
function isDryRun() {
return process.env["DRY_RUN"] !== void 0;
}
exports2.isDryRun = isDryRun;
var DryRunError = class extends Error {
constructor() {
super("Cannot call this function in dryRun mode.");
}
};
exports2.DryRunError = DryRunError;
}
});

//
var require_ts_node = __commonJS({
""(exports2) {
Expand Down Expand Up @@ -53955,39 +53988,6 @@ var require_config2 = __commonJS({
}
});

//
var require_dry_run = __commonJS({
""(exports2) {
"use strict";
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.DryRunError = exports2.isDryRun = exports2.addDryRunFlag = void 0;
function addDryRunFlag(args) {
return args.option("dry-run", {
type: "boolean",
default: false,
description: "Whether to do a dry run",
coerce: (dryRun) => {
if (dryRun) {
process.env["DRY_RUN"] = "1";
}
return dryRun;
}
});
}
exports2.addDryRunFlag = addDryRunFlag;
function isDryRun() {
return process.env["DRY_RUN"] !== void 0;
}
exports2.isDryRun = isDryRun;
var DryRunError = class extends Error {
constructor() {
super("Cannot call this function in dryRun mode.");
}
};
exports2.DryRunError = DryRunError;
}
});

//
var require_dist = __commonJS({
""(exports2) {
Expand Down Expand Up @@ -54361,10 +54361,10 @@ var require_git_client = __commonJS({
"use strict";
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.GitClient = exports2.GitCommandError = void 0;
var child_process_1 = require("child_process");
var dry_run_1 = require_dry_run();
var config_1 = require_config2();
var child_process_1 = require("child_process");
var console_1 = require_console();
var dry_run_1 = require_dry_run();
var github_12 = require_github2();
var github_urls_1 = require_github_urls();
var GitCommandError = class extends Error {
Expand Down Expand Up @@ -54405,7 +54405,7 @@ var require_git_client = __commonJS({
}, options), {
encoding: "utf8"
}));
if (result.stderr !== null) {
if (result.status !== 0 && result.stderr !== null) {
process.stderr.write(this.sanitizeConsoleOutput(result.stderr));
}
if (result.error !== void 0) {
Expand Down Expand Up @@ -54671,13 +54671,13 @@ Alternatively, a new token can be created at: ${github_urls_1.GITHUB_TOKEN_GENER
return { error };
}
async getForkOfAuthenticatedUser() {
const forks = await this.getForksForAuthenticatedUser();
const forks = await this.getAllForksOfAuthenticatedUser();
if (forks.length === 0) {
throw Error("Unable to find fork a for currently authenticated user.");
}
return forks[0];
}
async getForksForAuthenticatedUser() {
async getAllForksOfAuthenticatedUser() {
if (this._cachedForkRepositories !== null) {
return this._cachedForkRepositories;
}
Expand Down
9 changes: 4 additions & 5 deletions ng-dev/utils/git/git-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
* found in the LICENSE file at https://angular.io/license
*/

import {spawnSync, SpawnSyncOptions, SpawnSyncReturns} from 'child_process';

import {getConfig, GithubConfig, assertValidGithubConfig} from '../config';
import {debug, info} from '../console';
import {DryRunError, isDryRun} from '../dry-run';
import {GithubConfig, assertValidGithubConfig, getConfig} from '../config';
import {SpawnSyncOptions, SpawnSyncReturns, spawnSync} from 'child_process';
import {debug, info} from '../console';

import {GithubClient} from './github';
import {getRepositoryGitUrl} from './github-urls';
Expand Down Expand Up @@ -112,7 +111,7 @@ export class GitClient {
encoding: 'utf8',
});

if (result.stderr !== null) {
if (result.status !== 0 && result.stderr !== null) {
// Git sometimes prints the command if it failed. This means that it could
// potentially leak the Github token used for accessing the remote. To avoid
// printing a token, we sanitize the string before printing the stderr output.
Expand Down
76 changes: 38 additions & 38 deletions tools/local-actions/changelog/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -45199,6 +45199,39 @@ var require_inquirer = __commonJS({
}
});

//
var require_dry_run = __commonJS({
""(exports2) {
"use strict";
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.DryRunError = exports2.isDryRun = exports2.addDryRunFlag = void 0;
function addDryRunFlag(args) {
return args.option("dry-run", {
type: "boolean",
default: false,
description: "Whether to do a dry run",
coerce: (dryRun) => {
if (dryRun) {
process.env["DRY_RUN"] = "1";
}
return dryRun;
}
});
}
exports2.addDryRunFlag = addDryRunFlag;
function isDryRun() {
return process.env["DRY_RUN"] !== void 0;
}
exports2.isDryRun = isDryRun;
var DryRunError = class extends Error {
constructor() {
super("Cannot call this function in dryRun mode.");
}
};
exports2.DryRunError = DryRunError;
}
});

//
var require_ts_node = __commonJS({
""(exports2) {
Expand Down Expand Up @@ -45312,39 +45345,6 @@ var require_config2 = __commonJS({
}
});

//
var require_dry_run = __commonJS({
""(exports2) {
"use strict";
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.DryRunError = exports2.isDryRun = exports2.addDryRunFlag = void 0;
function addDryRunFlag(args) {
return args.option("dry-run", {
type: "boolean",
default: false,
description: "Whether to do a dry run",
coerce: (dryRun) => {
if (dryRun) {
process.env["DRY_RUN"] = "1";
}
return dryRun;
}
});
}
exports2.addDryRunFlag = addDryRunFlag;
function isDryRun() {
return process.env["DRY_RUN"] !== void 0;
}
exports2.isDryRun = isDryRun;
var DryRunError = class extends Error {
constructor() {
super("Cannot call this function in dryRun mode.");
}
};
exports2.DryRunError = DryRunError;
}
});

//
var require_dist_node11 = __commonJS({
""(exports2) {
Expand Down Expand Up @@ -45761,10 +45761,10 @@ var require_git_client = __commonJS({
"use strict";
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.GitClient = exports2.GitCommandError = void 0;
var child_process_1 = require("child_process");
var dry_run_1 = require_dry_run();
var config_12 = require_config2();
var child_process_1 = require("child_process");
var console_1 = require_console();
var dry_run_1 = require_dry_run();
var github_12 = require_github2();
var github_urls_1 = require_github_urls();
var GitCommandError = class extends Error {
Expand Down Expand Up @@ -45805,7 +45805,7 @@ var require_git_client = __commonJS({
}, options), {
encoding: "utf8"
}));
if (result.stderr !== null) {
if (result.status !== 0 && result.stderr !== null) {
process.stderr.write(this.sanitizeConsoleOutput(result.stderr));
}
if (result.error !== void 0) {
Expand Down Expand Up @@ -54698,13 +54698,13 @@ Alternatively, a new token can be created at: ${github_urls_1.GITHUB_TOKEN_GENER
return { error };
}
async getForkOfAuthenticatedUser() {
const forks = await this.getForksForAuthenticatedUser();
const forks = await this.getAllForksOfAuthenticatedUser();
if (forks.length === 0) {
throw Error("Unable to find fork a for currently authenticated user.");
}
return forks[0];
}
async getForksForAuthenticatedUser() {
async getAllForksOfAuthenticatedUser() {
if (this._cachedForkRepositories !== null) {
return this._cachedForkRepositories;
}
Expand Down

0 comments on commit 72fcac4

Please sign in to comment.