mriusero commited on
Commit
ea9236b
·
1 Parent(s): fe23b95

feat: code quality analyze

Browse files
Files changed (2) hide show
  1. app.py +3 -0
  2. tools/analyze_repo.py +60 -0
app.py CHANGED
@@ -11,6 +11,7 @@ from tools.web_search import DuckDuckGoSearchTool
11
  from tools.visit_webpage import VisitWebpageTool
12
  from tools.get_timezone import get_current_time_in_timezone
13
  from tools.calculate import calculator
 
14
 
15
  from Gradio_UI import GradioUI
16
 
@@ -28,6 +29,7 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
28
  final_answer = FinalAnswerTool()
29
  web_search = DuckDuckGoSearchTool()
30
  visit_webpage = VisitWebpageTool()
 
31
 
32
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
33
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
@@ -55,6 +57,7 @@ agent = CodeAgent(
55
  visit_webpage,
56
  get_current_time_in_timezone,
57
  calculator,
 
58
  ], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
 
11
  from tools.visit_webpage import VisitWebpageTool
12
  from tools.get_timezone import get_current_time_in_timezone
13
  from tools.calculate import calculator
14
+ from tools.analyze_repo import GitHubCodeQualityTool
15
 
16
  from Gradio_UI import GradioUI
17
 
 
29
  final_answer = FinalAnswerTool()
30
  web_search = DuckDuckGoSearchTool()
31
  visit_webpage = VisitWebpageTool()
32
+ analyze_code_quality = GitHubCodeQualityTool()
33
 
34
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
35
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
 
57
  visit_webpage,
58
  get_current_time_in_timezone,
59
  calculator,
60
+ analyze_code_quality,
61
  ], ## add your tools here (don't remove final answer)
62
  max_steps=6,
63
  verbosity_level=1,
tools/analyze_repo.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, Dict
2
+ import requests
3
+
4
+ class GitHubCodeQualityTool:
5
+ name = "github_code_quality"
6
+ description = "Analyzes the code quality of a public GitHub repository."
7
+ inputs = {
8
+ 'github_url': {'type': 'string', 'description': 'The URL of the public GitHub repository to analyze.'}
9
+ }
10
+ output_type = "dict"
11
+
12
+ def __init__(self):
13
+ pass
14
+
15
+ def forward(self, github_url: str) -> Dict[str, Any]:
16
+ """
17
+ Analyzes the code quality of a public GitHub repository.
18
+
19
+ Args:
20
+ github_url: The URL of the public GitHub repository to analyze.
21
+
22
+ Returns:
23
+ A dictionary containing the code quality analysis results.
24
+ """
25
+ metrics = {
26
+ "complexity": "Calculate the average cyclomatic complexity of functions",
27
+ "code_coverage": "Percentage of code covered by tests",
28
+ "issues": self.fetch_open_issues(github_url),
29
+ "contributors": self.fetch_contributors(github_url),
30
+ "last_commit": self.fetch_last_commit_date(github_url),
31
+ }
32
+
33
+ return metrics
34
+
35
+ def fetch_open_issues(self, github_url: str) -> int:
36
+ """Retrieves the number of open issues for a GitHub repository."""
37
+ api_url = f"https://api.github.com/repos/{self.extract_repo_info(github_url)}/issues"
38
+ response = requests.get(api_url)
39
+ issues = response.json()
40
+ return len(issues)
41
+
42
+ def fetch_contributors(self, github_url: str) -> int:
43
+ """Retrieves the number of contributors for a GitHub repository."""
44
+ api_url = f"https://api.github.com/repos/{self.extract_repo_info(github_url)}/contributors"
45
+ response = requests.get(api_url)
46
+ contributors = response.json()
47
+ return len(contributors)
48
+
49
+ def fetch_last_commit_date(self, github_url: str) -> str:
50
+ """Retrieves the date of the last commit for a GitHub repository."""
51
+ api_url = f"https://api.github.com/repos/{self.extract_repo_info(github_url)}/commits"
52
+ response = requests.get(api_url)
53
+ commits = response.json()
54
+ if commits:
55
+ return commits[0]['commit']['author']['date']
56
+ return "No commits found"
57
+
58
+ def extract_repo_info(self, github_url: str) -> str:
59
+ """Extracts repository information from the GitHub URL."""
60
+ return "/".join(github_url.split("/")[-2:])