diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-14 18:09:54 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-14 18:09:54 +0000 |
commit | f697dc5e76dfc5894df006d53b2b7e751653cf05 (patch) | |
tree | 1387cd225039e611f3683f96b318bb17d4c422cb /lib/gitlab | |
parent | 874ead9c3a50de4c4ca4551eaf5b7eb976d26b50 (diff) | |
download | gitlab-ce-f697dc5e76dfc5894df006d53b2b7e751653cf05.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/background_migration/backfill_deployment_clusters_from_deployments.rb | 19 | ||||
-rw-r--r-- | lib/gitlab/jira_import/labels_importer.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/legacy_github_import/client.rb | 7 |
3 files changed, 27 insertions, 16 deletions
diff --git a/lib/gitlab/background_migration/backfill_deployment_clusters_from_deployments.rb b/lib/gitlab/background_migration/backfill_deployment_clusters_from_deployments.rb new file mode 100644 index 00000000000..9778f360e87 --- /dev/null +++ b/lib/gitlab/background_migration/backfill_deployment_clusters_from_deployments.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Gitlab + module BackgroundMigration + # Backfill deployment_clusters for a range of deployments + class BackfillDeploymentClustersFromDeployments + def perform(start_id, end_id) + ActiveRecord::Base.connection.execute <<~SQL + INSERT INTO deployment_clusters (deployment_id, cluster_id) + SELECT deployments.id, deployments.cluster_id + FROM deployments + WHERE deployments.cluster_id IS NOT NULL + AND deployments.id BETWEEN #{start_id} AND #{end_id} + ON CONFLICT DO NOTHING + SQL + end + end + end +end diff --git a/lib/gitlab/jira_import/labels_importer.rb b/lib/gitlab/jira_import/labels_importer.rb index 142a2da5be9..35c434e48a4 100644 --- a/lib/gitlab/jira_import/labels_importer.rb +++ b/lib/gitlab/jira_import/labels_importer.rb @@ -11,28 +11,19 @@ module Gitlab end def execute - create_import_label(project) + cache_import_label(project) import_jira_labels end private - def create_import_label(project) - label = Labels::CreateService.new(build_label_attrs(project)).execute(project: project) - raise Projects::ImportService::Error, _('Failed to create import label for jira import.') unless label + def cache_import_label(project) + label = project.jira_imports.by_jira_project_key(jira_project_key).last.label + raise Projects::ImportService::Error, _('Failed to find import label for jira import.') unless label JiraImport.cache_import_label_id(project.id, label.id) end - def build_label_attrs(project) - import_start_time = project&.import_state&.last_update_started_at || Time.now - title = "jira-import-#{import_start_time.strftime('%Y-%m-%d-%H-%M-%S')}" - description = "Label for issues that were imported from jira on #{import_start_time.strftime('%Y-%m-%d %H:%M:%S')}" - color = "#{Label.color_for(title)}" - - { title: title, description: description, color: color } - end - def import_jira_labels # todo: import jira labels, see https://gitlab.com/gitlab-org/gitlab/-/issues/212651 job_waiter diff --git a/lib/gitlab/legacy_github_import/client.rb b/lib/gitlab/legacy_github_import/client.rb index 34634d20a16..f7eaafeb446 100644 --- a/lib/gitlab/legacy_github_import/client.rb +++ b/lib/gitlab/legacy_github_import/client.rb @@ -6,13 +6,14 @@ module Gitlab GITHUB_SAFE_REMAINING_REQUESTS = 100 GITHUB_SAFE_SLEEP_TIME = 500 - attr_reader :access_token, :host, :api_version + attr_reader :access_token, :host, :api_version, :wait_for_rate_limit_reset - def initialize(access_token, host: nil, api_version: 'v3') + def initialize(access_token, host: nil, api_version: 'v3', wait_for_rate_limit_reset: true) @access_token = access_token @host = host.to_s.sub(%r{/+\z}, '') @api_version = api_version @users = {} + @wait_for_rate_limit_reset = wait_for_rate_limit_reset if access_token ::Octokit.auto_paginate = false @@ -120,7 +121,7 @@ module Gitlab end def request(method, *args, &block) - sleep rate_limit_sleep_time if rate_limit_exceed? + sleep rate_limit_sleep_time if wait_for_rate_limit_reset && rate_limit_exceed? data = api.__send__(method, *args) # rubocop:disable GitlabSecurity/PublicSend return data unless data.is_a?(Array) |