Skip to content

Commit

Permalink
Update requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSaini101 committed Jul 25, 2024
1 parent 0ab2b47 commit 7fbebaa
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 32 deletions.
73 changes: 42 additions & 31 deletions .github/scripts/vote_tracker.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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');

Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion .github/workflows/vote-tracker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: actions/checkout@v4

- name: Installing Module
run: npm install @octokit/rest [email protected] --no-save
run: npm install [email protected] --no-save
shell: bash

- name: Run GitHub Script
Expand Down

0 comments on commit 7fbebaa

Please sign in to comment.