Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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 Previews

on:
pull_request:
branches:
- main

jobs:
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