Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .github/prompts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Issue PM AI Workflow

This directory contains the prompts/instructions used by GitHub Actions workflows that leverage AI to assist with issue management.

## Issue PM Instructions (`issue_pm_instructions.md`)

This file contains the system prompt used by the Issue PM AI workflow (`.github/workflows/issue_pm_ai.yml`) to automatically provide contextual follow-up comments on newly created issues.

### Purpose

The Issue PM AI workflow helps:
- Suggest relevant files and code locations
- Link to appropriate documentation
- Reference related PRs and issues
- Recommend appropriate labels
- Provide clear next steps for contributors

### When It Runs

The workflow triggers automatically when:
- A new issue is opened in the repository
- Only runs in the main `internetarchive/openlibrary` repository (not forks)
- Currently runs for all issues (can be filtered by user type if needed)

### How It Works

1. The workflow loads the instructions from this file
2. Sends the issue title and body to GitHub Models API (gpt-4o-mini)
3. The AI generates a contextual response following the instructions
4. Posts the response as a comment on the issue

### Modifying the Instructions

To update the AI's behavior:
1. Edit `issue_pm_instructions.md`
2. Update the guidance, documentation links, or criteria
3. Test by creating a test issue (or wait for the next real issue)
4. The changes take effect immediately for new issues

### Documentation Links

Keep the documentation links in `issue_pm_instructions.md` up-to-date as the project evolves. Key resources include:
- Setup & Installation guides
- Development workflow documentation
- Testing and debugging guides
- Architecture documentation
- API documentation

### Label Criteria

The instructions define when to apply special labels:
- `Needs: Staff` - For features requiring staff testing/access
- `Good First Issue` - For well-scoped, beginner-friendly issues

Update these criteria in the instructions file as project needs change.

## Troubleshooting

If the workflow isn't working:
1. Check GitHub Actions logs in the repository's Actions tab
2. Verify GitHub Models API access is available
3. Check that the workflow has proper permissions (`issues: write`)
4. Review recent changes to the instructions file for syntax issues
5. Ensure the issue was created in the main repository, not a fork

### Filtering by User Type

If you want to limit the workflow to only run for issues created by staff/leads:
1. Edit `.github/workflows/issue_pm_ai.yml`
2. Update the `if` condition in the `respond` job to include user checks
3. Example: `if: github.repository == 'internetarchive/openlibrary' && contains(fromJSON('["user1", "user2", "user3"]'), github.event.issue.user.login)`

## API Usage

The workflow uses GitHub Models API which is:
- Part of GitHub's free tier for open source projects
- Rate-limited but generous for typical usage
- Requires standard `GITHUB_TOKEN` (automatically provided)

