name: 'QA: Metrics PR Comment'

on:
  workflow_call:
    inputs:
      metrics:
        description: 'Comma-separated list of metric names to report'
        required: true
        type: string
      baseline-days:
        description: 'Number of days for the rolling baseline'
        required: false
        type: number
        default: 14

jobs:
  post-comment:
    name: Post Metrics Comment
    if: >-
      github.event_name == 'pull_request' &&
      !github.event.pull_request.head.repo.fork &&
      github.repository == 'n8n-io/n8n'
    runs-on: ubuntu-slim
    continue-on-error: true
    permissions:
      pull-requests: write
    steps:
      - uses: useblacksmith/checkout@41cdeedae8edb2e684ba22896a5fd2a3cb85db6b # v1
        with:
          sparse-checkout: .github/scripts/post-qa-metrics-comment.mjs
          sparse-checkout-cone-mode: false
      - name: Post QA metrics comparison
        env:
          QA_METRICS_COMMENT_WEBHOOK_URL: ${{ secrets.QA_METRICS_COMMENT_WEBHOOK_URL }}
          QA_METRICS_WEBHOOK_USER: ${{ secrets.QA_METRICS_WEBHOOK_USER }}
          QA_METRICS_WEBHOOK_PASSWORD: ${{ secrets.QA_METRICS_WEBHOOK_PASSWORD }}
          GITHUB_TOKEN: ${{ github.token }}
          METRICS: ${{ inputs.metrics }}
          BASELINE_DAYS: ${{ inputs.baseline-days }}
        run: |
          node .github/scripts/post-qa-metrics-comment.mjs \
            --metrics "$METRICS" \
            --baseline-days "$BASELINE_DAYS"
