Skip to content

Commit

Permalink
feat: add npm_args input (#855)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous committed Mar 2, 2024
1 parent 7408afb commit 7c5b5ed
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
| default_branch | Default branch | n/a |
| commit_title | Commit and PR title | `build(deps): npm audit fix` |
| labels | PR labels | `dependencies, javascript, security` |
| npm_args | Arguments for the `npm` command | n/a |

See [`action.yml`](action.yml).

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ inputs:
description: "PR labels"
required: false
default: "dependencies, javascript, security"
npm_args:
description: "Arguments for the `npm` command"
required: false
runs:
using: "node20"
main: "dist/index.cjs"
24 changes: 13 additions & 11 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18157,7 +18157,7 @@ var require_core = __commonJS({
process.env["PATH"] = `${inputPath}${path.delimiter}${process.env["PATH"]}`;
}
exports2.addPath = addPath2;
function getInput2(name, options) {
function getInput3(name, options) {
const val = process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
if (options && options.required && !val) {
throw new Error(`Input required and not supplied: ${name}`);
Expand All @@ -18167,9 +18167,9 @@ var require_core = __commonJS({
}
return val.trim();
}
exports2.getInput = getInput2;
exports2.getInput = getInput3;
function getMultilineInput(name, options) {
const inputs = getInput2(name, options).split("\n").filter((x) => x !== "");
const inputs = getInput3(name, options).split("\n").filter((x) => x !== "");
if (options && options.trimWhitespace === false) {
return inputs;
}
Expand All @@ -18179,7 +18179,7 @@ var require_core = __commonJS({
function getBooleanInput(name, options) {
const trueValue = ["true", "True", "TRUE"];
const falseValue = ["false", "False", "FALSE"];
const val = getInput2(name, options);
const val = getInput3(name, options);
if (trueValue.includes(val))
return true;
if (falseValue.includes(val))
Expand Down Expand Up @@ -25095,8 +25095,10 @@ async function aggregateReport(audit2, beforePackages, afterPackages) {
var import_exec2 = __toESM(require_exec(), 1);

// lib/npmArgs.js
var import_core2 = __toESM(require_core(), 1);
function npmArgs(...args) {
return [...args, "--ignore-scripts", "--no-progress"];
const defaultArgs = ((0, import_core2.getInput)("npm_args") ?? "").split(/\s+/u).filter(Boolean);
return [...args, ...defaultArgs, "--ignore-scripts", "--no-progress"];
}

// lib/audit.js
Expand Down Expand Up @@ -25127,7 +25129,7 @@ async function audit(execFn = import_exec2.getExecOutput) {
}

// lib/auditFix.js
var import_core2 = __toESM(require_core(), 1);
var import_core3 = __toESM(require_core(), 1);
var import_exec3 = __toESM(require_exec(), 1);
async function auditFix() {
const { exitCode, stderr } = await (0, import_exec3.getExecOutput)("npm", npmArgs("audit", "fix"), {
Expand All @@ -25137,7 +25139,7 @@ async function auditFix() {
throw new Error("Unexpected error occurred");
}
if (exitCode !== 0) {
(0, import_core2.warning)(stderr);
(0, import_core3.warning)(stderr);
}
}

Expand Down Expand Up @@ -25267,7 +25269,7 @@ function buildPullRequestBody(report, npmVersion) {
}

// lib/createOrUpdatePullRequest.js
var import_core3 = __toESM(require_core(), 1);
var import_core4 = __toESM(require_core(), 1);
var import_exec4 = __toESM(require_exec(), 1);
var github = __toESM(require_github(), 1);

Expand Down Expand Up @@ -25322,7 +25324,7 @@ ${commitBody}`]);
title,
body: pullBody
});
(0, import_core3.info)(`The pull request was updated successfully: ${pull.html_url}`);
(0, import_core4.info)(`The pull request was updated successfully: ${pull.html_url}`);
} else {
const newPull = await octokit.rest.pulls.create({
owner,
Expand All @@ -25332,14 +25334,14 @@ ${commitBody}`]);
head: branch,
base: baseBranch
});
(0, import_core3.info)(`The pull request was created successfully: ${newPull.data.html_url}`);
(0, import_core4.info)(`The pull request was created successfully: ${newPull.data.html_url}`);
const newLabels = await octokit.rest.issues.addLabels({
owner,
repo,
issue_number: newPull.data.number,
labels
});
(0, import_core3.info)(`The labels were added successfully: ${newLabels.data.map((l) => l.name).join(", ")}`);
(0, import_core4.info)(`The labels were added successfully: ${newLabels.data.map((l) => l.name).join(", ")}`);
}
}

Expand Down
5 changes: 4 additions & 1 deletion lib/npmArgs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { getInput } from "@actions/core";

/**
* @param {string[]} args
*/
export default function npmArgs(...args) {
return [...args, "--ignore-scripts", "--no-progress"];
const defaultArgs = (getInput("npm_args") ?? "").split(/\s+/u).filter(Boolean);
return [...args, ...defaultArgs, "--ignore-scripts", "--no-progress"];
}

0 comments on commit 7c5b5ed

Please sign in to comment.