From 5b0c7433a9d04cff2c02b54eaeaf867e902e5302 Mon Sep 17 00:00:00 2001 From: AayushSaini101 Date: Sun, 24 Mar 2024 16:51:27 +0530 Subject: [PATCH] Add workflow to enable voting --- .github/workflows/add_vote_label.yml | 70 ++++++++++++++++++++++++ .github/workflows/remove_vote_label.yml | 71 +++++++++++++++++++++++++ .gitvote.yml | 54 +++++++++++++++++++ 3 files changed, 195 insertions(+) create mode 100644 .github/workflows/add_vote_label.yml create mode 100644 .github/workflows/remove_vote_label.yml create mode 100644 .gitvote.yml diff --git a/.github/workflows/add_vote_label.yml b/.github/workflows/add_vote_label.yml new file mode 100644 index 000000000..b7f77f673 --- /dev/null +++ b/.github/workflows/add_vote_label.yml @@ -0,0 +1,70 @@ +name: Add label to PR on comment + +on: + issue_comment: + types: [created] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Get the comment body + id: get_comment_body + run: | + echo "Comment body: ${{ github.event.comment.body }}" | ls + + - name: Verify TSC Member + id: verify_member + uses: actions/github-script@v6 + with: + script: | + const fs = require('fs'); + const filePath = 'TSC_MEMBERS.json'; + const commenterName = context.payload.sender.login; + let isTSCMember = false; + + function readFileAndProcess(callback) { + fs.readFile(filePath, 'utf8', (err, data) => { + if (err) { + callback(err, null); + return; + } + try { + const jsonData = JSON.parse(data); + // Iterate over each object in the array + jsonData.forEach(item => { + if (item.github === commenterName) { + isTSCMember = true; + } + }); + // Invoke the callback function with the result + callback(null, isTSCMember); + } catch (parseError) { + callback(parseError, null); + } + }); + } + + readFileAndProcess((error, result) => { + if (error) { + console.error('Error:', error); + } else { + console.log('Is TSC Member:', result); + core.setOutput('isTSCMember', isTSCMember); + } + }); + + - name: Add the label + if: contains(github.event.comment.body, '/vote') && steps.verify_member.outputs.isTSCMember =='true' + run: + if [ "${{ github.event_name }}" = "pull_request" ]; then + gh pr edit ${{ github.event.pull_request.number }} --add-label "vote" + else + gh issue edit ${{ github.event.issue.number }} --add-label "vote" + fi + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + diff --git a/.github/workflows/remove_vote_label.yml b/.github/workflows/remove_vote_label.yml new file mode 100644 index 000000000..15d91a813 --- /dev/null +++ b/.github/workflows/remove_vote_label.yml @@ -0,0 +1,71 @@ +name: Remove vote label + +on: + issue_comment: + types: [created] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Get the comment body + id: get_comment_body + run: | + echo "Comment body: ${{ github.event.comment.body }}" + + - name: Verify TSC Member + id: verify_member + uses: actions/github-script@v6 + with: + script: | + const fs = require('fs'); + const filePath = 'TSC_MEMBERS.json'; + const commenterName = context.payload.sender.login; + let isTSCMember = false; + + function readFileAndProcess(callback) { + fs.readFile(filePath, 'utf8', (err, data) => { + if (err) { + callback(err, null); + return; + } + try { + const jsonData = JSON.parse(data); + // Iterate over each object in the array + jsonData.forEach(item => { + if (item.github === commenterName) { + isTSCMember = true; + } + }); + // Invoke the callback function with the result + callback(null, isTSCMember); + } catch (parseError) { + callback(parseError, null); + } + }); + } + + readFileAndProcess((error, result) => { + if (error) { + console.error('Error:', error); + } else { + console.log('Is TSC Member:', result); + core.setOutput('isTSCMember', isTSCMember); + } + }); + + - name: Add the label + if: contains(github.event.comment.body, '/cancel-vote') && steps.verify_member.outputs.isTSCMember =='true' + run: + run:| + if [ "${{ github.event_name }}" = "pull_request" ]; then + gh pr edit ${{ github.event.pull_request.number }} --remove-label "vote" + else + gh issue edit ${{ github.event.issue.number }} --remove-label "vote" + fi + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + diff --git a/.gitvote.yml b/.gitvote.yml new file mode 100644 index 000000000..312bc5055 --- /dev/null +++ b/.gitvote.yml @@ -0,0 +1,54 @@ +profiles: + default: + duration: 2m + pass_threshold: 51 + periodic_status_check: "1 week" + allowed_voters: + teams: + - tsc_members + users: + - aayushmau5 + - imabp + - akshatnema + - anandsunderraman + - arjungarg07 + - CameronRushton + - dalelane + - emilianozublena + - fmvilas + - GeraldLoeffler + - jonaslagoni + - KhudaDad414 + - lbroudoux + - m3lkior + - derberg + - magicmatatjahu + - AceTheCreator + - damaru-inc + - mcturco + - NektariosFifes + - Pakisan + - theschles + - pratik2315 + - rcoppen + - smoya + - Souvikns + - alequetzalli + - BOLT04 + - dan-r + - KieranM1999 + - JEFFLUFC + - thulieblack + - lewis-relph + - boyney123 + - Tenischev + - Samridhi-98 + - ron-debajyoti + - ivangsa + - Florence-Njeri + - whitlockjc + - char0n + - VisualBean + - Barbanio + - kennethaasan + - GreenRover \ No newline at end of file