2024-09-22 18:35:21 +01:00
|
|
|
name: Issue slash commands
|
2024-07-25 23:14:33 +01:00
|
|
|
|
|
|
|
on:
|
|
|
|
issue_comment:
|
|
|
|
types: [created, edited]
|
|
|
|
|
|
|
|
jobs:
|
2024-09-22 18:35:21 +01:00
|
|
|
issueCommands:
|
2024-07-25 23:14:33 +01:00
|
|
|
# Skip this job if the comment was created/edited on a PR
|
|
|
|
if: ${{ !github.event.issue.pull_request }}
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
permissions:
|
|
|
|
issues: write
|
|
|
|
pull-requests: none
|
|
|
|
contents: read
|
|
|
|
|
|
|
|
steps:
|
2024-09-21 15:14:39 +01:00
|
|
|
- run: echo "command=false" >> $GITHUB_ENV
|
|
|
|
|
2024-09-22 18:35:21 +01:00
|
|
|
- name: Check for /label command
|
|
|
|
id: check_label_command
|
|
|
|
run: |
|
|
|
|
if [[ "${{ contains(github.event.comment.body, '/label') }}" == "true" ]]; then
|
|
|
|
echo "command=true" >> $GITHUB_ENV
|
|
|
|
LABEL_NAME=$(echo "${{ github.event.comment.body }}" | awk -F"/label" '/\/label/ { match($2, /'\''([^'\'']*)'\''/, arr); if (arr[1] != "") print arr[1] }')
|
|
|
|
echo "label_command=true" >> $GITHUB_ENV
|
|
|
|
echo "label_name=${LABEL_NAME}" >> $GITHUB_ENV
|
|
|
|
else
|
|
|
|
echo "label_command=false" >> $GITHUB_ENV
|
|
|
|
fi
|
|
|
|
|
|
|
|
- name: Check for /unlabel command
|
|
|
|
id: check_unlabel_command
|
|
|
|
run: |
|
|
|
|
if [[ "${{ contains(github.event.comment.body, '/unlabel') }}" == "true" ]]; then
|
|
|
|
echo "command=true" >> $GITHUB_ENV
|
|
|
|
UNLABEL_NAME=$(echo "${{ github.event.comment.body }}" | awk -F"/unlabel" '/\/unlabel/ { match($2, /'\''([^'\'']*)'\''/, arr); if (arr[1] != "") print arr[1] }')
|
|
|
|
echo "unlabel_command=true" >> $GITHUB_ENV
|
|
|
|
echo "unlabel_name=${UNLABEL_NAME}" >> $GITHUB_ENV
|
|
|
|
else
|
|
|
|
echo "unlabel_command=false" >> $GITHUB_ENV
|
|
|
|
fi
|
|
|
|
|
2024-09-21 15:14:39 +01:00
|
|
|
- name: Check for /close command
|
|
|
|
id: check_close_command
|
2024-07-25 23:14:33 +01:00
|
|
|
run: |
|
|
|
|
if [[ "${{ contains(github.event.comment.body, '/close') }}" == "true" ]]; then
|
2024-09-21 15:14:39 +01:00
|
|
|
echo "command=true" >> $GITHUB_ENV
|
|
|
|
echo "close_command=true" >> $GITHUB_ENV
|
|
|
|
echo "reopen_command=false" >> $GITHUB_ENV
|
|
|
|
else
|
|
|
|
echo "close_command=false" >> $GITHUB_ENV
|
|
|
|
fi
|
|
|
|
|
|
|
|
- name: Check for /open or /reopen command
|
|
|
|
id: check_reopen_command
|
|
|
|
run: |
|
|
|
|
if [[ "${{ contains(github.event.comment.body, '/open') }}" == "true" ]] || [[ "${{ contains(github.event.comment.body, '/reopen') }}" == "true" ]]; then
|
|
|
|
echo "command=true" >> $GITHUB_ENV
|
|
|
|
echo "reopen_command=true" >> $GITHUB_ENV
|
|
|
|
echo "close_command=false" >> $GITHUB_ENV
|
2024-07-25 23:14:33 +01:00
|
|
|
else
|
2024-09-21 15:14:39 +01:00
|
|
|
echo "reopen_command=false" >> $GITHUB_ENV
|
2024-07-25 23:14:33 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
- name: Check if the user is allowed
|
|
|
|
id: check_user
|
2024-09-21 15:14:39 +01:00
|
|
|
if: env.command == 'true'
|
2024-07-25 23:14:33 +01:00
|
|
|
run: |
|
2024-09-22 18:35:21 +01:00
|
|
|
ALLOWED_USERS=("ChrisTitusTech" "afonsofrancof" "Marterich" "MyDrift-user" "Real-MullaC" "nnyyxxxx" "adamperkowski" "lj3954" "jeevithakannan2" "${{ github.event.issue.user.login }}")
|
2024-07-25 23:14:33 +01:00
|
|
|
if [[ " ${ALLOWED_USERS[@]} " =~ " ${{ github.event.comment.user.login }} " ]]; then
|
|
|
|
echo "user=true" >> $GITHUB_ENV
|
|
|
|
else
|
2024-09-22 18:35:21 +01:00
|
|
|
exit 0
|
2024-07-25 23:14:33 +01:00
|
|
|
fi
|
|
|
|
|
2024-09-22 18:35:21 +01:00
|
|
|
- name: Close issue
|
|
|
|
if: env.close_command == 'true'
|
2024-07-25 23:14:33 +01:00
|
|
|
env:
|
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
ISSUE_NUMBER: ${{ github.event.issue.number }}
|
|
|
|
run: |
|
|
|
|
echo Closing the issue...
|
2024-09-21 15:14:39 +01:00
|
|
|
if [[ "${{ contains(github.event.comment.body, 'not planned') }}" == "true" ]]; then
|
|
|
|
gh issue close $ISSUE_NUMBER --repo ${{ github.repository }} --reason 'not planned'
|
|
|
|
else
|
|
|
|
gh issue close $ISSUE_NUMBER --repo ${{ github.repository }}
|
|
|
|
fi
|
|
|
|
|
2024-09-22 18:35:21 +01:00
|
|
|
- name: Reopen issue
|
|
|
|
if: env.reopen_command == 'true'
|
2024-09-21 15:14:39 +01:00
|
|
|
env:
|
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
ISSUE_NUMBER: ${{ github.event.issue.number }}
|
|
|
|
run: |
|
|
|
|
echo Reopening the issue...
|
|
|
|
gh issue reopen $ISSUE_NUMBER --repo ${{ github.repository }}
|
2024-09-22 18:35:21 +01:00
|
|
|
|
|
|
|
- name: Label issue
|
|
|
|
if: env.label_command == 'true'
|
|
|
|
env:
|
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
ISSUE_NUMBER: ${{ github.event.issue.number }}
|
|
|
|
run: |
|
|
|
|
echo Labeling the issue...
|
|
|
|
gh issue edit $ISSUE_NUMBER --repo ${{ github.repository }} --add-label "${{ env.label_name }}"
|
|
|
|
|
|
|
|
- name: Remove labels
|
|
|
|
if: env.unlabel_command == 'true'
|
|
|
|
env:
|
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
ISSUE_NUMBER: ${{ github.event.issue.number }}
|
|
|
|
run: |
|
|
|
|
echo Unlabeling the issue...
|
|
|
|
gh issue edit $ISSUE_NUMBER --repo ${{ github.repository }} --remove-label "${{ env.unlabel_name }}"
|