All checks were successful
Auto Maintenance Cycle / pre-commit Autoupdate (push) Successful in 37s
74 lines
2.3 KiB
JavaScript
74 lines
2.3 KiB
JavaScript
const core = require("@actions/core");
|
|
|
|
async function getAndPostPullRequests() {
|
|
try {
|
|
core.info("Starting the action...");
|
|
|
|
// Retrieve inputs and token
|
|
const baseUrl = core.getInput("base_url") || "https://git.horstenkamp.eu";
|
|
core.info(`Base URL: ${baseUrl}`);
|
|
|
|
const owner = core.getInput("owner") || process.env.GITHUB_REPOSITORY_OWNER;
|
|
core.info(`Repository Owner: ${owner}`);
|
|
|
|
const repo =
|
|
core.getInput("repo") || process.env.GITHUB_REPOSITORY.split("/")[1];
|
|
core.info(`Repository Name: ${repo}`);
|
|
|
|
// core.info(`Post Data: ${JSON.stringify(postData)}`);
|
|
|
|
const githubToken = core.getInput("github_token");
|
|
core.info("GitHub token retrieved.");
|
|
|
|
// Headers with Authorization
|
|
const headers = {
|
|
Authorization: `token ${githubToken}`,
|
|
"Content-Type": "application/json",
|
|
};
|
|
|
|
// Construct the URL for the requests
|
|
const url = `${baseUrl}/api/v1/repos/${owner}/${repo}/pulls`;
|
|
core.info(`Constructed URL: ${url}`);
|
|
|
|
// Perform the GET request
|
|
core.info("Performing GET request...");
|
|
const get_url = `${url}?state=open`;
|
|
const getResponse = await fetch(get_url, { headers });
|
|
|
|
if (!getResponse.ok) {
|
|
throw new Error(`HTTP error! status: ${getResponse.status}`);
|
|
}
|
|
|
|
const pulls = await getResponse.json();
|
|
core.info(`GET request completed. Number of pulls: ${pulls.length}`);
|
|
|
|
// Logic to decide if a POST request is needed
|
|
if (pulls.length === 0) {
|
|
core.info("No open pulls found, proceeding with POST request...");
|
|
return { message: "Abort for thesting" };
|
|
// Perform the POST request
|
|
const postResponse = await fetch(url, {
|
|
method: "POST",
|
|
headers,
|
|
body: JSON.stringify(postData),
|
|
});
|
|
|
|
if (!postResponse.ok) {
|
|
throw new Error(`HTTP error! status: ${postResponse.status}`);
|
|
}
|
|
|
|
const postResult = await postResponse.json();
|
|
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." };
|
|
}
|
|
} catch (error) {
|
|
core.setFailed(`Action failed with error: ${error}`);
|
|
}
|
|
}
|
|
|
|
// Call the function
|
|
getAndPostPullRequests();
|