Use this guide to learn how to find the total lines of code (LoC) for a PR. Use this data to find your average or median LoC for PRs.
Because LoC is associated with commits, which are then associated with PRs, you must use both the
pull_requests endpoints to find this information.
In this article
Who can use this?
Grab the PRs
This first API call is our main source of information for all the other API calls in this guide. The below call returns all merged PRs 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 is flow.pluralsight.com. If you’re using Flow Enterprise Server, this is something other than flow.pluralsight.com.
- START_DATE/END_DATE: Select your start and end date.
This API request gives you, by PR, the following fields grouped by PR author:
- 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, 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 to a .csv file by adding
&format=csv at the end of the query.
Grab the user information
Now you can map the
created_by_id to the Flow apex user. Collect a comma separated list of the
created_by_id’s from the previous step and make an API call using the
user_alias endpoint to get user information.
- YOUR_USER_ID_LIST: This is the list of
created_by_idsfrom the previous step. They should be in a comma separated list.
The API call returns 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
LoC by PR
There are two ways you can grab the commit-level data associated with your PRs. You need to do this for each of your PRs, so writing a script may be in your best interest.
Use the commit_shas list to find LoC
Take all the
commit_shas associated with a PR from the first step and place them in the following API call:
- YOUR_COMMIT_SHA_LIST: A comma-separated list of commit shas for a PR from the first step.
This call aggregates the total LoC (HALOC) across all
commit_shas used in the API call.
Your results will look something like:
haloc_sum is the total LoC for the PR.
Repeat this step for each PR you want to calculate LoC for, then use these numbers to find the average or median for all PRs as desired.
Use the PR id to find LoC
Use the PR id for each PR from the first step to identify associated commits and aggregate their LoC (HALOC).
To aggregate the LoC for all commits associated with a PR, use the API call:
- PULL_REQUEST_ID: The id for the PR from the first step.
If you want to see the LoC for each commit in the PR, use the following API call:
Repeat this for each PR you want to calculate LoC for, then use these numbers to find the average or median for all PRs as desired.
If you need help, please contact Pluralsight Support.