# How Swarmia links PRs to deployments

A [deployment](https://help.swarmia.com/getting-started/configuration/configuring-deployments-in-swarmia) can include one or more pull requests. These are used for two main purposes:

1. **Calculating the** [**Change lead time**](https://help.swarmia.com/metrics-and-definitions/dora-metrics/change-lead-time) **and the** [**Time to deploy**](https://help.swarmia.com/metrics-and-definitions/dora-metrics/time-to-deploy) **metrics.** If a deployment has no associated pull request, these two metrics will be unavailable.
2. **Defining a deployment's ownership.** Deployments are [attributed based on the authors of the PRs in the deployment](https://help.swarmia.com/use-cases/track-dora-metrics/..#how-deployments-are-attributed-to-teams). A deployment without pull requests won't appear in any team's DORA metrics (but will be counted on the organization level).
3. **Adding better visibility into your deployments.** You can dig deeper into each deployment to see which changes (pull requests and the associated issues) were deployed to which environment and when.

## How PRs are automatically linked to deployments

When Swarmia receives a new deployment, we perform an automatic pull request detection for it. The PRs linked to a deployment are determined from the list of **merge commits** that occurred between the new deployment and the immediate previous deployment on the **same application** and **same environment**.

<figure><img src="https://2772466312-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMa8uBmGhQgR7MTPq9yh7%2Fuploads%2Fgit-blob-cb6ae6b0fbcc274bc6f3db1fa43ac1f969f95459%2FScreenshot%202025-04-29%20at%2018.10.59.png?alt=media" alt=""><figcaption><p>Associating pull requests to deployments</p></figcaption></figure>

### What about monorepos?

When using monorepos, we offer additional fields to help track deployments. You can read more here:

{% content-ref url="../../getting-started/configuration/configuring-deployments-in-swarmia/generate-deployments-via-the-deployment-api/generate-deployments-for-monorepos" %}
[generate-deployments-for-monorepos](https://help.swarmia.com/getting-started/configuration/configuring-deployments-in-swarmia/generate-deployments-via-the-deployment-api/generate-deployments-for-monorepos)
{% endcontent-ref %}

The logic to associate pull requests with deployments is quite similar when using the `includedCommitShas` field ([field specification](https://help.swarmia.com/track-dora-metrics/generate-deployments-via-the-deployment-api#sending-a-deployment)) in the deployment payload, except that instead of using the git diff between the current deployment and the previous one, we will use only the commits provided in the payload.
