Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements on fetch branchs #8

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions pullpanda.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@
import webbrowser
from collections import deque

GEMINI_AI_TOKEN = ""
GEMINI_AI_TOKEN = "AIzaSyA3Ilt0P2jPuADTcIWzUvIKxZC6-P9jS6Q"

CONFIG_FILE = "config.txt"

YELLOW = '\033[33m'
RED = '\033[31m'
GREEN = '\033[32m'
BLUE = '\033[34m'
RESET = '\033[0m'

def get_diff(repo_path):
"""
Calculate and print the differences (diff) between the current branch and the main branch of a Git repository.
Expand All @@ -23,8 +29,14 @@ def get_diff(repo_path):
# Access the current branch
current_branch = repo.active_branch

# Access the remote repository (origin)
origin = repo.remotes.origin

# Update the references from the remote repository
origin.fetch()

# Access the main branch
main_branch = repo.heads['develop'] # Assuming 'develop' as the main branch, modify as needed
main_branch = repo.refs['develop'] # Assuming 'develop' as the main branch, modify as needed

# Calculate the diff between the two branches
diff = repo.git.diff(main_branch.commit, current_branch.commit)
Expand Down Expand Up @@ -66,7 +78,7 @@ def process_api_calls(api_call_queue):

file_path = first_line.split(' ')[0][2:]

print(f"\nReviewing: {file_path}")
print(f"\n{BLUE}Reviewing: {RESET}{file_path}")

# Prepare data for the API request
data = {
Expand Down Expand Up @@ -109,9 +121,9 @@ def process_api_calls(api_call_queue):
markdown_text += markdown_chunk + "\n\n"

else:
print("Unable to find the 'text' parameter in the JSON response.")
print(f"{RED}Unable to find the 'text' parameter in the JSON response.")
else:
print("Failed to send code review request. Error:", response.text)
print(f"{RED}Failed to send code review request.")

# Wait for 10 seconds before the next API call
time.sleep(10)
Expand Down Expand Up @@ -183,7 +195,7 @@ def process_api_calls(api_call_queue):
file.write(html_content)

# Print the path of the saved file for the user
print("\nThe report file has been saved at: file://{}".format(file_path))
print("\n{}The report file has been saved at: file://{}".format(GREEN, file_path))

webbrowser.open('file://' + os.path.realpath(file_path))

Expand Down Expand Up @@ -257,24 +269,27 @@ def get_repo_path():
saved_path = file.readline().strip()
if saved_path:
# Ask the user if they want to use the saved path
user_input = input(f"Use the saved path '{saved_path}'? (Press Enter to accept or type a new path): ").strip()
user_input = input(f"{YELLOW}Use the saved path '{saved_path}'? (Press Enter to accept or type a new path): ").strip()
if user_input:
repo_path = user_input
else:
repo_path = saved_path
else:
repo_path = input("Please enter the path to your local repository: ").strip()
repo_path = input(f"{YELLOW}Please enter the path to your local repository: ").strip()
else:
repo_path = input("Please enter the path to your local repository: ").strip()
repo_path = input(f"{YELLOW}Please enter the path to your local repository: ").strip()

# Save the new path (if it was changed or entered for the first time)
with open(CONFIG_FILE, "w") as file:
file.write(repo_path)

return repo_path

# Request the repository path from the user
repo_path = get_repo_path()
try:
# Request the repository path from the user
repo_path = get_repo_path()

# Calculate and get the diff between the target and current branches
get_diff(repo_path)
# Calculate and get the diff between the target and current branches
get_diff(repo_path)
except KeyboardInterrupt:
print("\nExiting from script...")