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 ()
0 commit comments