Skip to main content
Glama

get_pr_diff

Fetch the raw patch/diff text for a specific GitHub pull request to analyze code changes and review modifications.

Instructions

Fetches the diff/patch of a specific pull request from a GitHub repository. Args: repo_owner (str): The owner of the GitHub repository. repo_name (str): The name of the GitHub repository. pr_number (int): The pull request number. Returns: str: The raw patch/diff text of the pull request if successful, otherwise None. Error Handling: Logs an error message and prints the traceback if the request fails or an exception occurs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_ownerYes
repo_nameYes
pr_numberYes

Implementation Reference

  • The handler function that executes the core logic of fetching the raw patch/diff for a specific GitHub pull request using the dedicated GitHub patch-diff API endpoint.
    def get_pr_diff(self, repo_owner: str, repo_name: str, pr_number: int) -> str: """ Fetches the diff/patch of a specific pull request from a GitHub repository. Args: repo_owner (str): The owner of the GitHub repository. repo_name (str): The name of the GitHub repository. pr_number (int): The pull request number. Returns: str: The raw patch/diff text of the pull request if successful, otherwise None. Error Handling: Logs an error message and prints the traceback if the request fails or an exception occurs. """ logging.info(f"Fetching PR diff for {repo_owner}/{repo_name}#{pr_number}") try: # Fetch PR details response = requests.get(f"https://patch-diff.githubusercontent.com/raw/{repo_owner}/{repo_name}/pull/{pr_number}.patch", headers=self._get_headers(), timeout=TIMEOUT) response.raise_for_status() pr_patch = response.text logging.info("Successfully fetched PR diff/patch") return pr_patch except Exception as e: logging.error(f"Error fetching PR diff: {str(e)}") traceback.print_exc() return str(e)
  • Dynamic registration of all public methods (including get_pr_diff) from GitHubIntegration instance as MCP tools via FastMCP.add_tool()
    def register_tools(self, methods: Any = None) -> None: for name, method in inspect.getmembers(methods): if (inspect.isfunction(method) or inspect.ismethod(method)) and not name.startswith("_"): self.mcp.add_tool(method)
  • Calls the register_tools method on the GitHubIntegration instance (self.gi) to register get_pr_diff and other methods as MCP tools.
    def _register_tools(self): self.register_tools(self.gi) self.register_tools(self.ip)
  • Helper method used by get_pr_diff to generate authenticated HTTP headers for GitHub API requests.
    def _get_headers(self): """ Constructs the HTTP headers required for GitHub API requests, including the authorization token. Returns: dict: A dictionary containing the required HTTP headers. Error Handling: Raises ValueError if the GitHub token is not set. """ if not self.github_token: raise ValueError("GitHub token is missing for API requests") headers = { 'Authorization': f'token {self.github_token}', 'Accept': 'application/vnd.github.v3+json' } return headers

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/saidsef/mcp-github-pr-issue-analyser'

If you have feedback or need assistance with the MCP directory API, please join our Discord server