# Linking pull requests to issues

## Why linking pull requests to issues is important

Linking pull requests to issues enables Swarmia to give you deeper insights into your work. Otherwise, we can't know what coding activity happened in an issue, meaning that we can only show you data from your issue tracker, giving a limited view to what actually happened.

A high linking rate is essential for making these features (and more) work well:

* Investment balance
* Software capitalization
* Work log by issue
* Initiatives

## Issue key matching

If you use Jira or Linear with their respective plugins that label PRs to link them to their issue, we’ll leverage that information. In addition, Swarmia can automatically detect Issue links from PRs in any of the following ways:

* Mention the **issue key** in the **Pull Request title** (e.g. Foobar \[CLOUD-123])
* Mention the **issue key** at the beginning of the **Pull Request description** (e.g. CLOUD-123 description description description)
* Add the **issue key URL** (e.g.<https://acme.atlassian.net/browse/CLOUD-123>) in the **Pull Request description.**
* **Start the Branch name** in GitHub with the **issue** **key** (e.g. CLOUD-123-foo) or use it after a slash (e.g. myname/bug/CLOUD-123-foo)

## AI-powered matching

This feature is currently in **alpha** and can be toggled on in [settings](http://app.swarmia.com/settings/pull-requests/automatic-linking).

When enabled, Swarmia uses AI to link a pull request to an issue when the two appear similar in name or description. The link will only be created if the PR author and issue assignee match, and the issue has been in progress recently. The PR author will receive a Slack notification, and the link can be overwritten directly from Slack or inside the Swarmia app.

When enabled, you'll be prompted whether you want AI to match the last 6 months of PRs. The PRs linked in this operation won't trigger Slack notifications.

## AI suggested issue links

Swarmia can automatically suggest relevant issues for a pull request based on its metadata. When a developer merges a pull request, for which we could not automatically determine the issue link, the Swarmia Slack bot will send them a message with suggested issue links:

<figure><img src="/files/qqYOPAlovMqag1qqPhpu" alt=""><figcaption><p>Swarmia bot sends a Slack message where the developer can quickly link the pull request to the relevant issue or investment category</p></figcaption></figure>

You can also manually search for the right issue, or link the pull request to an investment category if no relevant issue exists.

For these notifications to be enabled, these conditions need to be met:

1. The author of the pull request must have [Personal notifications](/settings/personal/notifications.md) enabled
2. The team that the author belongs to must have adopted the "Link pull requests to issues" [working agreement](/features/working-agreements.md)

## Manually linking pull requests to issues

It's also possible to manually link pull requests to issues from the Swarmia UI. Open the pull request popup from any view by clicking on a pull request, and you can change the issue and investment category that it is linked to:

<figure><img src="/files/XH3pnDqTixQPqvDbLKPt" alt=""><figcaption><p>The pull request popup allows you to change its linked issue and investment category</p></figcaption></figure>


---

# 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/settings/organization/linking-pull-requests-to-issues.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.
