Skip to content

Github Importer: thread diff notes

Problem statement

When importing a project from Github it imports merge requests diff notes, comments associated with a file diff, in a non-threaded way.

Github Gitlab
Update_README_md_by_anotherkassio___Pull_Request__1___anotherkassio_smallrepo Update_README_md___1____Merge_requests___Administrator___smallrepo___GitLab

Proposed solution

Each diff note is created by Gitlab::GithubImport::Importer::DiffNoteImporter, which fetches the data from Github's List review comments in a repository API. This documentation mentions that each diff note provides a in_reply_to_id, which can be used to create Gitlab discussions.

Implementation details

  • When the in_reply_to_id is empty
    • Create a new discussion_id
    • Map the pull_request_comment.id to the discussion_id created on redis (Github original id for the diff note). Example: 8 -> f9f509e301c2ff6112a365ca066cda63c183530c, where:
      • 8 is the original github id for the diff note;
      • f9f509e301c2ff6112a365ca066cda63c183530c is the discussion_id;
  • When the in_reply_to_id has a value
    • Use the github_id->discussion_id map to find the discussion id related to the in_reply_to_id;
    • Use the found discussion_id on the new diff note;
    • Add another entry to the github_id->discussion_id map to map the new diff note to the discussion_id, like 9 -> f9f509e301c2ff6112a365ca066cda63c183530c;
  • Currently there's no documentation wether the GithubImporter imports or not threaded notes, therefore an update on the documentation must be done (https://docs.gitlab.com/ee/user/project/import/github.html#import-your-project-from-github-to-gitlab);
  • Example of implementation https://gitlab.com/gitlab-org/gitlab/-/compare/master...githb-importer-threaded-diff-notes-proposal

Expected Result

Update_README_md___1____Merge_requests___Administrator___smallrepo___GitLab
Related Documentation
Edited by Kassio Borges