Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/src/Gren.js
Original file line number Diff line number Diff line change
Expand Up @@ -2300,10 +2300,15 @@ class Gren {
.toLowerCase()
.replace(/\w/, (a) => a.toUpperCase());
const outputs = Object.entries(options)
.filter((option) => option !== "debug")
.map(
([key, value]) => `${chalk.yellow(camelcaseToSpaces(key))}: ${value.toString() || "empty"}`,
);
.filter(([key]) => key !== "debug")
.map(([key, value]) => {
// --debug is the first thing anyone turns on in CI, and its output is the whole
// options object. A build log is not a private place to keep a credential that can
// write to the repository, so report that the token is set and not what it is.
const shown = key === "token" ? "<hidden>" : value.toString() || "empty";

return `${chalk.yellow(camelcaseToSpaces(key))}: ${shown}`;
});

process.stdout.write("\n" + chalk.blue("Options: \n") + outputs.join("\n") + "\n");
}
Expand Down
21 changes: 21 additions & 0 deletions test/Gren.membership.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,27 @@ describe("Gren release membership", () => {
assert.throws(() => createGren({ pullRequestRepos: ["just-a-name"] }), /owner\/repo/);
});

it("Should not print the token in the debug output", () => {
// --debug is the first thing anyone turns on in CI, and a build log is not a private
// place to keep a credential that can write to the repository.
const written = [];
const { write } = process.stdout;

process.stdout.write = (chunk) => written.push(String(chunk));

try {
createGren({ debug: true, token: "ghp_averysecrettoken" });
} finally {
process.stdout.write = write;
}

const output = written.join("");

assert.notInclude(output, "ghp_averysecrettoken", "The token is not in the output");
assert.include(output, "Token:", "The option is still reported");
assert.include(output, "Repo: current", "The other options are still reported");
});

it("Should reject commitNotes keys that are not commit SHAs", () => {
assert.throws(() => createGren({ commitNotes: { abc: {} } }), /at least 7 characters/);
});
Expand Down
Loading