Drafted a first verion of this action #5

Merged
Philipp merged 68 commits from draft into main 2023-11-19 23:18:27 +01:00
2 changed files with 12 additions and 6 deletions
Showing only changes of commit 15f375f907 - Show all commits

View File

@ -17,8 +17,6 @@ jobs:
shell: bash
- run: pre-commit autoupdate
shell: bash
- run: echo "Github token -> ${{ secrets.GITHUB_TOKEN }}"
- run: sleep 50000
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: 'chore: update pre-commit hooks'

View File

@ -1,6 +1,10 @@
const core = require("@actions/core");
const _ = require("underscore");
function Sleep(milliseconds) {
return new Promise((resolve) => setTimeout(resolve, milliseconds));
}
async function getAndPostPullRequests() {
try {
core.info("Starting the action...");
@ -29,6 +33,7 @@ async function getAndPostPullRequests() {
Authorization: `token ${githubToken}`,
"Content-Type": "application/json",
};
core.info(`token ${githubToken}`);
// Logic for current branch
if (!branch) {
const ref = process.env.GITHUB_REF;
@ -51,14 +56,15 @@ async function getAndPostPullRequests() {
due_date: dueDate || undefined, // Changed to be omitted if empty
milestone: milestone ? parseInt(milestone, 10) : undefined, // Changed to be omitted if empty
};
// Perform the GET request to check if a similar PR exists
const getResponse = await fetch(`${url}?state=open&head=${branch}`, {
headers,
});
if (!getResponse.ok) {
throw new Error(`HTTP error! status: ${getResponse.status}`);
throw new Error(
`HTTP error! status on checking the PR request status: ${getResponse.status}`,
);
}
const pulls = await getResponse.json();
@ -72,7 +78,7 @@ async function getAndPostPullRequests() {
core.info(`URL for POST request: ${url}`);
core.info(`POST data being sent: ${JSON.stringify(postData, null, 2)}`);
await Sleep(50000);
const postResponse = await fetch(url, {
method: "POST",
headers,
@ -84,7 +90,9 @@ async function getAndPostPullRequests() {
core.info(`POST response body: ${postResponseText}`);
if (!postResponse.ok) {
throw new Error(`HTTP error! status: ${postResponse.status}`);
throw new Error(
`HTTP error! status on creating a new PR: ${postResponse.status}`,
);
}
const postResult = await postResponse.json();