diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-01 09:07:45 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-01 09:07:45 +0000 |
commit | b11f7057d067885619ee3e513751f180b2e8ad85 (patch) | |
tree | dfb3077ea8716ed217f5ce4324be4e25a450c599 /lib | |
parent | e50050a8756a20b6aa118edbad3369674e4c63ba (diff) | |
download | gitlab-ce-b11f7057d067885619ee3e513751f180b2e8ad85.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/helpers.rb | 16 | ||||
-rw-r--r-- | lib/api/projects.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/jira_import.rb | 35 | ||||
-rw-r--r-- | lib/gitlab/jira_import/labels_importer.rb | 42 | ||||
-rw-r--r-- | lib/gitlab/usage_data.rb | 11 |
5 files changed, 95 insertions, 11 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 2f603dd6bed..be41788ac77 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -505,20 +505,28 @@ module API protected - def project_finder_params_ce - finder_params = { without_deleted: true } + def project_finder_params_visibility_ce + finder_params = {} + finder_params[:min_access_level] = params[:min_access_level] if params[:min_access_level] + finder_params[:visibility_level] = Gitlab::VisibilityLevel.level_value(params[:visibility]) if params[:visibility] finder_params[:owned] = true if params[:owned].present? finder_params[:non_public] = true if params[:membership].present? finder_params[:starred] = true if params[:starred].present? - finder_params[:visibility_level] = Gitlab::VisibilityLevel.level_value(params[:visibility]) if params[:visibility] finder_params[:archived] = archived_param unless params[:archived].nil? + finder_params + end + + def project_finder_params_ce + finder_params = project_finder_params_visibility_ce + finder_params[:without_deleted] = true finder_params[:search] = params[:search] if params[:search] finder_params[:search_namespaces] = true if params[:search_namespaces].present? finder_params[:user] = params.delete(:user) if params[:user] finder_params[:custom_attributes] = params[:custom_attributes] if params[:custom_attributes] - finder_params[:min_access_level] = params[:min_access_level] if params[:min_access_level] finder_params[:id_after] = params[:id_after] if params[:id_after] finder_params[:id_before] = params[:id_before] if params[:id_before] + finder_params[:last_activity_after] = params[:last_activity_after] if params[:last_activity_after] + finder_params[:last_activity_before] = params[:last_activity_before] if params[:last_activity_before] finder_params end diff --git a/lib/api/projects.rb b/lib/api/projects.rb index a33418c3336..ee0731a331f 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -73,6 +73,8 @@ module API optional :min_access_level, type: Integer, values: Gitlab::Access.all_values, desc: 'Limit by minimum access level of authenticated user' optional :id_after, type: Integer, desc: 'Limit results to projects with IDs greater than the specified ID' optional :id_before, type: Integer, desc: 'Limit results to projects with IDs less than the specified ID' + optional :last_activity_after, type: DateTime, desc: 'Limit results to projects with last_activity after specified time. Format: ISO 8601 YYYY-MM-DDTHH:MM:SSZ' + optional :last_activity_before, type: DateTime, desc: 'Limit results to projects with last_activity before specified time. Format: ISO 8601 YYYY-MM-DDTHH:MM:SSZ' use :optional_filter_params_ee end diff --git a/lib/gitlab/jira_import.rb b/lib/gitlab/jira_import.rb index 1486c754caf..fe4351d9029 100644 --- a/lib/gitlab/jira_import.rb +++ b/lib/gitlab/jira_import.rb @@ -6,6 +6,7 @@ module Gitlab FAILED_ISSUES_COUNTER_KEY = 'jira-import/failed/%{project_id}/%{collection_type}' NEXT_ITEMS_START_AT_KEY = 'jira-import/paginator/%{project_id}/%{collection_type}' + JIRA_IMPORT_LABEL = 'jira-import/import-label/%{project_id}' ITEMS_MAPPER_CACHE_KEY = 'jira-import/items-mapper/%{project_id}/%{collection_type}/%{jira_isssue_id}' ALREADY_IMPORTED_ITEMS_CACHE_KEY = 'jira-importer/already-imported/%{project}/%{collection_type}' @@ -25,23 +26,45 @@ module Gitlab FAILED_ISSUES_COUNTER_KEY % { project_id: project_id, collection_type: :issues } end + def self.import_label_cache_key(project_id) + JIRA_IMPORT_LABEL % { project_id: project_id } + end + def self.increment_issue_failures(project_id) - Gitlab::Cache::Import::Caching.increment(self.failed_issues_counter_cache_key(project_id)) + cache_class.increment(self.failed_issues_counter_cache_key(project_id)) end def self.get_issues_next_start_at(project_id) - Gitlab::Cache::Import::Caching.read(self.jira_issues_next_page_cache_key(project_id)).to_i + cache_class.read(self.jira_issues_next_page_cache_key(project_id)).to_i end def self.store_issues_next_started_at(project_id, value) cache_key = self.jira_issues_next_page_cache_key(project_id) - Gitlab::Cache::Import::Caching.write(cache_key, value) + cache_class.write(cache_key, value) + end + + def self.cache_issue_mapping(issue_id, jira_issue_id, project_id) + cache_key = JiraImport.jira_issue_cache_key(project_id, jira_issue_id) + cache_class.write(cache_key, issue_id) + end + + def self.get_import_label_id(project_id) + cache_class.read(JiraImport.import_label_cache_key(project_id)) + end + + def self.cache_import_label_id(project_id, label_id) + cache_class.write(JiraImport.import_label_cache_key(project_id), label_id) end def self.cache_cleanup(project_id) - Gitlab::Cache::Import::Caching.expire(self.failed_issues_counter_cache_key(project_id), JIRA_IMPORT_CACHE_TIMEOUT) - Gitlab::Cache::Import::Caching.expire(self.jira_issues_next_page_cache_key(project_id), JIRA_IMPORT_CACHE_TIMEOUT) - Gitlab::Cache::Import::Caching.expire(self.already_imported_cache_key(:issues, project_id), JIRA_IMPORT_CACHE_TIMEOUT) + cache_class.expire(self.import_label_cache_key(project_id), JIRA_IMPORT_CACHE_TIMEOUT) + cache_class.expire(self.failed_issues_counter_cache_key(project_id), JIRA_IMPORT_CACHE_TIMEOUT) + cache_class.expire(self.jira_issues_next_page_cache_key(project_id), JIRA_IMPORT_CACHE_TIMEOUT) + cache_class.expire(self.already_imported_cache_key(:issues, project_id), JIRA_IMPORT_CACHE_TIMEOUT) + end + + def self.cache_class + Gitlab::Cache::Import::Caching end end end diff --git a/lib/gitlab/jira_import/labels_importer.rb b/lib/gitlab/jira_import/labels_importer.rb new file mode 100644 index 00000000000..142a2da5be9 --- /dev/null +++ b/lib/gitlab/jira_import/labels_importer.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +module Gitlab + module JiraImport + class LabelsImporter < BaseImporter + attr_reader :job_waiter + + def initialize(project) + super + @job_waiter = JobWaiter.new + end + + def execute + create_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 + + 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 + end + end + end +end diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb index c131566380e..733cafd9d6c 100644 --- a/lib/gitlab/usage_data.rb +++ b/lib/gitlab/usage_data.rb @@ -174,10 +174,19 @@ module Gitlab git: { version: Gitlab::Git.version }, gitaly: { version: Gitaly::Server.all.first.server_version, servers: Gitaly::Server.count, filesystems: Gitaly::Server.filesystems }, gitlab_pages: { enabled: Gitlab.config.pages.enabled, version: Gitlab::Pages::VERSION }, - database: { adapter: Gitlab::Database.adapter_name, version: Gitlab::Database.version } + database: { adapter: Gitlab::Database.adapter_name, version: Gitlab::Database.version }, + app_server: { type: app_server_type } } end + def app_server_type + Gitlab::Runtime.identify.to_s + rescue Gitlab::Runtime::IdentificationError => e + Gitlab::AppLogger.error(e.message) + Gitlab::ErrorTracking.track_exception(e) + 'unknown_app_server_type' + end + def ingress_modsecurity_usage ::Clusters::Applications::IngressModsecurityUsageService.new.execute end |