Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 1 addition & 11 deletions penify_hook/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,7 @@ def generate_commit_summary(self, git_diff, instruction: str = "", repo_details
return None

def get_supported_file_types(self) -> list[str]:
"""Retrieve the supported file types from the API.

This function sends a request to the API endpoint
`/v1/file/supported_languages` to obtain a list of supported file types.
If the API call is successful (status code 200), it parses the JSON
response and returns the list of supported file types. If the API call
fails, it returns a default list of common file types.

Returns:
list[str]: A list of supported file types, either from the API or a default set.
"""
"""Retrieve a default list of supported file types."""
return ["py", "js", "ts", "java", "kt", "cs", "c", 'cpp', 'go', 'php', 'tsx','jsx']

def generate_commit_summary_with_llm(self, diff, message, generate_description: bool, repo_details, llm_client : LLMClient, jira_context=None):
Expand Down
25 changes: 4 additions & 21 deletions penify_hook/commands/auth_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,8 @@

def save_credentials(api_key):
# Try to save in .env file in git repo first
"""Save the API key in a priority-based manner.

This function attempts to save the API key in two locations, based on priority:
1. In a `.env` file located in the root of the Git repository if one is found.
2. In a global `.penify` file located in the user's home directory as a
fallback. The function first tries to locate the Git repository using
`recursive_search_git_folder`. If a Git repository is found, it reads the
existing `.env` file (if present), updates or adds the API key under the key
`PENIFY_API_TOKEN`, and writes the updated content back. If any error occurs
during this process, it falls back to saving the credentials in the global
`.penify` file. The function handles exceptions and prints appropriate error
messages.

Args:
api_key (str): The API key to save.

Returns:
bool: True if the API key is saved successfully, False otherwise.
"""
"""Save the API key in a `.env` file in the Git repository if found, otherwise in
the global `.penify` file."""
try:
from ..utils import recursive_search_git_folder
current_dir = os.getcwd()
Expand Down Expand Up @@ -103,7 +86,7 @@ def login(api_url, dashboard_url):
class TokenHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):

"""Handle a GET request to process login token and redirect or display error
"""Handle a GET request to process login token and display success or error
message."""
query = urllib.parse.urlparse(self.path).query
query_components = urllib.parse.parse_qs(query)
Expand Down Expand Up @@ -170,7 +153,7 @@ def do_GET(self):
thread.start()
def log_message(self, format, *args):
# Suppress log messages
"""Suppress log messages."""
"""Suppresses log messages."""
return

with socketserver.TCPServer(("", redirect_port), TokenHandler) as httpd:
Expand Down
15 changes: 1 addition & 14 deletions penify_hook/commands/doc_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,7 @@
import time

def generate_doc(api_url, token, location=None):
"""Generates documentation based on the given parameters.

This function initializes an API client using the provided API URL and token.
It then generates documentation by analyzing the specified location, which can
be a folder, a file, or the current working directory if no location is
provided. The function handles different types of analysis based on the input
location and reports any errors encountered during the process.

Args:
api_url (str): The URL of the API to connect to for documentation generation.
token (str): The authentication token for accessing the API.
location (str?): The path to a specific file or folder to analyze. If not provided,
the current working directory is used.
"""
"""Generates documentation using an API client by analyzing a specified location."""
t1 = time.time()
from ..api_client import APIClient
api_client = APIClient(api_url, token)
Expand Down
4 changes: 2 additions & 2 deletions penify_hook/commit_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, repo_path: str, api_client: APIClient, llm_client=None, jira_
self.jira_client: JiraClient = jira_client # Add JIRA client as an optional parameter

def get_summary(self, instruction: str, generate_description: bool) -> dict:
"""Generate a summary for the commit based on the staged changes."""
"""Generate a summary for the commit based on staged changes."""
diff = self.repo.git.diff('--cached')
if not diff:
raise ValueError("No changes to commit")
Expand Down Expand Up @@ -113,7 +113,7 @@ def process_jira_integration(self, title: str, description: str, msg: str) -> tu
return title, description

def _amend_commit(self):
"""Open the default git editor to amend the last commit message."""
"""Amend the last commit message in the repository."""
try:
# Change to the repository directory
os.chdir(self.repo_path)
Expand Down
8 changes: 1 addition & 7 deletions penify_hook/file_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,7 @@ def print_processing(self, file_path):
def run(self):

# Create a progress bar with appropriate stages
"""Runs the documentation process with a progress bar.

This method orchestrates the documentation process by creating a progress bar,
processing the file, and handling exceptions to ensure the progress bar
completes properly. It updates the progress bar through various stages and
provides feedback based on the result of the file processing.
"""
"""Runs the documentation process with a progress bar."""
stages = ["Validating", "Reading content", "Documenting", "Writing changes", "Completed"]
pbar, _ = create_stage_progress_bar(stages, f"Starting documenting")
logger.debug(f"Processing file: {self.file_path}")
Expand Down
Loading