diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-15 00:09:20 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-15 00:09:20 +0300 |
commit | db2275b561bace34d90b901226d7f46d33e4cbd9 (patch) | |
tree | 7fde15815e18d0818b9be7ce61ddd90a13ea0f8c /lib | |
parent | 3c6cad91a1a9d8732e8cb998f83d32dc19373b7b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/import_github.rb | 1 | ||||
-rw-r--r-- | lib/gitlab/data_builder/pipeline.rb | 1 | ||||
-rw-r--r-- | lib/gitlab/database/migration_helpers.rb | 11 | ||||
-rw-r--r-- | lib/gitlab/github_import/issuable_finder.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/github_import/settings.rb | 72 | ||||
-rw-r--r-- | lib/gitlab/github_import/single_endpoint_notes_importing.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/runtime.rb | 4 | ||||
-rw-r--r-- | lib/prometheus/pid_provider.rb | 2 |
8 files changed, 91 insertions, 10 deletions
diff --git a/lib/api/import_github.rb b/lib/api/import_github.rb index d91df47cd16..493cc038f46 100644 --- a/lib/api/import_github.rb +++ b/lib/api/import_github.rb @@ -43,6 +43,7 @@ module API optional :new_name, type: String, desc: 'New repo name' requires :target_namespace, type: String, desc: 'Namespace to import repo into' optional :github_hostname, type: String, desc: 'Custom GitHub enterprise hostname' + optional :optional_stages, type: Hash, desc: 'Optional stages of import to be performed' end post 'import/github' do result = Import::GithubService.new(client, current_user, params).execute(access_params, provider) diff --git a/lib/gitlab/data_builder/pipeline.rb b/lib/gitlab/data_builder/pipeline.rb index 320ebe5e80f..a75c7c539ae 100644 --- a/lib/gitlab/data_builder/pipeline.rb +++ b/lib/gitlab/data_builder/pipeline.rb @@ -63,6 +63,7 @@ module Gitlab def hook_attrs(pipeline) { id: pipeline.id, + iid: pipeline.iid, ref: pipeline.source_ref, tag: pipeline.tag, sha: pipeline.sha, diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb index 0568e734c78..df40e3b3868 100644 --- a/lib/gitlab/database/migration_helpers.rb +++ b/lib/gitlab/database/migration_helpers.rb @@ -296,12 +296,11 @@ module Gitlab with_lock_retries do execute("LOCK TABLE #{target}, #{source} IN SHARE ROW EXCLUSIVE MODE") if reverse_lock_order - execute <<-EOF.strip_heredoc ALTER TABLE #{source} ADD CONSTRAINT #{options[:name]} - FOREIGN KEY (#{options[:column]}) - REFERENCES #{target} (#{target_column}) + FOREIGN KEY (#{multiple_columns(options[:column])}) + REFERENCES #{target} (#{multiple_columns(target_column)}) #{on_delete_statement(options[:on_delete])} NOT VALID; EOF @@ -355,7 +354,7 @@ module Gitlab # - For standard rails foreign keys the prefix is `fk_rails_` # def concurrent_foreign_key_name(table, column, prefix: 'fk_') - identifier = "#{table}_#{column}_fk" + identifier = "#{table}_#{multiple_columns(column, separator: '_')}_fk" hashed_identifier = Digest::SHA256.hexdigest(identifier).first(10) "#{prefix}#{hashed_identifier}" @@ -1539,6 +1538,10 @@ into similar problems in the future (e.g. when new tables are created). private + def multiple_columns(columns, separator: ', ') + Array.wrap(columns).join(separator) + end + def cascade_statement(cascade) cascade ? 'CASCADE' : '' end diff --git a/lib/gitlab/github_import/issuable_finder.rb b/lib/gitlab/github_import/issuable_finder.rb index e7a1b7b3368..b960df581e4 100644 --- a/lib/gitlab/github_import/issuable_finder.rb +++ b/lib/gitlab/github_import/issuable_finder.rb @@ -80,12 +80,16 @@ module Gitlab end def timeout - if project.group.present? && ::Feature.enabled?(:github_importer_single_endpoint_notes_import, project.group, type: :ops) + if import_settings.enabled?(:single_endpoint_notes_import) Gitlab::Cache::Import::Caching::LONGER_TIMEOUT else Gitlab::Cache::Import::Caching::TIMEOUT end end + + def import_settings + ::Gitlab::GithubImport::Settings.new(project) + end end end end diff --git a/lib/gitlab/github_import/settings.rb b/lib/gitlab/github_import/settings.rb new file mode 100644 index 00000000000..77288b9fb98 --- /dev/null +++ b/lib/gitlab/github_import/settings.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +module Gitlab + module GithubImport + class Settings + OPTIONAL_STAGES = { + single_endpoint_issue_events_import: { + label: 'Import issue and pull request events', + details: <<-TEXT.split("\n").map(&:strip).join(' ') + For example, opened or closed, renamed, and labeled or unlabeled. + Time required to import these events depends on how many issues or pull requests your project has. + TEXT + }, + single_endpoint_notes_import: { + label: 'Use alternative comments import method', + details: <<-TEXT.split("\n").map(&:strip).join(' ') + The default method can skip some comments in large projects because of limitations of the GitHub API. + TEXT + }, + attachments_import: { + label: 'Import Markdown attachments', + details: <<-TEXT.split("\n").map(&:strip).join(' ') + Import Markdown attachments from repository comments, release posts, issue descriptions, + and pull request descriptions. These can include images, text, or binary attachments. + If not imported, links in Markdown to attachments break after you remove the attachments from GitHub. + TEXT + } + }.freeze + + def self.stages_array + OPTIONAL_STAGES.map do |stage_name, data| + { + name: stage_name.to_s, + label: s_(format("GitHubImport|%{text}", text: data[:label])), + details: s_(format("GitHubImport|%{text}", text: data[:details])) + } + end + end + + def initialize(project) + @project = project + end + + def write(user_settings) + user_settings = user_settings.to_h.with_indifferent_access + + optional_stages = fetch_stages_from_params(user_settings) + import_data = project.create_or_update_import_data(data: { optional_stages: optional_stages }) + import_data.save! + end + + def enabled?(stage_name) + project.import_data&.data&.dig('optional_stages', stage_name.to_s) || false + end + + def disabled?(stage_name) + !enabled?(stage_name) + end + + private + + attr_reader :project + + def fetch_stages_from_params(user_settings) + OPTIONAL_STAGES.keys.to_h do |stage_name| + enabled = Gitlab::Utils.to_boolean(user_settings[stage_name], default: false) + [stage_name, enabled] + end + end + end + end +end diff --git a/lib/gitlab/github_import/single_endpoint_notes_importing.rb b/lib/gitlab/github_import/single_endpoint_notes_importing.rb index ecdda83972b..3584288da57 100644 --- a/lib/gitlab/github_import/single_endpoint_notes_importing.rb +++ b/lib/gitlab/github_import/single_endpoint_notes_importing.rb @@ -4,10 +4,10 @@ # - SingleEndpointDiffNotesImporter # - SingleEndpointIssueNotesImporter # - SingleEndpointMergeRequestNotesImporter -# if `github_importer_single_endpoint_notes_import` feature flag is on. +# if enabled by Gitlab::GithubImport::Settings # # - SingleEndpointIssueEventsImporter -# if `github_importer_issue_events_import` feature flag is on. +# if enabled by Gitlab::GithubImport::Settings # # Fetches associated objects page by page to each item of parent collection. # Currently `associated` is note or event. diff --git a/lib/gitlab/runtime.rb b/lib/gitlab/runtime.rb index 5b1341207fd..6d95cb9a87b 100644 --- a/lib/gitlab/runtime.rb +++ b/lib/gitlab/runtime.rb @@ -25,9 +25,9 @@ module Gitlab if matches.one? matches.first elsif matches.none? - raise UnknownProcessError, "Failed to identify runtime for process #{Process.pid} (#{$0})" + raise UnknownProcessError, "Failed to identify runtime for process #{Process.pid} (#{$PROGRAM_NAME})" else - raise AmbiguousProcessError, "Ambiguous runtime #{matches} for process #{Process.pid} (#{$0})" + raise AmbiguousProcessError, "Ambiguous runtime #{matches} for process #{Process.pid} (#{$PROGRAM_NAME})" end end diff --git a/lib/prometheus/pid_provider.rb b/lib/prometheus/pid_provider.rb index d2563b4c806..05a2d3bd0c9 100644 --- a/lib/prometheus/pid_provider.rb +++ b/lib/prometheus/pid_provider.rb @@ -39,7 +39,7 @@ module Prometheus end def process_name - $0 + $PROGRAM_NAME end end end |