From c3187e940021f7d7a6dc82a1642863be26ff1b2b Mon Sep 17 00:00:00 2001 From: Matheus Marchini Date: Fri, 26 Jun 2020 18:39:00 -0700 Subject: [PATCH] feat: set error code in some failure cases Adds an method to `cli` to set the process exit code, and use that method on some known failure situations (missing config and `git node land` failed checks). There are still more places where we should set exit code. Ref: https://github.com/nodejs/node-core-utils/issues/442 --- lib/cli.js | 4 ++++ lib/landing_session.js | 1 + lib/session.js | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/lib/cli.js b/lib/cli.js index 5589e5b4..7e8611b8 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -164,6 +164,10 @@ class CLI { this.log(prefix + chalk.bold(`${error} ${obj}`)); } } + + setExitCode(statusCode) { + process.exitCode = statusCode; + } }; CLI.SPINNER_STATUS = SPINNER_STATUS; diff --git a/lib/landing_session.js b/lib/landing_session.js index 601640ec..0b7e191b 100644 --- a/lib/landing_session.js +++ b/lib/landing_session.js @@ -53,6 +53,7 @@ class LandingSession extends Session { await this.tryResetBranch(); } cli.ok(`Aborted \`git node land\` session in ${this.ncuDir}`); + cli.setExitCode(1); } async downloadAndPatch() { diff --git a/lib/session.js b/lib/session.js index 02d07c1a..4e107d84 100644 --- a/lib/session.js +++ b/lib/session.js @@ -35,6 +35,7 @@ class Session { if (!new RegExp(`${owner}/${repo}(?:.git)?$`).test(upstreamHref)) { cli.warn('Remote repository URL does not point to the expected ' + `repository ${owner}/${repo}`); + cli.setExitCode(1); } } @@ -343,6 +344,7 @@ class Session { '`master` branch, you can run:\n\n' + ' $ ncu-config set branch master'); cli.separator(); + cli.setExitCode(1); } if (!upstream) { cli.warn('You have not told git-node the remote you want to sync with.'); @@ -352,6 +354,7 @@ class Session { ' `remote-upstream`, you can run:\n\n' + ' $ ncu-config set upstream remote-upstream'); cli.separator(); + cli.setExitCode(1); } return missing; } @@ -363,6 +366,7 @@ class Session { cli.warn( 'You are in detached HEAD state. Please run git-node on a valid ' + 'branch'); + cli.setExitCode(1); return true; } if (rev === branch) { @@ -377,6 +381,7 @@ class Session { ' reconfigure the target branch with:\n\n' + ` $ ncu-config set branch ${rev}`); cli.separator(); + cli.setExitCode(1); return true; // TODO warn if backporting onto master branch }