Spaces:
Running
Running
Update github-repo-analyzer.py
Browse files- github-repo-analyzer.py +3 -80
github-repo-analyzer.py
CHANGED
@@ -6,7 +6,6 @@ from urllib.parse import urlparse
|
|
6 |
import requests
|
7 |
from github import Github
|
8 |
from git import Repo
|
9 |
-
import anthropic
|
10 |
from collections import defaultdict
|
11 |
import time
|
12 |
import numpy as np
|
@@ -149,15 +148,15 @@ def analyze_pull_requests(github_repo, max_prs):
|
|
149 |
'filtered_closed_prs': filtered_closed_prs
|
150 |
}
|
151 |
|
152 |
-
def call_llm(client, prompt, model="
|
153 |
-
message = client.
|
154 |
max_tokens=max_tokens,
|
155 |
model=model,
|
156 |
messages=[
|
157 |
{"role": "user", "content": prompt}
|
158 |
]
|
159 |
)
|
160 |
-
return message.content[0].
|
161 |
|
162 |
def safe_call_llm(client, prompt, retries=3):
|
163 |
for attempt in range(retries):
|
@@ -603,79 +602,3 @@ def generate_report(repo_info, code_analysis, issues_analysis, pr_analysis, fina
|
|
603 |
report += f"\n## Synthesis and Recommendations\n{final_analysis}\n"
|
604 |
|
605 |
return report
|
606 |
-
|
607 |
-
def main(repo_input, max_issues, max_prs):
|
608 |
-
github_token = os.environ.get("GITHUB_TOKEN")
|
609 |
-
if not github_token:
|
610 |
-
print("Error: GITHUB_TOKEN environment variable not set.")
|
611 |
-
sys.exit(1)
|
612 |
-
|
613 |
-
anthropic_api_key = os.environ.get("ANTHROPIC_API_KEY")
|
614 |
-
if not anthropic_api_key:
|
615 |
-
print("Error: ANTHROPIC_API_KEY environment variable not set.")
|
616 |
-
sys.exit(1)
|
617 |
-
|
618 |
-
owner, repo_name = get_repo_info(repo_input)
|
619 |
-
repo_url = f"https://github.com/{owner}/{repo_name}"
|
620 |
-
|
621 |
-
g = Github(github_token)
|
622 |
-
github_repo = g.get_repo(f"{owner}/{repo_name}")
|
623 |
-
|
624 |
-
client = anthropic.Anthropic(api_key=anthropic_api_key)
|
625 |
-
|
626 |
-
with tempfile.TemporaryDirectory() as temp_dir:
|
627 |
-
try:
|
628 |
-
print(f"Cloning repository {owner}/{repo_name}...")
|
629 |
-
repo_path = clone_repo(owner, repo_name, temp_dir)
|
630 |
-
|
631 |
-
print("Analyzing code...")
|
632 |
-
code_analysis = analyze_code(repo_path)
|
633 |
-
code_analysis['llm_analysis'] = llm_analyze_code(client, code_analysis)
|
634 |
-
|
635 |
-
print(f"Analyzing issues (max {max_issues})...")
|
636 |
-
issues_data = analyze_issues(github_repo, max_issues)
|
637 |
-
issues_analysis = llm_analyze_issues(client, issues_data, repo_url)
|
638 |
-
|
639 |
-
print(f"Analyzing pull requests (max {max_prs})...")
|
640 |
-
prs_data = analyze_pull_requests(github_repo, max_prs)
|
641 |
-
pr_analysis = llm_analyze_prs(client, prs_data, repo_url)
|
642 |
-
|
643 |
-
print("Synthesizing findings...")
|
644 |
-
final_analysis = llm_synthesize_findings(
|
645 |
-
client,
|
646 |
-
code_analysis.get('llm_analysis', ''),
|
647 |
-
issues_analysis.get('summary', ''),
|
648 |
-
pr_analysis.get('summary', '')
|
649 |
-
)
|
650 |
-
|
651 |
-
repo_info = {
|
652 |
-
"owner": owner,
|
653 |
-
"repo_name": repo_name,
|
654 |
-
}
|
655 |
-
|
656 |
-
print("Generating report...")
|
657 |
-
report = generate_report(repo_info, code_analysis, issues_analysis, pr_analysis, final_analysis)
|
658 |
-
|
659 |
-
print("\nAnalysis Report:")
|
660 |
-
print(report)
|
661 |
-
|
662 |
-
# Save the report to a file
|
663 |
-
with open(f"{owner}_{repo_name}_analysis.md", "w") as f:
|
664 |
-
f.write(report)
|
665 |
-
print(f"\nReport saved to {owner}_{repo_name}_analysis.md")
|
666 |
-
|
667 |
-
except Exception as e:
|
668 |
-
print(f"An error occurred: {str(e)}")
|
669 |
-
traceback.print_exc()
|
670 |
-
finally:
|
671 |
-
print("Cleaning up...")
|
672 |
-
|
673 |
-
if __name__ == "__main__":
|
674 |
-
parser = argparse.ArgumentParser(description="Analyze a GitHub repository with limits on issues and PRs.")
|
675 |
-
parser.add_argument("repo", help="Repository slug (owner/repo) or URL")
|
676 |
-
parser.add_argument("--max_issues", type=int, default=10, help="Maximum number of issues to analyze")
|
677 |
-
parser.add_argument("--max_prs", type=int, default=10, help="Maximum number of pull requests to analyze")
|
678 |
-
|
679 |
-
args = parser.parse_args()
|
680 |
-
|
681 |
-
main(args.repo, args.max_issues, args.max_prs)
|
|
|
6 |
import requests
|
7 |
from github import Github
|
8 |
from git import Repo
|
|
|
9 |
from collections import defaultdict
|
10 |
import time
|
11 |
import numpy as np
|
|
|
148 |
'filtered_closed_prs': filtered_closed_prs
|
149 |
}
|
150 |
|
151 |
+
def call_llm(client, prompt, model="nousresearch/hermes-3-llama-3.1-405b:free", max_tokens=4096):
|
152 |
+
message = client.chat.completions.create(
|
153 |
max_tokens=max_tokens,
|
154 |
model=model,
|
155 |
messages=[
|
156 |
{"role": "user", "content": prompt}
|
157 |
]
|
158 |
)
|
159 |
+
return message.content[0].message.content
|
160 |
|
161 |
def safe_call_llm(client, prompt, retries=3):
|
162 |
for attempt in range(retries):
|
|
|
602 |
report += f"\n## Synthesis and Recommendations\n{final_analysis}\n"
|
603 |
|
604 |
return report
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|