The accumulated number of added lines of code.
N/A
This metric is calculated by summing the additions of commits in the given data range.
Data Sources Required
This metric relies on commits collected from GitHub, GitLab or BitBucket.
Data Transformation Required
N/A
SQL Queries
The following SQL shows how to find the added lines of code in specific repositories, eg. ‘repo-1’ and ‘repo-2’.
SELECT
sum(c.additions) as added_lines_of_code
FROM
commits c
LEFT JOIN repo_commits rc ON c.sha = rc.commit_sha
LEFT JOIN repos r ON r.id = rc.repo_id
WHERE
-- please replace the repo ids with your own, or create a '$repo_id' variable in Grafana
r.id in ('repo-1','repo-2')
and message not like '%Merge%'
and $__timeFilter(c.authored_date)
-- the following condition will remove the month with incomplete data
and c.authored_date >= DATE_ADD(DATE_ADD($__timeFrom(), INTERVAL -DAY($__timeFrom())+1 DAY), INTERVAL +1 MONTH)
If you want to measure the monthly trend of added lines of code in the screenshot below, please run the following SQL in Grafana.
WITH _commits as(
SELECT
DATE_ADD(date(authored_date), INTERVAL -DAY(date(authored_date))+1 DAY) as time,
sum(additions) as added_lines_of_code
FROM commits
WHERE
message not like '%Merge%'
and $__timeFilter(authored_date)
-- the following condition will remove the month with incomplete data
and authored_date >= DATE_ADD(DATE_ADD($__timeFrom(), INTERVAL -DAY($__timeFrom())+1 DAY), INTERVAL +1 MONTH)
group by 1
)
SELECT
date_format(time,'%M %Y') as month,
added_lines_of_code
FROM _commits
ORDER BY time