forked from paradedb/paradedb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow the contributor to self-assign the issue
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 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,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.' | ||
}) |