-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (78 loc) · 2.78 KB
/
auto-pr.yml
File metadata and controls
89 lines (78 loc) · 2.78 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: Auto PR for Claude Branches
on:
push:
branches:
- 'claude/**'
permissions:
contents: read
pull-requests: write
jobs:
create-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract branch metadata
id: metadata
run: |
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
echo "branch=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
# Extract session ID from branch name (e.g., claude/start-implementation-H60OG)
SESSION_ID="${BRANCH_NAME##*-}"
echo "session_id=$SESSION_ID" >> "$GITHUB_OUTPUT"
- name: Check if PR exists
id: check-pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_EXISTS=$(gh pr list --head "${{ steps.metadata.outputs.branch }}" --json number --jq length)
echo "exists=$PR_EXISTS" >> "$GITHUB_OUTPUT"
- name: Get commit messages
if: steps.check-pr.outputs.exists == '0'
id: commits
run: |
# Get all commits on this branch that aren't on main
COMMITS=$(git log origin/main..HEAD --pretty=format:"- %s" | head -n 20)
# Get first commit title for PR title
FIRST_COMMIT_TITLE=$(git log origin/main..HEAD --pretty=format:"%s" | tail -n 1)
echo "first_title=$FIRST_COMMIT_TITLE" >> "$GITHUB_OUTPUT"
# Create PR body
{
echo "body<<EOF"
echo "## Changes"
echo ""
echo "$COMMITS"
echo ""
echo "---"
echo "*This PR was automatically created from branch \`${{ steps.metadata.outputs.branch }}\`*"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Create Pull Request
if: steps.check-pr.outputs.exists == '0'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create \
--title "${{ steps.commits.outputs.first_title }}" \
--body "${{ steps.commits.outputs.body }}" \
--base main \
--head "${{ steps.metadata.outputs.branch }}" \
--label "claude,automated"
- name: Summary
run: |
if [ "${{ steps.check-pr.outputs.exists }}" == "0" ]; then
{
echo "## ✅ Pull Request Created!"
echo ""
echo "- **Branch:** \`${{ steps.metadata.outputs.branch }}\`"
echo "- **Session:** ${{ steps.metadata.outputs.session_id }}"
} >> "$GITHUB_STEP_SUMMARY"
else
{
echo "## ℹ️ Pull Request Already Exists"
echo ""
echo "- **Branch:** \`${{ steps.metadata.outputs.branch }}\`"
} >> "$GITHUB_STEP_SUMMARY"
fi