[DORA] Improve "lead time for changes" calculation to use commit time
Problem to solve
Currently GitLab measures "lead time time for changes" (a DORA metric) as: "The median number of seconds between the merge of the merge request (MR) and the deployment of the MR’s commits for all MRs deployed during the time period." (source) That was probably the best minimal viable change, however it under-measures compared to the "official" definition, which is: "The median amount of time for a commit to be deployed into production." Commits are always made before, and sometimes long before, a merge request is merged. That means GitLab's measurement will always look better than it should.
Proposal
DORA "lead time for changes" should be measured from the individual commit time (not the commit-aggregated merge time). (Don't forget to update the documentation.)
It probably wouldn't be performant to measure this dynamically (by looking up all deployments in the time period, then looking up all commits associated with each deployment to calculate how long it took for them to be deployed). Instead, we should probably add an attribute to the MergeRequests::Metrics model. With this attribute we would track the median commit timestamp for all commits in a merge request, and update it whenever a commit is pushed to the merge request branch.