Skip to content

Commit

Permalink
chore(ci): fix Slack bot notification (#7598)
Browse files Browse the repository at this point in the history
1. backport notification fails due to new backport message.
2. build notification uses PR author instead of merger.
  • Loading branch information
outsinre committed Dec 14, 2023
1 parent f6fbe44 commit 94787cb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backport-fail-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
check_comment:
runs-on: ubuntu-latest
if: github.event.issue.pull_request != null && contains(github.event.comment.body, 'To backport manually, run these commands in your terminal')
if: github.event.issue.pull_request != null && contains(github.event.comment.body, 'cherry-pick the changes locally and resolve any conflicts')

steps:
- name: Fetch mapping file
Expand Down
22 changes: 20 additions & 2 deletions .github/workflows/release-and-tests-fail-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ jobs:
const mapping = await response.json();
return mapping;
- name: Retrieve PR info
id: retrieve_pr_info
env:
ACCESS_TOKEN: ${{ secrets.PAT }}
run: |
repo_name="${{ github.event.workflow_run.repository.full_name }}"
head_sha="${{ github.event.workflow_run.head_sha }}"
IFS=$'\t' read pr_html_url pr_user_login < <(curl -sS \
-H "Authorization: Bearer ${{ env.ACCESS_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$repo_name/commits/$head_sha/pulls" \
| jq -r '.[0] | [.html_url, .user.login] | @tsv')
echo "pr_html_url=$pr_html_url" >> $GITHUB_OUTPUT
echo "pr_user_login=$pr_user_login" >> $GITHUB_OUTPUT
shell: bash

- name: Generate Slack Payload
id: generate-payload
env:
Expand All @@ -36,16 +53,17 @@ jobs:
uses: actions/github-script@v7
with:
script: |
const pr_html_url = "${{ steps.retrieve_pr_info.outputs.pr_html_url }}";
const workflow_name = "${{ github.event.workflow_run.name }}";
const repo_name = "${{ github.event.workflow_run.repository.full_name }}";
const branch_name = "${{ github.event.workflow_run.head_branch }}";
const run_url = "${{ github.event.workflow_run.html_url }}";
const slack_mapping = JSON.parse(process.env.SLACK_MAPPING);
const actor_github_id = "${{ github.event.workflow_run.actor.login }}";
const actor_github_id = "${{ steps.retrieve_pr_info.outputs.pr_user_login }}";
const actor_slack_id = slack_mapping[actor_github_id];
const actor = actor_slack_id ? `<@${actor_slack_id}>` : actor_github_id;
const payload = {
text: `Hello ${actor} , workflow “${workflow_name}” failed in repo: "${repo_name}", branch: "${branch_name}". Please check it: ${run_url}.`,
text: `${actor} , workflow “${workflow_name}” failed, repo: "${repo_name}", branch: "${branch_name}", PR: "${pr_html_url}". Please check it: ${run_url}.`,
channel: process.env.SLACK_CHANNEL,
};
return JSON.stringify(payload);
Expand Down

0 comments on commit 94787cb

Please sign in to comment.