DORA Lead Time For Changes - Support multiple environment branches (with GitLab flow)
Summary
Currently, Lead Time For Changes of DORA metrics does not support Environment branches with GitLab flow. While the single branch operation with multiple deployment jobs (e.g. dev => staging => production jobs on master branch) is already supported, it's also nice to support multi-branch operation with a single deployment job for each (e.g. dev job on dev branch => staging job on staging branch => production job on production branch).
Problem details
Let's say we have an example project that has three branches:
-
main
(for development) staging
production
Each branch is deployed to a corresponding environment respectively. When we merge an MR to staging and an MR to production, we see the following response from the List of merge requests associated with a deployment API:
curl --header "PRIVATE-TOKEN: <PAT>" "https://gitlab.com/api/v4/projects/34858840/deployments/266494687/merge_requests" | jq '.[] | {id: .id, source_branch: .source_branch, target_branch: .target_branch, merged_at: .merged_at}'
{
"id": 147333506,
"source_branch": "staging",
"target_branch": "production",
"merged_at": "2022-03-28T08:55:13.956Z"
}
{
"id": 147332678,
"source_branch": "main",
"target_branch": "staging",
"merged_at": "2022-03-28T08:53:01.920Z"
}
As you can see, GitLab recognizes as if there are two merge requests have been deployed to Production environment (which looks off). This is because GitLab links MRs with deployments by commit diffs between latest deployment and previous deployment.
The Lead Time for Changes is calculated based on the deployment-MR links, and it currently doesn't understand the MR-chain, i.e. it needs to see the 147332678
and 147333506
as one merge request instead of separation MRs.