forked from anomalyco/models.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (89 loc) · 3.11 KB
/
Copy pathretry-issue-fixer.yml
File metadata and controls
102 lines (89 loc) · 3.11 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
name: Retry stalled issue fixes
on:
schedule:
- cron: "41 */6 * * *"
workflow_dispatch:
permissions:
contents: write
issues: read
pull-requests: read
concurrency:
group: retry-stalled-issue-fixes
cancel-in-progress: false
jobs:
retry:
if: github.repository == 'anomalyco/models.dev'
runs-on: ubuntu-latest
steps:
- name: Redispatch oldest issues without pull requests
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
cutoff="$(date -u -d '1 hour ago' '+%Y-%m-%dT%H:%M:%SZ')"
owner="${GITHUB_REPOSITORY%/*}"
repo="${GITHUB_REPOSITORY#*/}"
issues="$({
gh issue list \
--repo "$GITHUB_REPOSITORY" \
--state open \
--label automation \
--label model-sync \
--label missing-model \
--limit 1000 \
--json number,createdAt,labels
} | jq --arg cutoff "$cutoff" '
map(select(.createdAt <= $cutoff)) | sort_by(.createdAt)
')"
dispatched=0
dispatched_issues=()
while IFS= read -r issue; do
number="$(jq -r '.number' <<< "$issue")"
provider="$(jq -r '
[.labels[].name | select(startswith("provider:")) | ltrimstr("provider:")]
| first // empty
' <<< "$issue")"
if [ -z "$provider" ] || [ "$provider" = "openai" ]; then
continue
fi
closing_prs="$(gh api graphql \
-F owner="$owner" \
-F repo="$repo" \
-F number="$number" \
-f query='query($owner: String!, $repo: String!, $number: Int!) {
repository(owner: $owner, name: $repo) {
issue(number: $number) {
closedByPullRequestsReferences(first: 1, includeClosedPrs: true) {
totalCount
}
}
}
}' \
--jq '.data.repository.issue.closedByPullRequestsReferences.totalCount')"
if [ "$closing_prs" -gt 0 ]; then
continue
fi
jq -n \
--arg provider "$provider" \
--argjson issue_number "$number" \
'{
event_type: "missing-model",
client_payload: {
provider: $provider,
issue_number: $issue_number
}
}' \
| gh api "repos/$GITHUB_REPOSITORY/dispatches" --method POST --input -
dispatched=$((dispatched + 1))
dispatched_issues+=("#$number")
if [ "$dispatched" -eq 3 ]; then
break
fi
done < <(jq -c '.[]' <<< "$issues")
if [ "$dispatched" -eq 0 ]; then
echo "No stalled automated issues were eligible for retry." | tee -a "$GITHUB_STEP_SUMMARY"
else
printf 'Redispatched %d issue(s): %s\n' \
"$dispatched" "${dispatched_issues[*]}" \
| tee -a "$GITHUB_STEP_SUMMARY"
fi