diff --git a/.github/workflows/calico-github-issues-bot-trigger.yml b/.github/workflows/calico-github-issues-bot-trigger.yml new file mode 100644 index 00000000000..058b9fe085f --- /dev/null +++ b/.github/workflows/calico-github-issues-bot-trigger.yml @@ -0,0 +1,76 @@ +name: Trigger Calico Github Issues Bot + +on: + issues: + types: [opened] + issue_comment: + types: [created] + +permissions: + contents: read + issues: read + +jobs: + trigger-calico-github-issues-bot: + runs-on: ubuntu-latest + + # Ignore PR comments and bot comments + if: > + (github.event_name == 'issues') || + ( + github.event_name == 'issue_comment' && + github.event.issue.pull_request == null && + github.event.comment.user.type != 'Bot' + ) + + steps: + - name: Print debug info + run: | + echo "Event: ${{ github.event_name }}" + echo "Issue number: ${{ github.event.issue.number }}" + echo "Comment ID: ${{ github.event.comment.id }}" + echo "Author: ${{ github.event.comment.user.login }}" + + - name: Trigger Calico Github Issues Bot + env: + CALI_BOT_PAT: ${{ secrets.CALI_BOT_PAT }} + run: | + set -euo pipefail + + if [ -z "$CALI_BOT_PAT" ]; then + echo "CALI_BOT_PAT is not set" + exit 1 + fi + + EVENT_TYPE="" + COMMENT_ID="" + COMMENT_AUTHOR="" + + if [ "${{ github.event_name }}" = "issues" ]; then + EVENT_TYPE="issue_opened" + else + EVENT_TYPE="comment_created" + COMMENT_ID="${{ github.event.comment.id }}" + COMMENT_AUTHOR="${{ github.event.comment.user.login }}" + fi + + echo "Dispatching Calico Github Issues Bot with event: $EVENT_TYPE" + + curl --fail --show-error --silent -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $CALI_BOT_PAT" \ + https://api.github.com/repos/tigera/cali-bot/actions/workflows/process-issue.yml/dispatches \ + -d @- <