Skip to content

Commit

Permalink
fix: Sanitize inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese committed Nov 13, 2023
1 parent 26f9e3f commit beb38c8
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
const core = require("@actions/core");
const github = require("@actions/github");

const name = core.getInput("name");
const token = core.getInput("token");
const octokit = github.getOctokit(token);

const context = github.context;
const repoName = context.payload.repository.name;
const ownerName = context.payload.repository.owner.login;

let amount = core.getInput("amount");
if (amount === "" || amount === "0") amount = "1";

let owner = core.getInput("owner");
if (owner === "" || owner === "false") owner = ownerName;

let repository = core.getInput("repository");
if (repository === "" || repository === "false") repository = repoName;

const push_to_org = core.getInput("org") !== "" && core.getInput("org") !== "false";
const amount = input("amount", "1");
const push_to_org = (input("org", "") !== "");
const owner = input("owner", github.context.payload.repository.owner.login);
const repository = input("repository", github.context.payload.repository.name);

function path_() {

Expand All @@ -29,6 +18,15 @@ function path_() {

}

function input(name, def) {

let inp = core.getInput(name).trim();
if (inp === "" || inp.toLowerCase() === "false") return def;

return inp;

}

function increment(string, amount) {

// Extract string's number
Expand Down Expand Up @@ -113,9 +111,13 @@ const bootstrap = async () => {
const response = await setVariable(new_value);

if (response.status === 204) {
if (parseInt(amount, 10) === 0) {
return ("Amount was set to zero, value stays at " + old_value + ".");
}
if (parseInt(amount, 10) < 0) {
return ("Succesfully decremented " + name + " from " + old_value + " to " + new_value + ".");
} else {
}
if (parseInt(amount, 10) > 0) {
return ("Succesfully incremented " + name + " from " + old_value + " to " + new_value + ".");
}
}
Expand Down

0 comments on commit beb38c8

Please sign in to comment.