forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
124 lines (106 loc) · 4.48 KB
/
claude-random-fixes.yml
File metadata and controls
124 lines (106 loc) · 4.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
name: "Claude Random Fixes"
on:
workflow_dispatch:
inputs:
issue_count:
description: "Number of issues to pick and fix in parallel"
required: false
default: "1"
type: string
jobs:
pick-issues:
name: "Pick issues"
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
matrix: ${{ steps.pick-issues.outputs.matrix }}
permissions:
contents: read
issues: read
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
with:
egress-policy: audit
- name: "Pick random issues"
id: pick-issues
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_COUNT: ${{ inputs.issue_count || '1' }}
run: |
# Fetch all milestones once
MILESTONES=$(gh api "repos/phpstan/phpstan/milestones?per_page=100&state=all" \
--jq '[.[] | {title: .title, number: .number}]')
ISSUE_JSON="[]"
# Easy fixes - all issues
MILESTONE_NUM=$(echo "$MILESTONES" | jq -r '.[] | select(.title == "Easy fixes") | .number')
if [ -n "$MILESTONE_NUM" ]; then
ISSUES=$(gh api --paginate \
"repos/phpstan/phpstan/issues?state=open&milestone=${MILESTONE_NUM}&per_page=100" \
--jq '[.[] | {number: .number, title: .title}]' \
| jq -s 'add // []')
ISSUE_JSON=$(echo "[$ISSUE_JSON, $ISSUES]" | jq '.[0] + .[1]')
echo "Fetched $(echo "$ISSUES" | jq 'length') issues from Easy fixes"
else
echo "Warning: Could not find 'Easy fixes' milestone"
fi
# Dependent types - Bug label only
MILESTONE_NUM=$(echo "$MILESTONES" | jq -r '.[] | select(.title == "Dependent types") | .number')
if [ -n "$MILESTONE_NUM" ]; then
ISSUES=$(gh api --paginate \
"repos/phpstan/phpstan/issues?state=open&milestone=${MILESTONE_NUM}&labels=Bug&per_page=100" \
--jq '[.[] | {number: .number, title: .title}]' \
| jq -s 'add // []')
ISSUE_JSON=$(echo "[$ISSUE_JSON, $ISSUES]" | jq '.[0] + .[1]')
echo "Fetched $(echo "$ISSUES" | jq 'length') Bug issues from Dependent types"
else
echo "Warning: Could not find 'Dependent types' milestone"
fi
# Generics - Bug label only
MILESTONE_NUM=$(echo "$MILESTONES" | jq -r '.[] | select(.title == "Generics") | .number')
if [ -n "$MILESTONE_NUM" ]; then
ISSUES=$(gh api --paginate \
"repos/phpstan/phpstan/issues?state=open&milestone=${MILESTONE_NUM}&labels=Bug&per_page=100" \
--jq '[.[] | {number: .number, title: .title}]' \
| jq -s 'add // []')
ISSUE_JSON=$(echo "[$ISSUE_JSON, $ISSUES]" | jq '.[0] + .[1]')
echo "Fetched $(echo "$ISSUES" | jq 'length') Bug issues from Generics"
else
echo "Warning: Could not find 'Generics' milestone"
fi
# Deduplicate
ISSUE_JSON=$(echo "$ISSUE_JSON" | jq 'unique_by(.number)')
TOTAL=$(echo "$ISSUE_JSON" | jq 'length')
if [ "$TOTAL" -eq 0 ]; then
echo "No issues found across milestones"
exit 1
fi
COUNT=$ISSUE_COUNT
if [ "$COUNT" -gt "$TOTAL" ]; then
COUNT=$TOTAL
fi
# Pick COUNT random unique issues
SELECTED=$(echo "$ISSUE_JSON" | python3 -c "
import json, sys, random
issues = json.load(sys.stdin)
random.shuffle(issues)
count = min(int('$COUNT'), len(issues))
print(json.dumps(issues[:count]))
")
echo "Selected $COUNT issue(s) from $TOTAL total candidates"
for NUMBER in $(echo "$SELECTED" | jq -r '.[].number'); do
TITLE=$(echo "$SELECTED" | jq -r --argjson n "$NUMBER" '.[] | select(.number == $n) | .title')
echo "### Selected issue: #$NUMBER - $TITLE" >> "$GITHUB_STEP_SUMMARY"
done
echo "matrix=$(echo "$SELECTED" | jq -c '.')" >> "$GITHUB_OUTPUT"
fix:
name: "Fix #${{ matrix.issue.number }}: ${{ matrix.issue.title }}"
needs: pick-issues
strategy:
fail-fast: false
matrix:
issue: ${{ fromJson(needs.pick-issues.outputs.matrix) }}
uses: ./.github/workflows/claude-fix-issue.yml
with:
issue-number: ${{ matrix.issue.number }}
secrets: inherit