# PR Commenter Diff-Aware Action 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 values for repository info - Optional `diff` input — can post general PR comments without a diff - Remote URL usage for Gitea Actions --- ## Features - **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 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. --- ## Inputs | Input | Description | Required | Default | |-------|-------------|----------|---------| | `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 | `${{ 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 (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: 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 GitHub PR uses: "https://gitea.example.com/your-org/pr-commenter-action@main" with: platform: github token: ${{ secrets.GITHUB_TOKEN }} pr_index: ${{ github.event.pull_request.number }} diff: ${{ steps.gitdiff.outputs.diff }} comment_template: | Auto-comment on file: --- 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} ```