Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-10-19 15:57:54 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-10-19 15:57:54 +0300
commit419c53ec62de6e97a517abd5fdd4cbde3a942a34 (patch)
tree1f43a548b46bca8a5fb8fe0c31cef1883d49c5b6 /lib/gitlab/bitbucket_server_import
parent1da20d9135b3ad9e75e65b028bffc921aaf8deb7 (diff)
Add latest changes from gitlab-org/gitlab@16-5-stable-eev16.5.0-rc42
Diffstat (limited to 'lib/gitlab/bitbucket_server_import')
-rw-r--r--lib/gitlab/bitbucket_server_import/importers/pull_request_importer.rb10
-rw-r--r--lib/gitlab/bitbucket_server_import/importers/pull_requests_importer.rb25
-rw-r--r--lib/gitlab/bitbucket_server_import/project_creator.rb7
3 files changed, 38 insertions, 4 deletions
diff --git a/lib/gitlab/bitbucket_server_import/importers/pull_request_importer.rb b/lib/gitlab/bitbucket_server_import/importers/pull_request_importer.rb
index 34963452192..0d4de385f5e 100644
--- a/lib/gitlab/bitbucket_server_import/importers/pull_request_importer.rb
+++ b/lib/gitlab/bitbucket_server_import/importers/pull_request_importer.rb
@@ -30,7 +30,7 @@ module Gitlab
reviewer_ids: reviewers,
source_project_id: project.id,
source_branch: Gitlab::Git.ref_name(object[:source_branch_name]),
- source_branch_sha: object[:source_branch_sha],
+ source_branch_sha: source_branch_sha,
target_project_id: project.id,
target_branch: Gitlab::Git.ref_name(object[:target_branch_name]),
target_branch_sha: object[:target_branch_sha],
@@ -68,6 +68,14 @@ module Gitlab
end
end
end
+
+ def source_branch_sha
+ source_branch_sha = project.repository.commit(object[:source_branch_sha])&.sha
+
+ return source_branch_sha if source_branch_sha
+
+ project.repository.find_commits_by_message(object[:source_branch_sha])&.first&.sha
+ end
end
end
end
diff --git a/lib/gitlab/bitbucket_server_import/importers/pull_requests_importer.rb b/lib/gitlab/bitbucket_server_import/importers/pull_requests_importer.rb
index 92ec10bf037..ae73681f7f8 100644
--- a/lib/gitlab/bitbucket_server_import/importers/pull_requests_importer.rb
+++ b/lib/gitlab/bitbucket_server_import/importers/pull_requests_importer.rb
@@ -20,6 +20,22 @@ module Gitlab
break if pull_requests.empty?
+ commits_to_fetch = pull_requests.filter_map do |pull_request|
+ next if already_processed?(pull_request)
+ next unless pull_request.merged? || pull_request.closed?
+
+ [pull_request.source_branch_sha, pull_request.target_branch_sha]
+ end.flatten
+
+ # 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. As a result,
+ # they are not fetched by default.
+ #
+ # This method call explicitly fetches head and start commits for affected pull requests.
+ # That allows us to correctly assign diffs and commits to merge requests.
+ fetch_missing_commits(commits_to_fetch)
+
pull_requests.each do |pull_request|
# Needs to come before `already_processed?` as `jobs_remaining` resets to zero when the job restarts and
# jobs_remaining needs to be the total amount of enqueued jobs
@@ -42,6 +58,15 @@ module Gitlab
private
+ def fetch_missing_commits(commits_to_fetch)
+ return if commits_to_fetch.blank?
+ return unless Feature.enabled?(:fetch_commits_for_bitbucket_server, project.group)
+
+ project.repository.fetch_remote(project.import_url, refmap: commits_to_fetch, prune: false)
+ rescue StandardError => e
+ track_import_failure!(project, exception: e)
+ end
+
def sidekiq_worker_class
ImportPullRequestWorker
end
diff --git a/lib/gitlab/bitbucket_server_import/project_creator.rb b/lib/gitlab/bitbucket_server_import/project_creator.rb
index ddc678abdd8..be60e431b80 100644
--- a/lib/gitlab/bitbucket_server_import/project_creator.rb
+++ b/lib/gitlab/bitbucket_server_import/project_creator.rb
@@ -3,9 +3,9 @@
module Gitlab
module BitbucketServerImport
class ProjectCreator
- attr_reader :project_key, :repo_slug, :repo, :name, :namespace, :current_user, :session_data
+ attr_reader :project_key, :repo_slug, :repo, :name, :namespace, :current_user, :session_data, :timeout_strategy
- def initialize(project_key, repo_slug, repo, name, namespace, current_user, session_data)
+ def initialize(project_key, repo_slug, repo, name, namespace, current_user, session_data, timeout_strategy)
@project_key = project_key
@repo_slug = repo_slug
@repo = repo
@@ -13,6 +13,7 @@ module Gitlab
@namespace = namespace
@current_user = current_user
@session_data = session_data
+ @timeout_strategy = timeout_strategy
end
def execute
@@ -28,7 +29,7 @@ module Gitlab
import_url: repo.clone_url,
import_data: {
credentials: session_data,
- data: { project_key: project_key, repo_slug: repo_slug }
+ data: { project_key: project_key, repo_slug: repo_slug, timeout_strategy: timeout_strategy }
},
skip_wiki: true
).execute