diff options
Diffstat (limited to 'lib')
27 files changed, 239 insertions, 182 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 9e820f00c42..53774d4db1a 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -400,7 +400,6 @@ module API end class GroupDetail < Group - expose :runners_token, if: lambda { |group, options| options[:user_can_admin_group] } expose :projects, using: Entities::Project do |group, options| projects = GroupProjectsFinder.new( group: group, @@ -1045,12 +1044,7 @@ module API expose :job_events # Expose serialized properties expose :properties do |service, options| - # TODO: Simplify as part of https://gitlab.com/gitlab-org/gitlab-ce/issues/63084 - if service.data_fields_present? - service.data_fields.as_json.slice(*service.api_field_names) - else - service.properties.slice(*service.api_field_names) - end + service.properties.slice(*service.api_field_names) end end @@ -1286,7 +1280,7 @@ module API expose :author, using: Entities::UserBasic, if: -> (release, _) { release.author.present? } expose :commit, using: Entities::Commit, if: lambda { |_, _| can_download_code? } expose :upcoming_release?, as: :upcoming_release - expose :milestones, using: Entities::Milestone, if: -> (release, _) { release.milestones.present? } + expose :milestone, using: Entities::Milestone, if: -> (release, _) { release.milestone.present? } expose :assets do expose :assets_count, as: :count do |release, _| diff --git a/lib/api/groups.rb b/lib/api/groups.rb index 9d1628de7e5..4ae9b8c70d3 100644 --- a/lib/api/groups.rb +++ b/lib/api/groups.rb @@ -173,8 +173,7 @@ module API options = { with: params[:with_projects] ? Entities::GroupDetail : Entities::Group, - current_user: current_user, - user_can_admin_group: can?(current_user, :admin_group, group) + current_user: current_user } group, options = with_custom_attributes(group, options) diff --git a/lib/api/helpers/issues_helpers.rb b/lib/api/helpers/issues_helpers.rb index e272b13f3ae..8addcd18fe3 100644 --- a/lib/api/helpers/issues_helpers.rb +++ b/lib/api/helpers/issues_helpers.rb @@ -11,9 +11,6 @@ module API params :optional_issues_params_ee do end - params :optional_issue_not_params_ee do - end - def self.update_params_at_least_one_of [ :assignee_id, @@ -38,11 +35,8 @@ module API args = declared_params.merge(args) args.delete(:id) - args[:not] ||= {} args[:milestone_title] ||= args.delete(:milestone) - args[:not][:milestone_title] ||= args[:not]&.delete(:milestone) args[:label_name] ||= args.delete(:labels) - args[:not][:label_name] ||= args[:not]&.delete(:labels) args[:scope] = args[:scope].underscore if args[:scope] args[:sort] = "#{args[:order_by]}_#{args[:sort]}" diff --git a/lib/api/helpers/projects_helpers.rb b/lib/api/helpers/projects_helpers.rb index 07f0386d14d..f247c722c44 100644 --- a/lib/api/helpers/projects_helpers.rb +++ b/lib/api/helpers/projects_helpers.rb @@ -56,14 +56,6 @@ module API use :optional_project_params_ee end - params :optional_create_project_params_ee do - end - - params :optional_create_project_params do - use :optional_project_params - use :optional_create_project_params_ee - end - params :optional_filter_params_ee do end diff --git a/lib/api/helpers/services_helpers.rb b/lib/api/helpers/services_helpers.rb index eba4ebb4b6e..5331de3c035 100644 --- a/lib/api/helpers/services_helpers.rb +++ b/lib/api/helpers/services_helpers.rb @@ -1,3 +1,4 @@ +# coding: utf-8 # frozen_string_literal: true module API diff --git a/lib/api/issues.rb b/lib/api/issues.rb index d06550191ad..215178478d0 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -9,35 +9,28 @@ module API before { authenticate_non_get! } helpers do - params :negatable_issue_filter_params do + params :issues_stats_params do optional :labels, type: Array[String], coerce_with: Validations::Types::LabelsList.coerce, desc: 'Comma-separated list of label names' optional :milestone, type: String, desc: 'Milestone title' + optional :milestone, type: String, desc: 'Return issues for a specific milestone' optional :iids, type: Array[Integer], desc: 'The IID array of issues' optional :search, type: String, desc: 'Search issues for text present in the title, description, or any combination of these' optional :in, type: String, desc: '`title`, `description`, or a string joining them with comma' + optional :created_after, type: DateTime, desc: 'Return issues created after the specified time' + optional :created_before, type: DateTime, desc: 'Return issues created before the specified time' + optional :updated_after, type: DateTime, desc: 'Return issues updated after the specified time' + optional :updated_before, type: DateTime, desc: 'Return issues updated before the specified time' optional :author_id, type: Integer, desc: 'Return issues which are authored by the user with the given ID' optional :author_username, type: String, desc: 'Return issues which are authored by the user with the given username' mutually_exclusive :author_id, :author_username optional :assignee_id, types: [Integer, String], integer_none_any: true, - desc: 'Return issues which are assigned to the user with the given ID' + desc: 'Return issues which are assigned to the user with the given ID' optional :assignee_username, type: Array[String], check_assignees_count: true, - coerce_with: Validations::CheckAssigneesCount.coerce, - desc: 'Return issues which are assigned to the user with the given username' + coerce_with: Validations::CheckAssigneesCount.coerce, + desc: 'Return issues which are assigned to the user with the given username' mutually_exclusive :assignee_id, :assignee_username - end - - params :issues_stats_params do - use :negatable_issue_filter_params - optional :created_after, type: DateTime, desc: 'Return issues created after the specified time' - optional :created_before, type: DateTime, desc: 'Return issues created before the specified time' - optional :updated_after, type: DateTime, desc: 'Return issues updated after the specified time' - optional :updated_before, type: DateTime, desc: 'Return issues updated before the specified time' - - optional :not, type: Hash do - use :negatable_issue_filter_params - end optional :scope, type: String, values: %w[created-by-me assigned-to-me created_by_me assigned_to_me all], desc: 'Return issues for the given scope: `created_by_me`, `assigned_to_me` or `all`' diff --git a/lib/api/pipelines.rb b/lib/api/pipelines.rb index e09d226a13f..9e888368e7b 100644 --- a/lib/api/pipelines.rb +++ b/lib/api/pipelines.rb @@ -69,19 +69,6 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Gets a the latest pipeline for the project branch' do - detail 'This feature was introduced in GitLab 12.3' - success Entities::Pipeline - end - params do - optional :ref, type: String, desc: 'branch ref of pipeline' - end - get ':id/pipelines/latest' do - authorize! :read_pipeline, latest_pipeline - - present latest_pipeline, with: Entities::Pipeline - end - desc 'Gets a specific pipeline for the project' do detail 'This feature was introduced in GitLab 8.11' success Entities::Pipeline @@ -157,15 +144,7 @@ module API helpers do def pipeline - strong_memoize(:pipeline) do - user_project.ci_pipelines.find(params[:pipeline_id]) - end - end - - def latest_pipeline - strong_memoize(:latest_pipeline) do - user_project.latest_pipeline_for_ref(params[:ref]) - end + @pipeline ||= user_project.ci_pipelines.find(params[:pipeline_id]) end end end diff --git a/lib/api/projects.rb b/lib/api/projects.rb index c28b03ac6c9..74de9fcec68 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -68,8 +68,6 @@ module API params :create_params do optional :namespace_id, type: Integer, desc: 'Namespace ID for the new project. Default to the user namespace.' optional :import_url, type: String, desc: 'URL from which the project is imported' - optional :template_name, type: String, desc: "Name of template from which to create project" - mutually_exclusive :import_url, :template_name end def load_projects @@ -157,7 +155,7 @@ module API optional :name, type: String, desc: 'The name of the project' optional :path, type: String, desc: 'The path of the repository' at_least_one_of :name, :path - use :optional_create_project_params + use :optional_project_params use :create_params end post do diff --git a/lib/api/releases.rb b/lib/api/releases.rb index 4238529142c..5a31581c4da 100644 --- a/lib/api/releases.rb +++ b/lib/api/releases.rb @@ -54,7 +54,7 @@ module API requires :url, type: String end end - optional :milestones, type: Array, desc: 'The titles of the related milestones', default: [] + optional :milestone, type: String, desc: 'The title of the related milestone' optional :released_at, type: DateTime, desc: 'The date when the release will be/was ready. Defaults to the current time.' end post ':id/releases' do @@ -80,7 +80,7 @@ module API optional :name, type: String, desc: 'The name of the release' optional :description, type: String, desc: 'Release notes with markdown support' optional :released_at, type: DateTime, desc: 'The date when the release will be/was ready.' - optional :milestones, type: Array, desc: 'The titles of the related milestones' + optional :milestone, type: String, desc: 'The title of the related milestone' end put ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMENTS do authorize_update_release! diff --git a/lib/gitlab/auth/ldap/dn.rb b/lib/gitlab/auth/ldap/dn.rb index 0b496da784d..5df914aa367 100644 --- a/lib/gitlab/auth/ldap/dn.rb +++ b/lib/gitlab/auth/ldap/dn.rb @@ -1,3 +1,4 @@ +# -*- ruby encoding: utf-8 -*- # frozen_string_literal: true # Based on the `ruby-net-ldap` gem's `Net::LDAP::DN` diff --git a/lib/gitlab/background_migration/add_gitlab_instance_administration_project.rb b/lib/gitlab/background_migration/add_gitlab_instance_administration_project.rb deleted file mode 100644 index 730f1acee98..00000000000 --- a/lib/gitlab/background_migration/add_gitlab_instance_administration_project.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true -# rubocop:disable Style/Documentation - -module Gitlab - module BackgroundMigration - class AddGitlabInstanceAdministrationProject - def perform - Rails.logger.info("Creating Gitlab instance administration project") # rubocop:disable Gitlab/RailsLogger - - Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService.new.execute! - end - end - end -end diff --git a/lib/gitlab/ci/config/entry/job.rb b/lib/gitlab/ci/config/entry/job.rb index 5874b01ef2a..f750886a8c5 100644 --- a/lib/gitlab/ci/config/entry/job.rb +++ b/lib/gitlab/ci/config/entry/job.rb @@ -14,8 +14,8 @@ module Gitlab ALLOWED_WHEN = %w[on_success on_failure always manual delayed].freeze ALLOWED_KEYS = %i[tags script only except rules type image services allow_failure type stage when start_in artifacts cache - dependencies before_script needs after_script variables - environment coverage retry parallel extends interruptible timeout].freeze + dependencies needs before_script after_script variables + environment coverage retry parallel extends interruptible].freeze REQUIRED_BY_NEEDS = %i[stage].freeze @@ -46,8 +46,6 @@ module Gitlab message: "should be one of: #{ALLOWED_WHEN.join(', ')}" } - validates :timeout, duration: { limit: ChronicDuration.output(Project::MAX_BUILD_TIMEOUT) } - validates :dependencies, array_of_strings: true validates :needs, array_of_strings: true validates :extends, array_of_strings_or_string: true @@ -129,7 +127,7 @@ module Gitlab attributes :script, :tags, :allow_failure, :when, :dependencies, :needs, :retry, :parallel, :extends, :start_in, :rules, - :interruptible, :timeout + :interruptible def self.matching?(name, config) !name.to_s.start_with?('.') && @@ -220,7 +218,6 @@ module Gitlab retry: retry_defined? ? retry_value : nil, parallel: parallel_defined? ? parallel_value.to_i : nil, interruptible: interruptible_defined? ? interruptible_value : nil, - timeout: has_timeout? ? ChronicDuration.parse(timeout.to_s) : nil, artifacts: artifacts_value, after_script: after_script_value, ignore: ignored?, diff --git a/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml b/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml index 7f9a7df2f31..56ce33203ad 100644 --- a/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml @@ -2,26 +2,57 @@ container_scanning: stage: test - image: - name: registry.gitlab.com/gitlab-org/security-products/analyzers/klar:$CI_SERVER_VERSION_MAJOR-$CI_SERVER_VERSION_MINOR-stable - entrypoint: [] + image: docker:stable variables: - # By default, use the latest clair vulnerabilities database, however, allow it to be overridden here - # with a specific version to provide consistency for integration testing purposes - CLAIR_DB_IMAGE_TAG: latest - # Override this variable in your `.gitlab-ci.yml` file and set it to `fetch` if you want to provide a `clair-whitelist.yaml` file. - # See https://docs.gitlab.com/ee/user/application_security/container_scanning/index.html#overriding-the-container-scanning-template - # for details + DOCKER_DRIVER: overlay2 + DOCKER_TLS_CERTDIR: "" + # Defining two new variables based on GitLab's CI/CD predefined variables + # https://docs.gitlab.com/ee/ci/variables/#predefined-environment-variables + CI_APPLICATION_REPOSITORY: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG + CI_APPLICATION_TAG: $CI_COMMIT_SHA + # Prior to this, you need to have the Container Registry running for your project and setup a build job + # with at least the following steps: + # + # docker build -t $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG . + # docker push $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA + # + # Container Scanning deals with Docker images only so no need to import the project's Git repository: GIT_STRATEGY: none + # Services and containers running in the same Kubernetes pod are all sharing the same localhost address + # https://docs.gitlab.com/runner/executors/kubernetes.html + DOCKER_SERVICE: docker + DOCKER_HOST: tcp://${DOCKER_SERVICE}:2375/ + # https://hub.docker.com/r/arminc/clair-local-scan/tags + CLAIR_LOCAL_SCAN_VERSION: v2.0.8_0ed98e9ead65a51ba53f7cc53fa5e80c92169207 + CLAIR_EXECUTABLE_VERSION: v12 + CLAIR_EXECUTABLE_SHA: 44f2a3fdd7b0d102c98510e7586f6956edc89ab72c6943980f92f4979f7f4081 + ## Disable the proxy for clair-local-scan, otherwise Container Scanning will + ## fail when a proxy is used. + NO_PROXY: ${DOCKER_SERVICE},localhost allow_failure: true services: - - name: arminc/clair-db:$CLAIR_DB_IMAGE_TAG - alias: clair-vulnerabilities-db + - docker:stable-dind script: - # the kubernetes executor currently ignores the Docker image entrypoint value, so the start.sh script must - # be explicitly executed here in order for this to work with both the kubernetes and docker executors - # see this issue for more details https://gitlab.com/gitlab-org/gitlab-runner/issues/4125 - - /container-scanner/start.sh + - if [[ -n "$KUBERNETES_PORT" ]]; then { export DOCKER_SERVICE="localhost" ; export DOCKER_HOST="tcp://${DOCKER_SERVICE}:2375" ; } fi + - | + if [[ -n "$CI_REGISTRY_USER" ]]; then + echo "Logging to GitLab Container Registry with CI credentials..." + docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY" + echo "" + fi + - docker run -d --name db arminc/clair-db:latest + - docker run -p 6060:6060 --link db:postgres -d --name clair --restart on-failure arminc/clair-local-scan:${CLAIR_LOCAL_SCAN_VERSION} + - apk add -U wget ca-certificates + - docker pull ${CI_APPLICATION_REPOSITORY}:${CI_APPLICATION_TAG} + - wget https://github.com/arminc/clair-scanner/releases/download/${CLAIR_EXECUTABLE_VERSION}/clair-scanner_linux_amd64 + - echo "${CLAIR_EXECUTABLE_SHA} clair-scanner_linux_amd64" | sha256sum -c + - mv clair-scanner_linux_amd64 clair-scanner + - chmod +x clair-scanner + - touch clair-whitelist.yml + - retries=0 + - echo "Waiting for clair daemon to start" + - while( ! wget -T 10 -q -O /dev/null http://${DOCKER_SERVICE}:6060/v1/namespaces ) ; do sleep 1 ; echo -n "." ; if [ $retries -eq 10 ] ; then echo " Timeout, aborting." ; exit 1 ; fi ; retries=$(($retries+1)) ; done + - ./clair-scanner -c http://${DOCKER_SERVICE}:6060 --ip $(hostname -i) -r gl-container-scanning-report.json -l clair.log -w clair-whitelist.yml ${CI_APPLICATION_REPOSITORY}:${CI_APPLICATION_TAG} || true artifacts: reports: container_scanning: gl-container-scanning-report.json diff --git a/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml b/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml index a61731a24b7..88f4b72044c 100644 --- a/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml @@ -4,13 +4,28 @@ # List of the variables: https://gitlab.com/gitlab-org/security-products/sast#settings # How to set: https://docs.gitlab.com/ee/ci/yaml/#variables -sast: +.sast: stage: test + allow_failure: true + artifacts: + reports: + sast: gl-sast-report.json + only: + refs: + - branches + variables: + - $GITLAB_FEATURES =~ /\bsast\b/ + +variables: + SAST_ANALYZER_IMAGE_PREFIX: "registry.gitlab.com/gitlab-org/security-products/analyzers" + SAST_DISABLE_DIND: "false" + +sast: + extends: .sast image: docker:stable variables: DOCKER_DRIVER: overlay2 DOCKER_TLS_CERTDIR: "" - allow_failure: true services: - docker:stable-dind script: @@ -63,15 +78,116 @@ sast: --volume "$PWD:/code" \ --volume /var/run/docker.sock:/var/run/docker.sock \ "registry.gitlab.com/gitlab-org/security-products/sast:$SAST_VERSION" /app/bin/run /code - artifacts: - reports: - sast: gl-sast-report.json - dependencies: [] - only: - refs: - - branches - variables: - - $GITLAB_FEATURES =~ /\bsast\b/ except: variables: - $SAST_DISABLED + - $SAST_DISABLE_DIND == 'true' + +.analyzer: + extends: .sast + except: + variables: + - $SAST_DISABLE_DIND == 'false' + script: + - /analyzer run + +bandit-sast: + extends: .analyzer + image: + name: "$SAST_ANALYZER_IMAGE_PREFIX/bandit" + only: + variables: + - '$CI_PROJECT_REPOSITORY_LANGUAGES =~ /python/' + +brakeman-sast: + extends: .analyzer + image: + name: "$SAST_ANALYZER_IMAGE_PREFIX/brakeman" + only: + variables: + - '$CI_PROJECT_REPOSITORY_LANGUAGES =~ /ruby/' + +eslint-sast: + extends: .analyzer + image: + name: "$SAST_ANALYZER_IMAGE_PREFIX/eslint" + only: + variables: + - '$CI_PROJECT_REPOSITORY_LANGUAGES =~ /javascript/' + +flawfinder-sast: + extends: .analyzer + image: + name: "$SAST_ANALYZER_IMAGE_PREFIX/flawfinder" + only: + variables: + - '$CI_PROJECT_REPOSITORY_LANGUAGES =~ /\b(c\+\+|c\b)/' + +gosec-sast: + extends: .analyzer + image: + name: "$SAST_ANALYZER_IMAGE_PREFIX/gosec" + only: + variables: + - '$CI_PROJECT_REPOSITORY_LANGUAGES =~ /go/' + +nodejs-scan-sast: + extends: .analyzer + image: + name: "$SAST_ANALYZER_IMAGE_PREFIX/nodejs-scan" + only: + variables: + - '$CI_PROJECT_REPOSITORY_LANGUAGES =~ /javascript/' + +phpcs-security-audit-sast: + extends: .analyzer + image: + name: "$SAST_ANALYZER_IMAGE_PREFIX/phpcs-security-audit" + only: + variables: + - '$CI_PROJECT_REPOSITORY_LANGUAGES =~ /php/' + +pmd-apex-sast: + extends: .analyzer + image: + name: "$SAST_ANALYZER_IMAGE_PREFIX/pmd-apex" + only: + variables: + - '$CI_PROJECT_REPOSITORY_LANGUAGES =~ /apex/' + +secrets-sast: + extends: .analyzer + image: + name: "$SAST_ANALYZER_IMAGE_PREFIX/secrets" + +security-code-scan-sast: + extends: .analyzer + image: + name: "$SAST_ANALYZER_IMAGE_PREFIX/security-code-scan" + only: + variables: + - '$CI_PROJECT_REPOSITORY_LANGUAGES =~ /c\#/ || $CI_PROJECT_REPOSITORY_LANGUAGES =~ /visual basic/' + +sobelow-sast: + extends: .analyzer + image: + name: "$SAST_ANALYZER_IMAGE_PREFIX/sobelow" + only: + variables: + - '$CI_PROJECT_REPOSITORY_LANGUAGES =~ /elixir/' + +spotbugs-sast: + extends: .analyzer + image: + name: "$SAST_ANALYZER_IMAGE_PREFIX/spotbugs" + only: + variables: + - '$CI_PROJECT_REPOSITORY_LANGUAGES =~ /java\b/' + +tslint-sast: + extends: .analyzer + image: + name: "$SAST_ANALYZER_IMAGE_PREFIX/tslint" + only: + variables: + - '$CI_PROJECT_REPOSITORY_LANGUAGES =~ /typescript/' diff --git a/lib/gitlab/ci/yaml_processor.rb b/lib/gitlab/ci/yaml_processor.rb index f6a3abefcfb..986605efdc3 100644 --- a/lib/gitlab/ci/yaml_processor.rb +++ b/lib/gitlab/ci/yaml_processor.rb @@ -49,7 +49,6 @@ module Gitlab artifacts: job[:artifacts], cache: job[:cache], dependencies: job[:dependencies], - job_timeout: job[:timeout], before_script: job[:before_script], script: job[:script], after_script: job[:after_script], diff --git a/lib/gitlab/daemon.rb b/lib/gitlab/daemon.rb index 43c159fee27..2f4ae010e74 100644 --- a/lib/gitlab/daemon.rb +++ b/lib/gitlab/daemon.rb @@ -10,8 +10,8 @@ module Gitlab @instance end - def self.instance(*args) - @instance ||= initialize_instance(*args) + def self.instance + @instance ||= initialize_instance end attr_reader :thread diff --git a/lib/gitlab/devise_failure.rb b/lib/gitlab/devise_failure.rb deleted file mode 100644 index 4d27b706e1e..00000000000 --- a/lib/gitlab/devise_failure.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - class DeviseFailure < Devise::FailureApp - # If the request format is not known, send a redirect instead of a 401 - # response, since this is the outcome we're most likely to want - def http_auth? - return super unless Feature.enabled?(:devise_redirect_unknown_formats, default_enabled: true) - - request_format && super - end - end -end diff --git a/lib/gitlab/discussions_diff/file_collection.rb b/lib/gitlab/discussions_diff/file_collection.rb index 6692dd76438..4ab7314f509 100644 --- a/lib/gitlab/discussions_diff/file_collection.rb +++ b/lib/gitlab/discussions_diff/file_collection.rb @@ -4,16 +4,11 @@ module Gitlab module DiscussionsDiff class FileCollection include Gitlab::Utils::StrongMemoize - include Enumerable def initialize(collection) @collection = collection end - def each(&block) - @collection.each(&block) - end - # Returns a Gitlab::Diff::File with the given ID (`unique_identifier` in # Gitlab::Diff::File). def find_by_id(id) @@ -21,12 +16,20 @@ module Gitlab end # Writes cache and preloads highlighted diff lines for - # highlightable object IDs, in @collection. + # object IDs, in @collection. + # + # highlightable_ids - Diff file `Array` responding to ID. The ID will be used + # to generate the cache key. # # - Highlight cache is written just for uncached diff files # - The cache content is not updated (there's no need to do so) - def load_highlight - ids = highlightable_collection_ids + def load_highlight(highlightable_ids) + preload_highlighted_lines(highlightable_ids) + end + + private + + def preload_highlighted_lines(ids) cached_content = read_cache(ids) uncached_ids = ids.select.each_with_index { |_, i| cached_content[i].nil? } @@ -43,12 +46,6 @@ module Gitlab end end - private - - def highlightable_collection_ids - each.with_object([]) { |file, memo| memo << file.id unless file.resolved_at } - end - def read_cache(ids) HighlightCache.read_multiple(ids) end @@ -60,7 +57,9 @@ module Gitlab end def diff_files - strong_memoize(:diff_files) { map(&:raw_diff_file) } + strong_memoize(:diff_files) do + @collection.map(&:raw_diff_file) + end end # Processes the diff lines highlighting for diff files matching the given diff --git a/lib/gitlab/ee_compat_check.rb b/lib/gitlab/ee_compat_check.rb index 5cd90814ca3..20c31e06905 100644 --- a/lib/gitlab/ee_compat_check.rb +++ b/lib/gitlab/ee_compat_check.rb @@ -1,3 +1,4 @@ +# coding: utf-8 # frozen_string_literal: true # rubocop: disable Rails/Output diff --git a/lib/gitlab/etag_caching/router.rb b/lib/gitlab/etag_caching/router.rb index 7b921ab6199..3d14a8dde8d 100644 --- a/lib/gitlab/etag_caching/router.rb +++ b/lib/gitlab/etag_caching/router.rb @@ -53,6 +53,10 @@ module Gitlab 'project_build' ), Gitlab::EtagCaching::Router::Route.new( + %r(#{RESERVED_WORDS_PREFIX}/clusters/\d+/environments\z), + 'cluster_environments' + ), + Gitlab::EtagCaching::Router::Route.new( %r(#{RESERVED_WORDS_PREFIX}/environments\.json\z), 'environments' ), diff --git a/lib/gitlab/hook_data/merge_request_builder.rb b/lib/gitlab/hook_data/merge_request_builder.rb index 0678799b64b..a8e993e087e 100644 --- a/lib/gitlab/hook_data/merge_request_builder.rb +++ b/lib/gitlab/hook_data/merge_request_builder.rb @@ -34,7 +34,6 @@ module Gitlab end SAFE_HOOK_RELATIONS = %i[ - assignees labels total_time_spent ].freeze diff --git a/lib/gitlab/profiler.rb b/lib/gitlab/profiler.rb index 275151f7fc1..3f26b84be20 100644 --- a/lib/gitlab/profiler.rb +++ b/lib/gitlab/profiler.rb @@ -1,3 +1,4 @@ +# coding: utf-8 # frozen_string_literal: true module Gitlab diff --git a/lib/gitlab/quick_actions/issuable_actions.rb b/lib/gitlab/quick_actions/issuable_actions.rb index 340ec75c5f1..5cf24823ef5 100644 --- a/lib/gitlab/quick_actions/issuable_actions.rb +++ b/lib/gitlab/quick_actions/issuable_actions.rb @@ -1,3 +1,4 @@ +# coding: utf-8 # frozen_string_literal: true module Gitlab diff --git a/lib/gitlab/slash_commands/presenters/issue_move.rb b/lib/gitlab/slash_commands/presenters/issue_move.rb index 01f2025ee10..ca0644ede95 100644 --- a/lib/gitlab/slash_commands/presenters/issue_move.rb +++ b/lib/gitlab/slash_commands/presenters/issue_move.rb @@ -1,3 +1,4 @@ +# coding: utf-8 # frozen_string_literal: true module Gitlab diff --git a/lib/gitlab/time_tracking_formatter.rb b/lib/gitlab/time_tracking_formatter.rb index b15cb85dde0..31883527135 100644 --- a/lib/gitlab/time_tracking_formatter.rb +++ b/lib/gitlab/time_tracking_formatter.rb @@ -5,7 +5,7 @@ module Gitlab extend self # We may want to configure it through project settings in a future version. - CUSTOM_DAY_AND_MONTH_LENGTH = { hours_per_day: 8, days_per_month: 20 }.freeze + CUSTOM_DAY_AND_WEEK_LENGTH = { hours_per_day: 8, days_per_month: 20 }.freeze def parse(string) string = string.sub(/\A-/, '') @@ -14,7 +14,7 @@ module Gitlab begin ChronicDuration.parse( string, - CUSTOM_DAY_AND_MONTH_LENGTH.merge(default_unit: 'hours')) + CUSTOM_DAY_AND_WEEK_LENGTH.merge(default_unit: 'hours')) rescue nil end @@ -26,7 +26,7 @@ module Gitlab def output(seconds) ChronicDuration.output( seconds, - CUSTOM_DAY_AND_MONTH_LENGTH.merge( + CUSTOM_DAY_AND_WEEK_LENGTH.merge( format: :short, limit_to_hours: limit_to_hours_setting, weeks: true)) diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb index c6c2876033d..5cd54c302fc 100644 --- a/lib/gitlab/usage_data.rb +++ b/lib/gitlab/usage_data.rb @@ -3,7 +3,6 @@ module Gitlab class UsageData APPROXIMATE_COUNT_MODELS = [Label, MergeRequest, Note, Todo].freeze - BATCH_SIZE = 100 class << self def data(force_refresh: false) @@ -14,10 +13,10 @@ module Gitlab def uncached_data license_usage_data.merge(system_usage_data) - .merge(features_usage_data) - .merge(components_usage_data) - .merge(cycle_analytics_usage_data) - .merge(usage_counters) + .merge(features_usage_data) + .merge(components_usage_data) + .merge(cycle_analytics_usage_data) + .merge(usage_counters) end def to_json(force_refresh: false) @@ -97,8 +96,9 @@ module Gitlab todos: count(Todo), uploads: count(Upload), web_hooks: count(WebHook) - }.merge(services_usage) - .merge(approximate_counts) + } + .merge(services_usage) + .merge(approximate_counts) }.tap do |data| data[:counts][:user_preferences] = user_preferences_usage end @@ -173,34 +173,17 @@ module Gitlab def jira_usage # Jira Cloud does not support custom domains as per https://jira.atlassian.com/browse/CLOUD-6999 # so we can just check for subdomains of atlassian.net + services = count( + Service.unscoped.where(type: :JiraService, active: true) + .group("CASE WHEN properties LIKE '%.atlassian.net%' THEN 'cloud' ELSE 'server' END"), + fallback: Hash.new(-1) + ) - results = { - projects_jira_server_active: 0, - projects_jira_cloud_active: 0, - projects_jira_active: -1 + { + projects_jira_server_active: services['server'] || 0, + projects_jira_cloud_active: services['cloud'] || 0, + projects_jira_active: services['server'] == -1 ? -1 : services.values.sum } - - Service.unscoped - .where(type: :JiraService, active: true) - .includes(:jira_tracker_data) - .find_in_batches(batch_size: BATCH_SIZE) do |services| - - counts = services.group_by do |service| - # TODO: Simplify as part of https://gitlab.com/gitlab-org/gitlab-ce/issues/63084 - service_url = service.data_fields&.url || (service.properties && service.properties['url']) - service_url&.include?('.atlassian.net') ? :cloud : :server - end - - results[:projects_jira_server_active] += counts[:server].count if counts[:server] - results[:projects_jira_cloud_active] += counts[:cloud].count if counts[:cloud] - if results[:projects_jira_active] == -1 - results[:projects_jira_active] = count(services) - else - results[:projects_jira_active] += count(services) - end - end - - results end def user_preferences_usage diff --git a/lib/gitlab_danger.rb b/lib/gitlab_danger.rb index 499ae6111d7..b4768a9546d 100644 --- a/lib/gitlab_danger.rb +++ b/lib/gitlab_danger.rb @@ -10,17 +10,18 @@ class GitlabDanger prettier eslint database - commit_messages ].freeze CI_ONLY_RULES ||= %w[ metadata changelog specs + commit_messages roulette single_codebase gitlab_ui_wg ce_ee_vue_templates + only_documentation ].freeze MESSAGE_PREFIX = '==>'.freeze |