|
| 1 | +name: Assign Committer |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + types: [opened, reopened, ready_for_review] |
| 5 | + |
| 6 | +permissions: |
| 7 | + pull-requests: write |
| 8 | + |
| 9 | +jobs: |
| 10 | + assign-reviewer: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + if: ${{ github.event.pull_request.draft != true }} |
| 13 | + steps: |
| 14 | + - name: Add Assignee |
| 15 | + uses: actions/github-script@v7 |
| 16 | + with: |
| 17 | + script: | |
| 18 | + if (context.payload.pull_request.assignees.length === 0) { |
| 19 | + // Find suitable assignees |
| 20 | + const { data: members } = await github.rest.teams.listMembersInOrg({ // TODO This needs read:org permission |
| 21 | + org: "JuliaLang", |
| 22 | + team_slug: "committers", |
| 23 | + per_page: 100, // TODO: use pagination once we have more than 100 committers |
| 24 | + }); |
| 25 | + const member_logins = members.map(member => member.login); |
| 26 | +
|
| 27 | + // Skip PRs authored by committers |
| 28 | + const prAuthor = context.payload.pull_request.user.login; |
| 29 | + if (!member_logins.includes(prAuthor)) { |
| 30 | + |
| 31 | + // Assign random committer |
| 32 | + await github.rest.issues.addAssignees({ |
| 33 | + owner: context.repo.owner, |
| 34 | + repo: context.repo.repo, |
| 35 | + issue_number: context.payload.pull_request.number, |
| 36 | + assignees: member_logins[Math.floor(Math.random()*member_logins.length)], |
| 37 | + }); |
| 38 | + |
| 39 | + // Add the "pr review" label |
| 40 | + await github.rest.issues.addLabels({ |
| 41 | + owner: context.repo.owner, |
| 42 | + repo: context.repo.repo, |
| 43 | + issue_number: context.payload.pull_request.number, |
| 44 | + labels: ['status: waiting for PR reviewer'], |
| 45 | + }); |
| 46 | + } |
| 47 | + } |
0 commit comments