# How Swarmia links PRs to deployments

A [deployment](/settings/organization/configuring-deployments-in-swarmia.md) can include one or more pull requests. These are used for two main purposes:

1. **Calculating the** [**Change lead time**](/definitions/dora-metrics/change-lead-time.md) **and the** [**Time to deploy**](/definitions/dora-metrics/time-to-deploy.md) **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](/features/metrics/track-dora-metrics.md#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="/files/CANXBLTPsVJ80mZoKU81" 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="/pages/wDudV4eMechHLjbWszCH" %}
[Generate deployments for monorepos via the API](/settings/organization/configuring-deployments-in-swarmia/generate-deployments-via-the-deployment-api/generate-deployments-for-monorepos.md)
{% 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.swarmia.com/features/metrics/track-dora-metrics/how-swarmia-links-prs-to-deployments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
