-
-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathfeature_5000.py
More file actions
54 lines (42 loc) · 1.97 KB
/
feature_5000.py
File metadata and controls
54 lines (42 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import subprocess
import json
import re
def analyze_breakpoints(repo_path: str, issue_id: str) -> dict:
try:
# Check if the repository exists
if not os.path.exists(repo_path):
raise FileNotFoundError(f"The repository path {repo_path} does not exist.")
# Clone the repository if it does not exist
if not os.path.isdir(os.path.join(repo_path, '.git')):
subprocess.run(['git', 'clone', repo_path], check=True)
# Navigate to the repository directory
os.chdir(os.path.join(repo_path, 'app'))
# List all files with '.ts' extension for TypeScript files
ts_files = [f for f in os.listdir('.') if f.endswith('.ts')]
# Initialize a dictionary to store the analysis
analysis = {'issue_id': issue_id, 'files_analyzed': [], 'breakpoint_issues': []}
# Analyze each TypeScript file for breakpoints
for ts_file in ts_files:
with open(ts_file, 'r', encoding='utf-8') as file:
content = file.read()
breakpoints = re.findall(r'\bbreak\b', content)
# Count the number of breakpoints in the file
breakpoint_count = len(breakpoints)
# If there are no breakpoints, add to issues list
if breakpoint_count == 0:
analysis['breakpoint_issues'].append({'file': ts_file, 'message': 'No breakpoints found.'})
# Store the analysis for the file
analysis['files_analyzed'].append({
'file': ts_file,
'breakpoint_count': breakpoint_count
})
return analysis
except Exception as e:
return {'error': str(e)}
# Test cases
if __name__ == "__main__":
# Test with the provided repository
repo_url = 'https://github.com/tihansen/words-challenge/tree/master/app'
analysis_result = analyze_breakpoints(repo_url, '5000')
print(json.dumps(analysis_result, indent=4))