diff options
Diffstat (limited to 'lib/gitlab')
229 files changed, 899 insertions, 122 deletions
diff --git a/lib/gitlab/auth/saml/auth_hash.rb b/lib/gitlab/auth/saml/auth_hash.rb index 316354fd50c..1af9fa40c3a 100644 --- a/lib/gitlab/auth/saml/auth_hash.rb +++ b/lib/gitlab/auth/saml/auth_hash.rb @@ -28,7 +28,7 @@ module Gitlab end def extract_authn_context(document) - REXML::XPath.first(document, "//saml:AuthnStatement/saml:AuthnContext/saml:AuthnContextClassRef/text()").to_s + REXML::XPath.first(document, "//*[name()='saml:AuthnStatement' or name()='saml2:AuthnStatement']/*[name()='saml:AuthnContext' or name()='saml2:AuthnContext']/*[name()='saml:AuthnContextClassRef' or name()='saml2:AuthnContextClassRef']/text()").to_s end end end diff --git a/lib/gitlab/cache/ci/project_pipeline_status.rb b/lib/gitlab/cache/ci/project_pipeline_status.rb index dfbb83f7bb9..78b0eaac8cd 100644 --- a/lib/gitlab/cache/ci/project_pipeline_status.rb +++ b/lib/gitlab/cache/ci/project_pipeline_status.rb @@ -42,7 +42,7 @@ module Gitlab end def self.cache_key_for_project(project) - "#{Gitlab::Redis::Cache::CACHE_NAMESPACE}:projects/#{project.id}/pipeline_status/#{project.commit&.sha}" + "#{Gitlab::Redis::Cache::CACHE_NAMESPACE}:project:#{project.id}:pipeline_status:#{project.commit&.sha}" end def self.update_for_pipeline(pipeline) diff --git a/lib/gitlab/checks/commit_check.rb b/lib/gitlab/checks/commit_check.rb index 6dd74e8fb74..58267b6752f 100644 --- a/lib/gitlab/checks/commit_check.rb +++ b/lib/gitlab/checks/commit_check.rb @@ -10,8 +10,8 @@ module Gitlab def initialize(project, user, newrev, oldrev) @project = project @user = user - @newrev = user - @oldrev = user + @newrev = newrev + @oldrev = oldrev @file_paths = [] end diff --git a/lib/gitlab/ci/build/policy/changes.rb b/lib/gitlab/ci/build/policy/changes.rb index 7bf51519752..1663c875426 100644 --- a/lib/gitlab/ci/build/policy/changes.rb +++ b/lib/gitlab/ci/build/policy/changes.rb @@ -14,7 +14,7 @@ module Gitlab pipeline.modified_paths.any? do |path| @globs.any? do |glob| - File.fnmatch?(glob, path, File::FNM_PATHNAME | File::FNM_DOTMATCH) + File.fnmatch?(glob, path, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB) end end end diff --git a/lib/gitlab/ci/parsers/test/junit.rb b/lib/gitlab/ci/parsers/test/junit.rb index ed5a79d9b9b..2791730fd26 100644 --- a/lib/gitlab/ci/parsers/test/junit.rb +++ b/lib/gitlab/ci/parsers/test/junit.rb @@ -14,7 +14,7 @@ module Gitlab test_case = create_test_case(test_case) test_suite.add_test_case(test_case) end - rescue REXML::ParseException + rescue Nokogiri::XML::SyntaxError raise JunitParserError, "XML parsing failed" rescue raise JunitParserError, "JUnit parsing failed" diff --git a/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml b/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml index c759bb7098e..c90976b2040 100644 --- a/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml @@ -19,6 +19,15 @@ # * review: REVIEW_DISABLED # * stop_review: REVIEW_DISABLED # +# The sast and sast_dashboard jobs are executed to guarantee full compatibility +# with the group security dashboard and the security reports with old runners. +# If you use only runners with version 11.5 or above, you can disable the sast +# job by setting the OLD_REPORTS_DISABLED environment variable. If you use only +# runners with version below 11.5, you can disable the sast_dashboard job by +# setting the NEW_REPORTS_DISABLED environment variable. +# The sast_dashboard job will be removed in the future, when the sast job will +# use the new reports syntax. +# # In order to deploy, you must have a Kubernetes cluster configured either # via a project integration, or via group/project variables. # AUTO_DEVOPS_DOMAIN must also be set as a variable at the group or project @@ -27,7 +36,7 @@ # Continuous deployment to production is enabled by default. # If you want to deploy to staging first, set STAGING_ENABLED environment variable. # If you want to enable incremental rollout, either manual or time based, -# set INCREMENTAL_ROLLOUT_TYPE environment variable to "manual" or "timed". +# set INCREMENTAL_ROLLOUT_MODE environment variable to "manual" or "timed". # If you want to use canary deployments, set CANARY_ENABLED environment variable. # # If Auto DevOps fails to detect the proper buildpack, or if you want to @@ -116,7 +125,9 @@ code_quality: license_management: stage: test - image: "registry.gitlab.com/gitlab-org/security-products/license-management:$CI_SERVER_VERSION_MAJOR-$CI_SERVER_VERSION_MINOR-stable" + image: + name: "registry.gitlab.com/gitlab-org/security-products/license-management:$CI_SERVER_VERSION_MAJOR-$CI_SERVER_VERSION_MINOR-stable" + entrypoint: [""] allow_failure: true script: - license_management @@ -147,10 +158,10 @@ performance: only: refs: - branches - kubernetes: active except: variables: - $PERFORMANCE_DISABLED + - $KUBECONFIG == null sast: stage: test @@ -171,6 +182,29 @@ sast: except: variables: - $SAST_DISABLED + - $OLD_REPORTS_DISABLED + +sast_dashboard: + stage: test + image: docker:stable + allow_failure: true + services: + - docker:stable-dind + script: + - setup_docker + - sast + artifacts: + reports: + sast: gl-sast-report.json + only: + refs: + - branches + variables: + - $GITLAB_FEATURES =~ /\bsast\b/ + except: + variables: + - $SAST_DISABLED + - $NEW_REPORTS_DISABLED dependency_scanning: stage: test @@ -225,7 +259,6 @@ dast: only: refs: - branches - kubernetes: active variables: - $GITLAB_FEATURES =~ /\bdast\b/ except: @@ -233,6 +266,7 @@ dast: - master variables: - $DAST_DISABLED + - $KUBECONFIG == null review: stage: review @@ -254,12 +288,12 @@ review: only: refs: - branches - kubernetes: active except: refs: - master variables: - $REVIEW_DISABLED + - $KUBECONFIG == null stop_review: stage: cleanup @@ -277,12 +311,12 @@ stop_review: only: refs: - branches - kubernetes: active except: refs: - master variables: - $REVIEW_DISABLED + - $KUBECONFIG == null # Staging deploys are disabled by default since # continuous deployment to production is enabled by default @@ -306,9 +340,11 @@ staging: only: refs: - master - kubernetes: active variables: - $STAGING_ENABLED + except: + variables: + - $KUBECONFIG == null # Canaries are also disabled by default, but if you want them, # and know what the downsides are, you can enable this by setting @@ -331,9 +367,11 @@ canary: only: refs: - master - kubernetes: active variables: - $CANARY_ENABLED + except: + variables: + - $KUBECONFIG == null .production: &production_template stage: production @@ -359,13 +397,13 @@ production: only: refs: - master - kubernetes: active except: variables: - $STAGING_ENABLED - $CANARY_ENABLED - $INCREMENTAL_ROLLOUT_ENABLED - $INCREMENTAL_ROLLOUT_MODE + - $KUBECONFIG == null production_manual: <<: *production_template @@ -374,7 +412,6 @@ production_manual: only: refs: - master - kubernetes: active variables: - $STAGING_ENABLED - $CANARY_ENABLED @@ -382,6 +419,7 @@ production_manual: variables: - $INCREMENTAL_ROLLOUT_ENABLED - $INCREMENTAL_ROLLOUT_MODE + - $KUBECONFIG == null # This job implements incremental rollout on for every push to `master`. @@ -411,13 +449,13 @@ production_manual: only: refs: - master - kubernetes: active variables: - $INCREMENTAL_ROLLOUT_MODE == "manual" - $INCREMENTAL_ROLLOUT_ENABLED except: variables: - $INCREMENTAL_ROLLOUT_MODE == "timed" + - $KUBECONFIG == null .timed_rollout_template: &timed_rollout_template <<: *rollout_template @@ -426,9 +464,11 @@ production_manual: only: refs: - master - kubernetes: active variables: - $INCREMENTAL_ROLLOUT_MODE == "timed" + except: + variables: + - $KUBECONFIG == null timed rollout 10%: <<: *timed_rollout_template diff --git a/lib/gitlab/ci/variables/collection/item.rb b/lib/gitlab/ci/variables/collection/item.rb index fdf852e8788..cf8958e34c2 100644 --- a/lib/gitlab/ci/variables/collection/item.rb +++ b/lib/gitlab/ci/variables/collection/item.rb @@ -6,8 +6,8 @@ module Gitlab class Collection class Item def initialize(key:, value:, public: true, file: false) - raise ArgumentError, "`value` must be of type String, while it was: #{value.class}" unless - value.is_a?(String) || value.nil? + raise ArgumentError, "`#{key}` must be of type String, while it was: #{value.class}" unless + value.is_a?(String) @variable = { key: key, value: value, public: public, file: file diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index f3bd8b69869..8ba44dff06f 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -28,6 +28,7 @@ module Gitlab @repository = repository @diff_refs = diff_refs @fallback_diff_refs = fallback_diff_refs + @unfolded = false # Ensure items are collected in the the batch new_blob_lazy @@ -137,6 +138,24 @@ module Gitlab Gitlab::Diff::Parser.new.parse(raw_diff.each_line, diff_file: self).to_a end + # Changes diff_lines according to the given position. That is, + # it checks whether the position requires blob lines into the diff + # in order to be presented. + def unfold_diff_lines(position) + return unless position + + unfolder = Gitlab::Diff::LinesUnfolder.new(self, position) + + if unfolder.unfold_required? + @diff_lines = unfolder.unfolded_diff_lines + @unfolded = true + end + end + + def unfolded? + @unfolded + end + def highlighted_diff_lines @highlighted_diff_lines ||= Gitlab::Diff::Highlight.new(self, repository: self.repository).highlight diff --git a/lib/gitlab/diff/line.rb b/lib/gitlab/diff/line.rb index 74fed7c4b1b..f0c4977fc50 100644 --- a/lib/gitlab/diff/line.rb +++ b/lib/gitlab/diff/line.rb @@ -5,9 +5,9 @@ module Gitlab class Line SERIALIZE_KEYS = %i(line_code rich_text text type index old_pos new_pos).freeze - attr_reader :line_code, :type, :index, :old_pos, :new_pos + attr_reader :line_code, :type, :old_pos, :new_pos attr_writer :rich_text - attr_accessor :text + attr_accessor :text, :index def initialize(text, type, index, old_pos, new_pos, parent_file: nil, line_code: nil, rich_text: nil) @text, @type, @index = text, type, index @@ -21,7 +21,14 @@ module Gitlab end def self.init_from_hash(hash) - new(hash[:text], hash[:type], hash[:index], hash[:old_pos], hash[:new_pos], line_code: hash[:line_code], rich_text: hash[:rich_text]) + new(hash[:text], + hash[:type], + hash[:index], + hash[:old_pos], + hash[:new_pos], + parent_file: hash[:parent_file], + line_code: hash[:line_code], + rich_text: hash[:rich_text]) end def to_hash diff --git a/lib/gitlab/diff/lines_unfolder.rb b/lib/gitlab/diff/lines_unfolder.rb new file mode 100644 index 00000000000..9306b7e16a2 --- /dev/null +++ b/lib/gitlab/diff/lines_unfolder.rb @@ -0,0 +1,235 @@ +# frozen_string_literal: true + +# Given a position, calculates which Blob lines should be extracted, treated and +# injected in the current diff file lines in order to present a "unfolded" diff. +module Gitlab + module Diff + class LinesUnfolder + include Gitlab::Utils::StrongMemoize + + UNFOLD_CONTEXT_SIZE = 3 + + def initialize(diff_file, position) + @diff_file = diff_file + @blob = diff_file.old_blob + @position = position + @generate_top_match_line = true + @generate_bottom_match_line = true + + # These methods update `@generate_top_match_line` and + # `@generate_bottom_match_line`. + @from_blob_line = calculate_from_blob_line! + @to_blob_line = calculate_to_blob_line! + end + + # Returns merged diff lines with required blob lines with correct + # positions. + def unfolded_diff_lines + strong_memoize(:unfolded_diff_lines) do + next unless unfold_required? + + merged_diff_with_blob_lines + end + end + + # Returns the extracted lines from the old blob which should be merged + # with the current diff lines. + def blob_lines + strong_memoize(:blob_lines) do + # Blob lines, unlike diffs, doesn't start with an empty space for + # unchanged line, so the parsing and highlighting step can get fuzzy + # without the following change. + line_prefix = ' ' + blob_as_diff_lines = @blob.data.each_line.map { |line| "#{line_prefix}#{line}" } + + lines = Gitlab::Diff::Parser.new.parse(blob_as_diff_lines, diff_file: @diff_file).to_a + + from = from_blob_line - 1 + to = to_blob_line - 1 + + lines[from..to] + end + end + + def unfold_required? + strong_memoize(:unfold_required) do + next false unless @diff_file.text? + next false unless @position.unchanged? + next false if @diff_file.new_file? || @diff_file.deleted_file? + next false unless @position.old_line + # Invalid position (MR import scenario) + next false if @position.old_line > @blob.lines.size + next false if @diff_file.diff_lines.empty? + next false if @diff_file.line_for_position(@position) + next false unless unfold_line + + true + end + end + + private + + attr_reader :from_blob_line, :to_blob_line + + def merged_diff_with_blob_lines + lines = @diff_file.diff_lines + match_line = unfold_line + insert_index = bottom? ? -1 : match_line.index + + lines -= [match_line] unless bottom? + + lines.insert(insert_index, *blob_lines_with_matches) + + # The inserted blob lines have invalid indexes, so we need + # to reindex them. + reindex(lines) + + lines + end + + # Returns 'unchanged' blob lines with recalculated `old_pos` and + # `new_pos` and the recalculated new match line (needed if we for instance + # we unfolded once, but there are still folded lines). + def blob_lines_with_matches + old_pos = from_blob_line + new_pos = from_blob_line + offset + + new_blob_lines = [] + + new_blob_lines.push(top_blob_match_line) if top_blob_match_line + + blob_lines.each do |line| + new_blob_lines << Gitlab::Diff::Line.new(line.text, line.type, nil, old_pos, new_pos, + parent_file: @diff_file) + + old_pos += 1 + new_pos += 1 + end + + new_blob_lines.push(bottom_blob_match_line) if bottom_blob_match_line + + new_blob_lines + end + + def reindex(lines) + lines.each_with_index { |line, i| line.index = i } + end + + def top_blob_match_line + strong_memoize(:top_blob_match_line) do + next unless @generate_top_match_line + + old_pos = from_blob_line + new_pos = from_blob_line + offset + + build_match_line(old_pos, new_pos) + end + end + + def bottom_blob_match_line + strong_memoize(:bottom_blob_match_line) do + # The bottom line match addition is already handled on + # Diff::File#diff_lines_for_serializer + next if bottom? + next unless @generate_bottom_match_line + + position = line_after_unfold_position.old_pos + + old_pos = position + new_pos = position + offset + + build_match_line(old_pos, new_pos) + end + end + + def build_match_line(old_pos, new_pos) + blob_lines_length = blob_lines.length + old_line_ref = [old_pos, blob_lines_length].join(',') + new_line_ref = [new_pos, blob_lines_length].join(',') + new_match_line_str = "@@ -#{old_line_ref}+#{new_line_ref} @@" + + Gitlab::Diff::Line.new(new_match_line_str, 'match', nil, old_pos, new_pos) + end + + # Returns the first line position that should be extracted + # from `blob_lines`. + def calculate_from_blob_line! + return unless unfold_required? + + from = comment_position - UNFOLD_CONTEXT_SIZE + + # There's no line before the match if it's in the top-most + # position. + prev_line_number = line_before_unfold_position&.old_pos || 0 + + if from <= prev_line_number + 1 + @generate_top_match_line = false + from = prev_line_number + 1 + end + + from + end + + # Returns the last line position that should be extracted + # from `blob_lines`. + def calculate_to_blob_line! + return unless unfold_required? + + to = comment_position + UNFOLD_CONTEXT_SIZE + + return to if bottom? + + next_line_number = line_after_unfold_position.old_pos + + if to >= next_line_number - 1 + @generate_bottom_match_line = false + to = next_line_number - 1 + end + + to + end + + def offset + unfold_line.new_pos - unfold_line.old_pos + end + + def line_before_unfold_position + return unless index = unfold_line&.index + + @diff_file.diff_lines[index - 1] if index > 0 + end + + def line_after_unfold_position + return unless index = unfold_line&.index + + @diff_file.diff_lines[index + 1] if index >= 0 + end + + def bottom? + strong_memoize(:bottom) do + @position.old_line > last_line.old_pos + end + end + + # Returns the line which needed to be expanded in order to send a comment + # in `@position`. + def unfold_line + strong_memoize(:unfold_line) do + next last_line if bottom? + + @diff_file.diff_lines.find do |line| + line.old_pos > comment_position && line.type == 'match' + end + end + end + + def comment_position + @position.old_line + end + + def last_line + @diff_file.diff_lines.last + end + end + end +end diff --git a/lib/gitlab/diff/position.rb b/lib/gitlab/diff/position.rb index 9c4d9377593..e8f98f52111 100644 --- a/lib/gitlab/diff/position.rb +++ b/lib/gitlab/diff/position.rb @@ -103,6 +103,10 @@ module Gitlab @diff_refs ||= DiffRefs.new(base_sha: base_sha, start_sha: start_sha, head_sha: head_sha) end + def unfolded_diff?(repository) + diff_file(repository)&.unfolded? + end + def diff_file(repository) return @diff_file if defined?(@diff_file) @@ -136,7 +140,13 @@ module Gitlab return unless diff_refs.complete? return unless comparison = diff_refs.compare_in(repository.project) - comparison.diffs(diff_options).diff_files.first + file = comparison.diffs(diff_options).diff_files.first + + # We need to unfold diff lines according to the position in order + # to correctly calculate the line code and trace position changes. + file&.unfold_diff_lines(self) + + file end def get_formatter_class(type) diff --git a/lib/gitlab/file_detector.rb b/lib/gitlab/file_detector.rb index d6338b09e3d..2770469ca9f 100644 --- a/lib/gitlab/file_detector.rb +++ b/lib/gitlab/file_detector.rb @@ -8,7 +8,7 @@ module Gitlab module FileDetector PATTERNS = { # Project files - readme: %r{\A(readme|index)[^/]*\z}i, + readme: /\A(#{Regexp.union(*Gitlab::MarkupHelper::PLAIN_FILENAMES).source})(\.(#{Regexp.union(*Gitlab::MarkupHelper::EXTENSIONS).source}))?\z/i, changelog: %r{\A(changelog|history|changes|news)[^/]*\z}i, license: %r{\A((un)?licen[sc]e|copying)(\.[^/]+)?\z}i, contributing: %r{\Acontributing[^/]*\z}i, diff --git a/lib/gitlab/fogbugz_import/client.rb b/lib/gitlab/fogbugz_import/client.rb index acb000e3e23..dd747a79673 100644 --- a/lib/gitlab/fogbugz_import/client.rb +++ b/lib/gitlab/fogbugz_import/client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'fogbugz' module Gitlab diff --git a/lib/gitlab/fogbugz_import/importer.rb b/lib/gitlab/fogbugz_import/importer.rb index 98ea5b309a1..431911d1eee 100644 --- a/lib/gitlab/fogbugz_import/importer.rb +++ b/lib/gitlab/fogbugz_import/importer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module FogbugzImport class Importer diff --git a/lib/gitlab/fogbugz_import/project_creator.rb b/lib/gitlab/fogbugz_import/project_creator.rb index 1918d5b208d..3c71031a8d9 100644 --- a/lib/gitlab/fogbugz_import/project_creator.rb +++ b/lib/gitlab/fogbugz_import/project_creator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module FogbugzImport class ProjectCreator diff --git a/lib/gitlab/fogbugz_import/repository.rb b/lib/gitlab/fogbugz_import/repository.rb index d1dc63db2b2..b958dcf6cbf 100644 --- a/lib/gitlab/fogbugz_import/repository.rb +++ b/lib/gitlab/fogbugz_import/repository.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module FogbugzImport class Repository diff --git a/lib/gitlab/gfm/reference_rewriter.rb b/lib/gitlab/gfm/reference_rewriter.rb index 455814a9159..08d7db49ad7 100644 --- a/lib/gitlab/gfm/reference_rewriter.rb +++ b/lib/gitlab/gfm/reference_rewriter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Gfm ## @@ -31,19 +33,19 @@ module Gitlab class ReferenceRewriter RewriteError = Class.new(StandardError) - def initialize(text, source_project, current_user) + def initialize(text, source_parent, current_user) @text = text - @source_project = source_project + @source_parent = source_parent @current_user = current_user @original_html = markdown(text) @pattern = Gitlab::ReferenceExtractor.references_pattern end - def rewrite(target_project) + def rewrite(target_parent) return @text unless needs_rewrite? @text.gsub(@pattern) do |reference| - unfold_reference(reference, Regexp.last_match, target_project) + unfold_reference(reference, Regexp.last_match, target_parent) end end @@ -53,14 +55,14 @@ module Gitlab private - def unfold_reference(reference, match, target_project) + def unfold_reference(reference, match, target_parent) before = @text[0...match.begin(0)] after = @text[match.end(0)..-1] referable = find_referable(reference) return reference unless referable - cross_reference = build_cross_reference(referable, target_project) + cross_reference = build_cross_reference(referable, target_parent) return reference if reference == cross_reference if cross_reference.nil? @@ -72,17 +74,17 @@ module Gitlab end def find_referable(reference) - extractor = Gitlab::ReferenceExtractor.new(@source_project, + extractor = Gitlab::ReferenceExtractor.new(@source_parent, @current_user) extractor.analyze(reference) extractor.all.first end - def build_cross_reference(referable, target_project) + def build_cross_reference(referable, target_parent) if referable.respond_to?(:project) - referable.to_reference(target_project) + referable.to_reference(target_parent) else - referable.to_reference(@source_project, target_project: target_project) + referable.to_reference(@source_parent, target_project: target_parent) end end @@ -91,7 +93,7 @@ module Gitlab end def markdown(text) - Banzai.render(text, project: @source_project, no_original_data: true) + Banzai.render(text, project: @source_parent, no_original_data: true) end end end diff --git a/lib/gitlab/gfm/uploads_rewriter.rb b/lib/gitlab/gfm/uploads_rewriter.rb index f7e66697da3..3f06badf5d9 100644 --- a/lib/gitlab/gfm/uploads_rewriter.rb +++ b/lib/gitlab/gfm/uploads_rewriter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'fileutils' module Gitlab @@ -16,14 +18,15 @@ module Gitlab @pattern = FileUploader::MARKDOWN_PATTERN end - def rewrite(target_project) + def rewrite(target_parent) return @text unless needs_rewrite? @text.gsub(@pattern) do |markdown| file = find_file(@source_project, $~[:secret], $~[:file]) break markdown unless file.try(:exists?) - moved = FileUploader.copy_to(file, target_project) + klass = target_parent.is_a?(Namespace) ? NamespaceFileUploader : FileUploader + moved = klass.copy_to(file, target_parent) moved.markdown_link end end diff --git a/lib/gitlab/git/attributes_at_ref_parser.rb b/lib/gitlab/git/attributes_at_ref_parser.rb index 26b5bd520d5..cbddf836ce8 100644 --- a/lib/gitlab/git/attributes_at_ref_parser.rb +++ b/lib/gitlab/git/attributes_at_ref_parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git # Parses root .gitattributes file at a given ref diff --git a/lib/gitlab/git/attributes_parser.rb b/lib/gitlab/git/attributes_parser.rb index 08f4d7d4f5c..8b9d74ae8e7 100644 --- a/lib/gitlab/git/attributes_parser.rb +++ b/lib/gitlab/git/attributes_parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git # Class for parsing Git attribute files and extracting the attributes for diff --git a/lib/gitlab/git/blame.rb b/lib/gitlab/git/blame.rb index e25e15f5c80..b118eda37f8 100644 --- a/lib/gitlab/git/blame.rb +++ b/lib/gitlab/git/blame.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git class Blame diff --git a/lib/gitlab/git/blob.rb b/lib/gitlab/git/blob.rb index 0bd1d3420a2..9dd1c484d59 100644 --- a/lib/gitlab/git/blob.rb +++ b/lib/gitlab/git/blob.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Gitaly note: JV: seems to be completely migrated (behind feature flags). module Gitlab diff --git a/lib/gitlab/git/branch.rb b/lib/gitlab/git/branch.rb index 6351cfb83e3..9447cfa0fb6 100644 --- a/lib/gitlab/git/branch.rb +++ b/lib/gitlab/git/branch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git class Branch < Ref diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb index 2820491b65d..4f05c4b73a1 100644 --- a/lib/gitlab/git/commit.rb +++ b/lib/gitlab/git/commit.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Gitlab::Git::Commit is a wrapper around Gitaly::GitCommit module Gitlab module Git diff --git a/lib/gitlab/git/commit_stats.rb b/lib/gitlab/git/commit_stats.rb index 83a9fd5f81a..8815088d23c 100644 --- a/lib/gitlab/git/commit_stats.rb +++ b/lib/gitlab/git/commit_stats.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Gitlab::Git::CommitStats counts the additions, deletions, and total changes # in a commit. module Gitlab diff --git a/lib/gitlab/git/compare.rb b/lib/gitlab/git/compare.rb index 7cb842256d0..ab5245ba7cb 100644 --- a/lib/gitlab/git/compare.rb +++ b/lib/gitlab/git/compare.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Gitaly note: JV: no RPC's here. module Gitlab diff --git a/lib/gitlab/git/conflict/file.rb b/lib/gitlab/git/conflict/file.rb index f08dab59ce4..7ffe4a7ae81 100644 --- a/lib/gitlab/git/conflict/file.rb +++ b/lib/gitlab/git/conflict/file.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git module Conflict diff --git a/lib/gitlab/git/conflict/parser.rb b/lib/gitlab/git/conflict/parser.rb index fb5717dd556..20de8ebde4e 100644 --- a/lib/gitlab/git/conflict/parser.rb +++ b/lib/gitlab/git/conflict/parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git module Conflict diff --git a/lib/gitlab/git/conflict/resolution.rb b/lib/gitlab/git/conflict/resolution.rb index ab9be683e15..04299a2d10c 100644 --- a/lib/gitlab/git/conflict/resolution.rb +++ b/lib/gitlab/git/conflict/resolution.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git module Conflict diff --git a/lib/gitlab/git/conflict/resolver.rb b/lib/gitlab/git/conflict/resolver.rb index 307f1b8cb66..26e82643a4c 100644 --- a/lib/gitlab/git/conflict/resolver.rb +++ b/lib/gitlab/git/conflict/resolver.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git module Conflict diff --git a/lib/gitlab/git/diff.rb b/lib/gitlab/git/diff.rb index b2e2d49dd0b..74a4633424f 100644 --- a/lib/gitlab/git/diff.rb +++ b/lib/gitlab/git/diff.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git class Diff diff --git a/lib/gitlab/git/diff_collection.rb b/lib/gitlab/git/diff_collection.rb index 47ebca7c4a2..5c70cb6c66c 100644 --- a/lib/gitlab/git/diff_collection.rb +++ b/lib/gitlab/git/diff_collection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Gitaly note: JV: no RPC's here. module Gitlab diff --git a/lib/gitlab/git/gitmodules_parser.rb b/lib/gitlab/git/gitmodules_parser.rb index 4b505312f60..575e12390cd 100644 --- a/lib/gitlab/git/gitmodules_parser.rb +++ b/lib/gitlab/git/gitmodules_parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Gitaly note: JV: no RPC's here. module Gitlab diff --git a/lib/gitlab/git/hook_env.rb b/lib/gitlab/git/hook_env.rb index 620568d8817..892a069a3b7 100644 --- a/lib/gitlab/git/hook_env.rb +++ b/lib/gitlab/git/hook_env.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Gitaly note: JV: no RPC's here. module Gitlab diff --git a/lib/gitlab/git/index.rb b/lib/gitlab/git/index.rb index c2e4274e3ee..3b9b516308f 100644 --- a/lib/gitlab/git/index.rb +++ b/lib/gitlab/git/index.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git class Index diff --git a/lib/gitlab/git/lfs_changes.rb b/lib/gitlab/git/lfs_changes.rb index d7148165408..8e2a925dfea 100644 --- a/lib/gitlab/git/lfs_changes.rb +++ b/lib/gitlab/git/lfs_changes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git class LfsChanges diff --git a/lib/gitlab/git/lfs_pointer_file.rb b/lib/gitlab/git/lfs_pointer_file.rb index 2ae0a889590..b7019a221ac 100644 --- a/lib/gitlab/git/lfs_pointer_file.rb +++ b/lib/gitlab/git/lfs_pointer_file.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git class LfsPointerFile diff --git a/lib/gitlab/git/operation_service.rb b/lib/gitlab/git/operation_service.rb index 0584629ac84..8797d3dce24 100644 --- a/lib/gitlab/git/operation_service.rb +++ b/lib/gitlab/git/operation_service.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git class OperationService diff --git a/lib/gitlab/git/path_helper.rb b/lib/gitlab/git/path_helper.rb index 57b82a37d6c..e3a2031eeca 100644 --- a/lib/gitlab/git/path_helper.rb +++ b/lib/gitlab/git/path_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Gitaly note: JV: no RPC's here. module Gitlab diff --git a/lib/gitlab/git/pre_receive_error.rb b/lib/gitlab/git/pre_receive_error.rb index ac1ab7c39d5..03caace6fce 100644 --- a/lib/gitlab/git/pre_receive_error.rb +++ b/lib/gitlab/git/pre_receive_error.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git # diff --git a/lib/gitlab/git/raw_diff_change.rb b/lib/gitlab/git/raw_diff_change.rb index 98de9328071..e1002af40f6 100644 --- a/lib/gitlab/git/raw_diff_change.rb +++ b/lib/gitlab/git/raw_diff_change.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git # This class behaves like a struct with fields :blob_id, :blob_size, :operation, :old_path, :new_path diff --git a/lib/gitlab/git/ref.rb b/lib/gitlab/git/ref.rb index 31a280155bd..eec91194949 100644 --- a/lib/gitlab/git/ref.rb +++ b/lib/gitlab/git/ref.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git class Ref diff --git a/lib/gitlab/git/remote_mirror.rb b/lib/gitlab/git/remote_mirror.rb index 7f9520de5ce..e992d522e7f 100644 --- a/lib/gitlab/git/remote_mirror.rb +++ b/lib/gitlab/git/remote_mirror.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git class RemoteMirror diff --git a/lib/gitlab/git/remote_repository.rb b/lib/gitlab/git/remote_repository.rb index f40e59a8dd0..234541d8145 100644 --- a/lib/gitlab/git/remote_repository.rb +++ b/lib/gitlab/git/remote_repository.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git # diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 1642c4c5687..993955d1a6b 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'tempfile' require 'forwardable' require "rubygems/package" @@ -419,13 +421,17 @@ module Gitlab end def diff_stats(left_id, right_id) + if [left_id, right_id].any? { |ref| ref.blank? || Gitlab::Git.blank_ref?(ref) } + return empty_diff_stats + end + stats = wrapped_gitaly_errors do gitaly_commit_client.diff_stats(left_id, right_id) end Gitlab::Git::DiffStatsCollection.new(stats) rescue CommandError, TypeError - Gitlab::Git::DiffStatsCollection.new([]) + empty_diff_stats end # Returns a RefName for a given SHA @@ -962,6 +968,10 @@ module Gitlab private + def empty_diff_stats + Gitlab::Git::DiffStatsCollection.new([]) + end + def uncached_has_local_branches? wrapped_gitaly_errors do gitaly_repository_client.has_local_branches? diff --git a/lib/gitlab/git/repository_mirroring.rb b/lib/gitlab/git/repository_mirroring.rb index 752a91fbb60..7e63a6dc7cb 100644 --- a/lib/gitlab/git/repository_mirroring.rb +++ b/lib/gitlab/git/repository_mirroring.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git module RepositoryMirroring diff --git a/lib/gitlab/git/tag.rb b/lib/gitlab/git/tag.rb index bbf2ecdb1fa..ade708d0541 100644 --- a/lib/gitlab/git/tag.rb +++ b/lib/gitlab/git/tag.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git class Tag < Ref diff --git a/lib/gitlab/git/tree.rb b/lib/gitlab/git/tree.rb index b5b701699f0..51542bcaaa2 100644 --- a/lib/gitlab/git/tree.rb +++ b/lib/gitlab/git/tree.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git class Tree diff --git a/lib/gitlab/git/user.rb b/lib/gitlab/git/user.rb index 338e1a30c45..2c798844798 100644 --- a/lib/gitlab/git/user.rb +++ b/lib/gitlab/git/user.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git class User diff --git a/lib/gitlab/git/util.rb b/lib/gitlab/git/util.rb index 4708f22dcb3..03c2c1367b0 100644 --- a/lib/gitlab/git/util.rb +++ b/lib/gitlab/git/util.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Gitaly note: JV: no RPC's here. module Gitlab diff --git a/lib/gitlab/git/version.rb b/lib/gitlab/git/version.rb index 4bd91898457..64c89656167 100644 --- a/lib/gitlab/git/version.rb +++ b/lib/gitlab/git/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git module Version diff --git a/lib/gitlab/git/wiki.rb b/lib/gitlab/git/wiki.rb index 02c643d0da0..c43331bed60 100644 --- a/lib/gitlab/git/wiki.rb +++ b/lib/gitlab/git/wiki.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git class Wiki diff --git a/lib/gitlab/git/wiki_file.rb b/lib/gitlab/git/wiki_file.rb index 64313bb04e8..c05a5adc00c 100644 --- a/lib/gitlab/git/wiki_file.rb +++ b/lib/gitlab/git/wiki_file.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git class WikiFile diff --git a/lib/gitlab/git/wiki_page.rb b/lib/gitlab/git/wiki_page.rb index c4087c9ebdc..f6cac398548 100644 --- a/lib/gitlab/git/wiki_page.rb +++ b/lib/gitlab/git/wiki_page.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git class WikiPage diff --git a/lib/gitlab/git/wiki_page_version.rb b/lib/gitlab/git/wiki_page_version.rb index d5e7e70fd31..475a9d4d1b9 100644 --- a/lib/gitlab/git/wiki_page_version.rb +++ b/lib/gitlab/git/wiki_page_version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git class WikiPageVersion diff --git a/lib/gitlab/git/wraps_gitaly_errors.rb b/lib/gitlab/git/wraps_gitaly_errors.rb index 4b161f7e6ce..9963bcfbf1c 100644 --- a/lib/gitlab/git/wraps_gitaly_errors.rb +++ b/lib/gitlab/git/wraps_gitaly_errors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Git module WrapsGitalyErrors diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index d99a9f15371..8b455dc7696 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -139,7 +139,7 @@ module Gitlab ensure duration = Gitlab::Metrics::System.monotonic_time - start - # Keep track, seperately, for the performance bar + # Keep track, separately, for the performance bar self.query_time += duration gitaly_controller_action_duration_seconds.observe( current_transaction_labels.merge(gitaly_service: service.to_s, rpc: rpc.to_s), diff --git a/lib/gitlab/gitaly_client/attributes_bag.rb b/lib/gitlab/gitaly_client/attributes_bag.rb index 198a1de91c7..3f1a0ef4888 100644 --- a/lib/gitlab/gitaly_client/attributes_bag.rb +++ b/lib/gitlab/gitaly_client/attributes_bag.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient # This module expects an `ATTRS` const to be defined on the subclass diff --git a/lib/gitlab/gitaly_client/blob_service.rb b/lib/gitlab/gitaly_client/blob_service.rb index 086ce31e678..39547328210 100644 --- a/lib/gitlab/gitaly_client/blob_service.rb +++ b/lib/gitlab/gitaly_client/blob_service.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient class BlobService @@ -15,7 +17,7 @@ module Gitlab ) response = GitalyClient.call(@gitaly_repo.storage_name, :blob_service, :get_blob, request, timeout: GitalyClient.fast_timeout) - data = '' + data = [] blob = nil response.each do |msg| if blob.nil? @@ -27,6 +29,8 @@ module Gitlab return nil if blob.oid.blank? + data = data.join + Gitlab::Git::Blob.new( id: blob.oid, size: blob.size, diff --git a/lib/gitlab/gitaly_client/blobs_stitcher.rb b/lib/gitlab/gitaly_client/blobs_stitcher.rb index 5ca592ff812..01bab854082 100644 --- a/lib/gitlab/gitaly_client/blobs_stitcher.rb +++ b/lib/gitlab/gitaly_client/blobs_stitcher.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient class BlobsStitcher diff --git a/lib/gitlab/gitaly_client/commit_service.rb b/lib/gitlab/gitaly_client/commit_service.rb index 085b2a127a5..4e46cb9f05c 100644 --- a/lib/gitlab/gitaly_client/commit_service.rb +++ b/lib/gitlab/gitaly_client/commit_service.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient class CommitService @@ -93,7 +95,7 @@ module Gitlab response = GitalyClient.call(@repository.storage, :commit_service, :tree_entry, request, timeout: GitalyClient.medium_timeout) entry = nil - data = '' + data = [] response.each do |msg| if entry.nil? entry = msg @@ -103,7 +105,7 @@ module Gitlab data << msg.data end - entry.data = data + entry.data = data.join entry unless entry.oid.blank? end @@ -254,7 +256,7 @@ module Gitlab ) response = GitalyClient.call(@repository.storage, :commit_service, :raw_blame, request, timeout: GitalyClient.medium_timeout) - response.reduce("") { |memo, msg| memo << msg.data } + response.reduce([]) { |memo, msg| memo << msg.data }.join end def find_commit(revision) @@ -345,8 +347,8 @@ module Gitlab request = Gitaly::ExtractCommitSignatureRequest.new(repository: @gitaly_repo, commit_id: commit_id) response = GitalyClient.call(@repository.storage, :commit_service, :extract_commit_signature, request) - signature = ''.b - signed_text = ''.b + signature = +''.b + signed_text = +''.b response.each do |message| signature << message.signature @@ -364,7 +366,7 @@ module Gitlab request = Gitaly::GetCommitSignaturesRequest.new(repository: @gitaly_repo, commit_ids: commit_ids) response = GitalyClient.call(@repository.storage, :commit_service, :get_commit_signatures, request, timeout: GitalyClient.fast_timeout) - signatures = Hash.new { |h, k| h[k] = [''.b, ''.b] } + signatures = Hash.new { |h, k| h[k] = [+''.b, +''.b] } current_commit_id = nil response.each do |message| @@ -383,7 +385,7 @@ module Gitlab request = Gitaly::GetCommitMessagesRequest.new(repository: @gitaly_repo, commit_ids: commit_ids) response = GitalyClient.call(@repository.storage, :commit_service, :get_commit_messages, request, timeout: GitalyClient.fast_timeout) - messages = Hash.new { |h, k| h[k] = ''.b } + messages = Hash.new { |h, k| h[k] = +''.b } current_commit_id = nil response.each do |rpc_message| diff --git a/lib/gitlab/gitaly_client/conflict_files_stitcher.rb b/lib/gitlab/gitaly_client/conflict_files_stitcher.rb index c275a065bce..0e00f6e8c44 100644 --- a/lib/gitlab/gitaly_client/conflict_files_stitcher.rb +++ b/lib/gitlab/gitaly_client/conflict_files_stitcher.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient class ConflictFilesStitcher @@ -17,7 +19,7 @@ module Gitlab current_file = file_from_gitaly_header(gitaly_file.header) else - current_file.raw_content << gitaly_file.content + current_file.raw_content = "#{current_file.raw_content}#{gitaly_file.content}" end end end diff --git a/lib/gitlab/gitaly_client/conflicts_service.rb b/lib/gitlab/gitaly_client/conflicts_service.rb index aa7e03301f5..6304f998563 100644 --- a/lib/gitlab/gitaly_client/conflicts_service.rb +++ b/lib/gitlab/gitaly_client/conflicts_service.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient class ConflictsService diff --git a/lib/gitlab/gitaly_client/diff.rb b/lib/gitlab/gitaly_client/diff.rb index af9d674535b..dd192ccde1a 100644 --- a/lib/gitlab/gitaly_client/diff.rb +++ b/lib/gitlab/gitaly_client/diff.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient class Diff diff --git a/lib/gitlab/gitaly_client/diff_stitcher.rb b/lib/gitlab/gitaly_client/diff_stitcher.rb index da243ee2d1a..98d327a7329 100644 --- a/lib/gitlab/gitaly_client/diff_stitcher.rb +++ b/lib/gitlab/gitaly_client/diff_stitcher.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient class DiffStitcher @@ -20,7 +22,7 @@ module Gitlab current_diff = GitalyClient::Diff.new(diff_params) else - current_diff.patch += diff_msg.raw_patch_data + current_diff.patch = "#{current_diff.patch}#{diff_msg.raw_patch_data}" end if diff_msg.end_of_patch diff --git a/lib/gitlab/gitaly_client/health_check_service.rb b/lib/gitlab/gitaly_client/health_check_service.rb index 6c1213f5e20..0c495f60633 100644 --- a/lib/gitlab/gitaly_client/health_check_service.rb +++ b/lib/gitlab/gitaly_client/health_check_service.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient class HealthCheckService diff --git a/lib/gitlab/gitaly_client/namespace_service.rb b/lib/gitlab/gitaly_client/namespace_service.rb index d4e982b649a..f0be3cbebd2 100644 --- a/lib/gitlab/gitaly_client/namespace_service.rb +++ b/lib/gitlab/gitaly_client/namespace_service.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient class NamespaceService diff --git a/lib/gitlab/gitaly_client/notification_service.rb b/lib/gitlab/gitaly_client/notification_service.rb index 326e6f7dafc..873c3e4086d 100644 --- a/lib/gitlab/gitaly_client/notification_service.rb +++ b/lib/gitlab/gitaly_client/notification_service.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient class NotificationService diff --git a/lib/gitlab/gitaly_client/operation_service.rb b/lib/gitlab/gitaly_client/operation_service.rb index 4c78b790ce5..c32c2c0b2fb 100644 --- a/lib/gitlab/gitaly_client/operation_service.rb +++ b/lib/gitlab/gitaly_client/operation_service.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient class OperationService diff --git a/lib/gitlab/gitaly_client/queue_enumerator.rb b/lib/gitlab/gitaly_client/queue_enumerator.rb index b8018029552..3a412102abe 100644 --- a/lib/gitlab/gitaly_client/queue_enumerator.rb +++ b/lib/gitlab/gitaly_client/queue_enumerator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient class QueueEnumerator diff --git a/lib/gitlab/gitaly_client/ref_service.rb b/lib/gitlab/gitaly_client/ref_service.rb index 8acc22e809e..d5633d167ac 100644 --- a/lib/gitlab/gitaly_client/ref_service.rb +++ b/lib/gitlab/gitaly_client/ref_service.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient class RefService @@ -218,7 +220,7 @@ module Gitlab request = Gitaly::GetTagMessagesRequest.new(repository: @gitaly_repo, tag_ids: tag_ids) response = GitalyClient.call(@repository.storage, :ref_service, :get_tag_messages, request, timeout: GitalyClient.fast_timeout) - messages = Hash.new { |h, k| h[k] = ''.b } + messages = Hash.new { |h, k| h[k] = +''.b } current_tag_id = nil response.each do |rpc_message| diff --git a/lib/gitlab/gitaly_client/remote_service.rb b/lib/gitlab/gitaly_client/remote_service.rb index 4661448621b..24e8a5e16d3 100644 --- a/lib/gitlab/gitaly_client/remote_service.rb +++ b/lib/gitlab/gitaly_client/remote_service.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient class RemoteService diff --git a/lib/gitlab/gitaly_client/repository_service.rb b/lib/gitlab/gitaly_client/repository_service.rb index d7b36946b65..f968ebc2cbf 100644 --- a/lib/gitlab/gitaly_client/repository_service.rb +++ b/lib/gitlab/gitaly_client/repository_service.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient class RepositoryService @@ -56,9 +58,9 @@ module Gitlab request = Gitaly::GetInfoAttributesRequest.new(repository: @gitaly_repo) response = GitalyClient.call(@storage, :repository_service, :get_info_attributes, request, timeout: GitalyClient.fast_timeout) - response.each_with_object("") do |message, attributes| + response.each_with_object([]) do |message, attributes| attributes << message.attributes - end + end.join end def fetch_remote(remote, ssh_auth:, forced:, no_tags:, timeout:, prune: true) diff --git a/lib/gitlab/gitaly_client/server_service.rb b/lib/gitlab/gitaly_client/server_service.rb index ad898278353..0ade6942db9 100644 --- a/lib/gitlab/gitaly_client/server_service.rb +++ b/lib/gitlab/gitaly_client/server_service.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient # Meant for extraction of server data, and later maybe to perform misc task diff --git a/lib/gitlab/gitaly_client/storage_service.rb b/lib/gitlab/gitaly_client/storage_service.rb index 3a26dd58ff4..4edcb0b8ba9 100644 --- a/lib/gitlab/gitaly_client/storage_service.rb +++ b/lib/gitlab/gitaly_client/storage_service.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient class StorageService diff --git a/lib/gitlab/gitaly_client/storage_settings.rb b/lib/gitlab/gitaly_client/storage_settings.rb index 26d1f53f26c..754cccb6b3f 100644 --- a/lib/gitlab/gitaly_client/storage_settings.rb +++ b/lib/gitlab/gitaly_client/storage_settings.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient # This is a chokepoint that is meant to help us stop remove all places diff --git a/lib/gitlab/gitaly_client/util.rb b/lib/gitlab/gitaly_client/util.rb index 9c19c51d412..dce5d6a8ad0 100644 --- a/lib/gitlab/gitaly_client/util.rb +++ b/lib/gitlab/gitaly_client/util.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient module Util diff --git a/lib/gitlab/gitaly_client/wiki_file.rb b/lib/gitlab/gitaly_client/wiki_file.rb index 47c60c92484..ef2b23732d1 100644 --- a/lib/gitlab/gitaly_client/wiki_file.rb +++ b/lib/gitlab/gitaly_client/wiki_file.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient class WikiFile diff --git a/lib/gitlab/gitaly_client/wiki_page.rb b/lib/gitlab/gitaly_client/wiki_page.rb index a02d15db5dd..757a429fb8a 100644 --- a/lib/gitlab/gitaly_client/wiki_page.rb +++ b/lib/gitlab/gitaly_client/wiki_page.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitalyClient class WikiPage diff --git a/lib/gitlab/gitaly_client/wiki_service.rb b/lib/gitlab/gitaly_client/wiki_service.rb index 7c2c228ad01..2b3d622af4d 100644 --- a/lib/gitlab/gitaly_client/wiki_service.rb +++ b/lib/gitlab/gitaly_client/wiki_service.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'stringio' module Gitlab @@ -139,7 +141,7 @@ module Gitlab next unless message.name.present? || wiki_file if wiki_file - wiki_file.raw_data << message.raw_data + wiki_file.raw_data = "#{wiki_file.raw_data}#{message.raw_data}" else wiki_file = GitalyClient::WikiFile.new(message.to_h) # All gRPC strings in a response are frozen, so we get @@ -160,7 +162,7 @@ module Gitlab ) response = GitalyClient.call(@repository.storage, :wiki_service, :wiki_get_formatted_data, request) - response.reduce("") { |memo, msg| memo << msg.data } + response.reduce([]) { |memo, msg| memo << msg.data }.join end private diff --git a/lib/gitlab/gitlab_import/client.rb b/lib/gitlab/gitlab_import/client.rb index 38ef12491df..86474159f8b 100644 --- a/lib/gitlab/gitlab_import/client.rb +++ b/lib/gitlab/gitlab_import/client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitlabImport class Client diff --git a/lib/gitlab/gitlab_import/importer.rb b/lib/gitlab/gitlab_import/importer.rb index 047487f1d24..e84863deba8 100644 --- a/lib/gitlab/gitlab_import/importer.rb +++ b/lib/gitlab/gitlab_import/importer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitlabImport class Importer @@ -22,22 +24,22 @@ module Gitlab issues = client.issues(project_identifier) issues.each do |issue| - body = @formatter.author_line(issue["author"]["name"]) - body += issue["description"] + body = [@formatter.author_line(issue["author"]["name"])] + body << issue["description"] comments = client.issue_comments(project_identifier, issue["iid"]) if comments.any? - body += @formatter.comments_header + body << @formatter.comments_header end comments.each do |comment| - body += @formatter.comment(comment["author"]["name"], comment["created_at"], comment["body"]) + body << @formatter.comment(comment["author"]["name"], comment["created_at"], comment["body"]) end project.issues.create!( iid: issue["iid"], - description: body, + description: body.join, title: issue["title"], state: issue["state"], updated_at: issue["updated_at"], diff --git a/lib/gitlab/gitlab_import/project_creator.rb b/lib/gitlab/gitlab_import/project_creator.rb index 430b8c10058..35feea17351 100644 --- a/lib/gitlab/gitlab_import/project_creator.rb +++ b/lib/gitlab/gitlab_import/project_creator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GitlabImport class ProjectCreator diff --git a/lib/gitlab/gon_helper.rb b/lib/gitlab/gon_helper.rb index 860c39feb64..15137140639 100644 --- a/lib/gitlab/gon_helper.rb +++ b/lib/gitlab/gon_helper.rb @@ -8,7 +8,10 @@ module Gitlab def add_gon_variables gon.api_version = 'v4' - gon.default_avatar_url = URI.join(Gitlab.config.gitlab.url, ActionController::Base.helpers.image_path('no_avatar.png')).to_s + gon.default_avatar_url = + Gitlab::Utils.append_path( + Gitlab.config.gitlab.url, + ActionController::Base.helpers.image_path('no_avatar.png')) gon.max_file_size = Gitlab::CurrentSettings.max_attachment_size gon.asset_host = ActionController::Base.asset_host gon.webpack_public_path = webpack_public_path diff --git a/lib/gitlab/google_code_import/client.rb b/lib/gitlab/google_code_import/client.rb index b1dbf554e41..52d714880b5 100644 --- a/lib/gitlab/google_code_import/client.rb +++ b/lib/gitlab/google_code_import/client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GoogleCodeImport class Client diff --git a/lib/gitlab/google_code_import/importer.rb b/lib/gitlab/google_code_import/importer.rb index 0c08c0fedaa..1e7203cb82a 100644 --- a/lib/gitlab/google_code_import/importer.rb +++ b/lib/gitlab/google_code_import/importer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GoogleCodeImport class Importer diff --git a/lib/gitlab/google_code_import/project_creator.rb b/lib/gitlab/google_code_import/project_creator.rb index 326cfcaa8af..eaef85acb98 100644 --- a/lib/gitlab/google_code_import/project_creator.rb +++ b/lib/gitlab/google_code_import/project_creator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GoogleCodeImport class ProjectCreator diff --git a/lib/gitlab/google_code_import/repository.rb b/lib/gitlab/google_code_import/repository.rb index ad33fc2cad2..19627c8cd35 100644 --- a/lib/gitlab/google_code_import/repository.rb +++ b/lib/gitlab/google_code_import/repository.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GoogleCodeImport class Repository diff --git a/lib/gitlab/gpg/commit.rb b/lib/gitlab/gpg/commit.rb index 2bc081a6181..31bab20b044 100644 --- a/lib/gitlab/gpg/commit.rb +++ b/lib/gitlab/gpg/commit.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Gpg class Commit diff --git a/lib/gitlab/gpg/invalid_gpg_signature_updater.rb b/lib/gitlab/gpg/invalid_gpg_signature_updater.rb index 6972bd685f7..d892d27a917 100644 --- a/lib/gitlab/gpg/invalid_gpg_signature_updater.rb +++ b/lib/gitlab/gpg/invalid_gpg_signature_updater.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Gpg class InvalidGpgSignatureUpdater diff --git a/lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb b/lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb index 41004408dec..9bb1e8fc7a2 100644 --- a/lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb +++ b/lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module GrapeLogging module Formatters diff --git a/lib/gitlab/grape_logging/loggers/queue_duration_logger.rb b/lib/gitlab/grape_logging/loggers/queue_duration_logger.rb index 0adac79f25a..705e23adff2 100644 --- a/lib/gitlab/grape_logging/loggers/queue_duration_logger.rb +++ b/lib/gitlab/grape_logging/loggers/queue_duration_logger.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This grape_logging module (https://github.com/aserafin/grape_logging) makes it # possible to log how much time an API request was queued by Workhorse. module Gitlab diff --git a/lib/gitlab/grape_logging/loggers/user_logger.rb b/lib/gitlab/grape_logging/loggers/user_logger.rb index fa172861967..6caa6c715e7 100644 --- a/lib/gitlab/grape_logging/loggers/user_logger.rb +++ b/lib/gitlab/grape_logging/loggers/user_logger.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This grape_logging module (https://github.com/aserafin/grape_logging) makes it # possible to log the user who performed the Grape API action by retrieving # the user context from the request environment. diff --git a/lib/gitlab/graphql/authorize.rb b/lib/gitlab/graphql/authorize.rb index 93a903915b0..5e48bf9043d 100644 --- a/lib/gitlab/graphql/authorize.rb +++ b/lib/gitlab/graphql/authorize.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Graphql # Allow fields to declare permissions their objects must have. The field diff --git a/lib/gitlab/graphql/authorize/authorize_resource.rb b/lib/gitlab/graphql/authorize/authorize_resource.rb index 40895686a8a..a56c4f6368d 100644 --- a/lib/gitlab/graphql/authorize/authorize_resource.rb +++ b/lib/gitlab/graphql/authorize/authorize_resource.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Graphql module Authorize diff --git a/lib/gitlab/graphql/authorize/instrumentation.rb b/lib/gitlab/graphql/authorize/instrumentation.rb index 6cb8e617f62..d638d2b43ee 100644 --- a/lib/gitlab/graphql/authorize/instrumentation.rb +++ b/lib/gitlab/graphql/authorize/instrumentation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Graphql module Authorize diff --git a/lib/gitlab/graphql/connections.rb b/lib/gitlab/graphql/connections.rb index 2582ffeb2a8..fbccdfa7b08 100644 --- a/lib/gitlab/graphql/connections.rb +++ b/lib/gitlab/graphql/connections.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Graphql module Connections diff --git a/lib/gitlab/graphql/connections/keyset_connection.rb b/lib/gitlab/graphql/connections/keyset_connection.rb index 3c0d7e9784a..851054c0393 100644 --- a/lib/gitlab/graphql/connections/keyset_connection.rb +++ b/lib/gitlab/graphql/connections/keyset_connection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Graphql module Connections diff --git a/lib/gitlab/graphql/errors.rb b/lib/gitlab/graphql/errors.rb index f8c7ec24be1..fe74549e322 100644 --- a/lib/gitlab/graphql/errors.rb +++ b/lib/gitlab/graphql/errors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Graphql module Errors diff --git a/lib/gitlab/graphql/expose_permissions.rb b/lib/gitlab/graphql/expose_permissions.rb index e3779995406..365b7cca24f 100644 --- a/lib/gitlab/graphql/expose_permissions.rb +++ b/lib/gitlab/graphql/expose_permissions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Graphql module ExposePermissions diff --git a/lib/gitlab/graphql/present.rb b/lib/gitlab/graphql/present.rb index 2c7b64f1be9..7f69bf601d6 100644 --- a/lib/gitlab/graphql/present.rb +++ b/lib/gitlab/graphql/present.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Graphql module Present diff --git a/lib/gitlab/graphql/present/instrumentation.rb b/lib/gitlab/graphql/present/instrumentation.rb index f87fd147b15..ab03c40c22d 100644 --- a/lib/gitlab/graphql/present/instrumentation.rb +++ b/lib/gitlab/graphql/present/instrumentation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Graphql module Present diff --git a/lib/gitlab/graphql/variables.rb b/lib/gitlab/graphql/variables.rb index ffbaf65b512..b13ea37c21f 100644 --- a/lib/gitlab/graphql/variables.rb +++ b/lib/gitlab/graphql/variables.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Graphql class Variables diff --git a/lib/gitlab/graphs/commits.rb b/lib/gitlab/graphs/commits.rb index c4ffc19df09..66e1b2e78b4 100644 --- a/lib/gitlab/graphs/commits.rb +++ b/lib/gitlab/graphs/commits.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Graphs class Commits diff --git a/lib/gitlab/hashed_storage/migrator.rb b/lib/gitlab/hashed_storage/migrator.rb index 4edc251facb..1f29cf10cad 100644 --- a/lib/gitlab/hashed_storage/migrator.rb +++ b/lib/gitlab/hashed_storage/migrator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module HashedStorage # Hashed Storage Migrator diff --git a/lib/gitlab/hashed_storage/rake_helper.rb b/lib/gitlab/hashed_storage/rake_helper.rb index 22edd5f999d..38f552fab03 100644 --- a/lib/gitlab/hashed_storage/rake_helper.rb +++ b/lib/gitlab/hashed_storage/rake_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module HashedStorage module RakeHelper diff --git a/lib/gitlab/health_checks/base_abstract_check.rb b/lib/gitlab/health_checks/base_abstract_check.rb index 8b365dab185..1d31f59999c 100644 --- a/lib/gitlab/health_checks/base_abstract_check.rb +++ b/lib/gitlab/health_checks/base_abstract_check.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module HealthChecks module BaseAbstractCheck diff --git a/lib/gitlab/health_checks/db_check.rb b/lib/gitlab/health_checks/db_check.rb index 08495c0a59e..2bcd25cd3cc 100644 --- a/lib/gitlab/health_checks/db_check.rb +++ b/lib/gitlab/health_checks/db_check.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module HealthChecks class DbCheck diff --git a/lib/gitlab/health_checks/gitaly_check.rb b/lib/gitlab/health_checks/gitaly_check.rb index 1f623e0b6ec..898733fea5d 100644 --- a/lib/gitlab/health_checks/gitaly_check.rb +++ b/lib/gitlab/health_checks/gitaly_check.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module HealthChecks class GitalyCheck diff --git a/lib/gitlab/health_checks/metric.rb b/lib/gitlab/health_checks/metric.rb index d62d9136886..62a5216d159 100644 --- a/lib/gitlab/health_checks/metric.rb +++ b/lib/gitlab/health_checks/metric.rb @@ -1,3 +1,6 @@ -module Gitlab::HealthChecks # rubocop:disable Naming/FileName +# rubocop:disable Naming/FileName +# frozen_string_literal: true + +module Gitlab::HealthChecks Metric = Struct.new(:name, :value, :labels) end diff --git a/lib/gitlab/health_checks/prometheus_text_format.rb b/lib/gitlab/health_checks/prometheus_text_format.rb index b3c759b4730..2a8f9d31cd5 100644 --- a/lib/gitlab/health_checks/prometheus_text_format.rb +++ b/lib/gitlab/health_checks/prometheus_text_format.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module HealthChecks class PrometheusTextFormat diff --git a/lib/gitlab/health_checks/redis/cache_check.rb b/lib/gitlab/health_checks/redis/cache_check.rb index 2f6c4db12bb..0c8fe83893b 100644 --- a/lib/gitlab/health_checks/redis/cache_check.rb +++ b/lib/gitlab/health_checks/redis/cache_check.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module HealthChecks module Redis diff --git a/lib/gitlab/health_checks/redis/queues_check.rb b/lib/gitlab/health_checks/redis/queues_check.rb index 63d2882c5b2..b1e33b9f459 100644 --- a/lib/gitlab/health_checks/redis/queues_check.rb +++ b/lib/gitlab/health_checks/redis/queues_check.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module HealthChecks module Redis diff --git a/lib/gitlab/health_checks/redis/redis_check.rb b/lib/gitlab/health_checks/redis/redis_check.rb index 8ceb0a0aa46..f7e46fce134 100644 --- a/lib/gitlab/health_checks/redis/redis_check.rb +++ b/lib/gitlab/health_checks/redis/redis_check.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module HealthChecks module Redis diff --git a/lib/gitlab/health_checks/redis/shared_state_check.rb b/lib/gitlab/health_checks/redis/shared_state_check.rb index f1ea1ffe1be..285ac271929 100644 --- a/lib/gitlab/health_checks/redis/shared_state_check.rb +++ b/lib/gitlab/health_checks/redis/shared_state_check.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module HealthChecks module Redis diff --git a/lib/gitlab/health_checks/result.rb b/lib/gitlab/health_checks/result.rb index e323e2c9723..d32a6980eb8 100644 --- a/lib/gitlab/health_checks/result.rb +++ b/lib/gitlab/health_checks/result.rb @@ -1,3 +1,6 @@ -module Gitlab::HealthChecks # rubocop:disable Naming/FileName +# rubocop:disable Naming/FileName +# frozen_string_literal: true + +module Gitlab::HealthChecks Result = Struct.new(:success, :message, :labels) end diff --git a/lib/gitlab/health_checks/simple_abstract_check.rb b/lib/gitlab/health_checks/simple_abstract_check.rb index 96945ce5b20..3588260d6eb 100644 --- a/lib/gitlab/health_checks/simple_abstract_check.rb +++ b/lib/gitlab/health_checks/simple_abstract_check.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module HealthChecks module SimpleAbstractCheck diff --git a/lib/gitlab/hook_data/base_builder.rb b/lib/gitlab/hook_data/base_builder.rb index 1a91301e8be..d54175bce81 100644 --- a/lib/gitlab/hook_data/base_builder.rb +++ b/lib/gitlab/hook_data/base_builder.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module HookData class BaseBuilder diff --git a/lib/gitlab/hook_data/issuable_builder.rb b/lib/gitlab/hook_data/issuable_builder.rb index 65389835ad7..0803df65632 100644 --- a/lib/gitlab/hook_data/issuable_builder.rb +++ b/lib/gitlab/hook_data/issuable_builder.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module HookData class IssuableBuilder < BaseBuilder diff --git a/lib/gitlab/hook_data/issue_builder.rb b/lib/gitlab/hook_data/issue_builder.rb index dd63db969f6..c99353b9d49 100644 --- a/lib/gitlab/hook_data/issue_builder.rb +++ b/lib/gitlab/hook_data/issue_builder.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module HookData class IssueBuilder < BaseBuilder diff --git a/lib/gitlab/hook_data/merge_request_builder.rb b/lib/gitlab/hook_data/merge_request_builder.rb index 3aa6a4f3767..ad38e26e40a 100644 --- a/lib/gitlab/hook_data/merge_request_builder.rb +++ b/lib/gitlab/hook_data/merge_request_builder.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module HookData class MergeRequestBuilder < BaseBuilder diff --git a/lib/gitlab/hook_data/note_builder.rb b/lib/gitlab/hook_data/note_builder.rb index 81873e345d5..ae30ef6364b 100644 --- a/lib/gitlab/hook_data/note_builder.rb +++ b/lib/gitlab/hook_data/note_builder.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module HookData class NoteBuilder < BaseBuilder diff --git a/lib/gitlab/hook_data/wiki_page_builder.rb b/lib/gitlab/hook_data/wiki_page_builder.rb index 59c94a61cf2..67f06b1ca46 100644 --- a/lib/gitlab/hook_data/wiki_page_builder.rb +++ b/lib/gitlab/hook_data/wiki_page_builder.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module HookData class WikiPageBuilder < BaseBuilder diff --git a/lib/gitlab/http_io.rb b/lib/gitlab/http_io.rb index 9d7763fc5ac..e768b8adb12 100644 --- a/lib/gitlab/http_io.rb +++ b/lib/gitlab/http_io.rb @@ -161,14 +161,14 @@ module Gitlab ## # Note: If provider does not return content_range, then we set it as we requested # Provider: minio - # - When the file size is larger than requested Content-range, the Content-range is included in responces with Net::HTTPPartialContent 206 - # - When the file size is smaller than requested Content-range, the Content-range is included in responces with Net::HTTPPartialContent 206 + # - When the file size is larger than requested Content-range, the Content-range is included in responses with Net::HTTPPartialContent 206 + # - When the file size is smaller than requested Content-range, the Content-range is included in responses with Net::HTTPPartialContent 206 # Provider: AWS - # - When the file size is larger than requested Content-range, the Content-range is included in responces with Net::HTTPPartialContent 206 - # - When the file size is smaller than requested Content-range, the Content-range is included in responces with Net::HTTPPartialContent 206 + # - When the file size is larger than requested Content-range, the Content-range is included in responses with Net::HTTPPartialContent 206 + # - When the file size is smaller than requested Content-range, the Content-range is included in responses with Net::HTTPPartialContent 206 # Provider: GCS - # - When the file size is larger than requested Content-range, the Content-range is included in responces with Net::HTTPPartialContent 206 - # - When the file size is smaller than requested Content-range, the Content-range is included in responces with Net::HTTPOK 200 + # - When the file size is larger than requested Content-range, the Content-range is included in responses with Net::HTTPPartialContent 206 + # - When the file size is smaller than requested Content-range, the Content-range is included in responses with Net::HTTPOK 200 @chunk_range ||= (chunk_start...(chunk_start + @chunk.bytesize)) end diff --git a/lib/gitlab/i18n/metadata_entry.rb b/lib/gitlab/i18n/metadata_entry.rb index 36fc1bcdcb7..3764e379681 100644 --- a/lib/gitlab/i18n/metadata_entry.rb +++ b/lib/gitlab/i18n/metadata_entry.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module I18n class MetadataEntry diff --git a/lib/gitlab/i18n/po_linter.rb b/lib/gitlab/i18n/po_linter.rb index d8e7269a2c2..644ef8c8589 100644 --- a/lib/gitlab/i18n/po_linter.rb +++ b/lib/gitlab/i18n/po_linter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module I18n class PoLinter diff --git a/lib/gitlab/i18n/translation_entry.rb b/lib/gitlab/i18n/translation_entry.rb index 54adb98f42d..19c10b2e402 100644 --- a/lib/gitlab/i18n/translation_entry.rb +++ b/lib/gitlab/i18n/translation_entry.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module I18n class TranslationEntry diff --git a/lib/gitlab/import/logger.rb b/lib/gitlab/import/logger.rb index 8414954d141..ab3e822a4e9 100644 --- a/lib/gitlab/import/logger.rb +++ b/lib/gitlab/import/logger.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Import class Logger < ::Gitlab::JsonLogger diff --git a/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy.rb b/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy.rb index 7cbf653dd97..d39b6fe5955 100644 --- a/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy.rb +++ b/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport module AfterExportStrategies diff --git a/lib/gitlab/import_export/after_export_strategies/download_notification_strategy.rb b/lib/gitlab/import_export/after_export_strategies/download_notification_strategy.rb index 4371a7eff56..1b391314a74 100644 --- a/lib/gitlab/import_export/after_export_strategies/download_notification_strategy.rb +++ b/lib/gitlab/import_export/after_export_strategies/download_notification_strategy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport module AfterExportStrategies diff --git a/lib/gitlab/import_export/after_export_strategies/web_upload_strategy.rb b/lib/gitlab/import_export/after_export_strategies/web_upload_strategy.rb index 4f29bdcea2c..b30900f7c61 100644 --- a/lib/gitlab/import_export/after_export_strategies/web_upload_strategy.rb +++ b/lib/gitlab/import_export/after_export_strategies/web_upload_strategy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport module AfterExportStrategies diff --git a/lib/gitlab/import_export/after_export_strategy_builder.rb b/lib/gitlab/import_export/after_export_strategy_builder.rb index 7eabcae2380..37394f46a99 100644 --- a/lib/gitlab/import_export/after_export_strategy_builder.rb +++ b/lib/gitlab/import_export/after_export_strategy_builder.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class AfterExportStrategyBuilder diff --git a/lib/gitlab/import_export/attribute_cleaner.rb b/lib/gitlab/import_export/attribute_cleaner.rb index 7c9fc5c15bb..93b37b7bc5f 100644 --- a/lib/gitlab/import_export/attribute_cleaner.rb +++ b/lib/gitlab/import_export/attribute_cleaner.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class AttributeCleaner diff --git a/lib/gitlab/import_export/attributes_finder.rb b/lib/gitlab/import_export/attributes_finder.rb index 0c8fda07294..409243e68a5 100644 --- a/lib/gitlab/import_export/attributes_finder.rb +++ b/lib/gitlab/import_export/attributes_finder.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class AttributesFinder diff --git a/lib/gitlab/import_export/avatar_restorer.rb b/lib/gitlab/import_export/avatar_restorer.rb index 17796430811..be1b97bd7a7 100644 --- a/lib/gitlab/import_export/avatar_restorer.rb +++ b/lib/gitlab/import_export/avatar_restorer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class AvatarRestorer diff --git a/lib/gitlab/import_export/avatar_saver.rb b/lib/gitlab/import_export/avatar_saver.rb index 6ffebf83dd2..47ca898c690 100644 --- a/lib/gitlab/import_export/avatar_saver.rb +++ b/lib/gitlab/import_export/avatar_saver.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class AvatarSaver diff --git a/lib/gitlab/import_export/command_line_util.rb b/lib/gitlab/import_export/command_line_util.rb index 3adc44f8044..c9e2a6a78d9 100644 --- a/lib/gitlab/import_export/command_line_util.rb +++ b/lib/gitlab/import_export/command_line_util.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport module CommandLineUtil diff --git a/lib/gitlab/import_export/error.rb b/lib/gitlab/import_export/error.rb index 788eedf2686..454dc778b6b 100644 --- a/lib/gitlab/import_export/error.rb +++ b/lib/gitlab/import_export/error.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport Error = Class.new(StandardError) diff --git a/lib/gitlab/import_export/file_importer.rb b/lib/gitlab/import_export/file_importer.rb index 7fd66b4e244..05432f433e7 100644 --- a/lib/gitlab/import_export/file_importer.rb +++ b/lib/gitlab/import_export/file_importer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class FileImporter diff --git a/lib/gitlab/import_export/group_project_object_builder.rb b/lib/gitlab/import_export/group_project_object_builder.rb index 6c2af770119..1c62591ed5a 100644 --- a/lib/gitlab/import_export/group_project_object_builder.rb +++ b/lib/gitlab/import_export/group_project_object_builder.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport # Given a class, it finds or creates a new object diff --git a/lib/gitlab/import_export/hash_util.rb b/lib/gitlab/import_export/hash_util.rb index d4adeeb3797..b6ce89a973b 100644 --- a/lib/gitlab/import_export/hash_util.rb +++ b/lib/gitlab/import_export/hash_util.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class HashUtil diff --git a/lib/gitlab/import_export/import_export.yml b/lib/gitlab/import_export/import_export.yml index 9790818ecaf..b40eac3de9a 100644 --- a/lib/gitlab/import_export/import_export.yml +++ b/lib/gitlab/import_export/import_export.yml @@ -154,6 +154,8 @@ excluded_attributes: - :encrypted_token_iv - :encrypted_url - :encrypted_url_iv + services: + - :template methods: labels: diff --git a/lib/gitlab/import_export/importer.rb b/lib/gitlab/import_export/importer.rb index 72d5b9b830c..767f1b5de0e 100644 --- a/lib/gitlab/import_export/importer.rb +++ b/lib/gitlab/import_export/importer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class Importer diff --git a/lib/gitlab/import_export/json_hash_builder.rb b/lib/gitlab/import_export/json_hash_builder.rb index b48f63bcd7e..477499e1688 100644 --- a/lib/gitlab/import_export/json_hash_builder.rb +++ b/lib/gitlab/import_export/json_hash_builder.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport # Generates a hash that conforms with http://apidock.com/rails/Hash/to_json diff --git a/lib/gitlab/import_export/lfs_restorer.rb b/lib/gitlab/import_export/lfs_restorer.rb index b28c3c161b7..345c7880e30 100644 --- a/lib/gitlab/import_export/lfs_restorer.rb +++ b/lib/gitlab/import_export/lfs_restorer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class LfsRestorer diff --git a/lib/gitlab/import_export/lfs_saver.rb b/lib/gitlab/import_export/lfs_saver.rb index 29410e2331c..954f6f00078 100644 --- a/lib/gitlab/import_export/lfs_saver.rb +++ b/lib/gitlab/import_export/lfs_saver.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class LfsSaver diff --git a/lib/gitlab/import_export/members_mapper.rb b/lib/gitlab/import_export/members_mapper.rb index bcbaf00e11b..6be95a16513 100644 --- a/lib/gitlab/import_export/members_mapper.rb +++ b/lib/gitlab/import_export/members_mapper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class MembersMapper diff --git a/lib/gitlab/import_export/merge_request_parser.rb b/lib/gitlab/import_export/merge_request_parser.rb index 62a1833b39c..040a70d6775 100644 --- a/lib/gitlab/import_export/merge_request_parser.rb +++ b/lib/gitlab/import_export/merge_request_parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class MergeRequestParser diff --git a/lib/gitlab/import_export/project_tree_restorer.rb b/lib/gitlab/import_export/project_tree_restorer.rb index 99581eb0416..8cd4efd91cc 100644 --- a/lib/gitlab/import_export/project_tree_restorer.rb +++ b/lib/gitlab/import_export/project_tree_restorer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class ProjectTreeRestorer diff --git a/lib/gitlab/import_export/project_tree_saver.rb b/lib/gitlab/import_export/project_tree_saver.rb index 5510c0b8b2f..29f2dc80813 100644 --- a/lib/gitlab/import_export/project_tree_saver.rb +++ b/lib/gitlab/import_export/project_tree_saver.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class ProjectTreeSaver diff --git a/lib/gitlab/import_export/reader.rb b/lib/gitlab/import_export/reader.rb index e621c40fc7a..bc0d18e03fa 100644 --- a/lib/gitlab/import_export/reader.rb +++ b/lib/gitlab/import_export/reader.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class Reader diff --git a/lib/gitlab/import_export/relation_factory.rb b/lib/gitlab/import_export/relation_factory.rb index 2486b1e4921..097c7653754 100644 --- a/lib/gitlab/import_export/relation_factory.rb +++ b/lib/gitlab/import_export/relation_factory.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class RelationFactory @@ -211,7 +213,7 @@ module Gitlab def update_note_for_missing_author(author_name) @relation_hash['note'] = '*Blank note*' if @relation_hash['note'].blank? - @relation_hash['note'] += missing_author_note(@relation_hash['updated_at'], author_name) + @relation_hash['note'] = "#{@relation_hash['note']}#{missing_author_note(@relation_hash['updated_at'], author_name)}" end def admin_user? diff --git a/lib/gitlab/import_export/repo_restorer.rb b/lib/gitlab/import_export/repo_restorer.rb index 5a9bbceac67..921a06b4023 100644 --- a/lib/gitlab/import_export/repo_restorer.rb +++ b/lib/gitlab/import_export/repo_restorer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class RepoRestorer diff --git a/lib/gitlab/import_export/repo_saver.rb b/lib/gitlab/import_export/repo_saver.rb index 0c224bd1971..a60618dfcec 100644 --- a/lib/gitlab/import_export/repo_saver.rb +++ b/lib/gitlab/import_export/repo_saver.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class RepoSaver diff --git a/lib/gitlab/import_export/saver.rb b/lib/gitlab/import_export/saver.rb index 59a74083395..72f575db095 100644 --- a/lib/gitlab/import_export/saver.rb +++ b/lib/gitlab/import_export/saver.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class Saver diff --git a/lib/gitlab/import_export/shared.rb b/lib/gitlab/import_export/shared.rb index 6d7c36ce38b..c13e6c1d83b 100644 --- a/lib/gitlab/import_export/shared.rb +++ b/lib/gitlab/import_export/shared.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class Shared diff --git a/lib/gitlab/import_export/statistics_restorer.rb b/lib/gitlab/import_export/statistics_restorer.rb index bcdd9c12c85..3fafb01c37c 100644 --- a/lib/gitlab/import_export/statistics_restorer.rb +++ b/lib/gitlab/import_export/statistics_restorer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class StatisticsRestorer diff --git a/lib/gitlab/import_export/uploads_manager.rb b/lib/gitlab/import_export/uploads_manager.rb index 8511319cb1c..474e9d45566 100644 --- a/lib/gitlab/import_export/uploads_manager.rb +++ b/lib/gitlab/import_export/uploads_manager.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class UploadsManager diff --git a/lib/gitlab/import_export/uploads_restorer.rb b/lib/gitlab/import_export/uploads_restorer.rb index b4313ff4cb4..5f422dcbefa 100644 --- a/lib/gitlab/import_export/uploads_restorer.rb +++ b/lib/gitlab/import_export/uploads_restorer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class UploadsRestorer < UploadsSaver diff --git a/lib/gitlab/import_export/uploads_saver.rb b/lib/gitlab/import_export/uploads_saver.rb index 0275f686c5e..be1066c30b2 100644 --- a/lib/gitlab/import_export/uploads_saver.rb +++ b/lib/gitlab/import_export/uploads_saver.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class UploadsSaver diff --git a/lib/gitlab/import_export/version_checker.rb b/lib/gitlab/import_export/version_checker.rb index bd3c3ee3b2f..6d978d00ea5 100644 --- a/lib/gitlab/import_export/version_checker.rb +++ b/lib/gitlab/import_export/version_checker.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class VersionChecker diff --git a/lib/gitlab/import_export/version_saver.rb b/lib/gitlab/import_export/version_saver.rb index 7cf88298642..8230c0f1e77 100644 --- a/lib/gitlab/import_export/version_saver.rb +++ b/lib/gitlab/import_export/version_saver.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class VersionSaver diff --git a/lib/gitlab/import_export/wiki_repo_saver.rb b/lib/gitlab/import_export/wiki_repo_saver.rb index 2fd62c0fc7b..7303bcf61a4 100644 --- a/lib/gitlab/import_export/wiki_repo_saver.rb +++ b/lib/gitlab/import_export/wiki_repo_saver.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class WikiRepoSaver < RepoSaver diff --git a/lib/gitlab/import_export/wiki_restorer.rb b/lib/gitlab/import_export/wiki_restorer.rb index f33bfb332ab..28b5e7449cd 100644 --- a/lib/gitlab/import_export/wiki_restorer.rb +++ b/lib/gitlab/import_export/wiki_restorer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ImportExport class WikiRestorer < RepoRestorer diff --git a/lib/gitlab/kubernetes/config_map.rb b/lib/gitlab/kubernetes/config_map.rb index 9e55dae137c..0bcaaa03974 100644 --- a/lib/gitlab/kubernetes/config_map.rb +++ b/lib/gitlab/kubernetes/config_map.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Kubernetes class ConfigMap diff --git a/lib/gitlab/kubernetes/helm.rb b/lib/gitlab/kubernetes/helm.rb index 1cd4f9e17b7..03d38ec78fd 100644 --- a/lib/gitlab/kubernetes/helm.rb +++ b/lib/gitlab/kubernetes/helm.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + module Gitlab module Kubernetes module Helm - HELM_VERSION = '2.7.2'.freeze + HELM_VERSION = '2.11.0'.freeze KUBECTL_VERSION = '1.11.0'.freeze NAMESPACE = 'gitlab-managed-apps'.freeze SERVICE_ACCOUNT = 'tiller'.freeze diff --git a/lib/gitlab/kubernetes/helm/api.rb b/lib/gitlab/kubernetes/helm/api.rb index e21bc531444..fd3d187cbc3 100644 --- a/lib/gitlab/kubernetes/helm/api.rb +++ b/lib/gitlab/kubernetes/helm/api.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Kubernetes module Helm @@ -54,7 +56,11 @@ module Gitlab def create_config_map(command) command.config_map_resource.tap do |config_map_resource| - kubeclient.create_config_map(config_map_resource) + if config_map_exists?(config_map_resource) + kubeclient.update_config_map(config_map_resource) + else + kubeclient.create_config_map(config_map_resource) + end end end @@ -88,23 +94,21 @@ module Gitlab end end - def service_account_exists?(resource) - resource_exists? do - kubeclient.get_service_account(resource.metadata.name, resource.metadata.namespace) - end + def config_map_exists?(resource) + kubeclient.get_config_map(resource.metadata.name, resource.metadata.namespace) + rescue ::Kubeclient::ResourceNotFoundError + false end - def cluster_role_binding_exists?(resource) - resource_exists? do - kubeclient.get_cluster_role_binding(resource.metadata.name) - end + def service_account_exists?(resource) + kubeclient.get_service_account(resource.metadata.name, resource.metadata.namespace) + rescue ::Kubeclient::ResourceNotFoundError + false end - def resource_exists? - yield - rescue ::Kubeclient::HttpError => e - raise e unless e.error_code == 404 - + def cluster_role_binding_exists?(resource) + kubeclient.get_cluster_role_binding(resource.metadata.name) + rescue ::Kubeclient::ResourceNotFoundError false end end diff --git a/lib/gitlab/kubernetes/helm/base_command.rb b/lib/gitlab/kubernetes/helm/base_command.rb index f2ce24fefa1..2bcb428b25d 100644 --- a/lib/gitlab/kubernetes/helm/base_command.rb +++ b/lib/gitlab/kubernetes/helm/base_command.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Kubernetes module Helm diff --git a/lib/gitlab/kubernetes/helm/client_command.rb b/lib/gitlab/kubernetes/helm/client_command.rb new file mode 100644 index 00000000000..9940272a8bf --- /dev/null +++ b/lib/gitlab/kubernetes/helm/client_command.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module Gitlab + module Kubernetes + module Helm + module ClientCommand + def init_command + # Here we are always upgrading to the latest version of Tiller when + # installing an app. We ensure the helm version stored in the + # database is correct by also updating this after transition to + # :installed,:updated in Clusters::Concerns::ApplicationStatus + 'helm init --upgrade' + end + + def wait_for_tiller_command + # This is necessary to give Tiller time to restart after upgrade. + # Ideally we'd be able to use --wait but cannot because of + # https://github.com/helm/helm/issues/4855 + 'for i in $(seq 1 30); do helm version && break; sleep 1s; echo "Retrying ($i)..."; done' + end + + def repository_command + ['helm', 'repo', 'add', name, repository].shelljoin if repository + end + end + end + end +end diff --git a/lib/gitlab/kubernetes/helm/init_command.rb b/lib/gitlab/kubernetes/helm/init_command.rb index 6691080deca..88ed8572ffc 100644 --- a/lib/gitlab/kubernetes/helm/init_command.rb +++ b/lib/gitlab/kubernetes/helm/init_command.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Kubernetes module Helm diff --git a/lib/gitlab/kubernetes/helm/install_command.rb b/lib/gitlab/kubernetes/helm/install_command.rb index ff1c1657b98..961485005f7 100644 --- a/lib/gitlab/kubernetes/helm/install_command.rb +++ b/lib/gitlab/kubernetes/helm/install_command.rb @@ -1,8 +1,11 @@ +# frozen_string_literal: true + module Gitlab module Kubernetes module Helm class InstallCommand include BaseCommand + include ClientCommand attr_reader :name, :files, :chart, :version, :repository, :preinstall, :postinstall @@ -20,6 +23,7 @@ module Gitlab def generate_script super + [ init_command, + wait_for_tiller_command, repository_command, repository_update_command, preinstall_command, @@ -34,14 +38,6 @@ module Gitlab private - def init_command - 'helm init --client-only' - end - - def repository_command - ['helm', 'repo', 'add', name, repository].shelljoin if repository - end - def repository_update_command 'helm repo update' if repository end diff --git a/lib/gitlab/kubernetes/helm/pod.rb b/lib/gitlab/kubernetes/helm/pod.rb index e9c621d96f0..75484f80070 100644 --- a/lib/gitlab/kubernetes/helm/pod.rb +++ b/lib/gitlab/kubernetes/helm/pod.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Kubernetes module Helm diff --git a/lib/gitlab/kubernetes/helm/upgrade_command.rb b/lib/gitlab/kubernetes/helm/upgrade_command.rb index b36315f7a82..9daffc138b5 100644 --- a/lib/gitlab/kubernetes/helm/upgrade_command.rb +++ b/lib/gitlab/kubernetes/helm/upgrade_command.rb @@ -5,6 +5,7 @@ module Gitlab module Helm class UpgradeCommand include BaseCommand + include ClientCommand attr_reader :name, :chart, :version, :repository, :files @@ -20,6 +21,7 @@ module Gitlab def generate_script super + [ init_command, + wait_for_tiller_command, repository_command, script_command ].compact.join("\n") @@ -35,14 +37,6 @@ module Gitlab private - def init_command - 'helm init --client-only' - end - - def repository_command - "helm repo add #{name} #{repository}" if repository - end - def script_command upgrade_flags = "#{optional_version_flag}#{optional_tls_flags}" \ " --reset-values" \ diff --git a/lib/gitlab/kubernetes/kube_client.rb b/lib/gitlab/kubernetes/kube_client.rb index f266177bec1..b947f6b551e 100644 --- a/lib/gitlab/kubernetes/kube_client.rb +++ b/lib/gitlab/kubernetes/kube_client.rb @@ -16,7 +16,8 @@ module Gitlab SUPPORTED_API_GROUPS = { core: { group: 'api', version: 'v1' }, rbac: { group: 'apis/rbac.authorization.k8s.io', version: 'v1' }, - extensions: { group: 'apis/extensions', version: 'v1beta1' } + extensions: { group: 'apis/extensions', version: 'v1beta1' }, + knative: { group: 'apis/serving.knative.dev', version: 'v1alpha1' } }.freeze SUPPORTED_API_GROUPS.each do |name, params| diff --git a/lib/gitlab/kubernetes/namespace.rb b/lib/gitlab/kubernetes/namespace.rb index e6ff6160ab9..919f19c86d7 100644 --- a/lib/gitlab/kubernetes/namespace.rb +++ b/lib/gitlab/kubernetes/namespace.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Kubernetes class Namespace @@ -10,9 +12,7 @@ module Gitlab def exists? @client.get_namespace(name) - rescue ::Kubeclient::HttpError => ke - raise ke unless ke.error_code == 404 - + rescue ::Kubeclient::ResourceNotFoundError false end diff --git a/lib/gitlab/kubernetes/pod.rb b/lib/gitlab/kubernetes/pod.rb index f3842cdf762..81317e532b2 100644 --- a/lib/gitlab/kubernetes/pod.rb +++ b/lib/gitlab/kubernetes/pod.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Kubernetes module Pod diff --git a/lib/gitlab/legacy_github_import/base_formatter.rb b/lib/gitlab/legacy_github_import/base_formatter.rb index 11d1300e51e..0b19cf742ed 100644 --- a/lib/gitlab/legacy_github_import/base_formatter.rb +++ b/lib/gitlab/legacy_github_import/base_formatter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module LegacyGithubImport class BaseFormatter diff --git a/lib/gitlab/legacy_github_import/branch_formatter.rb b/lib/gitlab/legacy_github_import/branch_formatter.rb index 80fe1d67209..1177751457f 100644 --- a/lib/gitlab/legacy_github_import/branch_formatter.rb +++ b/lib/gitlab/legacy_github_import/branch_formatter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module LegacyGithubImport class BranchFormatter < BaseFormatter diff --git a/lib/gitlab/legacy_github_import/client.rb b/lib/gitlab/legacy_github_import/client.rb index d8ed0ebca9d..bc952147667 100644 --- a/lib/gitlab/legacy_github_import/client.rb +++ b/lib/gitlab/legacy_github_import/client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module LegacyGithubImport class Client diff --git a/lib/gitlab/legacy_github_import/comment_formatter.rb b/lib/gitlab/legacy_github_import/comment_formatter.rb index d2c7a8ae9f4..d83cc4f6b3c 100644 --- a/lib/gitlab/legacy_github_import/comment_formatter.rb +++ b/lib/gitlab/legacy_github_import/comment_formatter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module LegacyGithubImport class CommentFormatter < BaseFormatter diff --git a/lib/gitlab/legacy_github_import/importer.rb b/lib/gitlab/legacy_github_import/importer.rb index c5bde681365..43695451b87 100644 --- a/lib/gitlab/legacy_github_import/importer.rb +++ b/lib/gitlab/legacy_github_import/importer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module LegacyGithubImport class Importer diff --git a/lib/gitlab/legacy_github_import/issuable_formatter.rb b/lib/gitlab/legacy_github_import/issuable_formatter.rb index 7db4a54267e..1a0aefbbd62 100644 --- a/lib/gitlab/legacy_github_import/issuable_formatter.rb +++ b/lib/gitlab/legacy_github_import/issuable_formatter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module LegacyGithubImport class IssuableFormatter < BaseFormatter diff --git a/lib/gitlab/legacy_github_import/issue_formatter.rb b/lib/gitlab/legacy_github_import/issue_formatter.rb index 4c8825ccf19..2f46e2e30d1 100644 --- a/lib/gitlab/legacy_github_import/issue_formatter.rb +++ b/lib/gitlab/legacy_github_import/issue_formatter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module LegacyGithubImport class IssueFormatter < IssuableFormatter diff --git a/lib/gitlab/legacy_github_import/label_formatter.rb b/lib/gitlab/legacy_github_import/label_formatter.rb index e9663650903..89200e794d8 100644 --- a/lib/gitlab/legacy_github_import/label_formatter.rb +++ b/lib/gitlab/legacy_github_import/label_formatter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module LegacyGithubImport class LabelFormatter < BaseFormatter diff --git a/lib/gitlab/legacy_github_import/milestone_formatter.rb b/lib/gitlab/legacy_github_import/milestone_formatter.rb index a565294384d..2fe1b4258d3 100644 --- a/lib/gitlab/legacy_github_import/milestone_formatter.rb +++ b/lib/gitlab/legacy_github_import/milestone_formatter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module LegacyGithubImport class MilestoneFormatter < BaseFormatter diff --git a/lib/gitlab/legacy_github_import/project_creator.rb b/lib/gitlab/legacy_github_import/project_creator.rb index 5e96eb16754..ca1a1b8e9bd 100644 --- a/lib/gitlab/legacy_github_import/project_creator.rb +++ b/lib/gitlab/legacy_github_import/project_creator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module LegacyGithubImport class ProjectCreator diff --git a/lib/gitlab/legacy_github_import/pull_request_formatter.rb b/lib/gitlab/legacy_github_import/pull_request_formatter.rb index 94c2e99066a..5b847f13d4a 100644 --- a/lib/gitlab/legacy_github_import/pull_request_formatter.rb +++ b/lib/gitlab/legacy_github_import/pull_request_formatter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module LegacyGithubImport class PullRequestFormatter < IssuableFormatter diff --git a/lib/gitlab/legacy_github_import/release_formatter.rb b/lib/gitlab/legacy_github_import/release_formatter.rb index 3ed9d4f76da..8c0c17780ca 100644 --- a/lib/gitlab/legacy_github_import/release_formatter.rb +++ b/lib/gitlab/legacy_github_import/release_formatter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module LegacyGithubImport class ReleaseFormatter < BaseFormatter diff --git a/lib/gitlab/legacy_github_import/user_formatter.rb b/lib/gitlab/legacy_github_import/user_formatter.rb index 3794380e2d0..ec0e221b1ff 100644 --- a/lib/gitlab/legacy_github_import/user_formatter.rb +++ b/lib/gitlab/legacy_github_import/user_formatter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module LegacyGithubImport class UserFormatter diff --git a/lib/gitlab/legacy_github_import/wiki_formatter.rb b/lib/gitlab/legacy_github_import/wiki_formatter.rb index 27f45875c7c..ea52be5ee0f 100644 --- a/lib/gitlab/legacy_github_import/wiki_formatter.rb +++ b/lib/gitlab/legacy_github_import/wiki_formatter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module LegacyGithubImport class WikiFormatter diff --git a/lib/gitlab/manifest_import/manifest.rb b/lib/gitlab/manifest_import/manifest.rb index 4d6034fb956..7208fe5bbc5 100644 --- a/lib/gitlab/manifest_import/manifest.rb +++ b/lib/gitlab/manifest_import/manifest.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Class to parse manifest file and build a list of repositories for import # # <manifest> @@ -63,7 +65,7 @@ module Gitlab end def repository_url(name) - URI.join(remote, name).to_s + Gitlab::Utils.append_path(remote, name) end def remote diff --git a/lib/gitlab/manifest_import/project_creator.rb b/lib/gitlab/manifest_import/project_creator.rb index b5967c93735..837d65e5f7c 100644 --- a/lib/gitlab/manifest_import/project_creator.rb +++ b/lib/gitlab/manifest_import/project_creator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module ManifestImport class ProjectCreator diff --git a/lib/gitlab/metrics/background_transaction.rb b/lib/gitlab/metrics/background_transaction.rb index 5919ebb1493..fe1722b1095 100644 --- a/lib/gitlab/metrics/background_transaction.rb +++ b/lib/gitlab/metrics/background_transaction.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics class BackgroundTransaction < Transaction diff --git a/lib/gitlab/metrics/delta.rb b/lib/gitlab/metrics/delta.rb index bcf28eed84d..ab2d9e46390 100644 --- a/lib/gitlab/metrics/delta.rb +++ b/lib/gitlab/metrics/delta.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics # Class for calculating the difference between two numeric values. diff --git a/lib/gitlab/metrics/influx_db.rb b/lib/gitlab/metrics/influx_db.rb index ce9d3ec3de4..1359e973590 100644 --- a/lib/gitlab/metrics/influx_db.rb +++ b/lib/gitlab/metrics/influx_db.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics module InfluxDb diff --git a/lib/gitlab/metrics/instrumentation.rb b/lib/gitlab/metrics/instrumentation.rb index 023e9963493..651e241362c 100644 --- a/lib/gitlab/metrics/instrumentation.rb +++ b/lib/gitlab/metrics/instrumentation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics # Module for instrumenting methods. diff --git a/lib/gitlab/metrics/method_call.rb b/lib/gitlab/metrics/method_call.rb index f3290e3149c..85438011cb9 100644 --- a/lib/gitlab/metrics/method_call.rb +++ b/lib/gitlab/metrics/method_call.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics # Class for tracking timing information about method calls diff --git a/lib/gitlab/metrics/methods.rb b/lib/gitlab/metrics/methods.rb index f79eb0cd1bf..447d03bfca4 100644 --- a/lib/gitlab/metrics/methods.rb +++ b/lib/gitlab/metrics/methods.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # rubocop:disable Style/ClassVars module Gitlab diff --git a/lib/gitlab/metrics/methods/metric_options.rb b/lib/gitlab/metrics/methods/metric_options.rb index 70e122d4e15..8e6ceb74c09 100644 --- a/lib/gitlab/metrics/methods/metric_options.rb +++ b/lib/gitlab/metrics/methods/metric_options.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics module Methods diff --git a/lib/gitlab/metrics/metric.rb b/lib/gitlab/metrics/metric.rb index bd0afe53c51..9e4d70a71ff 100644 --- a/lib/gitlab/metrics/metric.rb +++ b/lib/gitlab/metrics/metric.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics # Class for storing details of a single metric (label, value, etc). diff --git a/lib/gitlab/metrics/null_metric.rb b/lib/gitlab/metrics/null_metric.rb index aabada5c21a..7dbd2a1f8e3 100644 --- a/lib/gitlab/metrics/null_metric.rb +++ b/lib/gitlab/metrics/null_metric.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics # Mocks ::Prometheus::Client::Metric and all derived metrics diff --git a/lib/gitlab/metrics/prometheus.rb b/lib/gitlab/metrics/prometheus.rb index d41a855bff1..cab1edab48f 100644 --- a/lib/gitlab/metrics/prometheus.rb +++ b/lib/gitlab/metrics/prometheus.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'prometheus/client' module Gitlab diff --git a/lib/gitlab/metrics/rack_middleware.rb b/lib/gitlab/metrics/rack_middleware.rb index 2d45765df3f..9aa97515961 100644 --- a/lib/gitlab/metrics/rack_middleware.rb +++ b/lib/gitlab/metrics/rack_middleware.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics # Rack middleware for tracking Rails and Grape requests. diff --git a/lib/gitlab/metrics/requests_rack_middleware.rb b/lib/gitlab/metrics/requests_rack_middleware.rb index 0dc19f31d03..74c956ab5af 100644 --- a/lib/gitlab/metrics/requests_rack_middleware.rb +++ b/lib/gitlab/metrics/requests_rack_middleware.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics class RequestsRackMiddleware diff --git a/lib/gitlab/metrics/samplers/base_sampler.rb b/lib/gitlab/metrics/samplers/base_sampler.rb index 37f90c4673d..6a062e93f0f 100644 --- a/lib/gitlab/metrics/samplers/base_sampler.rb +++ b/lib/gitlab/metrics/samplers/base_sampler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'logger' module Gitlab diff --git a/lib/gitlab/metrics/samplers/influx_sampler.rb b/lib/gitlab/metrics/samplers/influx_sampler.rb index ad97632e4eb..c4c38b23a55 100644 --- a/lib/gitlab/metrics/samplers/influx_sampler.rb +++ b/lib/gitlab/metrics/samplers/influx_sampler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics module Samplers diff --git a/lib/gitlab/metrics/samplers/ruby_sampler.rb b/lib/gitlab/metrics/samplers/ruby_sampler.rb index 7b2b3bedf04..232a58a7d69 100644 --- a/lib/gitlab/metrics/samplers/ruby_sampler.rb +++ b/lib/gitlab/metrics/samplers/ruby_sampler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'prometheus/client/support/unicorn' module Gitlab diff --git a/lib/gitlab/metrics/samplers/unicorn_sampler.rb b/lib/gitlab/metrics/samplers/unicorn_sampler.rb index ea325651fbb..4c4ec026823 100644 --- a/lib/gitlab/metrics/samplers/unicorn_sampler.rb +++ b/lib/gitlab/metrics/samplers/unicorn_sampler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics module Samplers diff --git a/lib/gitlab/metrics/sidekiq_metrics_exporter.rb b/lib/gitlab/metrics/sidekiq_metrics_exporter.rb index 47b4af5d649..56e106b9612 100644 --- a/lib/gitlab/metrics/sidekiq_metrics_exporter.rb +++ b/lib/gitlab/metrics/sidekiq_metrics_exporter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'webrick' require 'prometheus/client/rack/exporter' diff --git a/lib/gitlab/metrics/sidekiq_middleware.rb b/lib/gitlab/metrics/sidekiq_middleware.rb index df4bdf16847..0b4485feea9 100644 --- a/lib/gitlab/metrics/sidekiq_middleware.rb +++ b/lib/gitlab/metrics/sidekiq_middleware.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics # Sidekiq middleware for tracking jobs. diff --git a/lib/gitlab/metrics/subscribers/action_view.rb b/lib/gitlab/metrics/subscribers/action_view.rb index b600e8a2a50..c068f8017fd 100644 --- a/lib/gitlab/metrics/subscribers/action_view.rb +++ b/lib/gitlab/metrics/subscribers/action_view.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics module Subscribers diff --git a/lib/gitlab/metrics/subscribers/active_record.rb b/lib/gitlab/metrics/subscribers/active_record.rb index 04107296ae3..a02dd850582 100644 --- a/lib/gitlab/metrics/subscribers/active_record.rb +++ b/lib/gitlab/metrics/subscribers/active_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics module Subscribers diff --git a/lib/gitlab/metrics/subscribers/rails_cache.rb b/lib/gitlab/metrics/subscribers/rails_cache.rb index 250897a79c2..f633e1a9d7c 100644 --- a/lib/gitlab/metrics/subscribers/rails_cache.rb +++ b/lib/gitlab/metrics/subscribers/rails_cache.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics module Subscribers diff --git a/lib/gitlab/metrics/system.rb b/lib/gitlab/metrics/system.rb index e60e245cf89..426496855e3 100644 --- a/lib/gitlab/metrics/system.rb +++ b/lib/gitlab/metrics/system.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics # Module for gathering system/process statistics such as the memory usage. diff --git a/lib/gitlab/metrics/transaction.rb b/lib/gitlab/metrics/transaction.rb index 9f903e96585..468d7cb56fc 100644 --- a/lib/gitlab/metrics/transaction.rb +++ b/lib/gitlab/metrics/transaction.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics # Class for storing metrics information of a single transaction. diff --git a/lib/gitlab/metrics/web_transaction.rb b/lib/gitlab/metrics/web_transaction.rb index 723ca576aab..b2a43d46fb2 100644 --- a/lib/gitlab/metrics/web_transaction.rb +++ b/lib/gitlab/metrics/web_transaction.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Metrics class WebTransaction < Transaction @@ -40,7 +42,7 @@ module Gitlab # increasing the cardinality of our metrics, we limit the number of # possible suffixes. if suffix && ALLOWED_SUFFIXES.include?(suffix) - action += ".#{suffix}" + action = "#{action}.#{suffix}" end { controller: controller.class.name, action: action } diff --git a/lib/gitlab/middleware/go.rb b/lib/gitlab/middleware/go.rb index 1fd8f147b44..d1a87c3b3bb 100644 --- a/lib/gitlab/middleware/go.rb +++ b/lib/gitlab/middleware/go.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # A dumb middleware that returns a Go HTML document if the go-get=1 query string # is used irrespective if the namespace/project exists module Gitlab @@ -38,7 +40,7 @@ module Gitlab def go_body(path) config = Gitlab.config - project_url = URI.join(config.gitlab.url, path) + project_url = Gitlab::Utils.append_path(config.gitlab.url, path) import_prefix = strip_url(project_url.to_s) repository_url = if Gitlab::CurrentSettings.enabled_git_access_protocol == 'ssh' diff --git a/lib/gitlab/middleware/multipart.rb b/lib/gitlab/middleware/multipart.rb index 10cb1e7127e..84c2f0d5720 100644 --- a/lib/gitlab/middleware/multipart.rb +++ b/lib/gitlab/middleware/multipart.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Gitlab::Middleware::Multipart - a Rack::Multipart replacement # # Rack::Multipart leaves behind tempfiles in /tmp and uses valuable Ruby diff --git a/lib/gitlab/middleware/rails_queue_duration.rb b/lib/gitlab/middleware/rails_queue_duration.rb index bc70b2459ef..96c6a0a7d28 100644 --- a/lib/gitlab/middleware/rails_queue_duration.rb +++ b/lib/gitlab/middleware/rails_queue_duration.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This Rack middleware is intended to measure the latency between # gitlab-workhorse forwarding a request to the Rails application and the # time this middleware is reached. diff --git a/lib/gitlab/middleware/read_only.rb b/lib/gitlab/middleware/read_only.rb index 7f63e39b3aa..83c52a6c6e0 100644 --- a/lib/gitlab/middleware/read_only.rb +++ b/lib/gitlab/middleware/read_only.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Middleware class ReadOnly diff --git a/lib/gitlab/middleware/read_only/controller.rb b/lib/gitlab/middleware/read_only/controller.rb index 8dca431c005..89941a9efa0 100644 --- a/lib/gitlab/middleware/read_only/controller.rb +++ b/lib/gitlab/middleware/read_only/controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Middleware class ReadOnly diff --git a/lib/gitlab/middleware/release_env.rb b/lib/gitlab/middleware/release_env.rb index bfe8e113b5e..849cf8f759b 100644 --- a/lib/gitlab/middleware/release_env.rb +++ b/lib/gitlab/middleware/release_env.rb @@ -1,4 +1,7 @@ -module Gitlab # rubocop:disable Naming/FileName +# rubocop:disable Naming/FileName +# frozen_string_literal: true + +module Gitlab module Middleware # Some of middleware would hold env for no good reason even after the # request had already been processed, and we could not garbage collect diff --git a/lib/gitlab/middleware/static.rb b/lib/gitlab/middleware/static.rb index aa1e9dc0fdb..972fed2134c 100644 --- a/lib/gitlab/middleware/static.rb +++ b/lib/gitlab/middleware/static.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Middleware class Static < ActionDispatch::Static diff --git a/lib/gitlab/private_commit_email.rb b/lib/gitlab/private_commit_email.rb index bade2248ccd..536fc9dae3a 100644 --- a/lib/gitlab/private_commit_email.rb +++ b/lib/gitlab/private_commit_email.rb @@ -18,6 +18,10 @@ module Gitlab match[:id].to_i end + def user_ids_for_emails(emails) + emails.map { |email| user_id_for_email(email) }.compact.uniq + end + def for_user(user) hostname = Gitlab::CurrentSettings.current_application_settings.commit_email_hostname diff --git a/lib/gitlab/quick_actions/command_definition.rb b/lib/gitlab/quick_actions/command_definition.rb index 96415271316..c682eb22890 100644 --- a/lib/gitlab/quick_actions/command_definition.rb +++ b/lib/gitlab/quick_actions/command_definition.rb @@ -2,13 +2,14 @@ module Gitlab module QuickActions class CommandDefinition attr_accessor :name, :aliases, :description, :explanation, :params, - :condition_block, :parse_params_block, :action_block + :condition_block, :parse_params_block, :action_block, :warning def initialize(name, attributes = {}) @name = name @aliases = attributes[:aliases] || [] @description = attributes[:description] || '' + @warning = attributes[:warning] || '' @explanation = attributes[:explanation] || '' @params = attributes[:params] || [] @condition_block = attributes[:condition_block] @@ -33,11 +34,13 @@ module Gitlab def explain(context, arg) return unless available?(context) - if explanation.respond_to?(:call) - execute_block(explanation, context, arg) - else - explanation - end + message = if explanation.respond_to?(:call) + execute_block(explanation, context, arg) + else + explanation + end + + warning.empty? ? message : "#{message} (#{warning})" end def execute(context, arg) @@ -61,6 +64,7 @@ module Gitlab name: name, aliases: aliases, description: desc, + warning: warning, params: prms } end diff --git a/lib/gitlab/quick_actions/dsl.rb b/lib/gitlab/quick_actions/dsl.rb index d82dccd0db5..192c7ec2ff5 100644 --- a/lib/gitlab/quick_actions/dsl.rb +++ b/lib/gitlab/quick_actions/dsl.rb @@ -31,6 +31,10 @@ module Gitlab @description = block_given? ? block : text end + def warning(message = '') + @warning = message + end + # Allows to define params for the next quick action. # These params are shown in the autocomplete menu. # @@ -133,6 +137,7 @@ module Gitlab name, aliases: aliases, description: @description, + warning: @warning, explanation: @explanation, params: @params, condition_block: @condition_block, @@ -150,6 +155,7 @@ module Gitlab @explanation = nil @params = nil @condition_block = nil + @warning = nil @parse_params_block = nil end end diff --git a/lib/gitlab/repository_cache.rb b/lib/gitlab/repository_cache.rb index 56007574b1b..6b0808f5304 100644 --- a/lib/gitlab/repository_cache.rb +++ b/lib/gitlab/repository_cache.rb @@ -7,13 +7,13 @@ module Gitlab def initialize(repository, extra_namespace: nil, backend: Rails.cache) @repository = repository - @namespace = "#{repository.full_path}:#{repository.project.id}" + @namespace = "project:#{repository.project.id}" @namespace = "#{@namespace}:#{extra_namespace}" if extra_namespace @backend = backend end def cache_key(type) - "#{type}:#{namespace}" + "#{namespace}:#{type}" end def expire(key) diff --git a/lib/gitlab/sentry.rb b/lib/gitlab/sentry.rb index 24e3866128b..8079c5882c4 100644 --- a/lib/gitlab/sentry.rb +++ b/lib/gitlab/sentry.rb @@ -7,7 +7,7 @@ module Gitlab end def self.context(current_user = nil) - return unless self.enabled? + return unless enabled? Raven.tags_context(locale: I18n.locale) @@ -29,14 +29,22 @@ module Gitlab # # Provide an issue URL for follow up. def self.track_exception(exception, issue_url: nil, extra: {}) + track_acceptable_exception(exception, issue_url: issue_url, extra: extra) + + raise exception if should_raise? + end + + # This should be used when you do not want to raise an exception in + # development and test. If you need development and test to behave + # just the same as production you can use this instead of + # track_exception. + def self.track_acceptable_exception(exception, issue_url: nil, extra: {}) if enabled? extra[:issue_url] = issue_url if issue_url context # Make sure we've set everything we know in the context Raven.capture_exception(exception, extra: extra) end - - raise exception if should_raise? end def self.program_context diff --git a/lib/gitlab/view/presenter/base.rb b/lib/gitlab/view/presenter/base.rb index 36162faa1eb..c3fd6d317aa 100644 --- a/lib/gitlab/view/presenter/base.rb +++ b/lib/gitlab/view/presenter/base.rb @@ -11,8 +11,8 @@ module Gitlab attr_reader :subject - def can?(user, action, overriden_subject = nil) - super(user, action, overriden_subject || subject) + def can?(user, action, overridden_subject = nil) + super(user, action, overridden_subject || subject) end # delegate all #can? queries to the subject |