|
| 1 | +--- |
| 2 | +title: Customize a code quality check workflow |
| 3 | +linkTitle: Customize workflow |
| 4 | +summary: Adapt your GitHub and SonarQube workflow to focus on specific quality issues, integrate with CI/CD, and set custom thresholds. |
| 5 | +description: Learn how to customize prompts for specific quality issues, filter by file patterns, set quality thresholds, and integrate your workflow with GitHub Actions for automated code quality checks. |
| 6 | +weight: 20 |
| 7 | +--- |
| 8 | + |
| 9 | +Now that you understand the basics of automating code quality workflows with |
| 10 | +GitHub and SonarQube in E2B sandboxes, you can customize the workflow |
| 11 | +for your needs. |
| 12 | + |
| 13 | +## Focus on specific quality issues |
| 14 | + |
| 15 | +Modify the prompt to prioritize certain issue types: |
| 16 | + |
| 17 | +{{< tabs group="language" >}} |
| 18 | +{{< tab name="TypeScript" >}} |
| 19 | + |
| 20 | +```typescript |
| 21 | +const prompt = `Using SonarQube and GitHub MCP tools: |
| 22 | +
|
| 23 | +Focus only on: |
| 24 | +- Security vulnerabilities (CRITICAL priority) |
| 25 | +- Bugs (HIGH priority) |
| 26 | +- Skip code smells for this iteration |
| 27 | +
|
| 28 | +Analyze "${repoPath}" and fix the highest priority issues first.`; |
| 29 | +``` |
| 30 | + |
| 31 | +{{< /tab >}} |
| 32 | +{{< tab name="Python" >}} |
| 33 | + |
| 34 | +```python |
| 35 | +prompt = f"""Using SonarQube and GitHub MCP tools: |
| 36 | +
|
| 37 | +Focus only on: |
| 38 | +- Security vulnerabilities (CRITICAL priority) |
| 39 | +- Bugs (HIGH priority) |
| 40 | +- Skip code smells for this iteration |
| 41 | +
|
| 42 | +Analyze "{repo_path}" and fix the highest priority issues first.""" |
| 43 | +``` |
| 44 | + |
| 45 | +{{< /tab >}} |
| 46 | +{{< /tabs >}} |
| 47 | + |
| 48 | +## Integrate with CI/CD |
| 49 | + |
| 50 | +Add this workflow to GitHub Actions to run automatically on pull requests: |
| 51 | + |
| 52 | +{{< tabs group="language" >}} |
| 53 | +{{< tab name="TypeScript" >}} |
| 54 | + |
| 55 | +```yaml |
| 56 | +name: Automated quality checks |
| 57 | +on: |
| 58 | + pull_request: |
| 59 | + types: [opened, synchronize] |
| 60 | + |
| 61 | +jobs: |
| 62 | + quality: |
| 63 | + runs-on: ubuntu-latest |
| 64 | + steps: |
| 65 | + - uses: actions/checkout@v4 |
| 66 | + - uses: actions/setup-node@v4 |
| 67 | + with: |
| 68 | + node-version: "18" |
| 69 | + - run: npm install |
| 70 | + - run: npx tsx 06-quality-gated-pr.ts |
| 71 | + env: |
| 72 | + E2B_API_KEY: ${{ secrets.E2B_API_KEY }} |
| 73 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 74 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + SONARQUBE_TOKEN: ${{ secrets.SONARQUBE_TOKEN }} |
| 76 | + GITHUB_OWNER: ${{ github.repository_owner }} |
| 77 | + GITHUB_REPO: ${{ github.event.repository.name }} |
| 78 | + SONARQUBE_ORG: your-org-key |
| 79 | +``` |
| 80 | +
|
| 81 | +{{< /tab >}} |
| 82 | +{{< tab name="Python" >}} |
| 83 | +
|
| 84 | +```yaml |
| 85 | +name: Automated quality checks |
| 86 | +on: |
| 87 | + pull_request: |
| 88 | + types: [opened, synchronize] |
| 89 | + |
| 90 | +jobs: |
| 91 | + quality: |
| 92 | + runs-on: ubuntu-latest |
| 93 | + steps: |
| 94 | + - uses: actions/checkout@v4 |
| 95 | + - uses: actions/setup-python@v5 |
| 96 | + with: |
| 97 | + python-version: "3.8" |
| 98 | + - run: pip install e2b python-dotenv |
| 99 | + - run: python 06_quality_gated_pr.py |
| 100 | + env: |
| 101 | + E2B_API_KEY: ${{ secrets.E2B_API_KEY }} |
| 102 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 103 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 104 | + SONARQUBE_TOKEN: ${{ secrets.SONARQUBE_TOKEN }} |
| 105 | + GITHUB_OWNER: ${{ github.repository_owner }} |
| 106 | + GITHUB_REPO: ${{ github.event.repository.name }} |
| 107 | + SONARQUBE_ORG: your-org-key |
| 108 | +``` |
| 109 | +
|
| 110 | +{{< /tab >}} |
| 111 | +{{< /tabs >}} |
| 112 | +
|
| 113 | +## Filter by file patterns |
| 114 | +
|
| 115 | +Target specific parts of your codebase: |
| 116 | +
|
| 117 | +{{< tabs group="language" >}} |
| 118 | +{{< tab name="TypeScript" >}} |
| 119 | +
|
| 120 | +```typescript |
| 121 | +const prompt = `Analyze code quality but only consider: |
| 122 | +- Files in src/**/*.js |
| 123 | +- Exclude test files (*.test.js, *.spec.js) |
| 124 | +- Exclude build artifacts in dist/ |
| 125 | + |
| 126 | +Focus on production code only.`; |
| 127 | +``` |
| 128 | + |
| 129 | +{{< /tab >}} |
| 130 | +{{< tab name="Python" >}} |
| 131 | + |
| 132 | +```python |
| 133 | +prompt = """Analyze code quality but only consider: |
| 134 | +- Files in src/**/*.js |
| 135 | +- Exclude test files (*.test.js, *.spec.js) |
| 136 | +- Exclude build artifacts in dist/ |
| 137 | +
|
| 138 | +Focus on production code only.""" |
| 139 | +``` |
| 140 | + |
| 141 | +{{< /tab >}} |
| 142 | +{{< /tabs >}} |
| 143 | + |
| 144 | +## Set quality thresholds |
| 145 | + |
| 146 | +Define when PRs should be created: |
| 147 | + |
| 148 | +{{< tabs group="language" >}} |
| 149 | +{{< tab name="TypeScript" >}} |
| 150 | + |
| 151 | +```typescript |
| 152 | +const prompt = `Quality gate thresholds: |
| 153 | +- Only create PR if: |
| 154 | + * Bug count decreases by at least 1 |
| 155 | + * No new security vulnerabilities introduced |
| 156 | + * Code coverage does not decrease |
| 157 | + * Technical debt reduces by at least 15 minutes |
| 158 | +
|
| 159 | +If changes do not meet these thresholds, explain why and skip PR creation.`; |
| 160 | +``` |
| 161 | + |
| 162 | +{{< /tab >}} |
| 163 | +{{< tab name="Python" >}} |
| 164 | + |
| 165 | +```python |
| 166 | +prompt = """Quality gate thresholds: |
| 167 | +- Only create PR if: |
| 168 | + * Bug count decreases by at least 1 |
| 169 | + * No new security vulnerabilities introduced |
| 170 | + * Code coverage does not decrease |
| 171 | + * Technical debt reduces by at least 15 minutes |
| 172 | +
|
| 173 | +If changes do not meet these thresholds, explain why and skip PR creation.""" |
| 174 | +``` |
| 175 | + |
| 176 | +{{< /tab >}} |
| 177 | +{{< /tabs >}} |
| 178 | + |
| 179 | +## Next steps |
| 180 | + |
| 181 | +Learn how to troubleshoot common issues. |
0 commit comments