Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to get lines of code in all projects and repos for SonarQube license

Buying a license for SonarQube requires knowing how many lines of code you have in all projects and repositories, as the price of the Commercial Editions (Developer, Enterprise, and Data Center) depends on this number. Luckily, some tools like Awesome Graphs for Bitbucket can help with this task. In this post, I’ll share how to get the total number of lines of code in your Bitbucket Data Center instance using Awesome Graphs’ REST API.

Retrieve the lines of code across all projects and repositories

To get the number of added and deleted lines of code for the whole Bitbucket instance, all you need to do is make a single request to the REST API. Here’s an example of the curl command:

curl -X GET -u username:password "https://bitbucket.your-company-name.com/rest/awesome-graphs-api/latest/commits/statistics"

You can also adjust the command by adding query parameters to set a specific time frame or exclude merge commits. This is the type of data you'll get back after running this command: 

{
    "linesOfCode":{
        "added":5958278,
        "deleted":2970874
    },
    "commits":57595
}

The output shows you the number of lines of code added and deleted, as well as the total number of commits. Please note that blank lines are also counted. To obtain the total number of lines of code, subtract the number of deleted lines from the number of added ones.

Thus, with a simple curl command to the Awesome Graphs’ REST API, you can retrieve comprehensive data on added and deleted lines of code, empowering you to make informed decisions regarding SonarQube licensing. If you want to explore the process of counting lines of code for a particular project or repository, you can find a detailed guide here.

0 comments

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events