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:
parent
8e65a33d3e
commit
9e76cefde3
@ -30,8 +30,8 @@ jobs:
|
||||
uses: ./
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
branch: my-branch
|
||||
pr_title: My PR Title
|
||||
pr_body: My PR Body
|
||||
branch: update/pre-commit-hooks
|
||||
title: My PR Title
|
||||
body: My PR Body
|
||||
assignees: Philipp
|
||||
reviewers: Philipp
|
||||
|
@ -7,10 +7,13 @@ inputs:
|
||||
branch:
|
||||
description: Branch for which to create the PR
|
||||
required: true
|
||||
pr_title:
|
||||
base_branch:
|
||||
description: Branch in which should be mergbed. Defaults to main.
|
||||
required: false
|
||||
title:
|
||||
description: Title of the pull request
|
||||
required: true
|
||||
pr_body:
|
||||
body:
|
||||
description: Body of the pull request
|
||||
required: true
|
||||
assignees:
|
||||
|
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}`);
|
||||
|
Loading…
x
Reference in New Issue
Block a user