Skip to content

Commit

Permalink
Merge pull request #30 from testdriverai/yassine/add-pr-options
Browse files Browse the repository at this point in the history
Add PR options
  • Loading branch information
ianjennings authored Sep 27, 2024
2 parents e02b624 + a1dee5e commit aa3ae26
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 10 deletions.
18 changes: 18 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ inputs:
description: >-
Specify if a PR should be created with the updated test results. Defaults to "false"
default: "false"
required: false
pr-title:
description: >-
The title of the PR to be created
required: false
pr-base:
description: >-
The base branch to create the PR on.
default: main
required: false
pr-branch:
description: >-
The branch to create the PR from.
require: false
pr-test-filename:
description: >-
The filename of the test to be created in the PR.
required: false

outputs:
summary:
Expand Down
31 changes: 26 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33634,20 +33634,25 @@ const github = __nccwpck_require__(5438);

class Config {
constructor() {
const createPR = core.getInput("create-pr")?.toLowerCase()?.trim();
let createPR = core.getInput("create-pr")?.toLowerCase()?.trim() || "false";
if (!["true", "false"].includes(createPR)) {
throw new Error(
"Invalid value for create-pr input. It should be either true or false."
);
throw new Error("Invalid value for create-pr. It should be a boolean");
} else {
createPR = JSON.parse(createPR);
}

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),
createPR,
prBase: createPR ? core.getInput("pr-base") || "main" : "",
prBranch: createPR ? core.getInput("pr-branch") : "",
prTitle: createPR ? core.getInput("pr-title") : "",
prTestFilename: createPR ? core.getInput("pr-test-filename") : "",
};

// the values of github.context.repo.owner and github.context.repo.repo are taken from
Expand Down Expand Up @@ -40001,6 +40006,10 @@ const waitFor = (ms) => new Promise((r) => setTimeout(r, ms));
let os = config.input.os;
let testdriveraiVersion = config.input.version;
let createPR = config.input.createPR;
let prBranch = config.input.prBranch;
let prBase = config.input.prBase;
let prTitle = config.input.prTitle;
let prTestFilename = config.input.prTestFilename;

console.log(`testdriver@${pgkVersion}`);
console.log(`testdriver-action@${testdriverBranch}`);
Expand All @@ -40016,6 +40025,14 @@ const waitFor = (ms) => new Promise((r) => setTimeout(r, ms));
console.log(chalk.yellow("repo:"), repo);
console.log(chalk.yellow("branch:"), branch);
console.log(chalk.yellow("os:"), os);
console.log(chalk.yellow("createPR:"), createPR);
if (createPR) {
if (prBranch) console.log(chalk.yellow("prBranch:"), prBranch);
if (prBase) console.log(chalk.yellow("prBase:"), prBase);
if (prTitle) console.log(chalk.yellow("prTitle:"), prTitle);
if (prTestFilename)
console.log(chalk.yellow("prTestFilename:"), prTestFilename);
}
console.log(chalk.yellow("prompt:"));
console.log(prompt.replace(/\\n/g, "\n").replace(/\\r\\n/g, "\r\n"));
console.log(chalk.yellow("prerun:"));
Expand Down Expand Up @@ -40045,6 +40062,10 @@ const waitFor = (ms) => new Promise((r) => setTimeout(r, ms));
personalAccessToken,
testdriveraiVersion,
createPR,
prTitle,
prBase,
prBranch,
prTestFilename,
},
{
Accept: "application/json",
Expand Down
15 changes: 10 additions & 5 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@ const github = require("@actions/github");

class Config {
constructor() {
const createPR = core.getInput("create-pr")?.toLowerCase()?.trim();
let createPR = core.getInput("create-pr")?.toLowerCase()?.trim() || "false";
if (!["true", "false"].includes(createPR)) {
throw new Error(
"Invalid value for create-pr input. It should be either true or false."
);
throw new Error("Invalid value for create-pr. It should be a boolean");
} else {
createPR = JSON.parse(createPR);
}

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),
createPR,
prBase: createPR ? core.getInput("pr-base") || "main" : "",
prBranch: createPR ? core.getInput("pr-branch") : "",
prTitle: createPR ? core.getInput("pr-title") : "",
prTestFilename: createPR ? core.getInput("pr-test-filename") : "",
};

// the values of github.context.repo.owner and github.context.repo.repo are taken from
Expand Down
16 changes: 16 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const waitFor = (ms) => new Promise((r) => setTimeout(r, ms));
let os = config.input.os;
let testdriveraiVersion = config.input.version;
let createPR = config.input.createPR;
let prBranch = config.input.prBranch;
let prBase = config.input.prBase;
let prTitle = config.input.prTitle;
let prTestFilename = config.input.prTestFilename;

console.log(`testdriver@${pgkVersion}`);
console.log(`testdriver-action@${testdriverBranch}`);
Expand All @@ -51,6 +55,14 @@ const waitFor = (ms) => new Promise((r) => setTimeout(r, ms));
console.log(chalk.yellow("repo:"), repo);
console.log(chalk.yellow("branch:"), branch);
console.log(chalk.yellow("os:"), os);
console.log(chalk.yellow("createPR:"), createPR);
if (createPR) {
if (prBranch) console.log(chalk.yellow("prBranch:"), prBranch);
if (prBase) console.log(chalk.yellow("prBase:"), prBase);
if (prTitle) console.log(chalk.yellow("prTitle:"), prTitle);
if (prTestFilename)
console.log(chalk.yellow("prTestFilename:"), prTestFilename);
}
console.log(chalk.yellow("prompt:"));
console.log(prompt.replace(/\\n/g, "\n").replace(/\\r\\n/g, "\r\n"));
console.log(chalk.yellow("prerun:"));
Expand Down Expand Up @@ -84,6 +96,10 @@ const waitFor = (ms) => new Promise((r) => setTimeout(r, ms));
personalAccessToken,
testdriveraiVersion,
createPR,
prTitle,
prBase,
prBranch,
prTestFilename,
},
{
Accept: "application/json",
Expand Down

0 comments on commit aa3ae26

Please sign in to comment.