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.
pip install pr-commenterVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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.