Skip to content

Commit

Permalink
Merge pull request #29 from testdriverai/yassine/add-option-to-create-pr
Browse files Browse the repository at this point in the history
Add input config for testdriver to create a PR
  • Loading branch information
ianjennings authored Sep 19, 2024
2 parents 757c5a4 + 6e2e519 commit 056f330
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
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

0 comments on commit 056f330

Please sign in to comment.