diff --git a/README.md b/README.md index e7bd0e5..ba6f4e6 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ # 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 - Multiline comment templates - Cross-platform support (GitHub and Gitea) - 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. - **Diff-aware**: Parses a `git diff` to determine which lines were added. - **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. -- **Reusable**: Works as a composite action and can be called from any workflow. +- **Multiline templates**: Supports `{line}` for a single line and `{lines}` for all added lines in a file. +- **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` | | `token` | API token for authentication | yes | - | -| `api_url` | Gitea API URL (only required for Gitea, e.g., `https://gitea.example.com/api/v1`) | no | - | -| `repo_owner` | Repository owner (user/org) | yes | - | -| `repo_name` | Repository name | yes | - | +| `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) | no | `${{ github.repository_owner }}` | +| `repo_name` | Repository name | no | `${{ github.repository }}` | | `pr_index` | PR number (GitHub) or index (Gitea) | yes | - | -| `diff` | Git diff to parse (generated via `git diff`) | yes | - | -| `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}` | +| `diff` | Git diff to parse (optional). If empty, posts only a general PR comment. | no | - | +| `comment_template` | Multiline template for comment body. Use placeholders `{line}` and `{lines}` | no | `Auto-comment: changed line -> {line}` | --- ## Example Usage +### GitHub PR + ```yaml jobs: comment-pr-diff: @@ -44,11 +50,6 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.11" - - name: Generate git diff id: gitdiff run: | @@ -56,12 +57,10 @@ jobs: git diff origin/main > diff.txt - 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: platform: github token: ${{ secrets.GITHUB_TOKEN }} - repo_owner: ${{ github.repository_owner }} - repo_name: ${{ github.event.repository.name }} pr_index: ${{ github.event.pull_request.number }} diff: ${{ steps.gitdiff.outputs.diff }} comment_template: | @@ -70,3 +69,35 @@ jobs: Changed line: {line} Full added lines in this file: {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} +``` \ No newline at end of file