diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
commit | 9297025d0b7ddf095eb618dfaaab2ff8f2018d8b (patch) | |
tree | 865198c01d1824a9b098127baa3ab980c9cd2c06 /lib/bitbucket_server | |
parent | 6372471f43ee03c05a7c1f8b0c6ac6b8a7431dbe (diff) |
Add latest changes from gitlab-org/gitlab@16-7-stable-eev16.7.0-rc42
Diffstat (limited to 'lib/bitbucket_server')
-rw-r--r-- | lib/bitbucket_server/client.rb | 5 | ||||
-rw-r--r-- | lib/bitbucket_server/connection.rb | 38 | ||||
-rw-r--r-- | lib/bitbucket_server/paginator.rb | 1 | ||||
-rw-r--r-- | lib/bitbucket_server/representation/activity.rb | 16 | ||||
-rw-r--r-- | lib/bitbucket_server/representation/user.rb | 21 | ||||
-rw-r--r-- | lib/bitbucket_server/retry_with_delay.rb | 32 |
6 files changed, 101 insertions, 12 deletions
diff --git a/lib/bitbucket_server/client.rb b/lib/bitbucket_server/client.rb index 8e84afe51d7..432928b0591 100644 --- a/lib/bitbucket_server/client.rb +++ b/lib/bitbucket_server/client.rb @@ -29,6 +29,11 @@ module BitbucketServer get_collection(path, :repo, page_offset: page_offset, limit: limit) end + def users(project_key, page_offset: 0, limit: nil) + path = "/projects/#{project_key}/permissions/users" + get_collection(path, :user, page_offset: page_offset, limit: limit) + end + def create_branch(project_key, repo, branch_name, sha) payload = { name: branch_name, diff --git a/lib/bitbucket_server/connection.rb b/lib/bitbucket_server/connection.rb index 845acf034a5..668a4e79da0 100644 --- a/lib/bitbucket_server/connection.rb +++ b/lib/bitbucket_server/connection.rb @@ -3,6 +3,7 @@ module BitbucketServer class Connection include ActionView::Helpers::SanitizeHelper + include BitbucketServer::RetryWithDelay DEFAULT_API_VERSION = '1.0' SEPARATOR = '/' @@ -31,10 +32,13 @@ module BitbucketServer end def get(path, extra_query = {}) - response = Gitlab::HTTP.get(build_url(path), - basic_auth: auth, - headers: accept_headers, - query: extra_query) + response = if Feature.enabled?(:bitbucket_server_importer_exponential_backoff) + retry_with_delay do + Gitlab::HTTP.get(build_url(path), basic_auth: auth, headers: accept_headers, query: extra_query) + end + else + Gitlab::HTTP.get(build_url(path), basic_auth: auth, headers: accept_headers, query: extra_query) + end check_errors!(response) @@ -44,10 +48,13 @@ module BitbucketServer end def post(path, body) - response = Gitlab::HTTP.post(build_url(path), - basic_auth: auth, - headers: post_headers, - body: body) + response = if Feature.enabled?(:bitbucket_server_importer_exponential_backoff) + retry_with_delay do + Gitlab::HTTP.post(build_url(path), basic_auth: auth, headers: post_headers, body: body) + end + else + Gitlab::HTTP.post(build_url(path), basic_auth: auth, headers: post_headers, body: body) + end check_errors!(response) @@ -63,10 +70,13 @@ module BitbucketServer def delete(resource, path, body) url = delete_url(resource, path) - response = Gitlab::HTTP.delete(url, - basic_auth: auth, - headers: post_headers, - body: body) + response = if Feature.enabled?(:bitbucket_server_importer_exponential_backoff) + retry_with_delay do + Gitlab::HTTP.delete(url, basic_auth: auth, headers: post_headers, body: body) + end + else + Gitlab::HTTP.delete(url, basic_auth: auth, headers: post_headers, body: body) + end check_errors!(response) @@ -121,5 +131,9 @@ module BitbucketServer build_url(path) end end + + def logger + Gitlab::BitbucketServerImport::Logger + end end end diff --git a/lib/bitbucket_server/paginator.rb b/lib/bitbucket_server/paginator.rb index 8a494379864..cb2c0a84e2d 100644 --- a/lib/bitbucket_server/paginator.rb +++ b/lib/bitbucket_server/paginator.rb @@ -2,6 +2,7 @@ module BitbucketServer class Paginator + # Should be kept in-sync with `BITBUCKET_SERVER_PAGE_LENGTH` in app/assets/javascripts/import_entities/constants.js PAGE_LENGTH = 25 attr_reader :page_offset diff --git a/lib/bitbucket_server/representation/activity.rb b/lib/bitbucket_server/representation/activity.rb index 08bf30a5d1e..0be7425f2cb 100644 --- a/lib/bitbucket_server/representation/activity.rb +++ b/lib/bitbucket_server/representation/activity.rb @@ -3,6 +3,10 @@ module BitbucketServer module Representation class Activity < Representation::Base + def id + raw['id'] + end + def comment? action == 'COMMENTED' end @@ -45,6 +49,18 @@ module BitbucketServer commit['id'] end + def approved_event? + action == 'APPROVED' + end + + def approver_username + raw.dig('user', 'slug') + end + + def approver_email + raw.dig('user', 'emailAddress') + end + def created_at self.class.convert_timestamp(created_date) end diff --git a/lib/bitbucket_server/representation/user.rb b/lib/bitbucket_server/representation/user.rb new file mode 100644 index 00000000000..433baec1c42 --- /dev/null +++ b/lib/bitbucket_server/representation/user.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module BitbucketServer + module Representation + class User < Representation::Base + def email + user['emailAddress'] + end + + def username + user['slug'] + end + + private + + def user + raw['user'] + end + end + end +end diff --git a/lib/bitbucket_server/retry_with_delay.rb b/lib/bitbucket_server/retry_with_delay.rb new file mode 100644 index 00000000000..8a8c0e2dc14 --- /dev/null +++ b/lib/bitbucket_server/retry_with_delay.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +module BitbucketServer + module RetryWithDelay + extend ActiveSupport::Concern + + MAXIMUM_DELAY = 20 + + def retry_with_delay(&block) + run_retry_with_delay(&block) + end + + private + + def run_retry_with_delay + response = yield + + if response.code == 429 && response.headers.has_key?('retry-after') + retry_after = response.headers['retry-after'].to_i + + if retry_after <= MAXIMUM_DELAY + logger.info(message: "Retrying in #{retry_after} seconds due to 429 Too Many Requests") + sleep retry_after + + response = yield + end + end + + response + end + end +end |