|
| 1 | +name: Assign User on Comment |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + issue_comment: |
| 6 | + types: [created] |
| 7 | + |
| 8 | +jobs: |
| 9 | + assign: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + issues: write |
| 13 | + steps: |
| 14 | + - name: Check for "/assigntome" in comment |
| 15 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 16 | + env: |
| 17 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 18 | + with: |
| 19 | + script: | |
| 20 | + const issueComment = context.payload.comment.body; |
| 21 | + const assignRegex = /\/assigntome/i; |
| 22 | + if (assignRegex.test(issueComment)) { |
| 23 | + const assignee = context.payload.comment.user.login; |
| 24 | + const issueNumber = context.payload.issue.number; |
| 25 | + try { |
| 26 | + const { data: issue } = await github.rest.issues.get({ |
| 27 | + owner: context.repo.owner, |
| 28 | + repo: context.repo.repo, |
| 29 | + issue_number: issueNumber |
| 30 | + }); |
| 31 | + const hasLabel = issue.labels.some(label => label.name === 'docathon-2026'); |
| 32 | + if (hasLabel) { |
| 33 | + if (issue.assignee !== null) { |
| 34 | + await github.rest.issues.createComment({ |
| 35 | + owner: context.repo.owner, |
| 36 | + repo: context.repo.repo, |
| 37 | + issue_number: issueNumber, |
| 38 | + body: "The issue is already assigned. Please pick an opened and unnasigned issue with the [docathon-2026 label](https://github.com/pytorch/executorch/issues?q=is%3Aopen+is%3Aissue+label%3Adocathon-2026)" |
| 39 | + }); |
| 40 | + } else { |
| 41 | + await github.rest.issues.addAssignees({ |
| 42 | + owner: context.repo.owner, |
| 43 | + repo: context.repo.repo, |
| 44 | + issue_number: issueNumber, |
| 45 | + assignees: [assignee] |
| 46 | + }); |
| 47 | + } |
| 48 | + } else { |
| 49 | + const commmentMessage = "This issue does not have the correct label. Please pick an opened and unnasigned issue with the [docathon-2026 label](https://github.com/pytorch/executorch/issues?q=is%3Aopen+is%3Aissue+label%3Adocathon-2026)"; |
| 50 | + await github.rest.issues.createComment({ |
| 51 | + owner: context.repo.owner, |
| 52 | + repo: context.repo.repo, |
| 53 | + issue_number: issueNumber, |
| 54 | + body: commmentMessage |
| 55 | + }); |
| 56 | + } |
| 57 | + } catch (error) { |
| 58 | + console.error(error); |
| 59 | + } |
| 60 | + } |
0 commit comments