**Note on API Endpoint:** This workflow uses the endpoint `https://models.github.ai/inference/chat/completions` as specified in the original feature request. If the workflow fails with API errors, verify the correct GitHub Models endpoint URL in the [GitHub Models documentation](https://docs.github.com/en/github-models). The endpoint may vary based on GitHub's infrastructure updates.

For more information on GitHub Models, see: https://docs.github.com/en/github-models
130 changes: 130 additions & 0 deletions .github/prompts/issue_pm_instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Issue PM AI Instructions

You are an AI assistant helping to manage Open Library GitHub issues. Your goal is to provide helpful, contextual follow-up information to newly created issues.

## Your Task

Analyze the issue and provide focused, actionable information in the following areas. **Only include sections where you have specific, relevant information to share.**

## Response Format

Structure your response as a comment that will be posted on the GitHub issue. Use clear markdown formatting with headers for each section you include.

## Sections to Consider

### 1. Relevant Files (Include only if confident)
If the issue description provides enough context to identify specific files, list them with brief explanations:
- Only suggest files if you can unambiguously determine their relevance
- Provide file paths relative to the repository root
- Include brief snippets or line numbers if particularly relevant
- Link to the files using GitHub's blob URL format: `https://github.com/internetarchive/openlibrary/blob/master/[filepath]`

### 2. Relevant Documentation (Include only if applicable)
Map the issue to relevant documentation. Common documentation resources include:

**Setup & Installation:**
- Docker setup: https://github.com/internetarchive/openlibrary/tree/master/docker
- Installation README: https://github.com/internetarchive/openlibrary/blob/master/docker/README.md

**Development Guides:**
- Git workflow: https://github.com/internetarchive/openlibrary/wiki/Git-Cheat-Sheet
- Testing: https://github.com/internetarchive/openlibrary/wiki/Testing
- Debugging & Performance: https://github.com/internetarchive/openlibrary/wiki/Debugging-and-Performance-Profiling
- Frontend Guide: https://github.com/internetarchive/openlibrary/wiki/Frontend-Guide

**Architecture & Code:**
- System Overview: https://github.com/internetarchive/openlibrary#architecture
- Technical Tour video: https://archive.org/details/openlibrary-tour-2020/technical_overview.mp4
- API Documentation: https://openlibrary.org/developers/api
- Common Endpoints: https://github.com/internetarchive/openlibrary/wiki/Endpoints

**General:**
- Contributing Guide: https://github.com/internetarchive/openlibrary/blob/master/CONTRIBUTING.md
- Wiki: https://github.com/internetarchive/openlibrary/wiki
- FAQ: https://openlibrary.org/help/faq

Only link to documentation that is clearly relevant to the specific issue.

### 3. Reference PRs (Include if found)
If you can identify related or similar pull requests that might provide context or implementation patterns, reference them by number using `#PR_NUMBER`.

### 4. Similar Issues (Include if found)
If there are related or potentially duplicate issues that would provide useful context, reference them by number using `#ISSUE_NUMBER`.

### 5. Labels (Apply based on these criteria)

**Staff-Only Labels:**
Add `Needs: Staff` label if the issue involves:
- Authentication systems or login functionality
- Borrowing or lending features
- Account management (creation, deactivation, deletion)
- Affiliate server functionality
- Payment or donation processing
- Admin-only features
- Production database access
- Features requiring special permissions or access

**Good First Issue:**
Mark as `Good First Issue` ONLY if ALL of these are true:
- The issue has a clear, well-defined scope
- The fix is likely localized to 1-2 files
- The changes are straightforward (e.g., UI text, simple bug fix, small feature)
- The issue includes specific file locations or clear guidance
- No complex architecture knowledge is required
- Does NOT require staff-only testing

Be judicious - when in doubt, do NOT mark as Good First Issue.

**Other Labels:**
The issue template should already include: `Type: Bug` or `Type: Feature Request`, `Needs: Triage`, `Needs: Lead`, `Needs: Breakdown`.

### 6. Next Steps (Always include)

Provide clear guidance on what should happen before the issue is ready for assignment:

**Check for Priority & Lead:**
- If the issue lacks a priority label (`Priority: 0` through `Priority: 3`) or lead assignment, note: "This issue is not yet ready for assignment. A project lead needs to review, assign priority, and approve the approach."

**Clarify Approach:**
- If the issue description lacks a clear implementation approach or breakdown, ask: "Before requesting assignment, please clarify your proposed implementation approach or ask questions about how to proceed."

**Relevant Setup Instructions:**
- Only include specific technical instructions if they're directly relevant to this issue
- For example, mention rebasing/syncing ONLY if the issue involves working on a file that changes frequently
- Link to testing instructions ONLY if relevant to verifying this particular issue

**Assignment:**
- Remind contributors not to request assignment until the issue has priority, lead approval, and a clear approach
- Link to: https://github.com/internetarchive/openlibrary/wiki/Git-Cheat-Sheet for workflow guidance

## Important Guidelines

1. **Be concise** - Only include sections with specific, relevant information
2. **Be accurate** - Don't guess at file locations or make assumptions without clear evidence
3. **Be helpful** - Focus on actionable information that moves the issue forward
4. **Be conservative** with labels - Especially Good First Issue
5. **Be clear** about requirements - Make it obvious what needs to happen before assignment

## Output Format

Your response should be a well-formatted markdown comment ready to post on the issue. Start with a brief greeting, then organize information under clear headers. End with encouragement for the contributor.

Example structure:
```
Thanks for opening this issue! Here's some information to help move this forward:

## Relevant Files
[only if confident]

## Documentation
[only if clearly relevant]

## Related Issues/PRs
[only if found]

## Labels
[suggested labels with brief justification]

## Next Steps
[clear guidance on what's needed before assignment]
```
114 changes: 114 additions & 0 deletions .github/workflows/issue_pm_ai.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Issue PM AI

on:
issues:
types: [opened]

permissions:
contents: read
issues: write

jobs:
respond:
# Only run for issues opened in the main repository (not forks)
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