-
Notifications
You must be signed in to change notification settings - Fork 45
75 lines (65 loc) · 2.48 KB
/
bot-pr-title.yml
File metadata and controls
75 lines (65 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Bot PR Title Format
on:
pull_request_target:
types: [opened, edited, reopened, synchronize]
permissions:
contents: read
pull-requests: read
statuses: write
jobs:
check-title:
name: Check bot PR title format
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BOT_LOGIN: "ai-agent-kxrpc[bot]"
STATUS_CONTEXT: "Bot PR Title Format"
TITLE_PATTERN: '^KRPC-[0-9]+: .+'
steps:
- name: Skip if PR is not bot-authored
id: verify-bot
run: |
PR_AUTHOR="${{ github.event.pull_request.user.login }}"
if [ "$PR_AUTHOR" != "$BOT_LOGIN" ]; then
echo "PR author is '$PR_AUTHOR', not '$BOT_LOGIN'. Skipping."
echo "skip=true" >> "$GITHUB_OUTPUT"
else
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
- name: Validate PR title
id: validate
if: steps.verify-bot.outputs.skip == 'false'
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
echo "Title: $PR_TITLE"
echo "Pattern: $TITLE_PATTERN"
if [[ "$PR_TITLE" =~ $TITLE_PATTERN ]]; then
echo "state=success" >> "$GITHUB_OUTPUT"
echo "description=Title starts with KRPC-XXX: prefix" >> "$GITHUB_OUTPUT"
echo "PR title matches required format."
else
echo "state=failure" >> "$GITHUB_OUTPUT"
echo "description=Title must start with 'KRPC-<number>: '" >> "$GITHUB_OUTPUT"
echo "::error::PR title '$PR_TITLE' must start with 'KRPC-<number>: ' (e.g. 'KRPC-123: Fix something')."
fi
- name: Set commit status
run: |
REPO="${{ github.repository }}"
PR_SHA="${{ github.event.pull_request.head.sha }}"
PR_NUMBER="${{ github.event.pull_request.number }}"
if [ "${{ steps.verify-bot.outputs.skip }}" == "true" ]; then
STATE="success"
DESCRIPTION="Skipped (not a bot PR)"
else
STATE="${{ steps.validate.outputs.state }}"
DESCRIPTION="${{ steps.validate.outputs.description }}"
fi
gh api --method POST "repos/$REPO/statuses/$PR_SHA" \
--field state="$STATE" \
--field context="$STATUS_CONTEXT" \
--field description="$DESCRIPTION" \
--field target_url="https://github.com/$REPO/pull/$PR_NUMBER" > /dev/null
if [ "$STATE" != "success" ]; then
exit 1
fi