Content
Bug STC-652: Community contribution: GitHub/GitLab - Fix incorrect linking of MR/PR to work packages
View differences
Updated by Kabiru Mwenja 4 days ago
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_ (*Repo A* and _Repo B_) *Repo B*) to the same OpenProject instance.
2. In _Repo A_, *Repo A*, open merge request `!5` referencing a work package, e.g. `OP#100`.
3. In _Repo B_, *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 *Repo B*'s `!5` matches and overwrites the record created for _Repo A_'s *Repo A*'s `!5`, because the lookup matches on the per-project merge request number (GitLab's (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 *Repo B*'s merge request — and the link flips back and forth as each repository's 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 *Repo A*'s `!5` links only to `#100`, _Repo B_'s *Repo B*'s `!5` links only to `#200`, and pipelines/comments attach to the correct repository's 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`.
### Steps to reproduce
Reproduces with the GitLab integration (the GitHub integration shows the same class of mislinking):
1. Connect **two** GitLab repositories (_Repo A_
**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!) |
A webhook for _Repo B_'s
### 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
### 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`.