diff --git a/.github/workflows/code-review-gpt.yml b/.github/workflows/code-review-gpt.yml new file mode 100644 index 0000000..1083d0e --- /dev/null +++ b/.github/workflows/code-review-gpt.yml @@ -0,0 +1,34 @@ +name: Code Review GPT + +on: + pull_request: + branches: [master] + +permissions: + pull-requests: write + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Install code-review-gpt + run: npm install code-review-gpt + + - name: Run code review script + run: npx code-review-gpt review --ci=github + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BASE_SHA: ${{ github.event.pull_request.base.sha }} + MODEL: 'gpt-3.5-turbo' + GITHUB_SHA: ${{ github.sha }} + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} diff --git a/.github/workflows/pr_agent.yml b/.github/workflows/pr_agent.yml new file mode 100644 index 0000000..7efeb09 --- /dev/null +++ b/.github/workflows/pr_agent.yml @@ -0,0 +1,20 @@ +on: + pull_request: + types: [opened, reopened, ready_for_review] + issue_comment: +jobs: + pr_agent_job: + if: ${{ github.event.sender.type != 'Bot' }} + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + contents: write + name: Run pr agent on every pull request, respond to user comments + steps: + - name: PR Agent action step + id: pragent + uses: Codium-ai/pr-agent@main + env: + OPENAI_KEY: ${{ secrets.OPENAI_KEY }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml new file mode 100644 index 0000000..a240c41 --- /dev/null +++ b/.github/workflows/reviewdog.yml @@ -0,0 +1,275 @@ +name: reviewdog +on: + push: + branches: + - master + pull_request: + +jobs: + reviewdog-github-check: + permissions: + checks: write + contents: read + pull-requests: write + name: reviewdog (github-check) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + + - name: Install linters + run: go install golang.org/x/lint/golint@latest + + - name: Setup reviewdog + # uses: reviewdog/action-setup@v1 + run: | + go install ./cmd/reviewdog + + - name: Run reviewdog + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + golint ./... | reviewdog -f=golint -name=golint-github-check -reporter=github-check -level=warning + + - name: Run reviewdog with sub-dir (github-check) + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + cd ./_testdata/ && golint ./... | reviewdog -f=golint -name=golint-check-subdir -reporter=github-check -level=info -filter-mode=nofilter + + - name: Custom rdjson test (github-check) + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + cat ./_testdata/custom_rdjson.json | \ + reviewdog -name="custom-rdjson" -f=rdjson -reporter=github-check -level=info + + reviewdog-pr: + permissions: + checks: write + contents: read + pull-requests: write + if: github.event_name == 'pull_request' + name: reviewdog on Pull Request + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + + - name: Install linters + run: go install golang.org/x/lint/golint@latest + + - name: Setup reviewdog + # uses: reviewdog/action-setup@v1 + run: | + go install ./cmd/reviewdog + + - name: Run reviewdog (github-pr-check) + continue-on-error: true + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + reviewdog -reporter=github-pr-check -runners=golint,govet -fail-on-error + + - name: Run reviewdog (github-pr-review with tee) + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Remove Go Problem Matchers [1] as it reports duplicate results with + # reviewdog. + # [1]: https://github.com/actions/toolkit/blob/master/docs/commands.md#problem-matchers + echo "::remove-matcher owner=go::" + golint ./... | reviewdog -f=golint -name=golint-pr-review -reporter=github-pr-review -tee + + - name: Run reviewdog with sub-dir (github-pr-review) + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + cd ./_testdata/ && golint ./... | reviewdog -f=golint -name=golint-pr-review-subdir -reporter=github-pr-review -tee + + - name: Run reviewdog with sub-dir (local+fail-on-error) + run: | + echo 'var LocalTest = 14' >> ./_testdata/golint.go + cd ./_testdata/ && golint ./... | reviewdog -f=golint -diff="git diff" -fail-on-error || EXIT_CODE=$? + git reset --hard @ + test "${EXIT_CODE}" = 1 + + - name: Run reviewdog (github-pr-check with fail-on-error) + continue-on-error: true + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + cd ./_testdata/ && golint ./... | reviewdog -f=golint -name=golint-pr-check-fail-on-error -reporter=github-pr-check -fail-on-error + + - name: Run reviewdog (github-pr-check with -filter-mode=file) + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + golint | reviewdog -f=golint -name=golint-pr-check-filter-mode-file -reporter=github-pr-check -filter-mode=file -level=warning + + - name: Run reviewdog (github-pr-review -filter-mode=nofilter) + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + cd ./_testdata/ && golint ./... | reviewdog -f=golint -name=golint-pr-review-nofilter -reporter=github-pr-review -filter-mode=nofilter -fail-on-error || EXIT_CODE=$? + test "${EXIT_CODE}" = 1 + + - name: Unexpected failure (github-pr-review) + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + cd ./_testdata/ && reviewdog -conf=reviewdog_error.yml \ + -reporter=github-pr-review || EXIT_CODE=$? + test "${EXIT_CODE}" = 1 + - name: Unexpected failure (github-check) + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + cd ./_testdata/ && reviewdog -conf=reviewdog_error.yml \ + -reporter=github-check || EXIT_CODE=$? + test "${EXIT_CODE}" = 1 + - name: Unexpected failure (local) + run: | + cd ./_testdata/ && reviewdog -conf=reviewdog_error.yml \ + -reporter=local -diff='git diff master' || EXIT_CODE=$? + test "${EXIT_CODE}" = 1 + - name: Suggestion (rdjsonl) + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + cat ./_testdata/suggestions.json | \ + reviewdog -name="suggestion-test" -f=rdjsonl -reporter=github-pr-review + + - name: Custom rdjsonl test (github-pr-review) + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + cat ./_testdata/custom_rdjson.json | \ + reviewdog -name="custom-rdjson" -f=rdjson -reporter=github-pr-review + + - name: gofmt -s with reviewdog + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gofmt -s -d . | \ + reviewdog -name="gofmt" -f=diff -f.diff.strip=0 -reporter=github-pr-review + + golangci-lint: + permissions: + checks: write + contents: read + pull-requests: write + if: github.event_name == 'pull_request' + name: runner / golangci-lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: reviewdog/action-golangci-lint@v2 + with: + github_token: ${{ secrets.github_token }} + golangci_lint_flags: "--timeout 2m" + level: "warning" + reporter: github-pr-check + + staticcheck: + permissions: + checks: write + contents: read + pull-requests: write + if: github.event_name == 'pull_request' + name: runner / staticcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + - uses: reviewdog/action-staticcheck@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: github-pr-review + filter_mode: nofilter + fail_on_error: true + # workdir: ./_testdata/ + + misspell: + name: runner / misspell + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: reviewdog/action-misspell@v1 + with: + github_token: ${{ secrets.github_token }} + locale: "US" + reporter: github-check + + languagetool: + name: runner / languagetool + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: reviewdog/action-languagetool@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: github-check + level: info + patterns: | + **/*.md + !**/testdata/** + + shellcheck: + if: github.event_name == 'pull_request' + name: runner / shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: reviewdog/action-shellcheck@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: github-pr-review + + alex: + name: runner / alex + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: reviewdog/action-alex@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: github-check + level: info + + textlint: + name: runner / textlint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: reviewdog/action-setup@v1 + - run: npm install + - name: textlint + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + npx textlint -f checkstyle README.md | \ + reviewdog -f=checkstyle -name="textlint" -reporter=github-check -level=info + + sarif: + name: runner / textlint sarif + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: reviewdog/action-setup@v1 + - run: npm install + - name: textlint sarif + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + npx textlint -f @microsoft/eslint-formatter-sarif README.md | \ + reviewdog -f=sarif -name="textlint" -reporter=github-check -level=info + \ No newline at end of file diff --git a/error_example.py b/error_example.py new file mode 100644 index 0000000..012edf5 --- /dev/null +++ b/error_example.py @@ -0,0 +1,33 @@ +# Syntax error - missing colon +def greet(name) + print("Hello,", name) + +# Linting error - using single quotes instead of double quotes +print('This is a linting error') + +# Syntax error - invalid syntax in print statement +print("This will cause a syntax error" # missing closing parenthesis + +# Linting error - unused variable +x = 10 + +# Syntax error - invalid syntax in variable assignment +y = 10 # Missing semicolon + +# Linting error - indentation error +def my_function(): +print("Indentation error") + +# Syntax error - invalid syntax in function definition +def my_function() # Missing colon + print("This will cause a syntax error") + +# Linting error - line too long +this_is_a_long_variable_name_that_should_be_shortened_to_avoid_line_too_long_error = 10 + +# Syntax error - invalid syntax in if statement +if x == 10 # Missing colon + print("This will cause a syntax error") + +# Linting error - multiple imports on one line +import os, sys diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..dc72a30 --- /dev/null +++ b/go.mod @@ -0,0 +1,70 @@ +module github.com/reviewdog/reviewdog + +go 1.21.7 + +require ( + cloud.google.com/go/compute/metadata v0.2.3 + cloud.google.com/go/datastore v1.15.0 + code.gitea.io/sdk/gitea v0.17.1 + contrib.go.opencensus.io/exporter/stackdriver v0.13.12 + github.com/bradleyfalzon/ghinstallation/v2 v2.10.0 + github.com/golang/protobuf v1.5.4 + github.com/google/go-cmp v0.6.0 + github.com/google/go-github/v60 v60.0.0 + github.com/google/go-github/v61 v61.0.0 + github.com/haya14busa/go-actions-toolkit v0.0.0-20200105081403-ca0307860f01 + github.com/haya14busa/secretbox v0.0.0-20180525171038-07c7ecf409f5 + github.com/justinas/nosurf v1.1.1 + github.com/kylelemons/godebug v1.1.0 + github.com/mattn/go-shellwords v1.0.12 + github.com/rakyll/statik v0.1.7 + github.com/reva2/bitbucket-insights-api v1.0.0 + github.com/reviewdog/errorformat v0.0.0-20240311054359-739e471a49b3 + github.com/reviewdog/go-bitbucket v0.0.0-20201024094602-708c3f6a7de0 + github.com/stretchr/testify v1.9.0 + github.com/vvakame/sdlog v1.2.0 + github.com/xanzy/go-gitlab v0.102.0 + go.opencensus.io v0.24.0 + golang.org/x/build v0.0.0-20230906094020-6ed658a430ec + golang.org/x/oauth2 v0.19.0 + golang.org/x/sync v0.7.0 + google.golang.org/protobuf v1.33.0 + gopkg.in/yaml.v3 v3.0.1 +) + +require ( + cloud.google.com/go v0.110.7 // indirect + cloud.google.com/go/compute v1.23.0 // indirect + cloud.google.com/go/monitoring v1.15.1 // indirect + cloud.google.com/go/trace v1.10.1 // indirect + github.com/aws/aws-sdk-go v1.43.31 // indirect + github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/davidmz/go-pageant v1.0.2 // indirect + github.com/go-fed/httpsig v1.1.0 // indirect + github.com/golang-jwt/jwt/v4 v4.5.0 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/google/go-querystring v1.1.0 // indirect + github.com/google/s2a-go v0.1.4 // indirect + github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect + github.com/googleapis/gax-go/v2 v2.12.0 // indirect + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect + github.com/hashicorp/go-retryablehttp v0.7.2 // indirect + github.com/hashicorp/go-version v1.6.0 // indirect + github.com/jmespath/go-jmespath v0.4.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/prometheus/prometheus v2.5.0+incompatible // indirect + github.com/stretchr/objx v0.5.2 // indirect + golang.org/x/crypto v0.21.0 // indirect + golang.org/x/net v0.22.0 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/text v0.14.0 // indirect + golang.org/x/time v0.3.0 // indirect + golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect + google.golang.org/api v0.128.0 // indirect + google.golang.org/appengine v1.6.8-0.20221117013220-504804fb50de // indirect + google.golang.org/genproto v0.0.0-20230821184602-ccc8af3d0e93 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20230803162519-f966b187b2e5 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230803162519-f966b187b2e5 // indirect + google.golang.org/grpc v1.57.1 // indirect +)