Combine outputs from many jobs into a single comment
Project description
omni-comment
Combine outputs from many jobs into a single comment
Installation
pip install omni-comment
Usage
Create a file named omni-comment.yml to define the section IDs that can appear in the comment.
sections:
- test_results
- deploy_preview
- perf_stats
Now, import and call the omni_comment function to create or update the comment.
from omni_comment import omni_comment
result = omni_comment(
message="Hello world",
issue_number=123,
repo="owner/repo",
section="test_results",
token="github_token",
)
Options
| Name | Description | Required | Default |
|---|---|---|---|
token |
GitHub auth token | ✅ | |
repo |
The repository where to create the comment | ✅ | |
issue_number |
The issue number where to create the comment | ✅ | |
section |
The section ID that matches with the value in omni-comment.yml |
✅ | |
message |
Comment body | ||
title |
An optional title for the comment | ||
collapsed |
Whether the comment should be collapsed by default | False |
|
logger |
A custom logger to use | ||
config_path |
Path to the config file | omni-comment.yml |
Metadata (omni-comment.yml)
| Name | Description | Required |
|---|---|---|
sections |
A list of section IDs that defines the order of comment sections | ✅ |
title |
An optional title for the comment | |
intro |
An optional introduction for the comment that is displayed under the title |
How does it work?
I built this library to solve a problem we have at Ramp of lots of CI outputs that each need to post back to the PR via comments. The problem is, the more comments you have, the more noisy it gets.
The idea was, what if you had a single comment that contained everything? Test results, deploy preview URLs, warnings, etc. When you try to build that though, there are some challenges.
First, it should support workflows running in parallel, so the order in which the comments are posted is non deterministic. However, we want the order of sections in the comment to be consistent between runs. Additionally, we need to support updating the comment if you push a new commit, and the test results are now passing instead of failed.
The GitHub issue comments API only supports sending a complete comment body when making updates, so if we just get the current value and send it back with our updates, its possible that two separate jobs update the comment at the same time and one of the updates will be lost. To workaround this, we need a way for jobs to acquire a "lock" on the issue, so that they can safely get the current comment value, make edits, and push the updated value back to GitHub.
What better locking mechanism than reactions! Turns out, the
create reaction
API will return a 201 Created status when a reaction is newly created and a 200 OK when the
reaction already exists. Using this subtle API detail, this action will attempt to acquire a lock by
creating the reaction and waiting for a 201 status code. If it receives a 200 status code, it
will sleep and retry until it is able to acquire a lock (it will fail after 30 seconds if it fails
to acquire a lock). Once the lock is acquired, the existing comment will be downloaded, edited, and
pushed back to GitHub. After updating the comment, the lock is released by deleting the reaction.
Simple right? 😉
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file omni_comment-1.0.4.tar.gz.
File metadata
- Download URL: omni_comment-1.0.4.tar.gz
- Upload date:
- Size: 23.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c5bbcc779080d27f20a664c46be85eb6a4e72c5aa923544ddf2443ac32f53ac
|
|
| MD5 |
b1385240236d0aa191295f4a7cafba13
|
|
| BLAKE2b-256 |
a9258c736b0ea1e03d4f0888d8775aa63500cdd3cf47cbf8a607c4b158072173
|
Provenance
The following attestation bundles were made for omni_comment-1.0.4.tar.gz:
Publisher:
release.yml on mskelton/omni-comment-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
omni_comment-1.0.4.tar.gz -
Subject digest:
5c5bbcc779080d27f20a664c46be85eb6a4e72c5aa923544ddf2443ac32f53ac - Sigstore transparency entry: 1584316196
- Sigstore integration time:
-
Permalink:
mskelton/omni-comment-py@a49914ec72d4c87b008e276951602b4864fb2519 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mskelton
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a49914ec72d4c87b008e276951602b4864fb2519 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file omni_comment-1.0.4-py3-none-any.whl.
File metadata
- Download URL: omni_comment-1.0.4-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd190f51db033c34b8fd8e3a997402c56482adb8c1ad108deedba1ea71fc35e6
|
|
| MD5 |
07b80677a4fe9a33cd3f082985bc2dfa
|
|
| BLAKE2b-256 |
939f01bcc5e8b264e9a6b3f4860189118518666c38249727ad9e120df52f6e24
|
Provenance
The following attestation bundles were made for omni_comment-1.0.4-py3-none-any.whl:
Publisher:
release.yml on mskelton/omni-comment-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
omni_comment-1.0.4-py3-none-any.whl -
Subject digest:
fd190f51db033c34b8fd8e3a997402c56482adb8c1ad108deedba1ea71fc35e6 - Sigstore transparency entry: 1584316455
- Sigstore integration time:
-
Permalink:
mskelton/omni-comment-py@a49914ec72d4c87b008e276951602b4864fb2519 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mskelton
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a49914ec72d4c87b008e276951602b4864fb2519 -
Trigger Event:
workflow_dispatch
-
Statement type: