name: mattermost-ziti-webhook
on:
  create:
  delete:
  issues:
  issue_comment:
  pull_request_review:
    types: [submitted]
  pull_request_review_comment:
  pull_request:
    types: [opened, reopened]
  push:
  fork:
  release:
    types: [released]
  workflow_dispatch:
  watch:
    types: [started]

jobs:
  mattermost-ziti-webhook:
    runs-on: ubuntu-latest
    name: POST Webhook
    steps:
    - uses: openziti/ziti-mattermost-action-py@main
      if: |
        env.ZHOOK_URL != null
        && !(
          github.event_name == 'issue_comment'
          && github.event.sender.login == 'vercel[bot]'
          && (contains(github.event.comment.body, 'Building') || contains(github.event.comment.body, 'Ignored'))
        )
        && (
          github.event_name != 'pull_request_review'
          || (github.event_name == 'pull_request_review' && github.event.review.state == 'approved')
        )
      env:
        ZHOOK_URL: ${{ secrets.ZHOOK_URL }}
      with:
        zitiId: ${{ secrets.ZITI_MATTERMOST_IDENTITY }}
        webhookUrl: ${{ secrets.ZHOOK_URL }}
        eventJson: ${{ toJson(github.event) }}
        senderUsername: "GitHubZ"
        destChannel: "dev-notifications"

