Integrate CodeScene with Pull Requests¶
CodeScene offers an automated integration with GitHub, BitBucket, Azure DevOps or GitLab pull requests to incorporate the Delta Analysis results into existing delivery workflows.
Integration is different per provider:
Github via Checks with option of annotations
Bitbucket via either Builds or Code Insights Reports
Azure Status Check and Pull Request comment
GitLab via Merge Request Discussion comment
See GitHub, Bitbucket, Azure, GitLab presentation.
CodeScene and Pull Requests: Use Cases¶
The purposes of CodeScene’s pull request integration is to:
Specify quality gates that trigger in case the Code Health of a hotspot declines.
Serve as a quality gate and provide feedback on user-defined hotspot goals (e.g. Supervise, Planned Refactoring).
Prioritize code reviews based on the risk of the commits.
Get early warnings on new and complex code, and detect the absence of expected change coupling to catch omissions.
This topic is split into two documents. This document is about the PR Integration itself, configuring CodeScene with the Git Providers and the result presentation.
For the actual Delta Analysis itself, its use cases and value proposition look at PR Integration with CodeScene’s Delta Analysis.
Enable the Pull Request Integration¶
Navigate to your project’s configuration in CodeScene, navigate to Pull Request Integration settings.
If you’re using GitHub the first step is to install the GitHub app for the integration. CodeScene will inform you of this step, if needed:
With the app installed, all you need to do is to check a box and you are up and running with a single click:
If you are using Bitbucket you’ll need to install an Atlassian Connect App on the Workspaces of repositories of the CodeScene project, there is a link on the configuration page to install it.
Pull Request Analysis Results Presentation¶
Set Up an Automatic Analysis Schedule¶
To get the best results for the Pull Request Integration checks, it’s a good idea to set up an automatic full analysis for your project.
You can do this in the Analysis schedule section of the project configuration. See the Getting Started section to learn more about this feature.
Pull Requests: Statistics, Actions, and Impact¶
Available in Analysis Results, System menu, PR Statistics
No matter what baseline we start from, we never want our code to become harder to read, understand, or maintain. CodeScene’s pull request integration lets you stay on top of your development so that you can prioritize and act upon any negative trends. For that purpose, CodeScene visualizes the impact of pull requests over time:
The presented statistics are:
Checks performed: This is the total number of pull request analyses run by CodeScene.
Issues Detected: An issue is either a violated goal (e.g. a planned refactoring never happened), a reported code health decline, or new code with code health issues.
Issues Fixed: A positive action is when one of the detected issues is acted upon and mitigated.
Issues Ignored: This is the number of detected issues that were merged as-is, without remediation, to the main branch. Ignored issues lead to a failed goal and/or a code health decline.
CodeScene also calculates the total code health impact and presents it as monthly trends. These trends let you visualize and communicate improvements, as well as taking actions upon a larger decline:
In the preceding example, we see that Codebase A took on a significant amount of technical debt during November. This code health decline would also be reported as alerts on the CodeScene dashboard when the pull requests are merged. A recommended action in this case would be to plan goals to manage the new debt (see Manage Hotspots and Technical Debt with Goals).
Contrast this with Codebase B which shows a positive trend where smaller code improvements are delivered continuously.
Finally, you can inspect the details of individual pull requests if you need to drill down even further:
You can find the pull request statistics on your project’s analysis dashboard:
Enable CodeScene’s Status Badges¶
Available in Project Configuration, Status Badges.
Status badges allow your teams to keep an eye on the health of their projects at a glance:
The status badges are intended for embedding in your GitHub README file. Sample GitHub markup is provided on the “Status Badges” configuration tab.
Constraints and Limitations¶
Pull requests created from forked repositories are supported with a caveat: If the fork’s branch (from which the PR has been created) is not up to date with the corresponding upstream repository’s main branch then it’s possible that CodeScene fails to detect a code health decline (or an improvement) due to obsolete versions of changed files in the fork. This should only happen when the files modified by the PR has been changed, in the meantime, in the upstream repository . A recommended remedy is to keep forks synchronized with upstream repositories.