• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1name: Assign User on Comment
2
3on:
4  workflow_dispatch:
5  issue_comment:
6    types: [created]
7
8jobs:
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@v6
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-h1-2024');
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-h1-2024 label](https://github.com/pytorch/pytorch/issues?q=is%3Aopen+is%3Aissue+label%3Adocathon-h1-2024)."
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-h1-2024 label](https://github.com/pytorch/pytorch/issues?q=is%3Aopen+is%3Aissue+label%3Adocathon-h1-2024)."
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            }
61