# Bug COMMS-652 - Community contribution: GitHub/GitLab - Fix incorrect linking of MR/PR to work packages

Project: Stream Communicator
Status: closed
URL: https://community.openproject.org/work_packages/COMMS-652

## Open points

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | Medium |
| Module | Integrations / GitHub, Integrations / GitLab |
| Target versions | 17.7.0 |
| Observed in versions |  |
| Sprint |  |
| Backlog bucket |  |
| Bug found in version (deprecated) |  |
| Requires doc change | Yes |
| Accessibility | No |
| Pull preview | https://pr-23614-stc-652-communit-ip-157-90-247-104.my.opf.run |
| List |  |
| Labels |  |

## People

| Attribute | Value |
| --- | --- |
| Assignee |  |
| Accountable | Kabiru Mwenja |
| Product manager |  |
| Developers | Kabiru Mwenja |
| Designer |  |
| Ordered by |  |
| Signed off by | Wieland Lindenthal |
| Interest by |  |

## Planning

| Attribute | Value |
| --- | --- |
| Relevance |  |

## Costs

| Attribute | Value |
| --- | --- |
| Votes |  |
| Work |  |
| Labor costs |  |

## Description

Ref: <https://github.com/opf/openproject/pull/21932>

### Steps to reproduce

Reproduces with the GitLab integration (the GitHub integration shows the same class of mislinking):

1.  Connect **two** GitLab repositories (*Repo A* and *Repo B*) to the same OpenProject instance.

2.  In *Repo A*, open merge request `!5` referencing a work package, e.g. `OP#100`.

3.  In *Repo B*, open merge request `!5` (GitLab numbers merge requests per project, so this is also `!5`) referencing a different work package, e.g. `OP#200`.

4.  Let both `merge_request` webhooks reach OpenProject.

**Example with two repositories connected:**

| MR | Specified reference | Linked to |
| --- | --- | --- |
| `first_repo/merge_requests/1` | `OP#101` | `WP#101` ✅ |
| `first_repo/merge_requests/2` | `OP#102` | `WP#102` ✅ |
| `second_repo/merge_requests/1` | `OP#201` | `WP#101` ❌ (wrong\!) |
| `second_repo/merge_requests/2` | `OP#202` | `WP#102` ❌ (wrong\!) |

### What is the buggy behavior?

A webhook for *Repo B*'s `!5` matches and overwrites the record created for *Repo A*'s `!5`, because the lookup matches on the per-project merge request number (GitLab's internal ID, `iid`), which is `5` in both repositories. Work packages then link to a merge request from the wrong repository — e.g. `#100` shows *Repo B*'s merge request — and the link flips back and forth as each repository's webhooks arrive. The same affects issues, pipelines and comments. There is no error; the linking is silently wrong.

### What is the expected behavior?

Each merge request, pull request and issue is identified by its unique webhook URL rather than a number that repeats across repositories. *Repo A*'s `!5` links only to `#100`, *Repo B*'s `!5` links only to `#200`, and pipelines/comments attach to the correct repository's record.

### Environment

Server-side bug in the GitHub/GitLab integration modules — independent of installation type, browser, OS and language. Present in all current versions whenever more than one repository is connected; reproduced on the latest `dev`.
