Added an a check that validates if an similar PR already exists.
Some checks failed
Auto Maintenance Cycle / pre-commit Autoupdate (push) Failing after 33s
Some checks failed
Auto Maintenance Cycle / pre-commit Autoupdate (push) Failing after 33s
This commit is contained in:
22
index.js
22
index.js
@ -1,4 +1,5 @@
|
||||
const core = require("@actions/core");
|
||||
const _ = require("underscore");
|
||||
|
||||
async function getAndPostPullRequests() {
|
||||
try {
|
||||
@ -18,6 +19,9 @@ async function getAndPostPullRequests() {
|
||||
const branch = core.getInput("branch");
|
||||
core.info(`The branch ${branch} should be merged.`);
|
||||
|
||||
const base_branch = core.getInput("base_branch");
|
||||
core.info(`The branch ${base_branch} should be merged into.`);
|
||||
|
||||
// core.info(`Post Data: ${JSON.stringify(postData)}`);
|
||||
|
||||
const githubToken = core.getInput("github_token");
|
||||
@ -47,8 +51,14 @@ async function getAndPostPullRequests() {
|
||||
core.info(`GET repsonse ${JSON.stringify(pulls, 2)}`);
|
||||
|
||||
// Logic to decide if a POST request is needed
|
||||
if (pulls.length === 0) {
|
||||
core.info("No open pulls found, proceeding with POST request...");
|
||||
const targetPRFound = _.any(
|
||||
pulls,
|
||||
(pr) => pr.head.ref === branch && pr.base.ref === base_branch,
|
||||
);
|
||||
if (targetPRFound) {
|
||||
core.info(
|
||||
`No open pulls found, to merge ${branch} into ${base_branch}. Trying to create a new PR.`,
|
||||
);
|
||||
return { message: "Abort for thesting" };
|
||||
// Perform the POST request
|
||||
const postResponse = await fetch(url, {
|
||||
@ -65,8 +75,12 @@ async function getAndPostPullRequests() {
|
||||
core.info("POST request completed successfully.");
|
||||
return postResult;
|
||||
} else {
|
||||
core.info("No POST request made as conditions were not met.");
|
||||
return { message: "No POST request made as conditions were not met." };
|
||||
core.info(
|
||||
`There is already an PR for open that merges ${branch} into ${base_branch}.`,
|
||||
);
|
||||
return {
|
||||
message: `There is already an PR for open that merges ${branch} into ${base_branch}.`,
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed(`Action failed with error: ${error}`);
|
||||
|
Reference in New Issue
Block a user