Fetch missing commits during Bitbucket server import
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!
- Start a bitbucket server docker instance locally:
- 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
- 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
- Go to the project imports page and select Bitbucket Server and follow the steps to configure
- Create a project + repo on bitbucket. Create/Enable a merge strategy for "Squash" in Settings > Merge Strategies
- Create the following MRs:
- Merge one branch into another with squash and delete.
- Merge one branch into another with squash and delete and merge that into another branch with squash and delete.
- 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.
- Repeat the above but for MRs targeting master.
- Checkout master:
git checkout master
- Import the project into gitlab and note that some of the MRs don't have any commits or diffs.
MergeRequestDiff.where(state: 'empty').joins(:merge_request).where(merge_request: { source_project_id: <project_id> })
- Checkout this branch:
git checkout fix_bitbucket_server_diff_fetch
- 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.
-
I have evaluated the MR acceptance checklist for this MR.