Skip to content

feat(llma): add AI-powered taggers for LLM generation classification #19217

feat(llma): add AI-powered taggers for LLM generation classification

feat(llma): add AI-powered taggers for LLM generation classification #19217

name: Priority Review Slack Notifications
on:
pull_request:
types: [labeled, closed, ready_for_review]
pull_request_review:
types: [submitted]
env:
SLACK_CHANNEL: 'C0AEM55RJ77' # #dev-stamp-exchange
permissions:
contents: read
pull-requests: read
jobs:
# When a non-draft PR is labeled "priority-review", or a labeled PR is undrafted
notify-priority-review:
runs-on: ubuntu-latest
timeout-minutes: 5
if: >-
github.event.pull_request.head.repo.full_name == github.repository
&& (
(
github.event.action == 'labeled'
&& github.event.label.name == 'priority-review'
&& github.event.pull_request.draft == false
) || (
github.event.action == 'ready_for_review'
&& contains(github.event.pull_request.labels.*.name, 'priority-review')
)
)
steps:
- name: Get author display name and escape PR title
id: meta
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
script: |
const { data: user } = await github.rest.users.getByUsername({
username: context.payload.pull_request.user.login,
});
const name = user.name || context.payload.pull_request.user.login;
function escapeSlack(str) {
return str
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\|/g, '-')
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"');
}
core.setOutput('author', escapeSlack(name.split(' ')[0]));
core.setOutput('title', escapeSlack(context.payload.pull_request.title));
- name: Post to Slack
id: slack
uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a # v2.1.1
with:
method: chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
errors: true
payload: |
channel: "${{ env.SLACK_CHANNEL }}"
text: "Priority review requested: ${{ steps.meta.outputs.title }}"
unfurl_links: false
blocks:
- type: "section"
text:
type: "mrkdwn"
text: ":eyes: <${{ github.event.pull_request.html_url }}|#${{ github.event.pull_request.number }} ${{ steps.meta.outputs.title }}>\nby ${{ steps.meta.outputs.author }}"
- name: Save Slack message info
env:
SLACK_CHANNEL_ID: ${{ steps.slack.outputs.channel_id }}
SLACK_TS: ${{ steps.slack.outputs.ts }}
run: |
echo '{}' | jq \
--arg channel "$SLACK_CHANNEL_ID" \
--arg ts "$SLACK_TS" \
'{channel: $channel, ts: $ts}' > .priority-review-slack
- name: Cache Slack message info
uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5
with:
path: .priority-review-slack
key: priority-review-slack-pr-${{ github.event.pull_request.number }}
# When a priority-review PR is closed or merged, update the Slack message
cleanup-closed:
runs-on: ubuntu-latest
timeout-minutes: 5
if: >-
github.event.action == 'closed'
&& contains(github.event.pull_request.labels.*.name, 'priority-review')
steps:
- name: Restore Slack message info
uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5
with:
path: .priority-review-slack
key: priority-review-slack-pr-${{ github.event.pull_request.number }}
- name: Read Slack message info
id: slack_msg
run: |
if [ -f .priority-review-slack ]; then
echo "found=true" >> $GITHUB_OUTPUT
echo "channel=$(jq -r '.channel' .priority-review-slack)" >> $GITHUB_OUTPUT
echo "ts=$(jq -r '.ts' .priority-review-slack)" >> $GITHUB_OUTPUT
else
echo "found=false" >> $GITHUB_OUTPUT
fi
- name: Escape PR title and determine status
if: steps.slack_msg.outputs.found == 'true'
id: meta
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
script: |
function escapeSlack(str) {
return str
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\|/g, '-')
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"');
}
const merged = context.payload.pull_request.merged;
core.setOutput('title', escapeSlack(context.payload.pull_request.title));
core.setOutput('emoji', merged ? ':merged:' : ':closed:');
core.setOutput('status', merged ? 'merged' : 'closed');
- name: Update Slack message
if: steps.slack_msg.outputs.found == 'true'
continue-on-error: true
uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a # v2.1.1
with:
method: chat.update
token: ${{ secrets.SLACK_BOT_TOKEN }}
errors: true
payload: |
channel: "${{ steps.slack_msg.outputs.channel }}"
ts: "${{ steps.slack_msg.outputs.ts }}"
text: "${{ steps.meta.outputs.status }}: ${{ steps.meta.outputs.title }}"
blocks:
- type: "section"
text:
type: "mrkdwn"
text: "${{ steps.meta.outputs.emoji }} ~<${{ github.event.pull_request.html_url }}|#${{ github.event.pull_request.number }} ${{ steps.meta.outputs.title }}>~ (${{ steps.meta.outputs.status }})"
# When a priority-review PR is approved, update the Slack message
notify-reviewed:
runs-on: ubuntu-latest
timeout-minutes: 5
if: >-
github.event.action == 'submitted'
&& github.event.review.state == 'approved'
&& contains(github.event.pull_request.labels.*.name, 'priority-review')
steps:
- name: Restore Slack message info
uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5
with:
path: .priority-review-slack
key: priority-review-slack-pr-${{ github.event.pull_request.number }}
- name: Read Slack message info
id: slack_msg
run: |
if [ -f .priority-review-slack ]; then
echo "found=true" >> $GITHUB_OUTPUT
echo "channel=$(jq -r '.channel' .priority-review-slack)" >> $GITHUB_OUTPUT
echo "ts=$(jq -r '.ts' .priority-review-slack)" >> $GITHUB_OUTPUT
else
echo "found=false" >> $GITHUB_OUTPUT
fi
- name: Get display names and escape PR title
if: steps.slack_msg.outputs.found == 'true'
id: meta
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
script: |
function escapeSlack(str) {
return str
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\|/g, '-')
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"');
}
const [author, reviewer] = await Promise.all([
github.rest.users.getByUsername({ username: context.payload.pull_request.user.login }),
github.rest.users.getByUsername({ username: context.payload.review.user.login }),
]);
core.setOutput('author', escapeSlack((author.data.name || context.payload.pull_request.user.login).split(' ')[0]));
core.setOutput('reviewer', escapeSlack((reviewer.data.name || context.payload.review.user.login).split(' ')[0]));
core.setOutput('title', escapeSlack(context.payload.pull_request.title));
- name: Add checkmark reaction
if: steps.slack_msg.outputs.found == 'true'
continue-on-error: true # already_reacted is expected on multi-approval PRs
uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a # v2.1.1
with:
method: reactions.add
token: ${{ secrets.SLACK_BOT_TOKEN }}
errors: true
payload: |
channel: "${{ steps.slack_msg.outputs.channel }}"
timestamp: "${{ steps.slack_msg.outputs.ts }}"
name: "white_check_mark"
- name: Update main message
if: steps.slack_msg.outputs.found == 'true'
continue-on-error: true
uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a # v2.1.1
with:
method: chat.update
token: ${{ secrets.SLACK_BOT_TOKEN }}
errors: true
payload: |
channel: "${{ steps.slack_msg.outputs.channel }}"
ts: "${{ steps.slack_msg.outputs.ts }}"
text: "Reviewed and approved: ${{ steps.meta.outputs.title }}"
blocks:
- type: "section"
text:
type: "mrkdwn"
text: ":white_check_mark: <${{ github.event.pull_request.html_url }}|#${{ github.event.pull_request.number }} ${{ steps.meta.outputs.title }}>\nby ${{ steps.meta.outputs.author }} — reviewed and approved by ${{ steps.meta.outputs.reviewer }}"