### Install patchparser using pip Source: https://github.com/tdunlap607/patchparser/blob/main/README.md This command installs the patchparser Python package using pip. Ensure pip is installed and accessible in your environment. ```bash pip install patchparser ``` -------------------------------- ### Get Raw Commit Data from GitHub API with PatchParser Source: https://context7.com/tdunlap607/patchparser/llms.txt Retrieves the raw, unparsed commit data directly from the GitHub API, allowing for custom processing or inspection. Requires setting the GITHUB_TOKEN environment variable. The output includes commit SHA, message, and file change details. ```python from patchparser import github_parser import os # Set GitHub token in environment os.environ['GITHUB_TOKEN'] = 'your_token_here' # Get raw commit data from GitHub API raw_data = github_parser.raw_commit( repo_owner="s3c2", repo_name="vfcfinder", sha="f573763decf499349721c48f11dc8299a91255d1", verbose=True ) # Access raw GitHub API response print(f"Commit SHA: {raw_data['sha']}") print(f"Message: {raw_data['commit']['message']}") print(f"Files changed: {len(raw_data['files'])}") for file in raw_data['files']: print(f" {file['filename']}: +{file['additions']} -{file['deletions']}") ``` -------------------------------- ### Manage GitHub API Rate Limits with PatchParser Utils Source: https://context7.com/tdunlap607/patchparser/llms.txt Provides utilities for managing GitHub API rate limits, including checking current status and implementing smart waiting mechanisms to prevent throttling. The `smart_limit` function is automatically invoked by the `commit()` function. ```python from patchparser.utils import github_helper import os # Set your GitHub token token = os.environ.get('GITHUB_TOKEN') # Check current rate limit status rate_status = github_helper.github_rate_limit(token) print(f"Remaining: {rate_status['rate']['remaining']}/{rate_status['rate']['limit']}") print(f"Reset at: {rate_status['rate']['reset']}") # Smart rate limiting (automatically waits if limit is low) # Called automatically by commit() function github_helper.smart_limit(token=token, verbose=True) # Continue with API calls parsed = github_parser.commit( repo_owner="tdunlap607", repo_name="patchparser", sha="0dfe5bacc3833160dbe3ea9edf49cd7d599ad290", github_token=True ) ``` -------------------------------- ### Batch Commit Processing in Python Source: https://context7.com/tdunlap607/patchparser/llms.txt Processes multiple Git commits efficiently by iterating through a list of commit details (owner, repo, SHA). It includes error handling and rate limit considerations, suitable for batch operations. Requires a GitHub token for authentication. ```python from patchparser import github_parser import os import time os.environ['GITHUB_TOKEN'] = 'your_token_here' # List of commits to process commits = [ ("Lightning-AI", "lightning", "62f1e82e032eb16565e676d39e0db0cac7e34ace"), ("s3c2", "vfcfinder", "f573763decf499349721c48f11dc8299a91255d1"), ("tdunlap607", "patchparser", "0dfe5bacc3833160dbe3ea9edf49cd7d599ad290") ] all_parsed_data = [] for owner, repo, sha in commits: try: parsed = github_parser.commit( repo_owner=owner, repo_name=repo, sha=sha, github_token=True, verbose=True ) all_parsed_data.extend(parsed) # Check if commit exists if parsed[0]['commit_exist']: print(f"✓ Processed {owner}/{repo}@{sha[:7]}: {len(parsed)} patches") else: print(f"✗ Commit {owner}/{repo}@{sha[:7]} not found") except Exception as e: print(f"Error processing {owner}/{repo}@{sha[:7]}: {e}") continue print(f"\nTotal patches collected: {len(all_parsed_data)}") ``` -------------------------------- ### Parse Remote GitHub Commit using PatchParser Source: https://context7.com/tdunlap607/patchparser/llms.txt Fetches and parses a specific commit from a GitHub repository using the GitHub API. Requires the GITHUB_TOKEN environment variable for authentication. Outputs a list of dictionaries, each detailing patch features and commit metadata. ```python from patchparser import github_parser # Parse a commit from a GitHub repository # Requires GITHUB_TOKEN environment variable for authentication parsed_data = github_parser.commit( repo_owner="Lightning-AI", repo_name="lightning", sha="62f1e82e032eb16565e676d39e0db0cac7e34ace", github_token=True, verbose=True ) # Returns a list of dictionaries, one per patch # Each dictionary contains all extracted features for patch in parsed_data: print(f"File: {patch['file_name']}") print(f"Status: {patch['status']}") print(f"Additions: {patch['additions']}, Deletions: {patch['deletions']}") print(f"Original code (lines {patch['original_line_start']}-{patch['original_line_end']}):") print(patch['original_code']) print(f"Modified code (lines {patch['modified_line_start']}-{patch['modified_line_end']}):") print(patch['modified_code']) print(f"Author: {patch['commit_author_name']} <{patch['commit_author_email']}>") print(f"Message: {patch['message']}") ``` -------------------------------- ### Analyze Commit Features in Python Source: https://context7.com/tdunlap607/patchparser/llms.txt Extracts and analyzes key metrics from parsed commit data, such as total additions, deletions, files changed, and file types. This function is useful for research, reporting, and understanding commit characteristics. Requires a GitHub token. ```python from patchparser import github_parser import os os.environ['GITHUB_TOKEN'] = 'your_token_here' parsed = github_parser.commit( repo_owner="Lightning-AI", repo_name="lightning", sha="62f1e82e032eb16565e676d39e0db0cac7e34ace" ) # Aggregate statistics total_additions = sum(p['additions'] or 0 for p in parsed if p['additions']) total_deletions = sum(p['deletions'] or 0 for p in parsed if p['deletions']) files_changed = len(set(p['file_name'] for p in parsed if p['file_name'])) extensions = [p['file_extension'] for p in parsed if p['file_extension']] print(f"Commit Analysis:") print(f" Files changed: {files_changed}") print(f" Total additions: {total_additions}") print(f" Total deletions: {total_deletions}") print(f" Net change: {total_additions - total_deletions}") print(f" File types: {', '.join(set(extensions))}") print(f" Author: {parsed[0]['commit_author_name']}") print(f" Date: {parsed[0]['commit_author_date']}") ``` -------------------------------- ### Parse Raw Patch String in Python Source: https://context7.com/tdunlap607/patchparser/llms.txt Parses a raw Git diff patch string into structured code segments. This low-level function is useful for custom parsing workflows and provides details like additions, deletions, and the original/modified code. ```python from patchparser import github_parser # Example raw patch string from git diff raw_patch = """ def calculate_sum(a, b): - return a + b + result = a + b + return result def main(): print("Hello") """ # Parse the raw patch patch_data = github_parser.parse_raw_patch(raw_patch) print(f"Additions: {patch_data['additions']}") print(f"Deletions: {patch_data['deletions']}") print(f"Changes: {patch_data['changes']}") print(f"Original code:\n{patch_data['original_code']}") print(f"Modified code:\n{patch_data['modified_code']}") print(f"Added code:\n{patch_data['added_code']}") print(f"Deleted code:\n{patch_data['deleted_code']}") ``` -------------------------------- ### Parse Local Repository Commit using PatchParser Source: https://context7.com/tdunlap607/patchparser/llms.txt Parses a commit from a locally cloned Git repository without requiring API access. This is suitable for offline processing or large-scale analysis. The output structure is identical to the remote parsing method. ```python from patchparser import github_parser_local # Parse a commit from a local repository clone parsed_data = github_parser_local.commit_local_updated( repo_owner="Lightning-AI", repo_name="lightning", sha="62f1e82e032eb16565e676d39e0db0cac7e34ace", base_repo_path="/path/to/local/repo", verbose=True ) # Same structure as remote parsing for patch in parsed_data: print(f"File: {patch['file_name']}") print(f"Original file: {patch['original_file_name']}") print(f"Current file: {patch['current_file_name']}") print(f"Patch {patch['patch_number']+1}/{patch['total_patches']}") print(f"Added code:\n{patch['added_code']}") print(f"Deleted code:\n{patch['deleted_code']}") ``` -------------------------------- ### Parse GitHub Commit using patchparser Source: https://github.com/tdunlap607/patchparser/blob/main/README.md This Python code snippet demonstrates how to use the `github_parser.commit` function from the patchparser library to retrieve and parse features of a specific commit from a GitHub repository. It requires the repository owner, repository name, and the commit's SHA hash as input. ```python from patchparser import github_parser if __name__ == '__main__': # Parse a given commit for a GitHub repository parsed = github_parser.commit(repo_owner="Lightning-AI", repo_name="lightning", sha="62f1e82e032eb16565e676d39e0db0cac7e34ace") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.