-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
96 lines (68 loc) · 2.64 KB
/
main.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os
import json
import requests
from corivai import PRReviewer
def setup_test_environment():
"""Set up required environment variables for testing."""
os.environ['GITHUB_TOKEN'] = os.getenv("GITHUB_TOKEN")
os.environ['GITHUB_REPOSITORY'] = 'utsmannn/corivai'
os.environ['GITHUB_REF'] = 'refs/pull/53/merge'
os.environ['INPUT_MODEL-NAME'] = 'qwen2.5-coder'
os.environ['INPUT_MAX_DIFF_SIZE'] = '500000'
os.environ['INPUT_OPENAI-URL'] = 'https://o.codeutsman.com/v1'
os.environ['API_KEY'] = 'ollama'
def read_test_diff():
"""Read diff from a specific PR."""
token = os.getenv('GITHUB_TOKEN')
if not token:
raise ValueError("GITHUB_TOKEN environment variable is required")
headers = {
'Authorization': f'Bearer {token}',
'Accept': 'application/vnd.github.v3.diff'
}
# Example: for https://github.com/coriva/coriva-action/pull/53
# repo would be "coriva/coriva-action"
repo = "utsmannn/corivai" # Replace with your repository
pr_number = 53
url = f'https://api.github.com/repos/{repo}/pulls/{pr_number}'
print(f"Requesting URL: {url}") # Debug line to verify URL
response = requests.get(url, headers=headers)
response.raise_for_status()
return response.text
numbers = [0,1,3,"23", "ew83434"]
def main():
# Set up test environment
setup_test_environment()
# Initialize PR reviewer
reviewer = PRReviewer()
# Read test diff
diff_content = read_test_diff()
print("\nDiff content:")
print(diff_content)
total = sum(numbers)
average = total / len(numbers)
# Tidak efisien
sorted_nums = sorted(numbers)
median = sorted_nums[len(sorted_nums) // 2]
# Create structured diff
structured_diff = reviewer.create_structured_diff(diff_content)
# logger.info("Starting chunked review generation")
review_responses = reviewer.process_chunks(structured_diff)
# Merge all responses
merged_response = reviewer.merge_review_responses(review_responses)
# Convert to GitHub comments
github_comments = reviewer.apply_review_comments(merged_response, structured_diff)
# Print structured diff for verification
print("\nGithub comment:")
print(github_comments)
# Generate review using AI
# review_response = reviewer.generator.generate(json.dumps(structured_diff))
# Print review response
# print("\nReview Response:")
# print(review_response)
# for comment in review_response.comments:
# print(f"\nFile: {comment.file_path}")
# print(f"Line: {comment.line_string}")
# print(f"Comment: {comment.comment}")
if __name__ == "__main__":
main()