From ce4991f835c63dd664b1c2630f868d1ea20944d1 Mon Sep 17 00:00:00 2001 From: Shingo OKAWA Date: Fri, 25 Apr 2025 11:25:16 +0900 Subject: [PATCH] Add auto-assign-on-comment.yaml Signed-off-by: Shingo OKAWA --- .github/workflows/auto-assign-on-comment.yaml | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/auto-assign-on-comment.yaml diff --git a/.github/workflows/auto-assign-on-comment.yaml b/.github/workflows/auto-assign-on-comment.yaml new file mode 100644 index 0000000..56b88d0 --- /dev/null +++ b/.github/workflows/auto-assign-on-comment.yaml @@ -0,0 +1,50 @@ +name: Auto Assign on 'take' Comment +on: + issue_comment: + types: [created] +permissions: + issues: write +jobs: + assign: + runs-on: ubuntu-latest + if: (!github.event.issue.pull_request) && contains(github.event.comment.body, 'take') + concurrency: + group: ${{ github.actor }}-auto-assign-issue + cancel-in-progress: true + steps: + - name: Auto assign if comment includes 'take' + uses: actions/github-script@v7 + with: + script: | + const body = context.payload.comment.body.toLowerCase(); + const author = context.payload.comment.user.login; + const issue = context.payload.issue; + + // Check if comment includes 'take' + if (!body.includes('take')) { + console.log("Comment does not include 'take'; skipping."); + return; + } + + // Check if already assigned + const alreadyAssigned = issue.assignees.find(a => a.login === author); + if (alreadyAssigned) { + console.log(`${author} is already assigned; skipping.`); + return; + } + + // Check if there is any other assignee + if (issue.assignees.length > 0) { + console.log("Issue already has an assignee; skipping assignment."); + return; + } + + // Assign to commenter + await github.rest.issues.addAssignees({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue.number, + assignees: [author], + }); + + console.log(`Assigned ${author} to issue #${issue.number}`); \ No newline at end of file