├── .github ├── renovate.json └── workflows │ ├── depup.yml │ ├── test.yml │ ├── release.yml │ └── reviewdog.yml ├── testdata ├── test.sh └── gofmt.go ├── script.sh ├── LICENSE ├── action.yml └── README.md /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ], 5 | "labels": [ 6 | "bump:patch" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /testdata/test.sh: -------------------------------------------------------------------------------- 1 | find . -name *.ogg # Unquoted find/grep patterns 2 | 3 | grep '*foo*' file # Globs in regex contexts 4 | 5 | var = 42 # Spaces around = in assignments 6 | 7 | echo "The time is `date`" # Use $() instead 8 | -------------------------------------------------------------------------------- /testdata/gofmt.go: -------------------------------------------------------------------------------- 1 | package testdata 2 | 3 | func fmt () { 4 | // test 5 | // test line 6 | // test line 7 | // test line 8 | // test line 9 | // test line 10 | // test line 11 | // test line 12 | 13 | println( 14 | "hello, gofmt test" ) 15 | //comment 16 | } 17 | 18 | 19 | type s struct { A int } 20 | func (s s) String() { return "s" } 21 | -------------------------------------------------------------------------------- /.github/workflows/depup.yml: -------------------------------------------------------------------------------- 1 | name: depup 2 | on: 3 | schedule: 4 | - cron: "14 14 * * *" # Runs at 14:14 UTC every day 5 | repository_dispatch: 6 | types: [depup] 7 | workflow_dispatch: 8 | 9 | jobs: 10 | reviewdog: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 14 | - uses: reviewdog/action-depup/with-pr@94a1aaf4e4923064019214b48a43276218af7ad5 # v1.6.4 15 | with: 16 | file: action.yml 17 | version_name: reviewdog_version 18 | repo: reviewdog/reviewdog 19 | labels: "bump:minor" 20 | -------------------------------------------------------------------------------- /script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | if [ -n "${GITHUB_WORKSPACE}" ]; then 5 | cd "${GITHUB_WORKSPACE}" || exit 6 | fi 7 | 8 | export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" 9 | 10 | TMPFILE=$(mktemp) 11 | git diff >"${TMPFILE}" 12 | 13 | git stash -u 14 | 15 | # shellcheck disable=SC2086 16 | reviewdog \ 17 | -name="${INPUT_TOOL_NAME:-reviewdog-suggester}" \ 18 | -f=diff \ 19 | -f.diff.strip=1 \ 20 | -reporter="github-pr-review" \ 21 | -filter-mode="${INPUT_FILTER_MODE}" \ 22 | -fail-level="${INPUT_FAIL_LEVEL}" \ 23 | -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ 24 | -level="${INPUT_LEVEL}" \ 25 | ${INPUT_REVIEWDOG_FLAGS} <"${TMPFILE}" # INPUT_REVIEWDOG_FLAGS is intentionally split to pass multiple flags 26 | 27 | EXIT_CODE=$? 28 | 29 | if [ "${INPUT_CLEANUP}" = "true" ]; then 30 | git stash drop || true 31 | else 32 | git stash pop || true 33 | fi 34 | 35 | exit "${EXIT_CODE}" 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 reviewdog developers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | on: 3 | pull_request: 4 | jobs: 5 | test-gofmt: 6 | name: runner / suggester / gofmt 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 10 | - run: gofmt -w -s . 11 | - uses: ./ 12 | with: 13 | tool_name: gofmt 14 | filter_mode: nofilter 15 | 16 | test-shell: 17 | name: runner / suggester / shell 18 | runs-on: ubuntu-latest 19 | steps: 20 | - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 21 | - uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 22 | with: 23 | go-version: "1.25" 24 | - run: go install mvdan.cc/sh/v3/cmd/shfmt@latest 25 | 26 | - run: shfmt -i 2 -ci -w . 27 | - name: suggester / shfmt 28 | uses: ./ 29 | with: 30 | tool_name: shfmt 31 | 32 | # Need to install latest shellcheck to use diff output format as of writing (2020/08/03). 33 | - name: install shellcheck 34 | run: | 35 | scversion="latest" 36 | wget -qO- "https://github.com/koalaman/shellcheck/releases/download/${scversion?}/shellcheck-${scversion?}.linux.x86_64.tar.xz" | tar -xJv 37 | sudo cp "shellcheck-${scversion}/shellcheck" /usr/local/bin/ 38 | rm -rf "shellcheck-${scversion}/shellcheck" 39 | - run: shellcheck -f diff "$(shfmt -f .)" | patch -p1 40 | - name: suggester / shellcheck 41 | uses: ./ 42 | with: 43 | tool_name: shellcheck 44 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | on: 3 | push: 4 | branches: 5 | - master 6 | tags: 7 | - "v*.*.*" 8 | pull_request: 9 | types: 10 | - labeled 11 | 12 | jobs: 13 | release: 14 | if: github.event.action != 'labeled' 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 18 | 19 | # Bump version on merging Pull Requests with specific labels. 20 | # (bump:major,bump:minor,bump:patch) 21 | - id: bumpr 22 | if: "!startsWith(github.ref, 'refs/tags/')" 23 | uses: haya14busa/action-bumpr@faf6f474bcb6174125cfc569f0b2e24cbf03d496 # v1.11.4 24 | 25 | # Update corresponding major and minor tag. 26 | # e.g. Update v1 and v1.2 when releasing v1.2.3 27 | - uses: haya14busa/action-update-semver@7d2c558640ea49e798d46539536190aff8c18715 # v1.5.1 28 | if: "!steps.bumpr.outputs.skip" 29 | with: 30 | tag: ${{ steps.bumpr.outputs.next_version }} 31 | 32 | # Get tag name. 33 | - id: tag 34 | uses: haya14busa/action-cond@94f77f7a80cd666cb3155084e428254fea4281fd # v1.2.1 35 | with: 36 | cond: "${{ startsWith(github.ref, 'refs/tags/') }}" 37 | if_true: ${{ github.ref }} 38 | if_false: ${{ steps.bumpr.outputs.next_version }} 39 | 40 | # Create release 41 | - if: "steps.tag.outputs.value != ''" 42 | env: 43 | TAG_NAME: ${{ steps.tag.outputs.value }} 44 | CURRENT: ${{ steps.bumpr.outputs.current_version }} 45 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 46 | run: | 47 | gh release create "${TAG_NAME}" -t "Release ${TAG_NAME/refs\/tags\//}" --generate-notes --notes-start-tag "${CURRENT}" 48 | 49 | release-check: 50 | if: github.event.action == 'labeled' 51 | runs-on: ubuntu-latest 52 | steps: 53 | - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 54 | - name: Post bumpr status comment 55 | uses: haya14busa/action-bumpr@faf6f474bcb6174125cfc569f0b2e24cbf03d496 # v1.11.4 56 | -------------------------------------------------------------------------------- /.github/workflows/reviewdog.yml: -------------------------------------------------------------------------------- 1 | name: reviewdog 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | jobs: 8 | shellcheck: 9 | name: runner / shellcheck 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 13 | - uses: haya14busa/action-cond@94f77f7a80cd666cb3155084e428254fea4281fd # v1.2.1 14 | id: reporter 15 | with: 16 | cond: ${{ github.event_name == 'pull_request' }} 17 | if_true: "github-pr-review" 18 | if_false: "github-check" 19 | - uses: reviewdog/action-shellcheck@4c07458293ac342d477251099501a718ae5ef86e # v1.32.0 20 | with: 21 | github_token: ${{ secrets.github_token }} 22 | reporter: ${{ steps.reporter.outputs.value }} 23 | level: warning 24 | 25 | shfmt: 26 | name: runner / shfmt 27 | runs-on: ubuntu-latest 28 | steps: 29 | - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 30 | - uses: reviewdog/action-shfmt@d8f080930b9be5847b4f97e9f4122b81a82aaeac # v1.0.4 31 | 32 | actionlint: 33 | name: runner / actionlint 34 | runs-on: ubuntu-latest 35 | steps: 36 | - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 37 | - uses: reviewdog/action-actionlint@95395aac8c053577d0bc67eb7b74936c660c6f66 # v1.67.0 38 | with: 39 | reporter: github-check 40 | level: warning 41 | 42 | misspell: 43 | name: runner / misspell 44 | runs-on: ubuntu-latest 45 | steps: 46 | - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 47 | - uses: reviewdog/action-misspell@9daa94af4357dddb6fd3775de806bc0a8e98d3e4 # v1.26.3 48 | with: 49 | github_token: ${{ secrets.github_token }} 50 | reporter: github-check 51 | level: warning 52 | locale: "US" 53 | 54 | alex: 55 | name: runner / alex 56 | runs-on: ubuntu-latest 57 | steps: 58 | - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 59 | - uses: reviewdog/action-alex@6083b8ca333981fa617c6828c5d8fb21b13d916b # v1.16.0 60 | with: 61 | github_token: ${{ secrets.github_token }} 62 | reporter: github-check 63 | level: warning 64 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: "reviewdog-suggester: Suggest any code changes based on diff with reviewdog" 2 | description: "🐶 Suggest any code changes based on diff through GitHub Multi-line code suggestions" 3 | author: "haya14busa" 4 | inputs: 5 | github_token: 6 | description: "GITHUB_TOKEN" 7 | default: "${{ github.token }}" 8 | required: true 9 | path: 10 | description: "The directory in which reviewdog should run" 11 | default: "." 12 | required: false 13 | ### Flags for reviewdog ### 14 | tool_name: 15 | description: "Tool name to use for reviewdog reporter" 16 | default: "reviewdog-suggester" 17 | required: false 18 | level: 19 | description: "Report level for reviewdog [info,warning,error]" 20 | default: "warning" 21 | required: false 22 | filter_mode: 23 | description: | 24 | Filtering mode for the reviewdog command [added,diff_context,file,nofilter]. 25 | Default is diff_context. GitHub suggestions only support added and diff_context. 26 | default: "diff_context" 27 | required: false 28 | fail_level: 29 | description: | 30 | Exit code 1 for reviewdog if it finds at least 1 issue with severity greater than or equal to given level [any,info,warning,error]. 31 | If set to `none`, always exit with 0. 32 | Default is `none`. 33 | default: "none" 34 | required: false 35 | fail_on_error: 36 | description: | 37 | Exit code for reviewdog when errors are found [true,false] 38 | Default is `false`. 39 | deprecationMessage: Deprecated, use `fail_level` instead. 40 | default: "false" 41 | required: false 42 | reviewdog_flags: 43 | description: "Additional reviewdog flags" 44 | default: "" 45 | required: false 46 | ### Flags for reviewdog suggester ### 47 | cleanup: 48 | description: "Clean up non-committed changes after the action" 49 | default: "true" 50 | required: false 51 | runs: 52 | using: "composite" 53 | steps: 54 | - uses: reviewdog/action-setup@d8edfce3dd5e1ec6978745e801f9c50b5ef80252 # v1.4.0 55 | with: 56 | reviewdog_version: v0.21.0 57 | - run: | 58 | set -euo pipefail 59 | . "$GITHUB_ACTION_PATH/script.sh" 60 | shell: bash 61 | env: 62 | # INPUT_ is not available in Composite run steps 63 | # https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611 64 | INPUT_GITHUB_TOKEN: ${{ inputs.github_token }} 65 | INPUT_TOOL_NAME: ${{ inputs.tool_name }} 66 | INPUT_LEVEL: ${{ inputs.level }} 67 | INPUT_FILTER_MODE: ${{ inputs.filter_mode }} 68 | INPUT_FAIL_LEVEL: ${{ inputs.fail_level }} 69 | INPUT_FAIL_ON_ERROR: ${{ inputs.fail_on_error }} 70 | INPUT_REVIEWDOG_FLAGS: ${{ inputs.reviewdog_flags }} 71 | INPUT_CLEANUP: ${{ inputs.cleanup }} 72 | working-directory: ${{ inputs.path }} 73 | 74 | # Ref: https://haya14busa.github.io/github-action-brandings/ 75 | branding: 76 | icon: "edit" 77 | color: "red" 78 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # action-suggester 2 | 3 | [![Test](https://github.com/reviewdog/action-suggester/workflows/Test/badge.svg)](https://github.com/reviewdog/action-suggester/actions?query=workflow%3ATest) 4 | [![reviewdog](https://github.com/reviewdog/action-suggester/workflows/reviewdog/badge.svg)](https://github.com/reviewdog/action-suggester/actions?query=workflow%3Areviewdog) 5 | [![depup](https://github.com/reviewdog/action-suggester/workflows/depup/badge.svg)](https://github.com/reviewdog/action-suggester/actions?query=workflow%3Adepup) 6 | [![release](https://github.com/reviewdog/action-suggester/workflows/release/badge.svg)](https://github.com/reviewdog/action-suggester/actions?query=workflow%3Arelease) 7 | [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/reviewdog/action-suggester?logo=github&sort=semver)](https://github.com/reviewdog/action-suggester/releases) 8 | [![action-bumpr supported](https://img.shields.io/badge/bumpr-supported-ff69b4?logo=github&link=https://github.com/haya14busa/action-bumpr)](https://github.com/haya14busa/action-bumpr) 9 | [![Used-by counter](https://img.shields.io/endpoint?url=https://haya14busa.github.io/github-used-by/data/reviewdog/action-suggester/shieldsio.json)](https://github.com/haya14busa/github-used-by/tree/main/repo/reviewdog/action-suggester) 10 | 11 | ![shfmt demo](https://user-images.githubusercontent.com/3797062/89161351-75c31880-d5ad-11ea-8e05-b73b00a7783e.png) 12 | ![shellcheck demo](https://user-images.githubusercontent.com/3797062/89164248-cfc5dd00-d5b1-11ea-9983-188f56de7eba.png) 13 | ![gofmt demo](https://user-images.githubusercontent.com/3797062/89164333-ea985180-d5b1-11ea-9452-1240c2dc82f7.png) 14 | ![multiline demo](https://user-images.githubusercontent.com/3797062/89168305-a3ad5a80-d5b7-11ea-8939-be7ac1976d30.png) 15 | 16 | action-suggester is a handy action which suggests any code changes based on 17 | diff through GitHub Multi-line code suggestions by using [reviewdog](https://github.com/reviewdog/reviewdog). 18 | 19 | You can use any formatters or linters with auto-fix feature for any languages 20 | and the reviewdog suggester support any changes including inline change, 21 | multi-line changes, insertion, and deletion. 22 | 23 | ## Input 24 | 25 | ```yaml 26 | inputs: 27 | github_token: 28 | description: 'GITHUB_TOKEN' 29 | default: '${{ github.token }}' 30 | ### Flags for reviewdog ### 31 | tool_name: 32 | description: 'Tool name to use for reviewdog reporter' 33 | default: 'reviewdog-suggester' 34 | level: 35 | description: 'Report level for reviewdog [info,warning,error]' 36 | default: 'warning' 37 | filter_mode: 38 | description: | 39 | Filtering mode for the reviewdog command [added,diff_context,file,nofilter]. 40 | Default is diff_context. GitHub suggestions only support added and diff_context. 41 | default: 'diff_context' 42 | fail_level: 43 | description: | 44 | Exit code 1 for reviewdog if it finds at least 1 issue with severity greater than or equal to given level [none,any,info,warning,error]. 45 | If set to `none`, always exit with 0. 46 | Default is `none`. 47 | default: 'none' 48 | fail_on_error: 49 | description: | 50 | Exit code for reviewdog when errors are found [true,false] 51 | Default is `false`. 52 | deprecationMessage: Deprecated, use `fail_level` instead. 53 | default: 'false' 54 | reviewdog_flags: 55 | description: 'Additional reviewdog flags' 56 | default: '' 57 | ### Flags for reviewdog suggester ### 58 | cleanup: 59 | description: 'Clean up non-committed changes after the action' 60 | default: 'true' 61 | ``` 62 | 63 | ## Required Permissions 64 | 65 | The action requires the following permissions: 66 | 67 | ```yaml 68 | permissions: 69 | contents: read 70 | checks: write 71 | issues: write 72 | pull-requests: write 73 | ``` 74 | 75 | See [Assigning permissions to jobs](https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs) for more details. 76 | 77 | ## Usage Example 78 | 79 | ```yaml 80 | name: reviewdog-suggester 81 | on: [pull_request] # Support only pull_request event. 82 | jobs: 83 | go: 84 | name: runner / suggester / gofmt 85 | runs-on: ubuntu-latest 86 | steps: 87 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 88 | - run: gofmt -w -s . 89 | - uses: reviewdog/action-suggester@4747dbc9f9e37adba0943e681cc20db466642158 # v1.21.0 90 | with: 91 | tool_name: gofmt 92 | shell: 93 | name: runner / suggester / shell 94 | runs-on: ubuntu-latest 95 | steps: 96 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 97 | - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 98 | - run: go install mvdan.cc/sh/v3/cmd/shfmt@latest 99 | 100 | - run: shfmt -i 2 -ci -w . 101 | - name: suggester / shfmt 102 | uses: reviewdog/action-suggester@4747dbc9f9e37adba0943e681cc20db466642158 # v1.21.0 103 | with: 104 | tool_name: shfmt 105 | 106 | # Need to install latest shellcheck to use diff output format as of writing (2020/08/03). 107 | - name: install shellcheck 108 | run: | 109 | scversion="latest" 110 | wget -qO- "https://github.com/koalaman/shellcheck/releases/download/${scversion?}/shellcheck-${scversion?}.linux.x86_64.tar.xz" | tar -xJv 111 | sudo cp "shellcheck-${scversion}/shellcheck" /usr/local/bin/ 112 | rm -rf "shellcheck-${scversion}/shellcheck" 113 | - run: shellcheck -f diff $(shfmt -f .) | patch -p1 114 | - name: suggester / shellcheck 115 | uses: reviewdog/action-suggester@4747dbc9f9e37adba0943e681cc20db466642158 # v1.21.0 116 | with: 117 | tool_name: shellcheck 118 | ``` 119 | --------------------------------------------------------------------------------