Reworked the index.js
Some checks failed
Auto Maintenance Cycle / pre-commit Autoupdate (push) Failing after 32s

This commit is contained in:
Philipp Horstenkamp 2023-11-19 22:10:16 +01:00
parent 3baa2f745b
commit 1a139366a7
Signed by: Philipp
GPG Key ID: DD53EAC36AFB61B4

View File

@ -25,19 +25,10 @@ async function getAndPostPullRequests() {
// Headers with Authorization // Headers with Authorization
const headers = { const headers = {
Authorization: `token ${token}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}; };
core.info(`token ${token}`); core.info(`token ${token}`);
// Logic for current branch // Logic for current branch
if (!branch) {
const ref = process.env.GITHUB_REF;
if (ref && ref.startsWith("refs/heads/")) {
branch = ref.replace("refs/heads/", "");
}
}
core.info(`Preparing to merge branch ${branch} into ${base_branch}`);
// Prepare POST data // Prepare POST data
const postData = { const postData = {
@ -55,24 +46,11 @@ async function getAndPostPullRequests() {
headers, headers,
}); });
if (!getResponse.ok) {
throw new Error(
`HTTP error! status on checking the PR request status: ${getResponse.status}`,
);
}
const pulls = await getResponse.json();
const targetPRFound = _.any(
pulls,
(pr) => pr.head.ref === branch && pr.base.ref === base_branch,
);
if (!targetPRFound) {
// Perform the POST request // Perform the POST request
core.info(`URL for POST request: ${url}`); core.info(`URL for POST request: ${url}`);
core.info(`POST data being sent: ${JSON.stringify(postData, null, 2)}`); core.info(`POST data being sent: ${JSON.stringify(postData, null, 2)}`);
const postResponse = await fetch(url, { const postResponse = await fetch(`${url}?access_token=${token}`, {
method: "POST", method: "POST",
headers, headers,
body: JSON.stringify(postData), body: JSON.stringify(postData),
@ -91,12 +69,6 @@ async function getAndPostPullRequests() {
const postResult = await postResponse.json(); const postResult = await postResponse.json();
core.info("POST request completed successfully."); core.info("POST request completed successfully.");
return postResult; return postResult;
} else {
core.info(`A PR already exists to merge ${branch} into ${base_branch}.`);
return {
message: `A PR already exists to merge ${branch} into ${base_branch}.`,
};
}
} catch (error) { } catch (error) {
core.setFailed(`Action failed with error: ${error}`); core.setFailed(`Action failed with error: ${error}`);
} }