Skip to content

Fetch missing commits during Bitbucket server import

Vasilii Iakliushin requested to merge fix_bitbucket_server_diff_fetch into master

What does this MR do and why?

Contributes to #356240 (closed)

Problem

Bitbucket Server keeps tracks of references for open pull requests in refs/heads/pull-requests, but closed and merged requests get moved into hidden internal refs under stash-refs/pull-requests.

Because of that we don't fetch head_commit_sha for these merge requests. As a result, users see a merge request without any commits or diffs.

Solution

Bitbucket Pull Requests API returns head commit sha for requested pull requests. We can use these references to explicitly fetch missing commits.

After that, the merge request diff building process will have access to them and will be able to create diffs.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Thank you Maddie for the testing guide! 🙇

!133606 (comment 1598257729)

  1. Start a bitbucket server docker instance locally:
    1. https://gitlab.com/gitlab-org/manage/import-and-integrate/team/-/blob/main/integrations/bitbucket_server.md#set-up-local-bitbucket-instance-from-the-official-dockerhub-image
    2. Note: I had to bump the amount of memory and CPU to 4 CPUs and 4GB memory otherwise the process exits. You can monitor usage by running docker stats
  2. Go to the project imports page and select Bitbucket Server and follow the steps to configure
  3. Create a project + repo on bitbucket. Create/Enable a merge strategy for "Squash" in Settings > Merge Strategies
  4. Create the following MRs:
    1. Merge one branch into another with squash and delete.
    2. Merge one branch into another with squash and delete and merge that into another branch with squash and delete.
    3. Merge one branch into another with squash and delete, then open another MR merging that into another branch, decline the MR and delete the branches.
    4. Repeat the above but for MRs targeting master.
  5. Checkout master: git checkout master
  6. Import the project into gitlab and note that some of the MRs don't have any commits or diffs.
    1. MergeRequestDiff.where(state: 'empty').joins(:merge_request).where(merge_request: { source_project_id: <project_id> })
  7. Checkout this branch: git checkout fix_bitbucket_server_diff_fetch
  8. Import the project again and note that the MR has the commits and diffs now.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Vasilii Iakliushin

Merge request reports