Team Ai
Apppublic

alexcpn/code-review-agent

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
git_utils.py32 linesDownload Raw Back to root
1import requests2import re3from collections import defaultdict4import logging as log5 6 7def get_pr_diff_url(repo_url, pr_number):8    """ 9    Get the diff URL for a specific pull request number.10    Args:11        repo_url (str): The URL of the GitHub repository.12        pr_number (int): The pull request number.13    """14    pr_diff_url = f"https://patch-diff.githubusercontent.com/raw/{repo_url.split('/')[-2]}/{repo_url.split('/')[-1]}/pull/{pr_number}.diff"15    response = requests.get(pr_diff_url,verify=False)16 17    if response.status_code != 200:18        log.error(f"Failed to fetch diff: {response.status_code}")19        raise ValueError(f"Failed to fetch diff: {response.status_code}")20 21    diff_text = response.text22    file_diffs = defaultdict(str)23    file_diff_pattern = re.compile(r'^diff --git a/(.*?) b/\1$', re.MULTILINE)24    split_points = list(file_diff_pattern.finditer(diff_text))25    for i, match in enumerate(split_points):26        file_path = match.group(1)27        start = match.start()28        end = split_points[i + 1].start() if i + 1 < len(split_points) else len(diff_text)29        file_diffs[file_path] = diff_text[start:end]30    return file_diffs31 32