-
-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add github action to self-assign the issue
- Loading branch information
Showing
2 changed files
with
56 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# This workflow has been inspired by https://github.com/MrPowers/quinn/blob/main/.github/workflows/assign-on-comment.yml | ||
|
||
name: Auto assign the issue via `take` 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 == 'take' | ||
concurrency: | ||
# Only run one a time per user | ||
group: ${{ github.actor }}-auto-assign-issue | ||
steps: | ||
- name: Check if issue can be assigned | ||
id: check-assignee | ||
run: | | ||
# Check if the user is already assigned to the issue | ||
RESPONSE=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -LI https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/assignees/${{ github.event.comment.user.login }} -o /dev/null -w '%{http_code}' -s) | ||
echo "HTTP_CODE=$RESPONSE" >> $GITHUB_ENV | ||
- name: Assign issue to commenter | ||
if: env.HTTP_CODE == '204' | ||
run: | | ||
# Assign the issue to the user who commented 'take' | ||
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 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Log failure to assign | ||
if: env.HTTP_CODE != '204' | ||
run: | | ||
# Log the failure to assign the issue | ||
echo "Issue #${{ github.event.issue.number }} cannot be assigned to @${{ github.event.comment.user.login }}. HTTP response code: ${{ env.HTTP_CODE }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters