diff --git a/.github/workflows/docs-pr-alert.yml b/.github/workflows/docs-pr-alert.yml new file mode 100644 index 00000000000..8d6cf316684 --- /dev/null +++ b/.github/workflows/docs-pr-alert.yml @@ -0,0 +1,46 @@ +name: Post docs PRs to Slack + +# Posts a docs PR to #team-docs-alerts whenever it's ready for review: when +# it's opened as ready, and every time a draft is marked ready. Reuses the +# webhook from docs-master-alert.yml. +# pull_request_target is used so fork PRs can read the webhook secret. This +# workflow only reads the event payload. It never checks out or runs PR code. +on: + pull_request_target: + types: [opened, ready_for_review] + paths: + - 'apps/docs/**' + +permissions: {} + +jobs: + post-to-slack: + runs-on: ubuntu-latest + if: github.event.pull_request.draft == false + steps: + - name: Post to Slack + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DOCS_WEBHOOK_URL }} + with: + script: | + const webhookUrl = process.env.SLACK_WEBHOOK_URL + if (!webhookUrl) { + core.notice('SLACK_DOCS_WEBHOOK_URL is not set, skipping.') + return + } + + const pr = context.payload.pull_request + const isExternal = !pr.head.repo || pr.head.repo.full_name !== pr.base.repo.full_name + const escape = (text) => + text.replace(/&/g, '&').replace(//g, '>') + const text = `<${pr.html_url}|#${pr.number} ${escape(pr.title)}> ยท ${isExternal ? 'External' : 'Internal'}` + + const response = await fetch(webhookUrl, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ text, unfurl_links: false }), + }) + if (!response.ok) { + core.setFailed(`Slack returned ${response.status}: ${await response.text()}`) + } diff --git a/zizmor.yml b/zizmor.yml index 8c80c2129ba..978f031f959 100644 --- a/zizmor.yml +++ b/zizmor.yml @@ -3,6 +3,7 @@ rules: ignore: - 'authorize-vercel-deploys.yml' - 'docs-master-alert.yml' + - 'docs-pr-alert.yml' - 'external-pr-comment.yml' - 'kb-master-alert.yml' - 'label_prs.yml'