Automatically Resolving SonarQube Issues
Having Devin solves SonarQube issues through Github Actions
Devin’s API is a powerful tool designed to automatically resolve code issues detected by code scanning tools such as SonarQube. While this documentation focuses on SonarQube, the underlying strategy applies to other code scanning tools, including Veracode, Orca, and more.
If you’re interested in seeing this process in action, check out our demo repository and explore the detailed explanation in the Cognition blog post.
In production, the process will look like the following:
Automated Issue Resolution with Devin’s API
In production, the process of automatically resolving code issues using Devin’s API is streamlined and efficient. Below is a high-level overview of the steps involved:
1. Process Overview
-
Pull Request is opened: A pull request (PR) is submitted to the repository with changes that may contain issues identified by a code scanning tool.
-
GitHub Action is triggered: The opening of the PR automatically triggers a GitHub Action workflow.
-
GitHub Action calls Devin API: The GitHub Action sends a request to the Devin API, passing the identified issues for automated resolution.
-
Devin session is initialized: A Devin session spins up, receiving the context of the issue and attempting to resolve it based on the provided data.
-
Devin proposes PR for human review: Once the issue is resolved, Devin generates a PR with the proposed changes and submits it for human review.
2. Steps to Accomplish This
To integrate Devin’s API with your CI/CD pipeline, you will need to complete the following configurations:
-
Configure SonarQube for CI & API support:
- Ensure that SonarQube is configured to support continuous integration (CI) and API integration. If you prefer not to set up SonarQube for API access, you can use a cookie for authentication. Learn more about this setup here.
-
Configure GitHub environment to hold the required secrets:
- Set up the GitHub environment to securely store the necessary secrets, such as authentication tokens and configuration keys, to interact with Devin’s API and other integrated tools.
Once these steps are complete, your pipeline will be ready to automatically resolve issues using Devin’s API, speeding up the process and reducing the need for manual intervention.
- Test the Integration
Once your setup is complete, you can test the integration by manually triggering a GitHub Action. This will allow you to verify that the action correctly calls the Devin API and resolves the identified issues.
- View Devin Sessions Page
After the GitHub Action is triggered and Devin processes the issues, you can view the status and results on the Devin sessions page. This page provides detailed insights into the resolved issues and the proposed changes.
In Depth Guide
Please skip ahead, if your SonarQube project is already appropriately configured. Otherwise the following walks through how to ensure GitHub has access to SonarQube’s API.
Required Values from SonarQube To configure the integration, you will need to obtain the following three values from your
SonarQube instance: You will need three_values from SonarQube:
1. Create SONAR_TOKEN:
- Click on your account icon in the top right of SonarQube.
- Select Security from the dropdown.
- Under Tokens, click Generate Tokens.
- Name the token and click Generate.
- Copy the generated token for use in GitHub Actions.
2. Create SONAR_PROJECT
- Select the project in SonarQube.
- Click Information in the bottom left.
- Scroll down to find the project key.
3. Create SONAR_ORG
Refer to the steps above to locate your organization details in SonarQube.
Once you have all the required values, you’re ready to configure the GitHub Action.
This assumes you have a local SonarCloud properties file sonar-project.properties
that specifies:
The Github Action has the following source code
As a reminder devin_remediation.py
To ensure the GitHub Action sets the correct environment variables, add them to GitHub Repository Secrets.
Navigating to the correct settings can be tricky. Go to Security and edit Secrets. Add SONAR_TOKEN and DEVINS_API under Repository Secrets.
Once configured, you can monitor your GitHub Action in progress. If it runs successfully, it will appear as follows:
You can view Devin sessions in the Session Manager.
Once completed, Devin will automatically open pull requests. For GitLab users, refer to the linked guide.