Skip to content

Commit

Permalink
fix: fix undefined error and remove unused files (#1325)
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSaini101 committed Jul 26, 2024
1 parent bcff426 commit 3100867
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 52 deletions.
80 changes: 65 additions & 15 deletions .github/scripts/vote_tracker.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
const yaml = require('js-yaml');
const { readFile, writeFile } = require('fs').promises;
const path = require('path');

module.exports = async ({ context }) => {
const path = require("path")
module.exports = async ({ github, context, botCommentURL}) => {
try {
// Extract necessary details from the context
const message = context.payload.comment.body;
const eventNumber = context.issue.number;
const eventTitle = context.payload.issue.title;
const orgName = context.issue.owner;
const repoName = context.issue.repo;
let message, eventNumber, eventTitle, orgName, repoName;
if (botCommentURL) {
const voteCommentContext = await fetchCommentInformation();
message = voteCommentContext.messageBody
eventNumber = voteCommentContext.eventNumber
eventTitle = voteCommentContext.eventTitle
orgName = voteCommentContext.orgName
repoName = voteCommentContext.repoName
} else {
// Extract necessary details from the context when triggered by issue_comment
message = context.payload.comment.body;
eventNumber = context.issue.number;
eventTitle = context.payload.issue.title;
orgName = context.repo.owner;
repoName = context.repo.repo;
}

// Path to the vote tracking file
const voteTrackingFile = path.join('voteTrackingFile.json');
Expand Down Expand Up @@ -179,6 +188,7 @@ module.exports = async ({ context }) => {
console.error('Error reading voteTrackingFile.json:', readError);
throw readError;
}
let updatedVoteDetails = [...voteDetails]
const updatedTSCMembers = [];
const requiredKeys = ['name', 'lastParticipatedVoteTime', 'isVotedInLast3Months', 'lastVoteClosedTime', 'agreeCount', 'disagreeCount', 'abstainCount', 'notParticipatingCount'];
// Function to check if an object has all required keys
Expand Down Expand Up @@ -230,18 +240,58 @@ module.exports = async ({ context }) => {
} else {
console.log('No valid example member found in voteDetails.');
}

if (updatedTSCMembers.length > 0) {
try {
const combinedData = [...voteDetails, ...updatedTSCMembers];
await writeFile(voteTrackingFile, JSON.stringify(combinedData, null, 2));
return combinedData; // Return the updated data
updatedVoteDetails.concat(...updatedTSCMembers)
await writeFile(voteTrackingFile, JSON.stringify(updatedVoteDetails, null, 2));
} catch (writeError) {
console.error('Error wile writing file:' ,writeError)
}
}
return updatedVoteDetails
}
} catch (error) {
// Method to fetch information from the comment when workflow triggered manually
async function fetchCommentInformation() {
const urlParts = botCommentURL.split('/');
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);
let orgName = owner;
let repoName = repo;
let messageBody = '';
let eventTitle = '';

try {
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);
}

return {
orgName,
repoName,
eventNumber,
commentId,
messageBody,
eventTitle
};
}

}
catch (error) {
console.error('Error while running the vote_tracker workflow:', error);
}
}
}
16 changes: 12 additions & 4 deletions .github/workflows/vote-tracker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@ on:
issue_comment:
types: [created]

workflow_dispatch:
inputs:
bot_comment_url:
description: |
Provide URL pointing to gitvote bot comment that contains closing voting update. It looks like `https://github.com/asyncapi/community/issues/1313#issuecomment-2247595858`. We use this to update the voting summary in cases when we see errors in the voting status, when for example TSC member voted, but did a mistake and voted by adding emoji to main description or other bot comment instead of the correct way: which is adding an emoji to a comment from bot that opens the vote.
required: true

jobs:
track-vote:
if: ${{ github.actor == 'git-vote[bot]' && contains(github.event.comment.body, 'Vote closed')}}
if: ${{ github.actor == 'git-vote[bot]' && contains(github.event.comment.body, 'Vote closed') || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
steps:

- name: Checkout repository
uses: actions/checkout@v4

- name: Installing Module
run: npm install js-yaml@4.1.0
run: npm install js-yaml@4.1.0 --no-save
shell: bash

- name: Run GitHub Script
Expand All @@ -23,7 +30,8 @@ jobs:
with:
script: |
const script = require('./.github/scripts/vote_tracker.js');
await script({ github, context, core });
const botCommentURL = "${{ github.event.inputs.bot_comment_url || '' }}";
await script({ github, context, botCommentURL });
- name: Create Pull Request to update Vote Tracking Details
uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38 # uses 5.0.2 https://github.com/peter-evans/create-pull-request/releases/tag/v5.0.2
Expand All @@ -33,5 +41,5 @@ jobs:
committer: asyncapi-bot <info@asyncapi.io>
author: asyncapi-bot <info@asyncapi.io>
title: 'chore: vote tracking details'
body: 'Update the votetrackingDetails.md and votetracking.json'
body: 'Update the TSC_VOTING_OVERVIEW.md and voteTrackingFile.json'
branch: vote-trackingupdate/${{ github.job }}
28 changes: 0 additions & 28 deletions package-lock.json

This file was deleted.

5 changes: 0 additions & 5 deletions package.json

This file was deleted.

0 comments on commit 3100867

Please sign in to comment.