Files

114 lines
4.1 KiB
YAML

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"