Skip to main content

pr-commenter

Create and manage automatic comments in a Github PR

tests black PyPI version PyPI - Downloads

pr-commenter is CLI app to add a comment a Github PR based on content from stdin, files or environment variables.

You can create a new comment, hide a previous one of the same type or update the "current" one from a different process. This is done with a hidden metadata added to the comment so it could be detected in a subsequent run, and update or hide previous messages if needed.

Basic usage

Create a Github token with repo scope and export it as PR_COMMENTER_GITHUB_TOKEN environment variable

pr-commenter your/repo 12 comment.txt

Or from the standard input, using - as the file name

cat comment.txt | pr-commenter your/repo 12 -

This will simply create a new comment in the PR 12 with the content of comment.txt But there is much more.

Advanced example

Suposse you have a template failed_tests.j2 like this

{% if not is_append %}## Failed tests{% endif %}
 
[suite {{ CI_SUITE_NAME }}]({{ CI_SUITE_URL }}):

```bash
{% for line in input_lines %}{{ line }}
{% endfor %}

Then your test-runner produces a file failures.txt with the list of failed tests like this:

tests/test_client.py::test_client_simple
tests/test_client.py::test_client_complex

So we want to add a single comment to the PR with the failed tests for two different suites executions triggered by the same "commit".

In the post-build phase of both suites, you can run something like

pr-commenter your/repo $PR failures.txt -t failed_tests.j2 --build=$COMMIT

The first suite that finish will post a comment like this

<!-- pr-commenter: failed_tests.j2 abc123 -->
## Failed tests
 
[suite client](http://the-client-url):

```bash
tests/test_client.py::test_client_simple
tests/test_client.py::test_client_complex
```

Then the second suite will find that previous comment that was for the same template and same and commit ("abc123" in the example), so pr-commenter will edit the comment and append the new content.

The result will be something like this:

<!-- pr-commenter: failed_tests.j2 abc123 -->
## Failed tests
 
[suite client](http://the-client-url):

```bash
tests/test_client.py::test_client_simple
tests/test_client.py::test_client_complex
```

[suite server](http://the-server-url):

```bash
tests/test_server.py::test_server_1
```

In a next commit, the first suite that finishes will post a new comment, but this time the commit will be different, so the previous "abc123" comment will be minimized.

Templates

It uses Jinja2 templates. The stdin/files is passed and a variable input_lines And is_append will be True in case the new comment will be appended to an existent one (so you can ommit the header or footer, for instance).

In addition, the complete os.environ dictionary is passed, so all the environment variables are available in the template.

Install

  • Install the package with pipx
pip install --user pipx
pipx install pr-commenter

Alternatively, with pip

pip install --user pr-commenter
  • Create a Github token with repo scope and export it as PR_COMMENTER_GITHUB_TOKEN environment variable

Metadata

Release files for pr-commenter 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pr-commenter 0.2.4
File Size Uploaded
pr_commenter-0.2.4.tar.gz 5.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pr-commenter 0.2.4
File Interpreter ABI Platform
pr_commenter-0.2.4-py3-none-any.whl Python 3 none any Details

Total release size: 12.1 kB

Release files / pr_commenter-0.2.4.tar.gz

Download URL pr_commenter-0.2.4.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5496a2b8b176fe6e16906268df4cd787b5c99432ceab24d1f65cba69fccb65c0
BLAKE2b-256 checksum
How to use checksums
0bdb53de06c784e2612c0f8efabf098da9a2a6c1a3873dbc37d371c5859d8f51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 28, 2025.

Transparency log

Release files / pr_commenter-0.2.4-py3-none-any.whl

Download URL pr_commenter-0.2.4-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8098e21d56b6b70c413ce8b63dc4060ea3ccc9d8fe84e36afc185f748c476662
BLAKE2b-256 checksum
How to use checksums
7485c8b5d6164be9d3f56e24374ea0cbde5801870803de7454f16e1feaafcda8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 28, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page