Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/htunnicliff/replace-comment-html
An action to upsert HTML in GitHub issue or pull request comments using CSS selectors
https://github.com/htunnicliff/replace-comment-html
actions comments html
Last synced: 21 days ago
JSON representation
An action to upsert HTML in GitHub issue or pull request comments using CSS selectors
- Host: GitHub
- URL: https://github.com/htunnicliff/replace-comment-html
- Owner: htunnicliff
- License: mit
- Created: 2024-02-12T22:05:08.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-03-14T18:01:24.000Z (8 months ago)
- Last Synced: 2024-10-06T09:21:48.139Z (about 1 month ago)
- Topics: actions, comments, html
- Language: TypeScript
- Homepage:
- Size: 251 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Replace Comment HTML
This action upserts HTML in GitHub issue or pull request comments using CSS selectors.
## Usage
Here's an example of how you might use this action in a workflow:
```yaml
name: Deploy Previewson:
pull_request:
branches:
- mainjobs:
deploy:
strategy:
matrix:
env: [dev, stage, prod]
steps:
# ... steps to deploy preview envionment ...# Create a comment with an empty table
- uses: htunnicliff/replace-comment-html@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
selector: "#preview-links"
mode: create-only # This will create the table if it doesn't exist
html: |
Environment
Preview Link
# Add a row for the deployed environment
- uses: htunnicliff/replace-comment-html@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
parent-selector: "#preview-links tbody" # Append this row to the
selector: "tr#preview-link-${{ matrix.env }}"
mode: upsert # This will update the row if it exists, or create it if it doesn't
html: |
${{ matrix.env }}
Preview
# ...
```The resulting comment will contain a table that looks like this:
```html
Environment
Preview Link
dev
Preview
stage
Preview
prod
Preview
```
If this workflow runs again and a row exists with the given CSS selector, it will be replaced with a new version while other HTML remains unmodified.
## Inputs
| Name | Description | Default |
| ----------------- | ----------------------------------------------------------------------------- | -------------------------- |
| `html` | HTML to create or update | |
| `selector` | A CSS selector for identifying the element to update | |
| `parent-selector` | A CSS selector for identfying a parent to append the element to | `null` |
| `token` | `GITHUB_TOKEN` or a repo scoped [personal access token][PAT]. | `${{ github.token }}` |
| `repository` | The repository to update the comment in. | `${{ github.repository }}` |
| `issue-number` | The issue or pull request number to update the comment in. | Current PR or issue number |
| `mode` | The strategy to use for modifying comments (either `upsert` or `create-only`) | `upsert` |## Outputs
| Name | Description |
| ------------ | ------------------------------------------------- |
| `comment-id` | The ID of the comment that was created or updated |[PAT]: https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token