From 7fbebaa63bda66792d239b95f05cb5a8f4635c64 Mon Sep 17 00:00:00 2001 From: AayushSaini101 Date: Thu, 25 Jul 2024 23:00:11 +0530 Subject: [PATCH] Update requirements --- .github/scripts/vote_tracker.js | 73 +++++++++++++++++------------- .github/workflows/vote-tracker.yml | 2 +- 2 files changed, 43 insertions(+), 32 deletions(-) diff --git a/.github/scripts/vote_tracker.js b/.github/scripts/vote_tracker.js index 7c5592096..d257ec8a6 100644 --- a/.github/scripts/vote_tracker.js +++ b/.github/scripts/vote_tracker.js @@ -1,15 +1,15 @@ const yaml = require('js-yaml'); const { readFile, writeFile } = require('fs').promises; -const path = require('path'); - -module.exports = async ({ githuh, context, botCommentURL}) => { - +const path = require("path") +module.exports = async ({ github, context, botCommentURL}) => { try { - let message, eventNumber, eventTitle, orgName, repoName; - if (botCommentURL) { - await fetchCommentInformation() + const voteCommentContext = await fetchCommentInformation(); + message = voteCommentContext.messageBody + eventNumber = voteCommentContext.eventNumber + eventTitle = voteCommentContext.eventTitle + orgName = voteCommentContext.orgName } else { // Extract necessary details from the context when triggered by issue_comment message = context.payload.comment.body; @@ -18,7 +18,7 @@ module.exports = async ({ githuh, context, botCommentURL}) => { orgName = context.repo.owner; repoName = context.repo.repo; } - + // Path to the vote tracking file const voteTrackingFile = path.join('voteTrackingFile.json'); @@ -250,35 +250,46 @@ module.exports = async ({ githuh, context, botCommentURL}) => { } return updatedVoteDetails } - // Method to parse the comment that is executed by manually triggered - async function fetchCommentInformation(){ - const { Octokit } = await import("@octokit/rest"); + async function fetchCommentInformation() { const urlParts = botCommentURL.split('/'); - eventNumber = urlParts[urlParts.length - 1].split('#')[0]; + const eventNumber = urlParts[urlParts.length - 1].split('#')[0]; const commentId = urlParts[urlParts.length - 1].split('#')[1].replace('issuecomment-', ''); const [owner, repo] = urlParts.slice(3, 5); - orgName = owner - repoName = repo - const octokit = new Octokit(); - + let orgName = owner; + let repoName = repo; + let messageBody = ''; + let eventTitle = ''; + try { - message = await octokit.request("GET /repos/{owner}/{repo}/issues/comments/{comment_id}", { - owner: owner, - repo: repo, - comment_id: commentId - }); - message = message.data.body - const { data: issue } = await octokit.rest.issues.get({ - owner, - repo, - issue_number: eventNumber - }); - eventTitle = issue.title + const messageResponse = await github.request("GET /repos/{owner}/{repo}/issues/comments/{comment_id}", { + owner: owner, + repo: repo, + comment_id: commentId + }); + messageBody = messageResponse.data.body; + + const issueResponse = await github.rest.issues.get({ + owner, + repo, + issue_number: eventNumber + }); + eventTitle = issueResponse.data.title; } catch (error) { - console.error(error); + console.error(error); } - } -} catch (error) { + + return { + orgName, + repoName, + eventNumber, + commentId, + messageBody, + eventTitle + }; + } + + } + catch (error) { console.error('Error while running the vote_tracker workflow:', error); } } \ No newline at end of file diff --git a/.github/workflows/vote-tracker.yml b/.github/workflows/vote-tracker.yml index 9b7c68872..9b690aca8 100644 --- a/.github/workflows/vote-tracker.yml +++ b/.github/workflows/vote-tracker.yml @@ -21,7 +21,7 @@ jobs: uses: actions/checkout@v4 - name: Installing Module - run: npm install @octokit/rest js-yaml@4.1.0 --no-save + run: npm install js-yaml@4.1.0 --no-save shell: bash - name: Run GitHub Script