CLI utility for fetching SonarQube issues. Automatically detects PR IDs from branches and fetches SonarQube issues for code quality analysis. Includes AI editor integration for automated issue fixing. Supports GitHub and Bitbucket.
Since this package is published to GitHub Packages, you'll need to authenticate to install it.
npm install sonarflowOr install globally:
npm install -g sonarflowRun the interactive setup to configure your project:
npx sonarflow initThis will:
- Create
.sonarflowrc.jsonwith your project settings (repo, visibility, publicSonar, output path, preferred AI editor) - Add npm scripts to your
package.json - Create AI editor rules for automated issue fixing (Cursor, VSCode, Windsurf)
- Install a workspace icon theme so
.sonarflowrc.jsonuses a custom icon in VS Code/Cursor
Create a .env file in your project root:
# Git Provider (shared)
GIT_TOKEN=your-token # GitHub or Bitbucket token (required for PR detection)
GIT_EMAIL=your-email@example.com # Required for Bitbucket PR detection; optional for GitHub or if you already have configured `git config user.email`
# GitHub (only if using GitHub)
GITHUB_OWNER=your-username-or-org
GITHUB_REPO=your-repo-name
# SonarQube/SonarCloud Configuration
SONAR_TOKEN=your-sonar-token # Required for private Sonar; not needed if publicSonar=true
SONAR_ORGANIZATION=your-organization # For SonarCloud
SONAR_COMPONENT_KEYS=your-project-key # For SonarCloud fetch
SONAR_BASE_URL=https://sonarcloud.io/api/issues/search # Optional override
SONAR_PROJECT_KEY=your-project-key # SonarQube project identifierNotes:
- If
.sonarflowrc.jsonhas"publicSonar": true, the tool won't requireSONAR_TOKEN. - For Bitbucket PR detection, both
GIT_EMAILandGIT_TOKENare required.
To use this CLI you'll need tokens for your Git provider and, when fetching from private projects, for Sonar.
-
GitHub Personal Access Token
- What you need: Classic token with minimal scopes
- Scopes:
read:packages(required to install from GitHub Packages)repo(required if your repository is private to detect PRs)
- Guide: Create a GitHub personal access token (classic)
-
Bitbucket App Password
- What you need: App password for Bitbucket Cloud
- Permissions (minimum recommended):
- Repositories:
Read - Pull requests:
Read - Account:
Read(to resolve email/user when needed)
- Repositories:
- You must also set
GIT_EMAILto your Bitbucket email in.env. - Guide: Bitbucket Cloud — App passwords
-
Sonar Token
- Required only when fetching from private SonarQube/SonarCloud projects or when
.sonarflowrc.jsondoes not set"publicSonar": true. - Scope: Standard user token (no special permissions typically needed beyond access to the project)
- Guides:
- SonarCloud: Generating and using tokens
- SonarQube: Generate and use tokens
- Required only when fetching from private SonarQube/SonarCloud projects or when
After creating tokens, place them in your .env as shown in the "Set Up Environment Variables" section above.
# Fetch issues for current branch (auto-detects PR on GitHub/Bitbucket)
npx sonarflow fetch
# Fetch issues for a specific branch
npx sonarflow fetch my-branch
# Fetch issues from a SonarQube PR link
npx sonarflow fetch my-branch https://sonarcloud.io/project/issues?id=project&pullRequest=PR_KEY- Auto PR detection tries provider API first (GitHub or Bitbucket), then falls back to extracting from branch naming patterns.
- Issues are saved to
.sonarflow/issues.json.
# Interactive setup
npx sonarflow init# Check for updates and get latest version info
npx sonarflow updateAfter initialization, you can use the added npm scripts:
# Fetch issues
sonar:fetch- Automatic PR Detection: Detects PR IDs from your current git branch using GitHub or Bitbucket APIs
- Fallback Support: Falls back to branch-based extraction if PR detection fails
- PR Link Support: Fetch issues directly using a SonarQube PR link
- AI Editor Integration: Creates rules for Cursor, VSCode, Windsurf for automated issue fixing
- Custom Icon Theme: Installs a local theme under
.vscode/icon-theme/and setsworkbench.iconThemeso.sonarflowrc.jsonis visually distinguished in your workspace - Issue Summary: Displays a summary of issues by severity after fetching
- Configuration Management: Interactive setup for easy configuration
- Update Checking: Built-in command to check for updates and get latest version info
- Language: TypeScript (compiled to Node.js)
- Runtime: Node.js (>= 22.21.0)
- Package Manager/Registry: npm + GitHub Packages
- Build/Bundle: TypeScript
tsc - TypeScript Native Reference: microsoft/typescript-go (TypeScript 7 native preview)
- Lint/Format: Biome
- Lockfile: Bun (for development reproducibility)
- APIs: SonarQube/SonarCloud REST APIs, GitHub REST API, Bitbucket Cloud API
- Editor Integrations: Cursor, VSCode (Copilot), Windsurf rule templates
Since this CLI is designed to be used with npx, updating is simple:
# Use @latest to always get the most recent version
npx sonarflow@latest <command>- Detects the current git branch or uses provided branch name
- Attempts to find associated PR using GitHub or Bitbucket API, or branch name pattern matching
- Fetches SonarQube issues for the PR or branch
- Saves issues to
.sonarflow/issues.json - Displays a summary of fetched issues
- Prompts for project configuration (repo name, git provider, visibility, etc.)
- Creates configuration file
.sonarflowrc.json - Updates
package.jsonwith npm scripts - Creates AI editor rules based on your editor choice
.sonarflow/issues.json- Fetched SonarQube issues in JSON format.sonarflowrc.json- Project configuration.cursor/rules/sonarflow-autofix.mdc- Cursor AI rules (if selected).vscode/sonarflow-autofix.md- VSCode rules (if selected).windsurf/rules/sonarflow-autofix.mdc- Windsurf rules (if selected).rules/sonarflow-autofix.md- Generic rules (if selected "other")
The tool creates specific rules for your chosen AI editor to help with automated SonarQube issue fixing:
- Cursor: Creates
.cursor/rules/sonarflow-autofix.mdc - VSCode with Copilot: Creates
.vscode/sonarflow-autofix.md - Windsurf: Creates
.windsurf/rules/sonarflow-autofix.mdc - Other: Creates
.rules/sonarflow-autofix.md
These rules provide patterns and priorities for fixing common SonarQube issues.
- Node.js (>= 22.21.0)
- Git repository
- Git provider token (
GIT_TOKEN) and, for Bitbucket,GIT_EMAIL - SonarQube/SonarCloud access
ISC