Reworked the index.js
Some checks failed
Auto Maintenance Cycle / pre-commit Autoupdate (push) Failing after 32s
Some checks failed
Auto Maintenance Cycle / pre-commit Autoupdate (push) Failing after 32s
This commit is contained in:
parent
3baa2f745b
commit
1a139366a7
66
index.js
66
index.js
@ -25,19 +25,10 @@ async function getAndPostPullRequests() {
|
||||
|
||||
// Headers with Authorization
|
||||
const headers = {
|
||||
Authorization: `token ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
core.info(`token ${token}`);
|
||||
// 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
|
||||
const postData = {
|
||||
@ -55,48 +46,29 @@ async function getAndPostPullRequests() {
|
||||
headers,
|
||||
});
|
||||
|
||||
if (!getResponse.ok) {
|
||||
// Perform the POST request
|
||||
|
||||
core.info(`URL for POST request: ${url}`);
|
||||
core.info(`POST data being sent: ${JSON.stringify(postData, null, 2)}`);
|
||||
const postResponse = await fetch(`${url}?access_token=${token}`, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify(postData),
|
||||
});
|
||||
|
||||
const postResponseText = await postResponse.text();
|
||||
core.info(`POST request status: ${postResponse.status}`);
|
||||
core.info(`POST response body: ${postResponseText}`);
|
||||
|
||||
if (!postResponse.ok) {
|
||||
throw new Error(
|
||||
`HTTP error! status on checking the PR request status: ${getResponse.status}`,
|
||||
`HTTP error! status on creating a new PR: ${postResponse.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
|
||||
|
||||
core.info(`URL for POST request: ${url}`);
|
||||
core.info(`POST data being sent: ${JSON.stringify(postData, null, 2)}`);
|
||||
const postResponse = await fetch(url, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify(postData),
|
||||
});
|
||||
|
||||
const postResponseText = await postResponse.text();
|
||||
core.info(`POST request status: ${postResponse.status}`);
|
||||
core.info(`POST response body: ${postResponseText}`);
|
||||
|
||||
if (!postResponse.ok) {
|
||||
throw new Error(
|
||||
`HTTP error! status on creating a new PR: ${postResponse.status}`,
|
||||
);
|
||||
}
|
||||
|
||||
const postResult = await postResponse.json();
|
||||
core.info("POST request completed successfully.");
|
||||
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}.`,
|
||||
};
|
||||
}
|
||||
const postResult = await postResponse.json();
|
||||
core.info("POST request completed successfully.");
|
||||
return postResult;
|
||||
} catch (error) {
|
||||
core.setFailed(`Action failed with error: ${error}`);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user