C4E

Analyzing Branches & Pull Requests using IZ Analyzer

Written by:
Published on March 15, 2021

Analyzing Branches & Pull Requests using IZ Analyzer

Overview

In a standard development model, we create multiple branches to maintain various versions of the source code. Branches may be broadly classified into categories such as feature, release, development branches, and many more.

With all these classifications in place, how do we keep track of the code quality across branches?

With our latest Mulesoft code review tool IZ Analyzer Branch & Pull Request analysis available as an Open source plug-in, you can ensure that you maintain code quality consistency all the way down to the branch level in your Mule projects.

Prerequisites

This blog post assumes that the readers are aware of the following prerequisites –

Setting up Branch analysis

A branch is created in IZ Analyzer when the sonar.branch.name parameter is passed during analysis. The value passed for sonar.branch.name  will be visible in UI.

Analysing the master branch

NOTE:- We will be using a Mule project purely for demonstration purposes. Ideally Branches and Pull Requests can be analyzed for any type of project (Eg: Java, HTML etc).

Let us start with a sample Mule project called analyzer-orders-sapi and GIT as SCM tool.

MuleSoft Code Review

Let’s analyse the project from master branch using the following command

mvn sonar:sonar -Dsonar.projectKey=analyzer-orders-sapi -Dsonar.organization=<organization key> -Dsonar.host.url=https://analyzer.integralzone.com -Dsonar.login=<access token> -Dsonar.sources=. -Dsonar.branch.name=master

NOTE:- Notice the sonar.branch.name analysis parameter included in the command.

MuleSoft Code Review

As we see in the above image, issues are now categorized under master branch. Let’s create a GIT Branch and see how to analyse a Branch in the next step.

Analyzing non master Branches

Let’s create a new branch called “create_order_issue_fix” and switch to the new branch.

MuleSoft Code Review
Mulesoft static code analysis

We will add few additional lines of code in this new branch and analyze source code using the same command, which was used earlier to analyze the master branch. User will have to change the value of sonar.branch.name to create_order_issue_fix

mvn sonar:sonar -Dsonar.projectKey=analyzer-orders-sapi -Dsonar.organization=<organization key> -Dsonar.host.url=https://analyzer.integralzone.com -Dsonar.login=<access token> -Dsonar.sources=. -Dsonar.branch.name=create_order_issue_fix

Once the analysis is complete, we should be able to see the new branch under the Branches and Pull Requests dropdown menu of your project as shown below.

MuleSoft Code Review
Mulesoft static code analysis

Branch level issues will be displayed once we select the appropriate branch. Issues displayed at the branch level will be the new set of issues introduced in the branch when compared to the master branch.

MuleSoft Code Review
Mulesoft static code analysis

Analysing Pull Requests

Pull Request analysis shows your Pull Request’s Quality Gate and Analysis in the IZ Analyzer interface. This analysis shows new issues introduced by the Pull Request before merging with the target branch

Let’s create a Pull Request with create_order_issue_fix as source branch and master as target branch. We will be needing the Pull Request’s ID during the analysis.

Note: Use your SCM providers Web UI to create the Pull Request

Use the following command to analyze the created Pull Request.

vn sonar:sonar -Dsonar.projectKey=analyzer-orders-sapi -Dsonar.organization=<organization key> -Dsonar.host.url=https://analyzer.integralzone.com -Dsonar.login=<access token> -Dsonar.sources=. -Dsonar.pullrequest.key=101 -Dsonar.pullrequest.branch=create_order_issue_fix -Dsonar.pullrequest.base=master

We have added the following new parameters to analyze the Pull Request.

Parameter Name Description
sonar.pullrequest.key Unique identifier of your Pull Request. Must correspond to the key of the Pull Request in your SCM.
sonar.pullrequest.branch The name of the branch that contains the changes to be merged.
sonar.pullrequest.base The branch into which the Pull Request will be merged.

Once the analysis is complete we should be able to see the Pull Request under Branches and Pull Requests dropdown menu of your project as shown below.

MuleSoft Code Review
Mulesoft static code analysis

Issues at Pull Request level will be displayed once we select the appropriate branch. Issues displayed at branch level will be the new set of issues introduced in the Pull Request, when compared to the master branch.

MuleSoft Code Review
Mulesoft static code analysis

End Note

Hope you found this article interesting. Do drop us a comment below with your inputs, views, and opinions regarding uploading Mule coverage report using IZ Analyzer.

Try IZ Analyzer for Free

Try one of the most powerful code analysis and review products in the Mulesoft ecosystem for free.

Sign up now for a free trial below:

https://analyzer.integralzone.com/try

Want us to give you and your team an exclusive demo? Book a slot below:

Leave a Reply

Your email address will not be published. Required fields are marked *

Other Blog Posts

Other Blog Posts

IZ Analyzer – Scanning API Projects

In an API and microservices world, the quality of the deliverable becomes paramount – since a weak link can break the whole chain. In the previous blog posts, we had seen how Mulesoft code implementations could be quality tested in an automated manner with IZ Analyzer. Now with API Analyzer plugin, APIs can be quality …

Read more

Mind Your Code Quality; It’s an Asset

When comes to code quality, I have seen discussion rather than an argument that the main task of a developer is to deliver working code to the customer. Is it true? I don’t think so. It must be fully covered code; that means not only functionality-focused code, but the quality of code also matters. A …

Read more

Mule 4 Scheduler in Multi-Worker Environment

In MuleSoft projects, when there is a business requirement to self trigger a process, it can be realized in two unique ways:  Without human intervention Or Without external system invocation This is based on two further basic approaches: Schedule based (cron)  Time interval based  MuleSoft Scheduler MuleSoft provides the following scheduling mechanisms: Fixed Frequency schedule: Can …

Read more