RefineAI Logo
0
%

GitHub Integration

Learn how to integrate RefineAI with your GitHub repositories for seamless code optimization as part of your development workflow.

Overview

RefineAI's GitHub integration allows you to automatically analyze and optimize your code as part of your GitHub workflow. You can set up automated code reviews on pull requests, schedule regular codebase analyses, and implement optimizations through pull requests.

Key Features

  • Automated code analysis and optimization suggestions on pull requests
  • Scheduled repository-wide optimization scans
  • Implementation of optimizations through automatically generated pull requests
  • Detailed code quality and performance metrics in GitHub checks
  • Integration with GitHub Actions for CI/CD pipelines

Setting Up the Integration

Follow these steps to set up the RefineAI GitHub integration for your repositories:

1Install the RefineAI GitHub App

Install the RefineAI GitHub App from the GitHub Marketplace or directly from our website:

2Configure Repository Access

During installation, you'll be asked to select which repositories RefineAI should have access to. You can choose:

  • All repositories (current and future)
  • Only select repositories

For security and performance reasons, we recommend starting with a single repository and expanding access as needed.

3Add Configuration File

Create a .refineai.yml file in the root of your repository to customize the integration:

# RefineAI Configuration
version: 1

# Analysis settings
analysis:
  include:
    - "src/**/*.js"
    - "src/**/*.ts"
    - "src/**/*.jsx"
    - "src/**/*.tsx"
  exclude:
    - "**/*.test.js"
    - "**/*.spec.ts"
    - "node_modules/**"
    - "dist/**"
  
  # Analysis categories
  categories:
    performance: true
    security: true
    quality: true
  
  # Analysis depth: basic, standard, or deep
  depth: standard

# Pull request settings
pull_requests:
  # Enable automated PR analysis
  enabled: true
  
  # Comment on PRs with analysis results
  comment: true
  
  # Fail GitHub check if critical issues are found
  fail_on_critical: true
  
  # Maximum number of comments per PR
  max_comments: 10

# Optimization settings
optimization:
  # Strategy: safe, balanced, or aggressive
  strategy: balanced
  
  # Create PRs with optimizations
  create_pull_requests: true
  
  # Branch name prefix for optimization PRs
  branch_prefix: "refine-ai/optimize"
  
  # Labels to add to optimization PRs
  labels:
    - "refine-ai"
    - "optimization"

# Scheduled analysis (using cron syntax)
schedule:
  # Run weekly analysis on Sunday at 2 AM
  cron: "0 2 * * 0"
  
  # Branch to analyze for scheduled runs
  branch: "main"

This configuration file is optional. If not provided, RefineAI will use default settings.

4Verify Installation

To verify that the integration is working correctly, create a test pull request. RefineAI should automatically analyze the code and add comments with optimization suggestions.

Example PR Comment

RefineAI will add comments to your pull requests with detailed optimization suggestions, including code examples and performance impact estimates.

GitHub Actions Integration

In addition to the GitHub App, you can integrate RefineAI with your GitHub Actions workflows for more customized automation:

Example GitHub Actions Workflow

Create a .github/workflows/refine-ai.yml file with the following content:

name: RefineAI Code Optimization

on:
  # Run on pull requests
  pull_request:
    branches: [ main, develop ]
    
  # Run on push to main branch
  push:
    branches: [ main ]
    
  # Allow manual triggering
  workflow_dispatch:
  
  # Run weekly on Sunday
  schedule:
    - cron: '0 2 * * 0'

jobs:
  analyze:
    name: Analyze and Optimize Code
    runs-on: ubuntu-latest
    
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      
      - name: RefineAI Analyze
        uses: refine-ai/github-action@v1
        with:
          api-key: ${{ secrets.REFINE_AI_API_KEY }}
          github-token: ${{ secrets.GITHUB_TOKEN }}
          # Optional: Path to config file
          config-file: '.refineai.yml'
          # Optional: Analysis depth
          depth: 'standard'
          # Optional: Create optimization PRs
          create-optimization-prs: true

Workflow Integration

Here's how RefineAI integrates with your GitHub workflow:

Pull Request Analysis

When a pull request is opened or updated, RefineAI automatically analyzes the changes and adds comments with optimization suggestions. The analysis focuses on the changed files to provide relevant feedback.

Optimization Pull Requests

RefineAI can automatically create pull requests with optimized code based on the analysis results. These PRs include detailed descriptions of the optimizations and their expected impact on performance, security, and code quality.

GitHub Checks

RefineAI provides GitHub Checks that show the status of the analysis and optimization process. These checks can be configured to pass or fail based on the severity of the issues found, helping you maintain code quality standards.

Security Considerations

When using the GitHub integration, keep these security considerations in mind:

  • RefineAI requires read access to your code to perform analysis and write access to create optimization PRs
  • Your code is processed in secure, isolated environments and is not stored longer than necessary for analysis
  • For sensitive repositories, consider using the GitHub Actions integration with a self-hosted runner for maximum security
  • Review the permissions granted to the RefineAI GitHub App and limit them to only the repositories that need optimization