diff --git a/.github/workflows/assigntome-docathon.yml b/.github/workflows/assigntome-docathon.yml new file mode 100644 index 00000000000..92dec519296 --- /dev/null +++ b/.github/workflows/assigntome-docathon.yml @@ -0,0 +1,60 @@ +name: Assign User on Comment + +on: + workflow_dispatch: + issue_comment: + types: [created] + +jobs: + assign: + runs-on: ubuntu-latest + permissions: + issues: write + steps: + - name: Check for "/assigntome" in comment + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + script: | + const issueComment = context.payload.comment.body; + const assignRegex = /\/assigntome/i; + if (assignRegex.test(issueComment)) { + const assignee = context.payload.comment.user.login; + const issueNumber = context.payload.issue.number; + try { + const { data: issue } = await github.rest.issues.get({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueNumber + }); + const hasLabel = issue.labels.some(label => label.name === 'docathon-2026'); + if (hasLabel) { + if (issue.assignee !== null) { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueNumber, + 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)" + }); + } else { + await github.rest.issues.addAssignees({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueNumber, + assignees: [assignee] + }); + } + } else { + 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)"; + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueNumber, + body: commmentMessage + }); + } + } catch (error) { + console.error(error); + } + } diff --git a/.github/workflows/docathon-sync-label.yml b/.github/workflows/docathon-sync-label.yml new file mode 100644 index 00000000000..bf8197f8d64 --- /dev/null +++ b/.github/workflows/docathon-sync-label.yml @@ -0,0 +1,31 @@ +name: Docathon Labels Sync + +on: + pull_request_target: + types: [opened, synchronize, edited] + branches: [main] + +jobs: + check-labels: + if: github.repository_owner == 'pytorch' + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - name: Check out the repo + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + fetch-depth: 1 + - name: Set up Python + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 + with: + python-version: 3.x + - name: Install dependencies + run: | + pip install requests==2.32.3 + pip install PyGithub==2.3.0 + - name: Run Python script + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: python ./.github/scripts/docathon-label-sync.py ${{ github.event.pull_request.number }}