name: Slack Notifier

on:
  issues:
    types:
      - opened
      - closed
  pull_request:
    types:
      - opened
      - closed

permissions:
  contents: read

jobs:
  on-issue-opened:
    runs-on: ubuntu-latest
    if: github.event_name == 'issues' && github.event.action == 'opened'
    steps:
      - name: notify
        env:
          ISSUE_TITLE: ${{ github.event.issue.title }}
        run: |
          curl \
            -X POST \
            -H 'Content-Type: application/json' \
            -d '{"type": "issues_opened", "id": "${{ github.event.issue.number }}", "title": "'"$ISSUE_TITLE"'"}' \
            ${{ secrets.CI_SLACK_WEBHOOK_URL }}

  on-issue-closed:
    runs-on: ubuntu-latest
    if: github.event_name == 'issues' && github.event.action == 'closed'
    steps:
      - name: notify
        env:
          ISSUE_TITLE: ${{ github.event.issue.title }}
        run: |
          curl \
            -X POST \
            -H 'Content-Type: application/json' \
            -d '{"type": "issues_closed", "id": "${{ github.event.issue.number }}", "title": "'"$ISSUE_TITLE"'"}' \
            ${{ secrets.CI_SLACK_WEBHOOK_URL }}

  on-pr-opened:
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request' && github.event.action == 'opened'
    steps:
      - name: notify
        env:
          PR_TITLE: ${{ github.event.pull_request.title }}
        run: |
          curl \
            -X POST \
            -H 'Content-Type: application/json' \
            -d '{"type": "pullrequest_opened", "id": "${{ github.event.pull_request.number }}", "title": "'"$PR_TITLE"'"}' \
            ${{ secrets.CI_SLACK_WEBHOOK_URL }}

  on-pr-closed:
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request' && github.event.action == 'closed'
    steps:
      - name: notify
        env:
          PR_TITLE: ${{ github.event.pull_request.title }}
        run: |
          curl \
            -X POST \
            -H 'Content-Type: application/json' \
            -d '{"type": "pullrequest_closed", "id": "${{ github.event.pull_request.number }}", "title": "'"$PR_TITLE"'"}' \
            ${{ secrets.CI_SLACK_WEBHOOK_URL }}
