diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..34fdac7 --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,102 @@ +name: Static Analysis + +on: + pull_request: + branches: [ main ] + paths: + - '**.go' + - '**.js' + - '**.jsx' + - '.github/workflows/static-analysis.yml' + +jobs: + lint_and_fix_go: + name: Go Static Analysis + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.21' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ./code/go.sum + key: ${{ runner.os }}-go-${{ hashFiles('./code/go.sum') }} + + - name: Ensure Go module exists and tidy + run: | + if [ ! -f go.mod ]; then + go mod init github.com/${{ github.repository }} + fi + go mod tidy + working-directory: ./code + + - name: Install reviewdog + run: | + curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b /usr/local/bin + + - name: Install golangci-lint + run: | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.57.2 + echo "$(go env GOPATH)/bin" >> $GITHUB_PATH + working-directory: ./code + + - name: Run golangci-lint and report via reviewdog + run: | + golangci-lint run --out-format=checkstyle ./... | reviewdog -f=checkstyle -name="golangci-lint" -reporter=github-pr-review -fail-on-error=true + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + working-directory: ./code + + - name: Upload golangci-lint summary + if: always() + uses: actions/upload-artifact@v4 + with: + name: golangci-lint-summary + path: ./code + + - name: Summarize lint results + if: always() + uses: actions/github-script@v7 + with: + script: | + core.summary.addRaw("## Go Static Analysis Run in ./code\n") + + + lint_js: + name: JavaScript Static Analysis + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + steps: + - uses: actions/checkout@v4 + + - name: Find all JS/TS projects + id: find_projects + run: | + find . -name package.json -not -path "*/node_modules/*" > projects.txt + cat projects.txt + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Run ESLint via reviewdog (PR review) + uses: reviewdog/action-eslint@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + reporter: github-pr-review + eslint_flags: '**/*.{js,jsx,ts,tsx} --no-error-on-unmatched-pattern' + fail_level: error + workdir: ./js-code \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..40dfc46 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,26 @@ +linters: + enable: + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - misspell + - staticcheck + - unused + - errcheck + +linters-settings: + gofmt: + simplify: true + goimports: + local-prefixes: github.com/keploy/code-review-agent + +issues: + exclude-rules: + - path: _test\.go + linters: + - errcheck + +run: + timeout: 5m \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..9e92d6e --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Code Review Agent + + + diff --git a/code/main.go b/code/main.go new file mode 100644 index 0000000..e85e253 --- /dev/null +++ b/code/main.go @@ -0,0 +1 @@ +package code diff --git a/go.mod b/go.mod deleted file mode 100644 index ece20c9..0000000 --- a/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/keploy/code-review-agent - -go 1.24.3 diff --git a/js-code/.eslintrc.json b/js-code/.eslintrc.json new file mode 100644 index 0000000..801b1c1 --- /dev/null +++ b/js-code/.eslintrc.json @@ -0,0 +1,19 @@ +// runs-on: ubuntu-latest +{ + "env": { + "browser": true, + "es2021": true, + "node": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + }, + "rules": { + "no-unused-vars": "warn", + "semi": ["error", "always"], + "no-console": "off" + + } +} \ No newline at end of file diff --git a/js-code/main.js b/js-code/main.js new file mode 100644 index 0000000..e69de29 diff --git a/js-code/package.json b/js-code/package.json new file mode 100644 index 0000000..952023d --- /dev/null +++ b/js-code/package.json @@ -0,0 +1,15 @@ +{ + "name": "js-code", + "version": "1.0.0", + "description": "JavaScript code for static analysis", + "main": "main.js", + "scripts": { + "lint": "eslint . --ext .js,.jsx" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "eslint": "^8.0.0" + } +} diff --git a/main.go b/main.go deleted file mode 100644 index 21ccb8c..0000000 --- a/main.go +++ /dev/null @@ -1,5 +0,0 @@ -package codereviewagent - -func main(){ - // init codereview agent -} \ No newline at end of file