|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +name: Assign/unassign the issue via `take` or `untake` comment |
| 19 | +on: |
| 20 | + issue_comment: |
| 21 | + types: created |
| 22 | + |
| 23 | +permissions: |
| 24 | + issues: write |
| 25 | + |
| 26 | +jobs: |
| 27 | + issue_assign: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + if: (!github.event.issue.pull_request) && (github.event.comment.body == 'take' || github.event.comment.body == 'untake') |
| 30 | + concurrency: |
| 31 | + group: ${{ github.actor }}-issue-assign |
| 32 | + steps: |
| 33 | + - name: Take or untake issue |
| 34 | + env: |
| 35 | + COMMENT_BODY: ${{ github.event.comment.body }} |
| 36 | + ISSUE_NUMBER: ${{ github.event.issue.number }} |
| 37 | + USER_LOGIN: ${{ github.event.comment.user.login }} |
| 38 | + REPO: ${{ github.repository }} |
| 39 | + TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 40 | + run: | |
| 41 | + if [ "$COMMENT_BODY" == "take" ] |
| 42 | + then |
| 43 | + CODE=$(curl -H "Authorization: token $TOKEN" -LI https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER/assignees/$USER_LOGIN -o /dev/null -w '%{http_code}\n' -s) |
| 44 | + if [ "$CODE" -eq "204" ] |
| 45 | + then |
| 46 | + echo "Assigning issue $ISSUE_NUMBER to $USER_LOGIN" |
| 47 | + curl -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" -d "{\"assignees\": [\"$USER_LOGIN\"]}" https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER/assignees |
| 48 | + else |
| 49 | + echo "Cannot assign issue $ISSUE_NUMBER to $USER_LOGIN" |
| 50 | + fi |
| 51 | + elif [ "$COMMENT_BODY" == "untake" ] |
| 52 | + then |
| 53 | + echo "Unassigning issue $ISSUE_NUMBER from $USER_LOGIN" |
| 54 | + curl -X DELETE -H "Authorization: token $TOKEN" -H "Content-Type: application/json" -d "{\"assignees\": [\"$USER_LOGIN\"]}" https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER/assignees |
| 55 | + fi |
0 commit comments