From 28c2d53b52965aee7c4a01ad4c2a62e84c2535ce Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 13 Jun 2024 14:31:31 -0700 Subject: [PATCH] add review-assigner.yaml --- .github/workflows/review-assigner.yaml | 54 ++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .github/workflows/review-assigner.yaml diff --git a/.github/workflows/review-assigner.yaml b/.github/workflows/review-assigner.yaml new file mode 100644 index 0000000000..8d1c778105 --- /dev/null +++ b/.github/workflows/review-assigner.yaml @@ -0,0 +1,54 @@ +name: "Reviewer Assigner" + +on: + pull_request: + types: [opened] + issues: + types: [opened] + +permissions: + pull-requests: 'write' + +jobs: + assign-reviewer: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-node@v3 + - run: npm install @pagerduty/pdjs + - uses: actions/github-script@e69ef5462fd455e02edcaf4dd7708eda96b9eda0 # v7.0.0 + env: + PAGERDUTY_TOKEN: ${{ secrets.PAGERDUTY_TOKEN }} + with: + script: | + const { PAGERDUTY_TOKEN } = process.env + const { api } = require('@pagerduty/pdjs'); + + const reviewerList = new Map([ + ["Sheneska Williams", "sheneska"], + ["Mauricio Alvarez Leon", "BBBmau"], + ["Alex Somesan", "alexsomesan"], + ["Alex Pilon", "appilon"], + ["John Houston", "jrhouston"], + ["Aleksandr Rybolovlev", "arybolovlev"], + ]); + + const pd = api({token: PAGERDUTY_TOKEN}); + const reviewer = "" + console.log("triggered by: " + context.eventName) + pd.get('oncalls?escalation_policy_ids%5B%5D=PH8IF3M') + .then(({data}) => { + reviewer = data.oncalls[0].user.summary + console.log("Assigning issue to " + data.oncalls[0].user.summary); + }).catch(console.error) + if (context.eventName == "issues"){ + try{ + await github.rest.issues.addAssignees({ + owner: context.repo.owner, + repo: context.repo.repo, + assignees: reviewerList.get(reviewer), // this will be replaced with pagerduty resp + issue_number: context.issue.number, // issue.number is used for both issues and PRs + }) + } catch(error){ + core.setFailed("error assigning assignee:" + error) + } + }