Registry / devops / pr-commenter

pr-commenter

JSON →
library0.2.4pypypiunverified

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-commenter
INSTALL
IMPORT
SIG · PR-COMMENTER
P
pr-commenter
devopspythonv0.2.4
Install
3.8s avg
Import
—
Disk
46MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.2.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 47.2MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 3.8s · import 0.000s · 48MB
46MB installed
● package 46MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PRCommenter
✓ from pr_commenter import PRCommenter
✗ from pr_commenter import PRCommenter

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.

import os from pr_commenter.pr_commenter import PRCommenter from github import Github # Ensure GITHUB_TOKEN is set as an environment variable with 'repo' scope github_token = os.environ.get('GITHUB_TOKEN', '') if not github_token: raise ValueError("GITHUB_TOKEN environment variable not set.") g = Github(github_token) # Replace with your actual repository and PR number repo_name = "octocat/Spoon-Knife" # Example: 'your_user/your_repo_name' pr_number = 1 # Example: your PR number try: repo = g.get_repo(repo_name) pr = repo.get_pull(pr_number) pc = PRCommenter(pr) # Add a new comment comment_id = "my_unique_automation_id_123" print(f"Adding/Updating comment with ID: {comment_id}") pc.add_comment("This is an automated comment.", comment_id) # Update an existing comment pc.update_comment("This is an UPDATED automated comment.", comment_id) # Remove a comment # pc.remove_comment(comment_id) print("PR Commenter operations completed.") except Exception as e: print(f"An error occurred: {e}")
Debug
Known issues
gotchaThe `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.
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.
affects: All versions
gotchaGitHub 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.
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.
affects: All versions
gotchaThere 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`.
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.
affects: All versions
Upgrade
Version history
0.2.4latest on PyPI · released Feb 28, 2025
Audit
Dependencies
PyGithubrequiredCore dependency for interacting with the GitHub API.
Agent activity
17 hits · last 30 days
node
16
OpenAI (training)
1
Resources
pr-commenter — pip install pr-commenter · libregistry