# #
#   @type               github workflow
#   @desc               adds a label to a PR when the command "/accept" is typed in the issue comments
#                           do not attempt to use env variables in if condition.
#                           do not accept to change GITHUB_TOKEN.
#   @author             Aetherinox
#   @url                https://github.com/Aetherinox
# #

name: "🎫 Issue › Accept"
run-name: "🎫 Issue › Accept"

# #
#   triggers
# #

on:
    issue_comment:
        types: [created]

# #
#   environment variables
# #

env:
    LABEL_ACCEPT:         "Status 𐄂 Accepted"

    BOT_NAME_1:           AdminServ
    BOT_NAME_2:           AdminServX
    BOT_NAME_3:           EuropaServ
    BOT_NAME_DEPENDABOT:  dependabot[bot]

# #
#   jobs
# #

jobs:

    # #
    #   Job [ Deploy ]
    # #

    deploy:
        if: contains(github.event.comment.body, '/accept') && github.event.comment.user.login == 'Aetherinox'
        runs-on: ubuntu-latest
        steps:

            # #
            #   Add Label to accepted PR
            # #

            - name: >-
                  🏷️ Assign Label › ${{ env.LABEL_ACCEPT }}
              run: gh issue edit "$NUMBER" --add-label "$LABELS"
              env:
                  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
                  GH_REPO: ${{ github.repository }}
                  NUMBER: ${{ github.event.issue.number }}
                  LABELS: ${{ env.LABEL_ACCEPT }}

            # #
            #   Add assignee to accepted PR
            # #

            - name: >-
                  🏷️ Assign Assignee › ${{ github.repository_owner }}
              run: gh issue edit "$NUMBER" --add-assignee "$ASSIGNEE"
              env:
                  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
                  GH_REPO: ${{ github.repository }}
                  NUMBER: ${{ github.event.issue.number }}
                  ASSIGNEE: ${{ github.repository_owner }}
