Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Workflow to Auto Assign Issues on Comment #1399

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/auto-assign-issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Auto Assign Issues On Comment

on:
issue_comment:
types: [created]

permissions:
issues: write

jobs:
auto-assign:
runs-on: ubuntu-latest
if: (!github.event.issue.pull_request) && github.event.comment.body == '/assign'
concurrency:
# Only run one at a time per user
group: ${{ github.actor }}-auto-assign-issue
steps:
- name: Check current issue assignees
id: check-assignee
run: |
RESPONSE=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }})
CURRENT_ASSIGNEES=$(echo "$RESPONSE" | jq -r '.assignees[].login')

# Check if the commenter is already assigned
if echo "$CURRENT_ASSIGNEES" | grep -q "${{ github.event.comment.user.login }}"; then
echo "ASSIGNMENT_STATUS=already_assigned" >> $GITHUB_ENV

# Check if someone else is already assigned
elif [ -n "$CURRENT_ASSIGNEES" ]; then
echo "ASSIGNMENT_STATUS=assigned_to_others" >> $GITHUB_ENV

# No one is assigned, issue can be assigned to the commenter
else
echo "ASSIGNMENT_STATUS=can_assign" >> $GITHUB_ENV
fi

- name: Assign issue to commenter
if: env.ASSIGNMENT_STATUS == 'can_assign'
run: |
echo "Assigning issue #${{ github.event.issue.number }} to @${{ github.event.comment.user.login }}"
curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-d '{"assignees": ["${{ github.event.comment.user.login }}"]}' \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/assignees

- name: Log already assigned
if: env.ASSIGNMENT_STATUS == 'already_assigned'
run: |
echo "Issue #${{ github.event.issue.number }} is already assigned to @${{ github.event.comment.user.login }}."

- name: Log issue assigned to someone else
if: env.ASSIGNMENT_STATUS == 'assigned_to_others'
run: |
echo "Issue #${{ github.event.issue.number }} is already assigned to someone else: $CURRENT_ASSIGNEES."

- name: Comment on the issue based on outcome
run: |
if [ "${{ env.ASSIGNMENT_STATUS }}" == "can_assign" ]; then
COMMENT_BODY="Issue #${{ github.event.issue.number }} has been successfully assigned to @${{ github.event.comment.user.login }}."
elif [ "${{ env.ASSIGNMENT_STATUS }}" == "already_assigned" ]; then
COMMENT_BODY="Issue #${{ github.event.issue.number }} is already assigned to you, @${{ github.event.comment.user.login }}."
else
COMMENT_BODY="Issue #${{ github.event.issue.number }} is already assigned to someone else: $CURRENT_ASSIGNEES."
fi

curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-d '{"body": "'"${COMMENT_BODY}"'"}' \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments
Loading