Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add input config for testdriver to create a PR #29

Merged
merged 2 commits into from
Sep 19, 2024
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
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ inputs:
description: >-
The version of testdriverai to run. Defaults to "latest"
required: false
create-pr:
type: boolean
description: >-
Specify if a PR should be created with the updated test results. Defaults to "false"
default: "false"

outputs:
summary:
description: >-
Expand Down
23 changes: 16 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33634,13 +33634,20 @@ const github = __nccwpck_require__(5438);

class Config {
constructor() {
const createPR = core.getInput("create-pr")?.toLowerCase()?.trim();
if (!["true", "false"].includes(createPR)) {
throw new Error(
"Invalid value for create-pr input. It should be either true or false."
);
}
this.input = {
prompt: core.getInput("prompt"),
prerun: core.getInput("prerun"),
branch: core.getInput("branch") || "main",
key: core.getInput("key"),
os: core.getInput("os") || "windows",
version: core.getInput("version") || "latest",
createPR: JSON.parse(createPR),
};

// the values of github.context.repo.owner and github.context.repo.repo are taken from
Expand Down Expand Up @@ -39993,25 +40000,26 @@ const waitFor = (ms) => new Promise((r) => setTimeout(r, ms));
let key = config.input.key;
let os = config.input.os;
let testdriveraiVersion = config.input.version;
let createPR = config.input.createPR;

console.log(`testdriver@${pgkVersion}`);
console.log(`testdriver-action@${testdriverBranch}`);

let prompt = process.env.IS_DEV
? "open youtube"
: config.input.prompt.replace(/(\r\n|\n)/g, function (match) {
return match === "\n" ? "\\n" : "\\r\\n";
});
console.log("");
console.log(chalk.green('Inputs'));
return match === "\n" ? "\\n" : "\\r\\n";
});

console.log("");
console.log(chalk.green("Inputs"));
console.log(chalk.yellow("repo:"), repo);
console.log(chalk.yellow("branch:"), branch);
console.log(chalk.yellow("os:"), os);
console.log(chalk.yellow("prompt:"));
console.log(prompt.replace(/\\n/g, '\n').replace(/\\r\\n/g, '\r\n'));
console.log(prompt.replace(/\\n/g, "\n").replace(/\\r\\n/g, "\r\n"));
console.log(chalk.yellow("prerun:"));
console.log(prerun.replace(/\\n/g, '\n').replace(/\\r\\n/g, '\r\n'));
console.log(prerun.replace(/\\n/g, "\n").replace(/\\r\\n/g, "\r\n"));
console.log("");

console.log(chalk.green("TestDriver:"), '"Looking into it..."');
Expand All @@ -40036,6 +40044,7 @@ const waitFor = (ms) => new Promise((r) => setTimeout(r, ms));
os,
personalAccessToken,
testdriveraiVersion,
createPR,
},
{
Accept: "application/json",
Expand Down
7 changes: 7 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ const github = require("@actions/github");

class Config {
constructor() {
const createPR = core.getInput("create-pr")?.toLowerCase()?.trim();
if (!["true", "false"].includes(createPR)) {
throw new Error(
"Invalid value for create-pr input. It should be either true or false."
);
}
this.input = {
prompt: core.getInput("prompt"),
prerun: core.getInput("prerun"),
branch: core.getInput("branch") || "main",
key: core.getInput("key"),
os: core.getInput("os") || "windows",
version: core.getInput("version") || "latest",
createPR: JSON.parse(createPR),
};

// the values of github.context.repo.owner and github.context.repo.repo are taken from
Expand Down
16 changes: 9 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,26 @@ const waitFor = (ms) => new Promise((r) => setTimeout(r, ms));
let key = config.input.key;
let os = config.input.os;
let testdriveraiVersion = config.input.version;
let createPR = config.input.createPR;

console.log(`testdriver@${pgkVersion}`);
console.log(`testdriver-action@${testdriverBranch}`);

let prompt = process.env.IS_DEV
? "open youtube"
: config.input.prompt.replace(/(\r\n|\n)/g, function (match) {
return match === "\n" ? "\\n" : "\\r\\n";
});
console.log("");
console.log(chalk.green('Inputs'));
return match === "\n" ? "\\n" : "\\r\\n";
});

console.log("");
console.log(chalk.green("Inputs"));
console.log(chalk.yellow("repo:"), repo);
console.log(chalk.yellow("branch:"), branch);
console.log(chalk.yellow("os:"), os);
console.log(chalk.yellow("prompt:"));
console.log(prompt.replace(/\\n/g, '\n').replace(/\\r\\n/g, '\r\n'));
console.log(prompt.replace(/\\n/g, "\n").replace(/\\r\\n/g, "\r\n"));
console.log(chalk.yellow("prerun:"));
console.log(prerun.replace(/\\n/g, '\n').replace(/\\r\\n/g, '\r\n'));
console.log(prerun.replace(/\\n/g, "\n").replace(/\\r\\n/g, "\r\n"));
console.log("");

console.log(chalk.green("TestDriver:"), '"Looking into it..."');
Expand All @@ -78,6 +79,7 @@ const waitFor = (ms) => new Promise((r) => setTimeout(r, ms));
os,
personalAccessToken,
testdriveraiVersion,
createPR,
},
{
Accept: "application/json",
Expand Down
Loading