From 15f375f90772da2c3a2521e73fdc422ae8bcac18 Mon Sep 17 00:00:00 2001 From: Philipp Horstenkamp Date: Sun, 19 Nov 2023 19:22:59 +0100 Subject: [PATCH] Added some more changes. --- .gitea/workflows/maintenance.yaml | 2 -- index.js | 16 ++++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/maintenance.yaml b/.gitea/workflows/maintenance.yaml index 19859e0..eb84419 100644 --- a/.gitea/workflows/maintenance.yaml +++ b/.gitea/workflows/maintenance.yaml @@ -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' diff --git a/index.js b/index.js index 0b09c15..5f8c393 100644 --- a/index.js +++ b/index.js @@ -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();