Skip to content

Book page jump links are broken #2

Book page jump links are broken

Book page jump links are broken #2

Workflow file for this run

name: Issue PM AI
on:
issues:
types: [opened]
permissions:
contents: read
issues: write
models: read
jobs:
respond:
# Only run for issues opened in the main repository (not forks)
# TEMPORARILY DISABLED FOR TESTING PURPOSES
# if: github.repository == 'internetarchive/openlibrary'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Load PM AI Instructions
id: pm
run: |
{
echo "INSTRUCTIONS<<EOF"
cat .github/prompts/issue_pm_instructions.md
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Generate issue response (GitHub Models)
id: generate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_BODY: ${{ github.event.issue.body }}
INSTRUCTIONS: ${{ steps.pm.outputs.INSTRUCTIONS }}
run: |
# Construct the user message content
USER_MESSAGE="Issue title: $ISSUE_TITLE"$'\n\n'"Issue body:"$'\n'"$ISSUE_BODY"
# Build JSON payload using jq for proper escaping
PAYLOAD=$(jq -n \
--arg model "gpt-4o-mini" \
--arg system "$INSTRUCTIONS" \
--arg user "$USER_MESSAGE" \
'{
model: $model,
messages: [
{role: "system", content: $system},
{role: "user", content: $user}
]
}')
# Make API call to GitHub Models
# Note: Endpoint URL from feature request. Verify if workflow fails with API errors.
RESPONSE=$(curl -s -w "\n%{http_code}" https://models.github.ai/inference/chat/completions \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d "$PAYLOAD")
# Extract HTTP status code (last line)
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
RESPONSE_BODY=$(echo "$RESPONSE" | sed '$d')
echo "HTTP Status Code: $HTTP_CODE"
if [ "$HTTP_CODE" -eq 200 ]; then
CONTENT=$(echo "$RESPONSE_BODY" | jq -r '.choices[0].message.content')
if [ "$CONTENT" = "null" ] || [ -z "$CONTENT" ]; then
echo "Error: No content in API response"
echo "$RESPONSE_BODY" | jq .
exit 1
fi
# Save content to output
{
echo "CONTENT<<EOF"
echo "$CONTENT"
echo "EOF"
} >> "$GITHUB_OUTPUT"
else
echo "Error: API request failed with status $HTTP_CODE"
echo "$RESPONSE_BODY" | jq .
exit 1
fi
- name: Post response to issue
if: success()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
BODY: ${{ steps.generate.outputs.CONTENT }}
run: |
# Create JSON payload with proper escaping
PAYLOAD=$(jq -n --arg body "$BODY" '{body: $body}')
# Post comment to issue
HTTP_CODE=$(curl -s -w "%{http_code}" -o /tmp/comment_response.json \
-X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER/comments" \
-d "$PAYLOAD")
if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then
echo "Successfully posted comment to issue #$ISSUE_NUMBER"
cat /tmp/comment_response.json | jq .
else
echo "Error: Failed to post comment with status $HTTP_CODE"
cat /tmp/comment_response.json | jq .
exit 1
fi