Skip to content

Commit

Permalink
Add pr options
Browse files Browse the repository at this point in the history
  • Loading branch information
yassine-cc committed Sep 27, 2024
1 parent 056f330 commit 299b428
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 10 deletions.
17 changes: 17 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ 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.
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
49 changes: 44 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33634,11 +33634,11 @@ 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"),
Expand All @@ -33647,9 +33647,30 @@ class Config {
key: core.getInput("key"),
os: core.getInput("os") || "windows",
version: core.getInput("version") || "latest",
createPR: JSON.parse(createPR),
createPR,
prBranch: createPR ? core.getInput("pr-branch") : "",
prBase: createPR ? core.getInput("pr-base") : "",
prTitle: createPR ? core.getInput("pr-title") : "",
prTestFilename: createPR ? core.getInput("pr-test-filename") : "",
};

if (createPR) {
if (!this.input.prBranch) {
throw new Error("'pr-branch' is required when 'create-pr' is 'true'");
}
if (!this.input.prBase) {
throw new Error("'pr-base' is required when 'create-pr' is 'true'");
}
if (!this.input.prTitle) {
throw new Error("'pr-title' is required when 'create-pr' is 'true'");
}
if (!this.input.prTestFilename) {
throw new Error(
"'pr-test-filename' is required when 'create-pr' is 'true'"
);
}
}

// the values of github.context.repo.owner and github.context.repo.repo are taken from
// the environment variable GITHUB_REPOSITORY specified in "owner/repo" format and
// provided by the GitHub Action on the runtime
Expand Down Expand Up @@ -40001,6 +40022,11 @@ 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 prBody = config.input.prBody;
let prTestFilename = config.input.prTestFilename;

console.log(`testdriver@${pgkVersion}`);
console.log(`testdriver-action@${testdriverBranch}`);
Expand All @@ -40016,6 +40042,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) {
console.log(chalk.yellow("prBranch:"), prBranch);
console.log(chalk.yellow("prBase:"), prBase);
console.log(chalk.yellow("prTitle:"), prTitle);
console.log(chalk.yellow("prBody:"), prBody);
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 +40079,11 @@ const waitFor = (ms) => new Promise((r) => setTimeout(r, ms));
personalAccessToken,
testdriveraiVersion,
createPR,
prTitle,
prBody,
prBase,
prBranch,
prTestFilename,
},
{
Accept: "application/json",
Expand Down
31 changes: 26 additions & 5 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ 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"),
Expand All @@ -16,9 +16,30 @@ class Config {
key: core.getInput("key"),
os: core.getInput("os") || "windows",
version: core.getInput("version") || "latest",
createPR: JSON.parse(createPR),
createPR,
prBranch: createPR ? core.getInput("pr-branch") : "",
prBase: createPR ? core.getInput("pr-base") : "",
prTitle: createPR ? core.getInput("pr-title") : "",
prTestFilename: createPR ? core.getInput("pr-test-filename") : "",
};

if (createPR) {
if (!this.input.prBranch) {
throw new Error("'pr-branch' is required when 'create-pr' is 'true'");
}
if (!this.input.prBase) {
throw new Error("'pr-base' is required when 'create-pr' is 'true'");
}
if (!this.input.prTitle) {
throw new Error("'pr-title' is required when 'create-pr' is 'true'");
}
if (!this.input.prTestFilename) {
throw new Error(
"'pr-test-filename' is required when 'create-pr' is 'true'"
);
}
}

// the values of github.context.repo.owner and github.context.repo.repo are taken from
// the environment variable GITHUB_REPOSITORY specified in "owner/repo" format and
// provided by the GitHub Action on the runtime
Expand Down
18 changes: 18 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ 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 prBody = config.input.prBody;
let prTestFilename = config.input.prTestFilename;

console.log(`testdriver@${pgkVersion}`);
console.log(`testdriver-action@${testdriverBranch}`);
Expand All @@ -51,6 +56,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) {
console.log(chalk.yellow("prBranch:"), prBranch);
console.log(chalk.yellow("prBase:"), prBase);
console.log(chalk.yellow("prTitle:"), prTitle);
console.log(chalk.yellow("prBody:"), prBody);
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 @@ -80,6 +93,11 @@ const waitFor = (ms) => new Promise((r) => setTimeout(r, ms));
personalAccessToken,
testdriveraiVersion,
createPR,
prTitle,
prBody,
prBase,
prBranch,
prTestFilename,
},
{
Accept: "application/json",
Expand Down

0 comments on commit 299b428

Please sign in to comment.