# 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: - 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 --- ## 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 single line and `{lines}` for all added lines in a file. - **Reusable**: Works as a composite action and can be called from any workflow. --- ## 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 | - | | `repo_owner` | Repository owner (user/org) | yes | - | | `repo_name` | Repository name | yes | - | | `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}` | --- ## Example Usage ```yaml jobs: comment-pr-diff: runs-on: ubuntu-latest 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: | git fetch origin main git diff origin/main > diff.txt - name: Post diff-aware comments to GitHub PR uses: ./ # path to this action 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: | Auto-comment on file: --- Changed line: {line} Full added lines in this file: {lines}