Skip to content

Commit 1799d5a

Browse files
Add a github workflow for analyzing issues using Claude
1 parent 76b8870 commit 1799d5a

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
import json
6+
from typing import Dict, Any
7+
from anthropic import Anthropic
8+
from github import Github
9+
from github.Issue import Issue
10+
11+
def get_github_event() -> Dict[str, Any]:
12+
"""Read GitHub event data from the event file."""
13+
event_path = os.getenv('GITHUB_EVENT_PATH')
14+
if not event_path:
15+
raise ValueError("GITHUB_EVENT_PATH not set")
16+
17+
with open(event_path, 'r') as f:
18+
return json.load(f)
19+
20+
def analyze_issue_with_claude(issue_title: str, issue_body: str) -> str:
21+
anthropic = Anthropic(api_key=os.getenv('ANTHROPIC_API_KEY'))
22+
23+
# FIXME - Add actual prompt here
24+
prompt = f"""You are an AI assistant helping open source maintainers clarify GitHub issues.
25+
Please analyze this issue and identify what information is missing or needs clarification.
26+
Focus on technical details, reproduction steps, and system information that would help resolve the issue.
27+
28+
Issue Title: {issue_title}
29+
Issue Body: {issue_body}
30+
31+
Please provide a response in the following format:
32+
1. Missing Information (bullet points of what's needed)
33+
2. Clarifying Questions (specific questions to ask the issue author)
34+
3. Next Steps (suggested actions for the issue author)"""
35+
36+
message = anthropic.messages.create(
37+
model="claude-3-5-sonnet-20241022",
38+
max_tokens=1024,
39+
messages=[{
40+
"role": "user",
41+
"content": prompt
42+
}]
43+
)
44+
45+
return message.content[0].text
46+
47+
def post_comment(issue: Issue, analysis: str):
48+
"""Post Claude's analysis as a comment on the issue."""
49+
comment_body = f"""Hello! 👋 I'm an AI assistant helping to analyze this issue.
50+
51+
{analysis}
52+
53+
Note: I'm an automated assistant helping to gather information. A maintainer will review this issue soon."""
54+
55+
issue.create_comment(comment_body)
56+
57+
def main():
58+
try:
59+
# Get GitHub token and create GitHub client
60+
github_token = os.getenv('GITHUB_TOKEN')
61+
if not github_token:
62+
raise ValueError("GITHUB_TOKEN not set")
63+
64+
gh = Github(github_token)
65+
66+
# Get event data
67+
event = get_github_event()
68+
issue_data = event['issue']
69+
70+
# Get repository info
71+
repo_name = os.getenv('GITHUB_REPOSITORY')
72+
if not repo_name:
73+
raise ValueError("GITHUB_REPOSITORY not set")
74+
75+
repo = gh.get_repo(repo_name)
76+
issue = repo.get_issue(number=issue_data['number'])
77+
78+
# Analyze issue with Claude
79+
analysis = analyze_issue_with_claude(
80+
issue_title=issue_data['title'],
81+
issue_body=issue_data['body']
82+
)
83+
84+
# Post the analysis as a comment
85+
post_comment(issue, analysis)
86+
87+
except Exception as e:
88+
print(f"Error: {str(e)}", file=sys.stderr)
89+
sys.exit(1)
90+
91+
if __name__ == "__main__":
92+
main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
anthropic>=0.18.1
2+
PyGithub>=2.2.0
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Issue Analyzer
2+
on:
3+
issues:
4+
types: [opened, labeled]
5+
6+
jobs:
7+
analyze-issue:
8+
runs-on: ubuntu-latest
9+
# FIXME - Add the actual condition to use in order to trigger this workflow
10+
if: contains(github.event.issue.labels.*.name, 'needs-clarification')
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: '3.11'
19+
20+
- name: Install Dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install -r .github/actions/issue-analyzer/requirements.txt
24+
25+
- name: Analyze Issue
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
29+
run: python .github/actions/issue-analyzer/main.py

0 commit comments

Comments
 (0)