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: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
branch: my-branch
|
branch: update/pre-commit-hooks
|
||||||
pr_title: My PR Title
|
title: My PR Title
|
||||||
pr_body: My PR Body
|
body: My PR Body
|
||||||
assignees: Philipp
|
assignees: Philipp
|
||||||
reviewers: Philipp
|
reviewers: Philipp
|
||||||
|
@ -7,10 +7,13 @@ inputs:
|
|||||||
branch:
|
branch:
|
||||||
description: Branch for which to create the PR
|
description: Branch for which to create the PR
|
||||||
required: true
|
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
|
description: Title of the pull request
|
||||||
required: true
|
required: true
|
||||||
pr_body:
|
body:
|
||||||
description: Body of the pull request
|
description: Body of the pull request
|
||||||
required: true
|
required: true
|
||||||
assignees:
|
assignees:
|
||||||
|
22
index.js
22
index.js
@ -1,4 +1,5 @@
|
|||||||
const core = require("@actions/core");
|
const core = require("@actions/core");
|
||||||
|
const _ = require("underscore");
|
||||||
|
|
||||||
async function getAndPostPullRequests() {
|
async function getAndPostPullRequests() {
|
||||||
try {
|
try {
|
||||||
@ -18,6 +19,9 @@ async function getAndPostPullRequests() {
|
|||||||
const branch = core.getInput("branch");
|
const branch = core.getInput("branch");
|
||||||
core.info(`The branch ${branch} should be merged.`);
|
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)}`);
|
// core.info(`Post Data: ${JSON.stringify(postData)}`);
|
||||||
|
|
||||||
const githubToken = core.getInput("github_token");
|
const githubToken = core.getInput("github_token");
|
||||||
@ -47,8 +51,14 @@ async function getAndPostPullRequests() {
|
|||||||
core.info(`GET repsonse ${JSON.stringify(pulls, 2)}`);
|
core.info(`GET repsonse ${JSON.stringify(pulls, 2)}`);
|
||||||
|
|
||||||
// Logic to decide if a POST request is needed
|
// Logic to decide if a POST request is needed
|
||||||
if (pulls.length === 0) {
|
const targetPRFound = _.any(
|
||||||
core.info("No open pulls found, proceeding with POST request...");
|
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" };
|
return { message: "Abort for thesting" };
|
||||||
// Perform the POST request
|
// Perform the POST request
|
||||||
const postResponse = await fetch(url, {
|
const postResponse = await fetch(url, {
|
||||||
@ -65,8 +75,12 @@ async function getAndPostPullRequests() {
|
|||||||
core.info("POST request completed successfully.");
|
core.info("POST request completed successfully.");
|
||||||
return postResult;
|
return postResult;
|
||||||
} else {
|
} else {
|
||||||
core.info("No POST request made as conditions were not met.");
|
core.info(
|
||||||
return { message: "No POST request made as conditions were not met." };
|
`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) {
|
} catch (error) {
|
||||||
core.setFailed(`Action failed with error: ${error}`);
|
core.setFailed(`Action failed with error: ${error}`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user