diff --git a/action.yml b/action.yml index cd9afb7..cde59b1 100644 --- a/action.yml +++ b/action.yml @@ -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: diff --git a/dist/index.js b/dist/index.js index 9020925..ef95781 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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"), @@ -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 @@ -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}`); @@ -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:")); @@ -40045,6 +40079,11 @@ const waitFor = (ms) => new Promise((r) => setTimeout(r, ms)); personalAccessToken, testdriveraiVersion, createPR, + prTitle, + prBody, + prBase, + prBranch, + prTestFilename, }, { Accept: "application/json", diff --git a/src/config.js b/src/config.js index 3062686..913ba22 100644 --- a/src/config.js +++ b/src/config.js @@ -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"), @@ -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 diff --git a/src/index.js b/src/index.js index 3de78c3..8de80a6 100644 --- a/src/index.js +++ b/src/index.js @@ -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}`); @@ -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:")); @@ -80,6 +93,11 @@ const waitFor = (ms) => new Promise((r) => setTimeout(r, ms)); personalAccessToken, testdriveraiVersion, createPR, + prTitle, + prBody, + prBase, + prBranch, + prTestFilename, }, { Accept: "application/json",