GitHub import should rewrite #xxx links for MRs to !xxx format
<!--IssueSummary start--> <details> <summary> Everyone can contribute. [Help move this issue forward](https://handbook.gitlab.com/handbook/marketing/developer-relations/contributor-success/community-contributors-workflows/#contributor-links) while earning points, leveling up and collecting rewards. </summary> - [Close this issue](https://contributors.gitlab.com/manage-issue?action=close&projectId=278964&issueIid=478851) </details> <!--IssueSummary end--> <!--- Please read this! Before opening a new issue, make sure to search for keywords in the issues filtered by the "regression" or "type::bug" label: - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=regression - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=type::bug and verify the issue you're about to submit isn't a duplicate. ---> ### Summary GitHub import should rewrite `#xxx` links for MRs to `!xxx` format ### Steps to reproduce 1. Import a project from GitHub to GitLab, using the built-in GitHub importer. The project should contain one or more PR or issue comments containing a reference to a Pull Request (`#xxx`). 2. The project will be imported, but the reference in the comment will remain as `#xxx`. Because GitLab uses different formats to refer to issues (`#xxx`) and Merge Requests (`!xxx`), the reference(s) will essentially be broken after the import. ### Example Project <!-- If possible, please create an example project here on GitLab.com that exhibits the problematic behavior, and link to it here in the bug report. If you are using an older version of GitLab, this will also determine whether the bug is fixed in a more recent version. --> N/A ### What is the current *bug* behavior? See above. The references are retained as-is (`#xxx`) instead of being rewritten to `!xxx` format. ### What is the expected *correct* behavior? <!-- Describe what you should see instead. --> References to _Merge Requests_ (only) should be rewritten to `!xxx` format, and references to _issues_ should remain as `#xxx`. ### Possible fixes <!-- If you can, link to the line of code that might be responsible for the problem. --> The challenge with this issue is to distinguish between which references should be retained as `#xxx` and which ones should be rewritten to `!xxx` format. GitHub uses the `#xxx` notion for both of these, while they differ in GitLab so logic is needed on our place to deal with this distinction. For what it's worth, the following Rails console snippet seems to work fine on my (self-hosted GitLab Community) instance. It will surely need polishing and adjustments to be used in the GitHub importer proper, but feel free to use it as inspiration for a full fix. (I tried getting started with a GitLab Community Fork branch fixing this in the importer, but it's too complex for me given my current bandwidth.) _Update 2024-11-19_: I fixed similar Rails scripts for issue and MR descriptions too. All of those are available in a dedicated repo in my GitLab instance [here](https://gitlab.perlang.org/perlang/gitlab-import-rails-snippets). The other scripts are also available further down in this issue: https://gitlab.com/gitlab-org/gitlab/-/issues/478851#note_2218190231. ```ruby # Loops over all issue and MR notes and fixes #xxx GitHub ambiguous PR/issue # references where the xxx number refers to an existing GitLab MR. # notes = Note.all notes.each { |note| modified = false issue_or_mr_references = note.note.scan(/#\d+/) issue_or_mr_references.each { |iid| iid.delete!('#') merge_request = MergeRequest.find_by(iid: iid) if merge_request note.note.sub!("\##{iid}", "!#{iid}") modified = true end } if modified puts "Note with ID #{note.id} updated" note.save! end } ```
issue