Skip to content

[Prod] Resource dashboard hybrid counting, software updates, dev improvements, capitalization fixes, citations refactor #245

[Prod] Resource dashboard hybrid counting, software updates, dev improvements, capitalization fixes, citations refactor

[Prod] Resource dashboard hybrid counting, software updates, dev improvements, capitalization fixes, citations refactor #245

name: Pull Request Notifications
on:
pull_request:
branches:
- production
types: [ready_for_review]
jobs:
notify_slack:
runs-on: ubuntu-latest
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_CHANNEL: "acf-ohs-ttahub--contractor-customer-team"
GITHUB_REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
steps:
- name: Get PR body
uses: actions/github-script@v7
id: get-body
with:
result-encoding: string
script: return context.payload.pull_request.body;
- name: Notify Slack when a PR to production is opened
run: |
echo "${{ steps.get-body.outputs.result }}" > pr_body.md
extract_section() {
awk -v section="$1" '
BEGIN {found=0}
$0 ~ section {found=1; next}
/^## / && found {exit}
found {print}
' pr_body.md | head -c 600
}
DESC=$(extract_section "^## Description of change")
TEST=$(extract_section "^## How to test")
ISSUES=$(extract_section "^## Issue")
PR_LINK="https://github.com/$GITHUB_REPOSITORY/pull/$PR_NUMBER"
JSON=$(jq -n \
--arg channel "$SLACK_CHANNEL" \
--arg pr_number "#$PR_NUMBER" \
--arg pr_link "$PR_LINK" \
--arg title "$PR_TITLE" \
--arg desc "> $(echo "$DESC" | sed 's/^/> /')" \
--arg issues "$(echo "$ISSUES" | sed 's/^/> /')" \
'{
channel: $channel,
blocks: [
{ type: "section", text: { type: "mrkdwn", text: ":rocket: A production PR <\($pr_link)|\($pr_number)> is now open!" } },
{ type: "section", text: { type: "mrkdwn", text: "*Title:*\n\($title)" } },
{ type: "section", text: { type: "mrkdwn", text: "*Description of change:*\n\($desc)" } },
{ type: "section", text: { type: "mrkdwn", text: "*Issues:*\n\($issues)" } },
{ type: "section", text: { type: "mrkdwn", text: ":link: <\($pr_link)|View PR on GitHub>" } }
]
}')
curl -X POST -H "Authorization: Bearer $SLACK_BOT_TOKEN" \
-H 'Content-type: application/json;charset=utf-8' \
--data "$JSON" https://slack.com/api/chat.postMessage