From 83d6ebd22a319af66b5898ee6795eebecf5359bc Mon Sep 17 00:00:00 2001 From: Philipp Horstenkamp Date: Sun, 19 Nov 2023 14:35:26 +0100 Subject: [PATCH] Added a few arguments. --- index.js | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 54edc48..09c0c0a 100644 --- a/index.js +++ b/index.js @@ -16,13 +16,27 @@ async function getAndPostPullRequests() { core.getInput("repo") || process.env.GITHUB_REPOSITORY.split("/")[1]; core.info(`Repository Name: ${repo}`); - const branch = core.getInput("branch"); const base_branch = core.getInput("base_branch") || "main"; + const assigneesInput = core.getInput("assignees"); + const reviewersInput = core.getInput("reviewers"); + const labelsInput = core.getInput("labels"); + const githubToken = core.getInput("github_token"); + + const branch = core.getInput("branch"); + if (!branch) { + const ref = process.env.GITHUB_REF; + if (ref && ref.startsWith("refs/heads/")) { + branch = ref.replace("refs/heads/", ""); + } + } + core.info(`The branch ${branch} should be merged into ${base_branch} .`); + if (!body) { + core.warning("Warning: PR body is empty."); + } // core.info(`Post Data: ${JSON.stringify(postData)}`); - const githubToken = core.getInput("github_token"); core.info("GitHub token retrieved."); // Headers with Authorization @@ -56,7 +70,20 @@ async function getAndPostPullRequests() { core.info( `No open pulls found, to merge ${branch} into ${base_branch}. Trying to create a new PR.`, ); - return { message: "Abort for thesting" }; + // return { message: "Abort for thesting" }; + // Perform the POST request + // Prepare POST data + const postData = { + title: title, + body: body, + head: branch, + base: base_branch, + }; + + if (assigneesInput) postData.assignees = assigneesInput.split(","); + if (reviewersInput) postData.reviewers = reviewersInput.split(","); + if (labelsInput) postData.labels = labelsInput.split(","); + // Perform the POST request const postResponse = await fetch(url, { method: "POST",