Skip to content

GitHub Action for automated code quality gates - supports Node.js, Java, Spring Boot

License

Notifications You must be signed in to change notification settings

tahseen137/code-quality-gate-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Code Quality Gate Bot ๐Ÿšฆ

GitHub Action CI License: MIT TypeScript Node.js GitHub issues GitHub stars

Automated code quality enforcement for your pull requests. Never merge substandard code again!

A GitHub Action that enforces code quality standards on every pull request. Supports Node.js, Java, and Spring Boot projects. Blocks merges if code doesn't meet quality thresholds.

โœจ Features

Feature Description
๐ŸŒ Multi-Language Support Node.js, Java, Spring Boot
๐Ÿ“Š Coverage Checking Ensures minimum code coverage percentage
๐Ÿ” Linting Enforcement ESLint (Node.js), Checkstyle (Java)
โœ… Type Checking TypeScript (Node.js), Compilation (Java)
๐Ÿ”ฎ Auto-Detection Automatically detects project type
๐Ÿ’ฌ PR Comments Posts detailed results directly on PRs
๐Ÿšฅ Check Status Integrates with branch protection rules

๐Ÿ“ธ Example Output

When a PR fails quality gates:

โŒ Code Quality Gate FAILED

### Coverage
โŒ Coverage: 45% (threshold: 70%)

### Linting  
โœ… No linting errors found

### Type Checking
โŒ TypeScript errors found: 3 error(s)

Please fix the issues above before merging.

When a PR passes:

โœ… Code Quality Gate PASSED

### Coverage
โœ… Coverage: 85% (threshold: 70%)

### Linting
โœ… No linting errors found

### Type Checking
โœ… No TypeScript errors found

All quality gates passed! ๐ŸŽ‰

๐Ÿš€ Quick Start

1. Add the Workflow

Create .github/workflows/quality-gate.yml:

For Node.js Projects

name: Code Quality Gate

on:
  pull_request:
    branches: [main, develop]

jobs:
  quality-gate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'
      
      - name: Install dependencies
        run: npm ci
      
      - name: Run tests with coverage
        run: npm run test:coverage
      
      - name: Run quality gate
        uses: tahseen137/code-quality-gate-bot@v1
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          project-type: nodejs
          coverage-threshold: 70

For Java/Spring Boot Projects

name: Code Quality Gate

on:
  pull_request:
    branches: [main, develop]

jobs:
  quality-gate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Setup Java
        uses: actions/setup-java@v4
        with:
          java-version: '21'
          distribution: 'temurin'
          cache: maven
      
      - name: Run tests with coverage
        run: mvn clean test jacoco:report
      
      - name: Run quality gate
        uses: tahseen137/code-quality-gate-bot@v1
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          project-type: springboot
          coverage-threshold: 70
          coverage-report-path: target/site/jacoco/jacoco.xml

2. Configure Your Project

Node.js

Ensure your package.json has these scripts:

{
  "scripts": {
    "test:coverage": "jest --coverage",
    "lint": "eslint src --ext .ts",
    "type-check": "tsc --noEmit"
  }
}

Java/Spring Boot

Add Jacoco plugin to pom.xml:

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.8.8</version>
  <executions>
    <execution>
      <goals>
        <goal>prepare-agent</goal>
      </goals>
    </execution>
    <execution>
      <id>report</id>
      <phase>test</phase>
      <goals>
        <goal>report</goal>
      </goals>
    </execution>
  </executions>
</plugin>

3. Set Branch Protection (Recommended)

  1. Go to Settings โ†’ Branches
  2. Click Add rule for your main branch
  3. Check Require status checks to pass before merging
  4. Search for and select Code Quality Gate

Now PRs cannot be merged until quality gates pass! ๐Ÿ”’

โš™๏ธ Configuration

Inputs

Input Required Default Description
github-token Yes - GitHub token for API access
project-type No auto Project type: nodejs, java, springboot, or auto
coverage-threshold No 70 Minimum code coverage percentage
coverage-report-path No auto Path to coverage report (auto-detected if not provided)

Coverage Report Paths

Project Type Default Path
Node.js coverage/coverage-final.json
Java/Spring Boot target/site/jacoco/jacoco.xml

๐Ÿ› ๏ธ Supported Languages

Language Linting Type Check Coverage
Node.js/TypeScript ESLint TypeScript Jest/Vitest
Java Checkstyle Maven/Gradle Jacoco
Spring Boot Checkstyle Maven/Gradle Jacoco

๐Ÿ”ง Development

# Install dependencies
npm install

# Build the project
npm run build

# Run linting
npm run lint

# Type check
npm run type-check

๐Ÿ—บ๏ธ Roadmap

  • Python support (pytest)
  • Go support
  • Rust support
  • Configuration file (.quality-gate.yml)
  • Slack/Discord notifications
  • Custom linting rules
  • Ignore patterns

๐Ÿค Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

Built with:


Made with โค๏ธ by Tahseen-ur Rahman

About

GitHub Action for automated code quality gates - supports Node.js, Java, Spring Boot

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published