{"id":10057,"library":"pr-commenter","title":"PR Commenter","description":"PR Commenter is a Python library that simplifies the process of adding, updating, and removing automated comments on GitHub Pull Requests. It leverages PyGithub to interact with the GitHub API, providing a clean interface for managing discussion threads. The current version is 0.2.4, and releases are generally made on an 'as-needed' basis, with a focus on stability for its core functionality.","status":"active","version":"0.2.4","language":"en","source_language":"en","source_url":"https://github.com/dkhunt/pr-commenter","tags":["github","pull-request","automation","commenting","ci"],"install":[{"cmd":"pip install pr-commenter","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency for interacting with the GitHub API.","package":"PyGithub","optional":false}],"imports":[{"note":"The PRCommenter class is nested within an inner 'pr_commenter' module.","wrong":"from pr_commenter import PRCommenter","symbol":"PRCommenter","correct":"from pr_commenter.pr_commenter import PRCommenter"}],"quickstart":{"code":"import os\nfrom pr_commenter.pr_commenter import PRCommenter\nfrom github import Github\n\n# Ensure GITHUB_TOKEN is set as an environment variable with 'repo' scope\ngithub_token = os.environ.get('GITHUB_TOKEN', '')\nif not github_token:\n    raise ValueError(\"GITHUB_TOKEN environment variable not set.\")\n\ng = Github(github_token)\n\n# Replace with your actual repository and PR number\nrepo_name = \"octocat/Spoon-Knife\" # Example: 'your_user/your_repo_name'\npr_number = 1 # Example: your PR number\n\ntry:\n    repo = g.get_repo(repo_name)\n    pr = repo.get_pull(pr_number)\n    pc = PRCommenter(pr)\n\n    # Add a new comment\n    comment_id = \"my_unique_automation_id_123\"\n    print(f\"Adding/Updating comment with ID: {comment_id}\")\n    pc.add_comment(\"This is an automated comment.\", comment_id)\n\n    # Update an existing comment\n    pc.update_comment(\"This is an UPDATED automated comment.\", comment_id)\n\n    # Remove a comment\n    # pc.remove_comment(comment_id)\n\n    print(\"PR Commenter operations completed.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to initialize `PRCommenter` and use its primary methods: `add_comment`, `update_comment`, and `remove_comment`. It requires a GitHub Personal Access Token with appropriate 'repo' scope permissions, passed via the `GITHUB_TOKEN` environment variable, to interact with your repository and pull requests."},"warnings":[{"fix":"Always use a unique `comment_id` when initially adding a comment. Ensure the `comment_id` passed to `update_comment` or `remove_comment` exactly matches the ID of the target comment.","message":"The `comment_id` parameter is crucial for managing automated comments. If you reuse the same `comment_id` with `add_comment`, it will create duplicate comments instead of updating existing ones. `update_comment` and `remove_comment` rely on this ID to find the correct comment.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Generate a GitHub PAT with the 'repo' scope (or at least specific write permissions for pull requests/issues). Store it securely (e.g., as an environment variable `GITHUB_TOKEN`) and ensure it's provided to the `github.Github` constructor.","message":"GitHub Personal Access Tokens (PATs) used with `PyGithub` and `pr-commenter` must have sufficient permissions. Typically, the 'repo' scope is required to create, update, and delete comments on pull requests.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Maintain a record of the `comment_id`s used for your automated comments. To remove multiple, loop through your stored IDs and call `pc.remove_comment(id)` for each.","message":"There is no built-in `remove_all_comments` method for all comments added by the `PRCommenter` instance. If you need to remove multiple automated comments, you must iterate through them and call `remove_comment` for each `comment_id`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Verify your `GITHUB_TOKEN` environment variable or direct string value. Check the PAT's expiration date and ensure it has the necessary 'repo' scope (or specific 'issues' / 'pull requests' write permissions) on GitHub.","cause":"The GitHub Personal Access Token (PAT) provided is invalid, expired, or has insufficient permissions.","error":"github.GithubException.BadCredentialsException: 401 {'message': 'Bad credentials'}"},{"fix":"Double-check the `repo_name` (e.g., 'owner/repo') and `pr_number`. Ensure the GitHub token has read access to that specific repository and pull request.","cause":"The repository name or pull request number provided to `g.get_repo()` or `repo.get_pull()` does not exist or is inaccessible to the authenticated user.","error":"github.GithubException.UnknownObjectException: 404 {'message': 'Not Found' ...}"},{"fix":"Ensure that the `comment_id` you pass to `update_comment` or `remove_comment` exactly matches the ID of a comment previously created with `add_comment`. `add_comment` should only be called once per unique `comment_id` to prevent duplicates if you intend to update it later.","cause":"The `comment_id` used for `update_comment` or `remove_comment` does not match an existing comment added by `pr-commenter`, or `add_comment` was called multiple times with the same `comment_id`.","error":"Comments are added, but `update_comment` or `remove_comment` doesn't work or creates duplicates."}]}