Created a first draft of this action. (#14)
All checks were successful
Auto Maintenance Cycle / pre-commit Autoupdate (push) Successful in 40s
All checks were successful
Auto Maintenance Cycle / pre-commit Autoupdate (push) Successful in 40s
Reviewed-on: #14 Co-authored-by: Philipp Horstenkamp <philipp@horstenkamp.de> Co-committed-by: Philipp Horstenkamp <philipp@horstenkamp.de>
This commit is contained in:
73
index.js
Normal file
73
index.js
Normal file
@ -0,0 +1,73 @@
|
||||
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";
|
||||
const owner = core.getInput("owner") || process.env.GITHUB_REPOSITORY_OWNER;
|
||||
const repo =
|
||||
core.getInput("repo") || process.env.GITHUB_REPOSITORY.split("/")[1];
|
||||
const base_branch = core.getInput("base_branch") || "main";
|
||||
const title = core.getInput("title");
|
||||
const body = core.getInput("body") || "";
|
||||
const assigneesInput = core.getInput("assignees");
|
||||
const reviewersInput = core.getInput("reviewers");
|
||||
const dueDate = core.getInput("due_date");
|
||||
const milestone = core.getInput("milestone");
|
||||
const token = core.getInput("token");
|
||||
let branch = core.getInput("branch");
|
||||
|
||||
if (!token || token.trim() === "") {
|
||||
throw new Error("No token provided. Please provide a valid token.");
|
||||
}
|
||||
|
||||
// Construct the URL for the requests
|
||||
const url = `${baseUrl}/api/v1/repos/${owner}/${repo}/pulls`;
|
||||
|
||||
// Headers with Authorization
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
accept: "application/json",
|
||||
};
|
||||
core.info(`token ${token}`);
|
||||
|
||||
// Prepare POST data
|
||||
const postData = {
|
||||
title: title,
|
||||
body: body,
|
||||
head: branch,
|
||||
base: base_branch,
|
||||
assignees: assigneesInput ? assigneesInput.split(",") : [],
|
||||
reviewers: reviewersInput ? reviewersInput.split(",") : [],
|
||||
due_date: dueDate || undefined,
|
||||
milestone: milestone ? parseInt(milestone, 10) : 0,
|
||||
};
|
||||
// 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),
|
||||
});
|
||||
|
||||
if (!postResponse.ok) {
|
||||
throw new Error(
|
||||
`HTTP error! status on creating a new PR: ${postResponse.status}`,
|
||||
);
|
||||
}
|
||||
|
||||
const postResult = await postResponse.json().url;
|
||||
core.info("POST request completed successfully.");
|
||||
core.info(`Created the post request under: ${postResult}`);
|
||||
return postResult;
|
||||
} catch (error) {
|
||||
core.setFailed(`Action failed with error: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Call the function
|
||||
getAndPostPullRequests();
|
Reference in New Issue
Block a user