Updating README.
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
# PR Commenter Diff-Aware Action
|
# PR Commenter Diff-Aware Action
|
||||||
|
|
||||||
A GitHub Action to automatically post comments to pull requests on **GitHub** or **Gitea**, based on a `git diff`. Supports:
|
A GitHub/Gitea Action to automatically post comments to pull requests based on a `git diff`. Supports:
|
||||||
|
|
||||||
- Inline comments per changed line
|
- Inline comments per changed line
|
||||||
- Multiline comment templates
|
- Multiline comment templates
|
||||||
- Cross-platform support (GitHub and Gitea)
|
- Cross-platform support (GitHub and Gitea)
|
||||||
- Diff-aware commenting, automatically detecting added lines
|
- Diff-aware commenting, automatically detecting added lines
|
||||||
- Default comment template with optional overrides
|
- Default values for repository info
|
||||||
|
- Optional `diff` input — can post general PR comments without a diff
|
||||||
|
- Remote URL usage for Gitea Actions
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -15,8 +17,10 @@ A GitHub Action to automatically post comments to pull requests on **GitHub** or
|
|||||||
- **GitHub & Gitea support**: Works seamlessly on both platforms.
|
- **GitHub & Gitea support**: Works seamlessly on both platforms.
|
||||||
- **Diff-aware**: Parses a `git diff` to determine which lines were added.
|
- **Diff-aware**: Parses a `git diff` to determine which lines were added.
|
||||||
- **Inline comments**: Comments appear directly on changed lines in PRs.
|
- **Inline comments**: Comments appear directly on changed lines in PRs.
|
||||||
- **Multiline templates**: Supports `{line}` for single line and `{lines}` for all added lines in a file.
|
- **Multiline templates**: Supports `{line}` for a single line and `{lines}` for all added lines in a file.
|
||||||
- **Reusable**: Works as a composite action and can be called from any workflow.
|
- **Optional diff**: If no diff is provided, posts a general PR comment.
|
||||||
|
- **Default repository values**: `repo_name`, `repo_owner`, and `api_url` default to GitHub environment variables if not provided.
|
||||||
|
- **Remote URL usage**: Can reference the action directly from a Git repository URL for Gitea.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -26,17 +30,19 @@ A GitHub Action to automatically post comments to pull requests on **GitHub** or
|
|||||||
|-------|-------------|----------|---------|
|
|-------|-------------|----------|---------|
|
||||||
| `platform` | Target platform: `github` or `gitea` | yes | `github` |
|
| `platform` | Target platform: `github` or `gitea` | yes | `github` |
|
||||||
| `token` | API token for authentication | yes | - |
|
| `token` | API token for authentication | yes | - |
|
||||||
| `api_url` | Gitea API URL (only required for Gitea, e.g., `https://gitea.example.com/api/v1`) | no | - |
|
| `api_url` | Gitea API URL (only required for Gitea, e.g., `https://gitea.example.com/api/v1`) | no | `${{ github.api_url }}` |
|
||||||
| `repo_owner` | Repository owner (user/org) | yes | - |
|
| `repo_owner` | Repository owner (user/org) | no | `${{ github.repository_owner }}` |
|
||||||
| `repo_name` | Repository name | yes | - |
|
| `repo_name` | Repository name | no | `${{ github.repository }}` |
|
||||||
| `pr_index` | PR number (GitHub) or index (Gitea) | yes | - |
|
| `pr_index` | PR number (GitHub) or index (Gitea) | yes | - |
|
||||||
| `diff` | Git diff to parse (generated via `git diff`) | yes | - |
|
| `diff` | Git diff to parse (optional). If empty, posts only a general PR comment. | no | - |
|
||||||
| `comment_template` | Multiline template for comment body. Use `{line}` for a single line and `{lines}` for all added lines in the file | yes | `Auto-comment: changed line -> {line}` |
|
| `comment_template` | Multiline template for comment body. Use placeholders `{line}` and `{lines}` | no | `Auto-comment: changed line -> {line}` |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
|
### GitHub PR
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
jobs:
|
jobs:
|
||||||
comment-pr-diff:
|
comment-pr-diff:
|
||||||
@@ -44,11 +50,6 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v4
|
|
||||||
with:
|
|
||||||
python-version: "3.11"
|
|
||||||
|
|
||||||
- name: Generate git diff
|
- name: Generate git diff
|
||||||
id: gitdiff
|
id: gitdiff
|
||||||
run: |
|
run: |
|
||||||
@@ -56,12 +57,10 @@ jobs:
|
|||||||
git diff origin/main > diff.txt
|
git diff origin/main > diff.txt
|
||||||
|
|
||||||
- name: Post diff-aware comments to GitHub PR
|
- name: Post diff-aware comments to GitHub PR
|
||||||
uses: ./ # path to this action
|
uses: "https://gitea.example.com/your-org/pr-commenter-action@main"
|
||||||
with:
|
with:
|
||||||
platform: github
|
platform: github
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
repo_owner: ${{ github.repository_owner }}
|
|
||||||
repo_name: ${{ github.event.repository.name }}
|
|
||||||
pr_index: ${{ github.event.pull_request.number }}
|
pr_index: ${{ github.event.pull_request.number }}
|
||||||
diff: ${{ steps.gitdiff.outputs.diff }}
|
diff: ${{ steps.gitdiff.outputs.diff }}
|
||||||
comment_template: |
|
comment_template: |
|
||||||
@@ -70,3 +69,35 @@ jobs:
|
|||||||
Changed line: {line}
|
Changed line: {line}
|
||||||
Full added lines in this file:
|
Full added lines in this file:
|
||||||
{lines}
|
{lines}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Gitea PR
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
jobs:
|
||||||
|
comment-pr-diff:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Generate git diff
|
||||||
|
id: gitdiff
|
||||||
|
run: |
|
||||||
|
git fetch origin main
|
||||||
|
git diff origin/main > diff.txt
|
||||||
|
|
||||||
|
- name: Post diff-aware comments to Gitea PR
|
||||||
|
uses: "https://gitea.example.com/your-org/pr-commenter-action@main"
|
||||||
|
with:
|
||||||
|
platform: gitea
|
||||||
|
token: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
api_url: "https://gitea.example.com/api/v1"
|
||||||
|
pr_index: 42
|
||||||
|
diff: ${{ steps.gitdiff.outputs.diff }}
|
||||||
|
comment_template: |
|
||||||
|
Auto-comment on file:
|
||||||
|
---
|
||||||
|
Changed line: {line}
|
||||||
|
Full added lines in this file:
|
||||||
|
{lines}
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user