-
-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add new worklow to track the voting process #1278
Merged
Merged
Changes from 19 commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
422213e
Add new worklow to track the voting process
AayushSaini101 ab5f4f0
Merge branch 'master' into Issue-1268
AayushSaini101 dc9e22d
Merge branch 'master' into Issue-1268
AayushSaini101 63a26df
Updated structure of the worklow
AayushSaini101 f6853b8
Add extra field to track not participated count
AayushSaini101 0788db0
Update the names of variables
AayushSaini101 430f472
Update variables
AayushSaini101 5cb67c6
Update the vote tracking workflow
AayushSaini101 9f4c86e
Remove extra variables
AayushSaini101 82e2d61
Update the tracker concept
AayushSaini101 cea8957
Update
AayushSaini101 27917da
update names
AayushSaini101 171f667
update issue name
AayushSaini101 1051429
Introduce Markdown to track voting details
AayushSaini101 597f206
Merge branch 'master' into Issue-1268
AayushSaini101 07bebfa
Merge branch 'master' into Issue-1268
AayushSaini101 711d9f6
Add doc about the new workflow and optimise tracker
AayushSaini101 bfd0988
Use proper variable naming
AayushSaini101 711b464
Merge branch 'master' into Issue-1268
AayushSaini101 08c37ab
Update voting.md
AayushSaini101 7a41ad2
Update .github/scripts/vote_tracker.js
AayushSaini101 8c12491
Update voting.md
AayushSaini101 34fcb9b
Update required changes
AayushSaini101 7f4e172
Merge branch 'master' into Issue-1268
AayushSaini101 8cb254b
Update to check tsc member
AayushSaini101 bf6e6e4
Update voting file yml
AayushSaini101 796386b
remove logging
AayushSaini101 be7732a
Fix undefined issue
AayushSaini101 17443f5
Fix the format
AayushSaini101 901932e
Merge branch 'master' into Issue-1268
AayushSaini101 7e461c5
Update voting.md
AayushSaini101 dd19fca
Update voting.md
AayushSaini101 936f6b0
Update .github/workflows/vote-tracker.yml
AayushSaini101 541b512
Update the workflow
AayushSaini101 998863c
Remove extra space
AayushSaini101 8b7fb66
Update requirments
AayushSaini101 cde79e9
Merge branch 'master' into Issue-1268
AayushSaini101 2ce1a67
Update vote_tracker.js
AayushSaini101 3173ed1
Update vote_tracker.js
AayushSaini101 daf62e4
Update voteTrackingFile.json
AayushSaini101 1a0b934
Update .github/scripts/vote_tracker.js
AayushSaini101 7dcec19
Update vote_tracker.js
AayushSaini101 f9ddf5a
Merge branch 'master' into Issue-1268
AayushSaini101 9b822e3
Update voteTrackingFile.json
AayushSaini101 928ad7e
Update voting.md
AayushSaini101 944c20e
Merge branch 'master' into Issue-1268
AayushSaini101 f09efa9
Add markdown file and update the md file generator flow
AayushSaini101 a2e9222
Update voting.md
AayushSaini101 348c3a8
Merge branch 'master' into Issue-1268
AayushSaini101 b03a2be
Fix invalid data
AayushSaini101 320b543
Fix md file
AayushSaini101 ddb9272
Update TSC_VOTING_OVERVIEW.md
AayushSaini101 6c20357
Update voteTrackingFile.json
AayushSaini101 e96e819
Update TSC_VOTING_OVERVIEW.md
AayushSaini101 e520dda
Update voteTrackingFile.json
AayushSaini101 173327a
Update TSC_VOTING_OVERVIEW.md
AayushSaini101 21f7e76
Update voteTrackingFile.json
AayushSaini101 8d9dcf1
Merge branch 'master' into Issue-1268
AayushSaini101 0fc7c38
Add lowerCase matching
AayushSaini101 cc4e3f8
add lowercase
AayushSaini101 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
const yaml = require('js-yaml'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const message = process.env.COMMENT_BODY; | ||
const eventNumber = process.env.EVENT_NUMBER; | ||
const eventTitle = process.env.EVENT_TITLE | ||
const orgName = process.env.ORG_NAME | ||
const repoName = process.env.REPO_NAME | ||
const filePath = path.join('VoteTracking.json'); | ||
|
||
const bindingVotesSectionMatch = message.match(/Binding votes \(\d+\)[\s\S]*?(?=(<details>|$))/); | ||
const bindingVotesSection = bindingVotesSectionMatch ? bindingVotesSectionMatch[0] : ''; | ||
const rows = bindingVotesSection.match(/\| @\w+.*?\|.*?\|.*?\|/g) || []; | ||
const latestVotes = rows.map(row => { | ||
const [ , user, vote, timestamp] = row.split('|').map(col => col.trim()); | ||
return { user: user.replace('@', ''), vote, timestamp, isVotedInLast3Months: true }; | ||
}); | ||
|
||
// Initialize vote tracking file if it doesn't exist | ||
if (!fs.existsSync(filePath)) { | ||
const yamlData = fs.readFileSync('MAINTAINERS.yaml', 'utf8'); | ||
const parsedData = yaml.load(yamlData); | ||
const tscMembers = parsedData.filter(entry => entry.isTscMember).map(entry => ({ | ||
name: entry.github, | ||
lastParticipatedVoteTime: '', | ||
hasVotedInLast3Months: 'false', | ||
lastVoteClosedTime: new Date().toISOString().split('T')[0], | ||
agreeCount: 0, | ||
disagreeCount: 0, | ||
abstainCount: 0, | ||
notParticipatingCount: 0 | ||
})); | ||
fs.writeFileSync(filePath, JSON.stringify(tscMembers, null, 2)); | ||
} | ||
|
||
const voteDetails = JSON.parse(fs.readFileSync(filePath, 'utf8')); | ||
const latestVotesInfo = [] | ||
voteDetails.map(voteInfo => { | ||
const currentTime = new Date().toISOString().split('T')[0]; | ||
const userInfo = latestVotes.find(vote => vote.user === voteInfo.name); | ||
const choice = userInfo ? userInfo.vote : "Not participated"; | ||
|
||
if (userInfo) { | ||
voteInfo.hasVotedInLast3Months = true; | ||
voteInfo.lastParticipatedVoteTime = currentTime; | ||
voteInfo[choice === "In favor" ? 'agreeCount' : choice === "Against" ? 'disagreeCount' : 'abstainCount']++; | ||
} else { | ||
voteInfo.notParticipatingCount++; | ||
voteInfo.lastVoteClosedTime = currentTime; | ||
if (!checkVotingDurationMoreThanThreeMonths(voteInfo)) { | ||
voteInfo.hasVotedInLast3Months = false; | ||
} | ||
} | ||
|
||
let updatedVoteInfo = {}; | ||
Object.keys(voteInfo).forEach(key => { | ||
if (key == 'name') { | ||
updatedVoteInfo['name'] = voteInfo.name | ||
updatedVoteInfo[eventTitle+"$$"+eventNumber] = choice | ||
} | ||
else { | ||
updatedVoteInfo[key] = voteInfo[key]; | ||
} | ||
}) | ||
latestVotesInfo.push(updatedVoteInfo) | ||
}); | ||
|
||
fs.writeFileSync(filePath, JSON.stringify(latestVotesInfo, null, 2)); | ||
|
||
// Check voting duration | ||
function checkVotingDurationMoreThanThreeMonths(voteInfo) { | ||
const currentDate = new Date(); | ||
const threeMonthsAgoDate = new Date(currentDate); | ||
threeMonthsAgoDate.setMonth(currentDate.getMonth() - 3); | ||
return new Date(voteInfo.lastVoteClosedTime) >= threeMonthsAgoDate && | ||
new Date(voteInfo.lastParticipatedVoteTime) <= threeMonthsAgoDate; | ||
} | ||
|
||
// Convert JSON data to markdown table | ||
function jsonToMarkdownTable(data) { | ||
const keys = Object.keys(data[0]); | ||
let markdownTable = '| ' + keys.map(key => { | ||
if (key.includes('$$')) { | ||
const [title, number] = key.split('$$'); | ||
return `[${title}](https://github.com/${orgName}/${repoName}/issues/${number})`; | ||
} | ||
const titles = { | ||
name: "Github user name", | ||
lastParticipatedVoteTime: "Last participated vote time of the user", | ||
hasVotedInLast3Months: "Voted in last 3 months or not", | ||
lastVoteClosedTime: "Last vote closed time", | ||
agreeCount: "Number of agreements votes", | ||
disagreeCount: "Number of disagreements votes", | ||
abstainCount: "Number of abstentions votes", | ||
notParticipatingCount: "Number of non-participations votes" | ||
AayushSaini101 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
return `<span style="position: relative; cursor: pointer;" title="${titles[key] || key}">${key}</span>`; | ||
}).join(' | ') + ' |\n'; | ||
|
||
markdownTable += '| ' + keys.map(() => '---').join(' | ') + ' |\n'; | ||
markdownTable += data.map(obj => '| ' + keys.map(key => { | ||
if (key === 'name') return `[${obj[key]}](https://github.com/${obj[key]})`; | ||
if (key.includes('$$')) { | ||
const icons = { | ||
derberg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"In favor": "👍", | ||
"Against": "👎", | ||
"Abstain": "👀", | ||
"Not participated": "🔕" | ||
}; | ||
return `<span style="position: relative; cursor: pointer;" title="${obj[key]}">${icons[obj[key]] || obj[key]}</span>`; | ||
} | ||
return obj[key]; | ||
}).join(' | ') + ' |').join('\n'); | ||
|
||
return markdownTable; | ||
} | ||
|
||
const markdownTable = jsonToMarkdownTable(latestVotesInfo); | ||
fs.writeFileSync('voteTrackingDetails.md', markdownTable); | ||
console.log('Markdown table has been written to voteTrackingDetails.md'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Vote Tracker | ||
|
||
on: | ||
issue_comment: | ||
types: [created] | ||
derberg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
jobs: | ||
track-vote: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Node.js | ||
derberg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '14' | ||
|
||
- name: Install the dependencies | ||
run: npm install [email protected] | ||
shell: bash | ||
|
||
- name: Configure Git | ||
run: | | ||
git config --global user.name "github-actions[bot]" | ||
git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
|
||
- name: Run vote tracker script | ||
id: vote_tracker | ||
if: | | ||
github.event.comment.user.login == 'git-vote[bot]' && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't we have this login validation on a job level, to basically not run entire job if this was not met? case with comment body There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done @derberg |
||
contains(github.event.comment.body, 'Vote closed') | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
COMMENT_BODY: ${{ github.event.comment.body }} | ||
EVENT_NUMBER: ${{ github.event.issue.number }} | ||
EVENT_TITLE: ${{ github.event.issue.title }} | ||
ORG_NAME: ${{ github.repository_owner }} | ||
REPO_NAME: ${{ github.event.repository.name }} | ||
run: | | ||
node .github/scripts/vote_tracker.js | ||
echo "::set-output name=ran_successfully::true" | ||
|
||
- name: Commit VotingTracking.json | ||
derberg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if: steps.vote_tracker.outputs.ran_successfully == 'true' | ||
run: | | ||
git add voteTrackingDetails.md | ||
git add VoteTracking.json | ||
git commit -m "Update voteTrackingDetails.md" | ||
git push | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the funcion is
async
, and you call it withawait
then lets properly use some async/await code, and not old school syncfs
functions.example:
every single use of await, should be wrapped in proper try/catch and when you catch an error, enrich it with proper additional comment, where error happened.
for example once you refactor
fs.readFileSync('MAINTAINERS.yaml', 'utf8')
then please properly describe the error as something likeUnable to read MAINTAINERS.yaml file
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done , also added try catch blow during reading and writing into files