Skip to content

Commit 3426c08

Browse files
authored
Merge pull request #6039 from github/jc/slackNotify
Add chatterbox Slack notifications for failed PR lint runs
2 parents 884c183 + 3488d94 commit 3426c08

3 files changed

Lines changed: 66 additions & 1 deletion

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Notify on linter failure
2+
permissions:
3+
contents: read
4+
5+
on:
6+
workflow_run:
7+
workflows:
8+
- Lint OpenAPI Descriptions
9+
types:
10+
- completed
11+
12+
jobs:
13+
notify:
14+
name: Notify #api-platform about failed lint
15+
if: |
16+
github.event.workflow_run.conclusion == 'failure' &&
17+
contains(fromJSON('["pull_request", "workflow_dispatch"]'), github.event.workflow_run.event) &&
18+
github.event.workflow_run.repository.full_name == 'github/rest-api-description'
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Post failure to chatterbox
22+
env:
23+
CHATTERBOX_URL: ${{ secrets.CHATTERBOX_URL }}
24+
CHATTERBOX_TOKEN: ${{ secrets.CHATTERBOX_TOKEN }}
25+
RUN_URL: ${{ github.event.workflow_run.html_url }}
26+
RUN_NAME: ${{ github.event.workflow_run.name }}
27+
BRANCH: ${{ github.event.workflow_run.head_branch }}
28+
COMMIT: ${{ github.event.workflow_run.head_sha }}
29+
PR_URL: ${{ github.event.workflow_run.pull_requests[0].html_url }}
30+
REPO: ${{ github.event.workflow_run.repository.full_name }}
31+
TRIGGER_EVENT: ${{ github.event.workflow_run.event }}
32+
run: |
33+
if [ -z "$CHATTERBOX_URL" ] || [ -z "$CHATTERBOX_TOKEN" ]; then
34+
echo "CHATTERBOX_URL or CHATTERBOX_TOKEN is not configured; skipping notification."
35+
exit 0
36+
fi
37+
38+
short_sha="${COMMIT:0:7}"
39+
40+
if [ -n "$PR_URL" ]; then
41+
target_line="• PR: ${PR_URL}"
42+
else
43+
target_line="• Trigger: ${TRIGGER_EVENT}"
44+
fi
45+
46+
message=":warning: Linter workflow failed in ${REPO}.\n• Workflow: ${RUN_NAME}\n${target_line}\n• Branch: ${BRANCH}\n• Commit: ${short_sha}\n• Run: ${RUN_URL}"
47+
48+
curl --fail --silent --show-error \
49+
-X POST \
50+
-u "${CHATTERBOX_TOKEN}:" \
51+
"${CHATTERBOX_URL%/}/topics/%23api-platform" \
52+
--data "$message"

.github/workflows/linter.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ permissions:
44
contents: read
55

66
on:
7-
- push
7+
push:
8+
pull_request:
9+
workflow_dispatch:
810

911
jobs:
1012
lint:

CONTRIBUTING.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ Please note that this project is released with a [Contributor Code of Conduct][c
1919

2020
We will gladly accept pull requests for contributions to other files in this repository.
2121

22+
## CI notifications
23+
24+
The `Notify on linter failure` workflow posts failed pull request lint runs to `#api-platform` through chatterbox.
25+
26+
To enable notifications, configure these repository-level Actions secrets:
27+
28+
- `CHATTERBOX_URL`
29+
- `CHATTERBOX_TOKEN`
30+
31+
This workflow is defined in `.github/workflows/linter-failure-notifier.yml`.
32+
2233
### Submitting a pull request
2334

2435
0. [Fork][fork] and clone the repository

0 commit comments

Comments
 (0)