Skip to content

feat: JS and Go static Analysis Integrated #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: init-proj
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Code Review Agent



1 change: 1 addition & 0 deletions code/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package code
3 changes: 0 additions & 3 deletions go.mod

This file was deleted.

19 changes: 19 additions & 0 deletions js-code/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -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"

}
}
Empty file added js-code/main.js
Empty file.
15 changes: 15 additions & 0 deletions js-code/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
5 changes: 0 additions & 5 deletions main.go

This file was deleted.