Deployment–Pull Request Linking#
DevLake links deployments to pull requests by matching cicd_deployment_commits.commit_sha against each PR's merge commit SHA (pull_requests.merge_commit_sha). This join is the foundation of DORA's Change Lead Time metric — specifically the PrDeployTime segment (PR merge → deployment finish).
Data Model#
Three tables participate in the linkage:
| Table | Role |
|---|---|
cicd_deployment_commits | One row per (deployment, commit) pair. Carries CommitSha, RepoId, Environment, Result, and PrevSuccessDeploymentCommitId. |
commits_diffs | Rows produced by refdiff: (NewCommitSha, OldCommitSha, CommitSha) — every code commit reachable in NewCommitSha but not in OldCommitSha. |
project_pr_metrics | Per-PR lead-time decomposition; DeploymentCommitId FK points to the cicd_deployment_commits row that first deployed the PR. |
cicd_deployment_commits.commit_sha is copied directly from cicd_pipeline_commits.commit_sha (the pipeline-reported SHA), not independently derived as a merge or head commit . For DORA Lead Time, this means the deployment tool must report the merged commit SHA for the join to succeed.
Linking Mechanism#
The DORA plugin's calculateChangeLeadTime task iterates over all PRs and, for each PR, calls getDeploymentCommit(pr.MergeCommitSha) . That helper executes a single query that:
- Joins
cicd_deployment_commits dc→ prior successful deployment commitpviadc.prev_success_deployment_commit_id = p.id - Joins
commits_diffs cdwherecd.new_commit_sha = dc.commit_sha AND cd.old_commit_sha = COALESCE(p.commit_sha, '')— this constrains the search to commits introduced by one deployment window - Joins
project_mapping pmto scope the query to the current project - Filters on
cd.commit_sha = <PR merge SHA>,dc.environment = PRODUCTION,dc.result = SUCCESS, and a non-emptyprev_success_deployment_commit_id - Orders by deployment start date + ID ascending,
LIMIT 1— returns the earliest production deployment that contained the PR's merge commit
In plain terms: a PR is considered "deployed" when its merge commit SHA appears in the commits_diffs diff window between two consecutive successful production deployments.
DORA Pipeline Stages That Enable the Link#
The DORA plugin runs a three-stage pipeline :
- Stage 1 —
generateDeploymentCommitsbuildscicd_deployment_commits;enrichPrevSuccessDeploymentCommitssetsPrevSuccessDeploymentCommitIdon each row to bound the diff range. - Stage 2 — refdiff's
calculateDeploymentCommitsDiffwalks the git graph between consecutive deployment SHAs and writescommits_diffsrows . - Stage 3 —
calculateChangeLeadTimeperforms the PR-to-deployment join described above and writes results toproject_pr_metrics.
Per-Tool commit_sha Population#
Each connector plugin is responsible for supplying the correct commit SHA when writing cicd_pipeline_commits. Examples:
- Azure DevOps — uses
build.SourceVersion(the pipeline trigger SHA) - GitHub (GraphQL) — maps
GithubDeployment→CicdDeploymentCommit, with environment classification via user-configured regex
If a tool reports the branch tip SHA rather than the merge commit SHA, the commits_diffs join will still find the PR's commits as long as they are reachable in the commit graph between the two deployment SHAs.
Key Files#
| File | Purpose |
|---|---|
dora/tasks/change_lead_time_calculator.go | Core PR-to-deployment join and project_pr_metrics writes |
core/models/domainlayer/devops/cicd_deployment_commit.go | CicdDeploymentCommit schema |
core/models/domainlayer/crossdomain/project_pr_metric.go | ProjectPrMetric schema including DeploymentCommitId |
dora/impl/impl.go | DORA plugin pipeline orchestration |
azuredevops_go/tasks/ci_cd_build_converter.go | Example: how Azure DevOps populates CommitSha |