forked from anomalyco/models.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (96 loc) · 4.13 KB
/
Copy pathissue-fixer.yml
File metadata and controls
113 lines (96 loc) · 4.13 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
name: Issue Fixer
on:
issues:
types: [opened]
repository_dispatch:
types: [missing-model]
permissions:
contents: write
issues: write
pull-requests: write
concurrency: issue-fixer-${{ github.event.issue.number || github.event.client_payload.issue_number }}
jobs:
fix:
if: >-
github.repository == 'anomalyco/models.dev'
&& !contains(github.event.issue.labels.*.name, 'provider:openai')
&& github.event.client_payload.provider != 'openai'
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
ISSUE_NUMBER: ${{ github.event.issue.number || github.event.client_payload.issue_number }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: dev
- name: Load issue
run: |
set -euo pipefail
ISSUE_FILE="$RUNNER_TEMP/issue.json"
gh issue view "$ISSUE_NUMBER" --json number,title,body,labels > "$ISSUE_FILE"
echo "ISSUE_FILE=$ISSUE_FILE" >> "$GITHUB_ENV"
- name: Install opencode
run: curl -fsSL https://opencode.ai/install | bash
- name: Run issue fixer
env:
OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
OPENCODE_PERMISSION: '{"bash":"deny"}'
run: |
set -euo pipefail
EVENTS_FILE="$RUNNER_TEMP/issue-fixer-events.jsonl"
RESPONSE_FILE="$RUNNER_TEMP/issue-fixer-response.md"
PROMPT_FILE="$RUNNER_TEMP/issue-fixer-prompt.md"
echo "RESPONSE_FILE=$RESPONSE_FILE" >> "$GITHUB_ENV"
jq -r '
"A new GitHub issue was opened in anomalyco/models.dev.\n\n"
+ "Issue #\(.number): \(.title)\n\n"
+ "Body:\n" + (.body // "") + "\n\n"
+ "Decide whether this is an actionable model catalog data fix.\n\n"
+ "If it asks for a model to be added or for factual model/provider metadata to be corrected, make the minimal TOML changes in the repository. Do not use Bash. Do not create branches, commits, comments, or pull requests yourself.\n\n"
+ "If it is a feature request, a request to track a new kind of information, a question, or any miscellaneous non-catalog-data request, do not edit files. Respond briefly that it needs maintainer review and no automated fix was opened."
' "$ISSUE_FILE" > "$PROMPT_FILE"
opencode run --agent issue-fixer -m opencode/grok-4.5 --format json < "$PROMPT_FILE" | tee "$EVENTS_FILE"
if ! jq -ers 'map(select(.type == "text") | .part.text) | last | select(length > 0)' "$EVENTS_FILE" > "$RESPONSE_FILE"; then
echo "Issue fixer did not produce a final response." >&2
exit 1
fi
- name: Check changed paths
if: success()
run: |
while IFS= read -r line; do
path="${line:3}"
case "$path" in
models/*.toml|providers/*.toml) ;;
*) exit 1 ;;
esac
done < <(git status --porcelain)
- name: Create pull request
if: success()
env:
BRANCH: issue-${{ github.event.issue.number || github.event.client_payload.issue_number }}
run: |
set -euo pipefail
ISSUE_TITLE="$(jq -r .title "$ISSUE_FILE")"
if [ -z "$(git status --porcelain)" ]; then
if [ -s "$RESPONSE_FILE" ]; then
gh issue comment "$ISSUE_NUMBER" --body-file "$RESPONSE_FILE"
fi
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git switch -c "$BRANCH"
git add -A
TITLE="fix: ${ISSUE_TITLE:0:200}"
git commit -m "$TITLE"
git push origin "$BRANCH"
PR_BODY="$RUNNER_TEMP/issue-fixer-pr-body.md"
{
cat "$RESPONSE_FILE"
echo
echo "Closes #$ISSUE_NUMBER"
echo
echo "Automated by the issue fixer: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
} > "$PR_BODY"
gh pr create --base dev --head "$BRANCH" --title "$TITLE" --body-file "$PR_BODY"