API guide: LoC by PR

Tags: Flow

This tutorial will walk you through how to grab total lines of code (LoC) submitted in a PR. Use this data to then calculate median or average LoC by PR. Because LoC is associated with commits, you will need to use two endpoints, commits and pull_requests, to get the data we need.

Grab the PRs

This first API call will be our main source of information for all the other API calls in this guide. The below call will return all mergedPRs within the START_DATE and END_DATE you designate.

  • HOSTNAME: is the IP address or URL for the Flow application. If you’re using the cloud instance of Flow, this will be flow.pluralsight.com. If you’re using an on-premise version of Flow, this will be something other than flow.pluralsight.com.
  • START_DATE/END_DATE: Select your start and end date. Notice we are using the "closed_at" filters which will only return PRs that are closed or merged.

You will see, by PR, the following fields grouped by PR author (created_by_id)

  • PR ID = id
  • Project_id – Project id.
  • Commit Shas – associated commits shas for each PR
  • Created_at = date at which the PR was created
  • Created_by_id – Alias who created the PR
  • PR Title – Title of PR
  • Closed_at = date at which the PR was closed
  • State – state of PR, this should be “merged” since that is what we are filtering for

If you want to include merged AND closed PRs you can remove the filter "&state=merged' and the API call will automatically include any PR that were merged or closed during your date range.

You can export this data into excel by adding &format=csv at the end of the query. Use this document to guide you through the processes of opening it in an excel spreadsheet.

Note: If you are interested in calculating PR LoC by User continue to the Step 2, otherwise move on to Step 3.

back to top

Grab the user information

Next you will want map the created_by_id to the actual user. In order to do that you need to grab all created_by_id’s from Step 1 and run it through the user_alias endpoint to grab the user information.

  • YOUR_USER_ID_LIST: This is the list of created_by_ids from Step 1. They should be in a comma separated list.

This will return a consolidated list of all the users with their name and apex_user_id which you can now map to your original list of PR created_by_ids.

back to top

LoC by PR

There are two ways you can grab the commit level data associated with your PRs. You will need to do this for each of your PRs, so writing a script may be in your best interest.

Option A: Take all the commit_shas associated with a PR from Step 1 and place them in the following API call.

  • YOUR_COMMIT_SHA_LIST : This is a comma separated list of commit shas for all PRs from Step 1.

This list of commit_shas will look something like this from Step 1:

<title>Testing Applications</title>

This option will aggregate the total LoC (HALOC) across all commits_shas that you used in the API call.

Your results will look something like this:


Where haloc_sum will be the total LoC for the PR.

Option B: You can use the PR ID in the commits endpoint to identify any associated commits.

  • PULL_REQUEST_ID: This is the <id> for the PR from Step 1

The above API query will return a list of commit shas that are associated with the PR. It will show you the hexsha, HALOC (LoC) by commit and the commit ID.

If you wanted to aggregate the HALOC across these commits you can do so using this API call:


Once you run through each of your PRs and grab the total LoC (HALOC) you can then calculate the average or median LoC per PR.

back to top

If you need help, please email support@pluralsight.com for 24/7 assistance.