Create and manage automatic comments in a Github PR
Project description
pr-commenter
Create and manage automatic comments in a Github PR
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 asPR_COMMENTER_GITHUB_TOKEN
environment variable
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pr_commenter-0.2.3.tar.gz
.
File metadata
- Download URL: pr_commenter-0.2.3.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fd405c3bf5c79402e447a4b4ce0a46c64b6d424e0099993eff4b30dc9a97bda |
|
MD5 | c533b304f96cf46738c884f82006f71e |
|
BLAKE2b-256 | e4bcde3ad19d53a0c894130573c94bfe57765d728d77318985b4953231297212 |
File details
Details for the file pr_commenter-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: pr_commenter-0.2.3-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 108e324bdf8f9491143c97d4153b99f1bab9bd81d339412088f1cb8edba86564 |
|
MD5 | f020df6dc7b2492082a4042960e1cbdb |
|
BLAKE2b-256 | 0119ddb00e1ab79278976e563c952c299b9d87772cedeb47d774d5a807d55aa9 |