Skip to content

Commit

Permalink
feat: Allow the contributor to self-assign the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Weijun-H committed Sep 18, 2024
1 parent 928c2bb commit c9ac2b9
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/take.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Assign Issue via 'take' Comment

on:
issue_comment:
types: [created]

permissions:
issues: write

jobs:
issue_assign:
runs-on: ubuntu-latest
if: |
!github.event.issue.pull_request &&
contains(github.event.comment.body, '/take')
concurrency:
group: ${{ github.workflow }}-${{ github.event.issue.number }}
cancel-in-progress: true

steps:
- name: Check if commenter can be assigned
id: check_assignee
run: |
HTTP_CODE=$(curl -X GET \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-o /dev/null -w '%{http_code}\n' -s \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/assignees/${{ github.event.comment.user.login }}")
if [ "$HTTP_CODE" -eq "204" ]; then
echo "can_assign=true" >> $GITHUB_OUTPUT
else
echo "can_assign=false" >> $GITHUB_OUTPUT
fi
- name: Assign issue
if: steps.check_assignee.outputs.can_assign == 'true'
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-d '{"assignees": ["${{ github.event.comment.user.login }}"]}' \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/assignees"
echo "Issue #${{ github.event.issue.number }} assigned to ${{ github.event.comment.user.login }}"
- name: Comment if assignment failed
if: steps.check_assignee.outputs.can_assign == 'false'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.name,
body: '@${{ github.event.comment.user.login }} Unable to assign this issue to you. You may not have the necessary permissions.'
})

0 comments on commit c9ac2b9

Please sign in to comment.