diff options
76 files changed, 1316 insertions, 307 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 69272c5d261..024f2929252 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -27,6 +27,7 @@ variables: GET_SOURCES_ATTEMPTS: "3" KNAPSACK_RSPEC_SUITE_REPORT_PATH: knapsack/${CI_PROJECT_NAME}/rspec_report-master.json KNAPSACK_SPINACH_SUITE_REPORT_PATH: knapsack/${CI_PROJECT_NAME}/spinach_report-master.json + FLAKY_RSPEC_SUITE_REPORT_PATH: rspec_flaky/${CI_PROJECT_NAME}/report-master.json before_script: - bundle --version @@ -45,16 +46,17 @@ stages: tags: - gitlab-org -.knapsack-state: &knapsack-state +.tests-metadata-state: &tests-metadata-state services: [] variables: SETUP_DB: "false" USE_BUNDLE_INSTALL: "false" - KNAPSACK_S3_BUCKET: "gitlab-ce-cache" + TESTS_METADATA_S3_BUCKET: "gitlab-ce-cache" artifacts: expire_in: 31d paths: - knapsack/ + - rspec_flaky/ .use-pg: &use-pg services: @@ -86,7 +88,7 @@ stages: except: - /(^docs[\/-].*|.*-docs$)/ -.rspec-knapsack: &rspec-knapsack +.rspec-metadata: &rspec-metadata <<: *dedicated-runner <<: *pull-cache stage: test @@ -96,8 +98,13 @@ stages: - export CI_NODE_TOTAL=${JOB_NAME[-1]} - export KNAPSACK_REPORT_PATH=knapsack/${CI_PROJECT_NAME}/${JOB_NAME[0]}_node_${CI_NODE_INDEX}_${CI_NODE_TOTAL}_report.json - export KNAPSACK_GENERATE_REPORT=true + - export ALL_FLAKY_RSPEC_REPORT_PATH=rspec_flaky/${CI_PROJECT_NAME}/all_node_${CI_NODE_INDEX}_${CI_NODE_TOTAL}_report.json + - export NEW_FLAKY_RSPEC_REPORT_PATH=rspec_flaky/${CI_PROJECT_NAME}/new_node_${CI_NODE_INDEX}_${CI_NODE_TOTAL}_report.json + - export FLAKY_RSPEC_GENERATE_REPORT=true - export CACHE_CLASSES=true - cp ${KNAPSACK_RSPEC_SUITE_REPORT_PATH} ${KNAPSACK_REPORT_PATH} + - cp ${FLAKY_RSPEC_SUITE_REPORT_PATH} ${ALL_FLAKY_RSPEC_REPORT_PATH} + - '[[ -f $NEW_FLAKY_RSPEC_REPORT_PATH ]] || echo "{}" > ${NEW_FLAKY_RSPEC_REPORT_PATH}' - scripts/gitaly-test-spawn - knapsack rspec "--color --format documentation" artifacts: @@ -106,20 +113,21 @@ stages: paths: - coverage/ - knapsack/ + - rspec_flaky/ - tmp/capybara/ -.rspec-knapsack-pg: &rspec-knapsack-pg - <<: *rspec-knapsack +.rspec-metadata-pg: &rspec-metadata-pg + <<: *rspec-metadata <<: *use-pg <<: *except-docs -.rspec-knapsack-mysql: &rspec-knapsack-mysql - <<: *rspec-knapsack +.rspec-metadata-mysql: &rspec-metadata-mysql + <<: *rspec-metadata <<: *use-mysql <<: *only-if-want-mysql <<: *except-docs -.spinach-knapsack: &spinach-knapsack +.spinach-metadata: &spinach-metadata <<: *dedicated-runner <<: *pull-cache stage: test @@ -140,13 +148,13 @@ stages: - knapsack/ - tmp/capybara/ -.spinach-knapsack-pg: &spinach-knapsack-pg - <<: *spinach-knapsack +.spinach-metadata-pg: &spinach-metadata-pg + <<: *spinach-metadata <<: *use-pg <<: *except-docs -.spinach-knapsack-mysql: &spinach-knapsack-mysql - <<: *spinach-knapsack +.spinach-metadata-mysql: &spinach-metadata-mysql + <<: *spinach-metadata <<: *use-mysql <<: *only-if-want-mysql <<: *except-docs @@ -176,40 +184,70 @@ build-package: - //@gitlab-org/gitlab-ce - //@gitlab-org/gitlab-ee -# Prepare and merge knapsack tests -knapsack: - <<: *knapsack-state +# Retrieve knapsack and rspec_flaky reports +retrieve-tests-metadata: + <<: *tests-metadata-state <<: *dedicated-runner <<: *except-docs stage: prepare cache: - key: knapsack - paths: - - knapsack/ + key: tests_metadata policy: pull script: - mkdir -p knapsack/${CI_PROJECT_NAME}/ - - wget -O $KNAPSACK_RSPEC_SUITE_REPORT_PATH http://${KNAPSACK_S3_BUCKET}.s3.amazonaws.com/$KNAPSACK_RSPEC_SUITE_REPORT_PATH || rm $KNAPSACK_RSPEC_SUITE_REPORT_PATH - - wget -O $KNAPSACK_SPINACH_SUITE_REPORT_PATH http://${KNAPSACK_S3_BUCKET}.s3.amazonaws.com/$KNAPSACK_SPINACH_SUITE_REPORT_PATH || rm $KNAPSACK_SPINACH_SUITE_REPORT_PATH + - wget -O $KNAPSACK_RSPEC_SUITE_REPORT_PATH http://${TESTS_METADATA_S3_BUCKET}.s3.amazonaws.com/$KNAPSACK_RSPEC_SUITE_REPORT_PATH || rm $KNAPSACK_RSPEC_SUITE_REPORT_PATH + - wget -O $KNAPSACK_SPINACH_SUITE_REPORT_PATH http://${TESTS_METADATA_S3_BUCKET}.s3.amazonaws.com/$KNAPSACK_SPINACH_SUITE_REPORT_PATH || rm $KNAPSACK_SPINACH_SUITE_REPORT_PATH - '[[ -f $KNAPSACK_RSPEC_SUITE_REPORT_PATH ]] || echo "{}" > ${KNAPSACK_RSPEC_SUITE_REPORT_PATH}' - '[[ -f $KNAPSACK_SPINACH_SUITE_REPORT_PATH ]] || echo "{}" > ${KNAPSACK_SPINACH_SUITE_REPORT_PATH}' + - mkdir -p rspec_flaky/${CI_PROJECT_NAME}/ + - wget -O $FLAKY_RSPEC_SUITE_REPORT_PATH http://${TESTS_METADATA_S3_BUCKET}.s3.amazonaws.com/$FLAKY_RSPEC_SUITE_REPORT_PATH || rm $FLAKY_RSPEC_SUITE_REPORT_PATH + - '[[ -f $FLAKY_RSPEC_SUITE_REPORT_PATH ]] || echo "{}" > ${FLAKY_RSPEC_SUITE_REPORT_PATH}' -update-knapsack: - <<: *knapsack-state +update-tests-metadata: + <<: *tests-metadata-state <<: *dedicated-runner <<: *only-canonical-masters stage: post-test cache: - key: knapsack + key: tests_metadata paths: - knapsack/ + - rspec_flaky/ policy: push script: - retry gem install fog-aws mime-types - scripts/merge-reports ${KNAPSACK_RSPEC_SUITE_REPORT_PATH} knapsack/${CI_PROJECT_NAME}/rspec-pg_node_*.json - scripts/merge-reports ${KNAPSACK_SPINACH_SUITE_REPORT_PATH} knapsack/${CI_PROJECT_NAME}/spinach-pg_node_*.json - - '[[ -z ${KNAPSACK_S3_BUCKET} ]] || scripts/sync-reports put $KNAPSACK_S3_BUCKET $KNAPSACK_RSPEC_SUITE_REPORT_PATH $KNAPSACK_SPINACH_SUITE_REPORT_PATH' + - scripts/merge-reports ${FLAKY_RSPEC_SUITE_REPORT_PATH} rspec_flaky/${CI_PROJECT_NAME}/all_node_*.json + - '[[ -z ${TESTS_METADATA_S3_BUCKET} ]] || scripts/sync-reports put $TESTS_METADATA_S3_BUCKET $KNAPSACK_RSPEC_SUITE_REPORT_PATH $KNAPSACK_SPINACH_SUITE_REPORT_PATH' + - '[[ -z ${TESTS_METADATA_S3_BUCKET} ]] || scripts/sync-reports put $TESTS_METADATA_S3_BUCKET $FLAKY_RSPEC_SUITE_REPORT_PATH' - rm -f knapsack/${CI_PROJECT_NAME}/*_node_*.json + - rm -f rspec_flaky/${CI_PROJECT_NAME}/all_node_*.json + +flaky-examples-check: + <<: *dedicated-runner + image: ruby:2.3-alpine + services: [] + before_script: [] + cache: {} + variables: + SETUP_DB: "false" + USE_BUNDLE_INSTALL: "false" + NEW_FLAKY_SPECS_REPORT: rspec_flaky/${CI_PROJECT_NAME}/new_rspec_flaky_examples.json + stage: post-test + allow_failure: yes + only: + - branches + except: + - master + artifacts: + expire_in: 30d + paths: + - rspec_flaky/ + script: + - '[[ -f $NEW_FLAKY_SPECS_REPORT ]] || echo "{}" > ${NEW_FLAKY_SPECS_REPORT}' + - scripts/merge-reports $NEW_FLAKY_SPECS_REPORT rspec_flaky/${CI_PROJECT_NAME}/new_node_*.json + - scripts/detect-new-flaky-examples $NEW_FLAKY_SPECS_REPORT setup-test-env: <<: *use-pg @@ -232,69 +270,69 @@ setup-test-env: - public/assets - tmp/tests -rspec-pg 0 25: *rspec-knapsack-pg -rspec-pg 1 25: *rspec-knapsack-pg -rspec-pg 2 25: *rspec-knapsack-pg -rspec-pg 3 25: *rspec-knapsack-pg -rspec-pg 4 25: *rspec-knapsack-pg -rspec-pg 5 25: *rspec-knapsack-pg -rspec-pg 6 25: *rspec-knapsack-pg -rspec-pg 7 25: *rspec-knapsack-pg -rspec-pg 8 25: *rspec-knapsack-pg -rspec-pg 9 25: *rspec-knapsack-pg -rspec-pg 10 25: *rspec-knapsack-pg -rspec-pg 11 25: *rspec-knapsack-pg -rspec-pg 12 25: *rspec-knapsack-pg -rspec-pg 13 25: *rspec-knapsack-pg -rspec-pg 14 25: *rspec-knapsack-pg -rspec-pg 15 25: *rspec-knapsack-pg -rspec-pg 16 25: *rspec-knapsack-pg -rspec-pg 17 25: *rspec-knapsack-pg -rspec-pg 18 25: *rspec-knapsack-pg -rspec-pg 19 25: *rspec-knapsack-pg -rspec-pg 20 25: *rspec-knapsack-pg -rspec-pg 21 25: *rspec-knapsack-pg -rspec-pg 22 25: *rspec-knapsack-pg -rspec-pg 23 25: *rspec-knapsack-pg -rspec-pg 24 25: *rspec-knapsack-pg - -rspec-mysql 0 25: *rspec-knapsack-mysql -rspec-mysql 1 25: *rspec-knapsack-mysql -rspec-mysql 2 25: *rspec-knapsack-mysql -rspec-mysql 3 25: *rspec-knapsack-mysql -rspec-mysql 4 25: *rspec-knapsack-mysql -rspec-mysql 5 25: *rspec-knapsack-mysql -rspec-mysql 6 25: *rspec-knapsack-mysql -rspec-mysql 7 25: *rspec-knapsack-mysql -rspec-mysql 8 25: *rspec-knapsack-mysql -rspec-mysql 9 25: *rspec-knapsack-mysql -rspec-mysql 10 25: *rspec-knapsack-mysql -rspec-mysql 11 25: *rspec-knapsack-mysql -rspec-mysql 12 25: *rspec-knapsack-mysql -rspec-mysql 13 25: *rspec-knapsack-mysql -rspec-mysql 14 25: *rspec-knapsack-mysql -rspec-mysql 15 25: *rspec-knapsack-mysql -rspec-mysql 16 25: *rspec-knapsack-mysql -rspec-mysql 17 25: *rspec-knapsack-mysql -rspec-mysql 18 25: *rspec-knapsack-mysql -rspec-mysql 19 25: *rspec-knapsack-mysql -rspec-mysql 20 25: *rspec-knapsack-mysql -rspec-mysql 21 25: *rspec-knapsack-mysql -rspec-mysql 22 25: *rspec-knapsack-mysql -rspec-mysql 23 25: *rspec-knapsack-mysql -rspec-mysql 24 25: *rspec-knapsack-mysql - -spinach-pg 0 5: *spinach-knapsack-pg -spinach-pg 1 5: *spinach-knapsack-pg -spinach-pg 2 5: *spinach-knapsack-pg -spinach-pg 3 5: *spinach-knapsack-pg -spinach-pg 4 5: *spinach-knapsack-pg - -spinach-mysql 0 5: *spinach-knapsack-mysql -spinach-mysql 1 5: *spinach-knapsack-mysql -spinach-mysql 2 5: *spinach-knapsack-mysql -spinach-mysql 3 5: *spinach-knapsack-mysql -spinach-mysql 4 5: *spinach-knapsack-mysql +rspec-pg 0 25: *rspec-metadata-pg +rspec-pg 1 25: *rspec-metadata-pg +rspec-pg 2 25: *rspec-metadata-pg +rspec-pg 3 25: *rspec-metadata-pg +rspec-pg 4 25: *rspec-metadata-pg +rspec-pg 5 25: *rspec-metadata-pg +rspec-pg 6 25: *rspec-metadata-pg +rspec-pg 7 25: *rspec-metadata-pg +rspec-pg 8 25: *rspec-metadata-pg +rspec-pg 9 25: *rspec-metadata-pg +rspec-pg 10 25: *rspec-metadata-pg +rspec-pg 11 25: *rspec-metadata-pg +rspec-pg 12 25: *rspec-metadata-pg +rspec-pg 13 25: *rspec-metadata-pg +rspec-pg 14 25: *rspec-metadata-pg +rspec-pg 15 25: *rspec-metadata-pg +rspec-pg 16 25: *rspec-metadata-pg +rspec-pg 17 25: *rspec-metadata-pg +rspec-pg 18 25: *rspec-metadata-pg +rspec-pg 19 25: *rspec-metadata-pg +rspec-pg 20 25: *rspec-metadata-pg +rspec-pg 21 25: *rspec-metadata-pg +rspec-pg 22 25: *rspec-metadata-pg +rspec-pg 23 25: *rspec-metadata-pg +rspec-pg 24 25: *rspec-metadata-pg + +rspec-mysql 0 25: *rspec-metadata-mysql +rspec-mysql 1 25: *rspec-metadata-mysql +rspec-mysql 2 25: *rspec-metadata-mysql +rspec-mysql 3 25: *rspec-metadata-mysql +rspec-mysql 4 25: *rspec-metadata-mysql +rspec-mysql 5 25: *rspec-metadata-mysql +rspec-mysql 6 25: *rspec-metadata-mysql +rspec-mysql 7 25: *rspec-metadata-mysql +rspec-mysql 8 25: *rspec-metadata-mysql +rspec-mysql 9 25: *rspec-metadata-mysql +rspec-mysql 10 25: *rspec-metadata-mysql +rspec-mysql 11 25: *rspec-metadata-mysql +rspec-mysql 12 25: *rspec-metadata-mysql +rspec-mysql 13 25: *rspec-metadata-mysql +rspec-mysql 14 25: *rspec-metadata-mysql +rspec-mysql 15 25: *rspec-metadata-mysql +rspec-mysql 16 25: *rspec-metadata-mysql +rspec-mysql 17 25: *rspec-metadata-mysql +rspec-mysql 18 25: *rspec-metadata-mysql +rspec-mysql 19 25: *rspec-metadata-mysql +rspec-mysql 20 25: *rspec-metadata-mysql +rspec-mysql 21 25: *rspec-metadata-mysql +rspec-mysql 22 25: *rspec-metadata-mysql +rspec-mysql 23 25: *rspec-metadata-mysql +rspec-mysql 24 25: *rspec-metadata-mysql + +spinach-pg 0 5: *spinach-metadata-pg +spinach-pg 1 5: *spinach-metadata-pg +spinach-pg 2 5: *spinach-metadata-pg +spinach-pg 3 5: *spinach-metadata-pg +spinach-pg 4 5: *spinach-metadata-pg + +spinach-mysql 0 5: *spinach-metadata-mysql +spinach-mysql 1 5: *spinach-metadata-mysql +spinach-mysql 2 5: *spinach-metadata-mysql +spinach-mysql 3 5: *spinach-metadata-mysql +spinach-mysql 4 5: *spinach-metadata-mysql # Static analysis jobs .ruby-static-analysis: &ruby-static-analysis diff --git a/.rubocop.yml b/.rubocop.yml index 18d8e009da6..d25b4ac39c9 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1045,7 +1045,7 @@ RSpec/BeforeAfterAll: RSpec/DescribeClass: Enabled: false -# Use `described_class` for tested class / module. +# Checks that the second argument to `describe` specifies a method. RSpec/DescribeMethod: Enabled: false @@ -1053,8 +1053,7 @@ RSpec/DescribeMethod: RSpec/DescribeSymbol: Enabled: true -# Checks that the second argument to top level describe is the tested method -# name. +# Checks that tests use `described_class`. RSpec/DescribedClass: Enabled: true diff --git a/GITALY_SERVER_VERSION b/GITALY_SERVER_VERSION index ae6dd4e2032..c25c8e5b741 100644 --- a/GITALY_SERVER_VERSION +++ b/GITALY_SERVER_VERSION @@ -1 +1 @@ -0.29.0 +0.30.0 @@ -402,7 +402,7 @@ group :ed25519 do end # Gitaly GRPC client -gem 'gitaly', '~> 0.26.0' +gem 'gitaly', '~> 0.27.0' gem 'toml-rb', '~> 0.3.15', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 3d435b6f901..d443209349d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -270,7 +270,7 @@ GEM po_to_json (>= 1.0.0) rails (>= 3.2.0) gherkin-ruby (0.3.2) - gitaly (0.26.0) + gitaly (0.27.0) google-protobuf (~> 3.1) grpc (~> 1.0) github-linguist (4.7.6) @@ -984,7 +984,7 @@ DEPENDENCIES gettext (~> 3.2.2) gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails_js (~> 1.2.0) - gitaly (~> 0.26.0) + gitaly (~> 0.27.0) github-linguist (~> 4.7.0) gitlab-flowdock-git-hook (~> 1.0.1) gitlab-markup (~> 1.5.1) diff --git a/app/assets/javascripts/projects/project_new.js b/app/assets/javascripts/projects/project_new.js index 985521aef34..7f972b6f6ee 100644 --- a/app/assets/javascripts/projects/project_new.js +++ b/app/assets/javascripts/projects/project_new.js @@ -36,7 +36,7 @@ const bindEvents = () => { $('.how_to_import_link').on('click', (e) => { e.preventDefault(); - $('.how_to_import_link').next('.modal').show(); + $(e.currentTarget).next('.modal').show(); }); $('.modal-header .close').on('click', () => { diff --git a/app/assets/stylesheets/framework/dropdowns.scss b/app/assets/stylesheets/framework/dropdowns.scss index 02e0ba74158..1bb04b59a2a 100644 --- a/app/assets/stylesheets/framework/dropdowns.scss +++ b/app/assets/stylesheets/framework/dropdowns.scss @@ -725,9 +725,9 @@ } // TODO: change global style and remove mixin -@mixin new-style-dropdown { - .dropdown-menu, - .dropdown-menu-nav { +@mixin new-style-dropdown($selector: '') { + #{$selector}.dropdown-menu, + #{$selector}.dropdown-menu-nav { .divider { margin: 6px 0; } @@ -773,7 +773,7 @@ } } - .dropdown-menu-align-right { + #{$selector}.dropdown-menu-align-right { margin-top: 2px; } } diff --git a/app/assets/stylesheets/framework/typography.scss b/app/assets/stylesheets/framework/typography.scss index bf5f124d142..96409b10b99 100644 --- a/app/assets/stylesheets/framework/typography.scss +++ b/app/assets/stylesheets/framework/typography.scss @@ -339,6 +339,8 @@ a > code { @extend .ref-name; } +@include new-style-dropdown('.git-revision-dropdown'); + /** * Apply Markdown typography * diff --git a/app/assets/stylesheets/pages/note_form.scss b/app/assets/stylesheets/pages/note_form.scss index c90642178fc..b4468d6d0a2 100644 --- a/app/assets/stylesheets/pages/note_form.scss +++ b/app/assets/stylesheets/pages/note_form.scss @@ -108,6 +108,7 @@ background-color: $orange-50; border-radius: $border-radius-default $border-radius-default 0 0; border: 1px solid $border-gray-normal; + border-bottom: none; padding: 3px 12px; margin: auto; align-items: center; @@ -132,22 +133,9 @@ } } -.not-confidential { - padding: 0; - border-top: none; -} - -.right-sidebar-expanded { - .md-area { - border-radius: 0; - border-top: none; - } -} - -.right-sidebar-collapsed { - .confidential-issue-warning { - border-bottom: none; - } +.confidential-issue-warning + .md-area { + border-top-left-radius: 0; + border-top-right-radius: 0; } .discussion-form { diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e93f34498d6..1d24563a6a6 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -7,6 +7,7 @@ class ProjectsController < Projects::ApplicationController before_action :repository, except: [:index, :new, :create] before_action :assign_ref_vars, only: [:show], if: :repo_exists? before_action :tree, only: [:show], if: [:repo_exists?, :project_view_files?] + before_action :project_export_enabled, only: [:export, :download_export, :remove_export, :generate_new_export] # Authorize before_action :authorize_admin_project!, only: [:edit, :update, :housekeeping, :download_export, :export, :remove_export, :generate_new_export] @@ -390,4 +391,8 @@ class ProjectsController < Projects::ApplicationController url_for(params) end + + def project_export_enabled + render_404 unless current_application_settings.project_export_enabled? + end end diff --git a/app/controllers/unicorn_test_controller.rb b/app/controllers/unicorn_test_controller.rb index b7a1a046be0..ed04bd1f77d 100644 --- a/app/controllers/unicorn_test_controller.rb +++ b/app/controllers/unicorn_test_controller.rb @@ -1,12 +1,14 @@ +# :nocov: if Rails.env.test? class UnicornTestController < ActionController::Base def pid render plain: Process.pid.to_s end - + def kill Process.kill(params[:signal], Process.pid) render plain: 'Bye!' end end end +# :nocov: diff --git a/app/finders/admin/projects_finder.rb b/app/finders/admin/projects_finder.rb index a5ba791a513..7176bfe22d6 100644 --- a/app/finders/admin/projects_finder.rb +++ b/app/finders/admin/projects_finder.rb @@ -18,7 +18,7 @@ class Admin::ProjectsFinder end def execute - items = Project.with_statistics + items = Project.without_deleted.with_statistics items = items.in_namespace(namespace_id) if namespace_id.present? items = items.where(visibility_level: visibility_level) if visibility_level.present? items = items.with_push if with_push.present? diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb index 6825adcb39f..150188f0b65 100644 --- a/app/helpers/application_settings_helper.rb +++ b/app/helpers/application_settings_helper.rb @@ -146,6 +146,7 @@ module ApplicationSettingsHelper :plantuml_enabled, :plantuml_url, :polling_interval_multiplier, + :project_export_enabled, :prometheus_metrics_enabled, :recaptcha_enabled, :recaptcha_private_key, diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index bd7c4cd45ea..8e446ff6dd8 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -241,6 +241,7 @@ class ApplicationSetting < ActiveRecord::Base performance_bar_allowed_group_id: nil, plantuml_enabled: false, plantuml_url: nil, + project_export_enabled: true, recaptcha_enabled: false, repository_checks_enabled: true, repository_storages: ['default'], diff --git a/app/models/broadcast_message.rb b/app/models/broadcast_message.rb index 944725d91c3..3692bcc680d 100644 --- a/app/models/broadcast_message.rb +++ b/app/models/broadcast_message.rb @@ -14,9 +14,15 @@ class BroadcastMessage < ActiveRecord::Base default_value_for :color, '#E75E40' default_value_for :font, '#FFFFFF' + CACHE_KEY = 'broadcast_message_current'.freeze + + after_commit :flush_redis_cache + def self.current - Rails.cache.fetch("broadcast_message_current", expires_in: 1.minute) do - where('ends_at > :now AND starts_at <= :now', now: Time.zone.now).order([:created_at, :id]).to_a + Rails.cache.fetch(CACHE_KEY) do + where('ends_at > :now AND starts_at <= :now', now: Time.zone.now) + .reorder(id: :asc) + .to_a end end @@ -31,4 +37,8 @@ class BroadcastMessage < ActiveRecord::Base def ended? ends_at < Time.zone.now end + + def flush_redis_cache + Rails.cache.delete(CACHE_KEY) + end end diff --git a/app/models/member.rb b/app/models/member.rb index dc9247bc9a0..b26b5017183 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -276,6 +276,13 @@ class Member < ActiveRecord::Base @notification_setting ||= user.notification_settings_for(source) end + def notifiable?(type, opts = {}) + # always notify when there isn't a user yet + return true if user.blank? + + NotificationRecipientService.notifiable?(user, type, notifiable_options.merge(opts)) + end + private def send_invite @@ -332,4 +339,8 @@ class Member < ActiveRecord::Base def notification_service NotificationService.new end + + def notifiable_options + {} + end end diff --git a/app/models/members/group_member.rb b/app/models/members/group_member.rb index 47040f95533..661e668dbf9 100644 --- a/app/models/members/group_member.rb +++ b/app/models/members/group_member.rb @@ -30,6 +30,10 @@ class GroupMember < Member 'Group' end + def notifiable_options + { group: group } + end + private def send_invite diff --git a/app/models/members/project_member.rb b/app/models/members/project_member.rb index c0e17f4bfc8..b6f1dd272cd 100644 --- a/app/models/members/project_member.rb +++ b/app/models/members/project_member.rb @@ -87,6 +87,10 @@ class ProjectMember < Member project.owner == user end + def notifiable_options + { project: project } + end + private def delete_member_todos diff --git a/app/models/notification_recipient.rb b/app/models/notification_recipient.rb index 418b42d8f1d..dc862565a71 100644 --- a/app/models/notification_recipient.rb +++ b/app/models/notification_recipient.rb @@ -5,14 +5,22 @@ class NotificationRecipient custom_action: nil, target: nil, acting_user: nil, - project: nil + project: nil, + group: nil, + skip_read_ability: false ) + unless NotificationSetting.levels.key?(type) || type == :subscription + raise ArgumentError, "invalid type: #{type.inspect}" + end + @custom_action = custom_action @acting_user = acting_user @target = target - @project = project || @target&.project + @project = project || default_project + @group = group || @project&.group @user = user @type = type + @skip_read_ability = skip_read_ability end def notification_setting @@ -77,6 +85,8 @@ class NotificationRecipient def has_access? DeclarativePolicy.subject_scope do return false unless user.can?(:receive_notifications) + return true if @skip_read_ability + return false if @project && !user.can?(:read_project, @project) return true unless read_ability @@ -96,6 +106,7 @@ class NotificationRecipient private def read_ability + return nil if @skip_read_ability return @read_ability if instance_variable_defined?(:@read_ability) @read_ability = @@ -111,12 +122,18 @@ class NotificationRecipient end end + def default_project + return nil if @target.nil? + return @target if @target.is_a?(Project) + return @target.project if @target.respond_to?(:project) + end + def find_notification_setting project_setting = @project && user.notification_settings_for(@project) return project_setting unless project_setting.nil? || project_setting.global? - group_setting = @project&.group && user.notification_settings_for(@project.group) + group_setting = @group && user.notification_settings_for(@group) return group_setting unless group_setting.nil? || group_setting.global? diff --git a/app/models/user.rb b/app/models/user.rb index 7935b89662b..a4615436245 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1069,6 +1069,7 @@ class User < ActiveRecord::Base # Added according to https://github.com/plataformatec/devise/blob/7df57d5081f9884849ca15e4fde179ef164a575f/README.md#activejob-integration def send_devise_notification(notification, *args) + return true unless can?(:receive_notifications) devise_mailer.send(notification, self, *args).deliver_later end diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index df04b1a4fe3..4267879b03d 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -10,9 +10,11 @@ class NotificationService # only if ssh key is not deploy key # # This is security email so it will be sent - # even if user disabled notifications + # even if user disabled notifications. However, + # it won't be sent to internal users like the + # ghost user or the EE support bot. def new_key(key) - if key.user + if key.user&.can?(:receive_notifications) mailer.new_ssh_key_email(key.id).deliver_later end end @@ -22,14 +24,14 @@ class NotificationService # This is a security email so it will be sent even if the user user disabled # notifications def new_gpg_key(gpg_key) - if gpg_key.user + if gpg_key.user&.can?(:receive_notifications) mailer.new_gpg_key_email(gpg_key.id).deliver_later end end # Always notify user about email added to profile def new_email(email) - if email.user + if email.user&.can?(:receive_notifications) mailer.new_email_email(email.id).deliver_later end end @@ -185,6 +187,8 @@ class NotificationService # Notify new user with email after creation def new_user(user, token = nil) + return true unless notifiable?(user, :mention) + # Don't email omniauth created users mailer.new_user_email(user.id, token).deliver_later unless user.identities.any? end @@ -206,19 +210,27 @@ class NotificationService # Members def new_access_request(member) + return true unless member.notifiable?(:subscription) + mailer.member_access_requested_email(member.real_source_type, member.id).deliver_later end def decline_access_request(member) + return true unless member.notifiable?(:subscription) + mailer.member_access_denied_email(member.real_source_type, member.source_id, member.user_id).deliver_later end # Project invite def invite_project_member(project_member, token) + return true unless project_member.notifiable?(:subscription) + mailer.member_invited_email(project_member.real_source_type, project_member.id, token).deliver_later end def accept_project_invite(project_member) + return true unless project_member.notifiable?(:subscription) + mailer.member_invite_accepted_email(project_member.real_source_type, project_member.id).deliver_later end @@ -232,10 +244,14 @@ class NotificationService end def new_project_member(project_member) + return true unless project_member.notifiable?(:mention, skip_read_ability: true) + mailer.member_access_granted_email(project_member.real_source_type, project_member.id).deliver_later end def update_project_member(project_member) + return true unless project_member.notifiable?(:mention) + mailer.member_access_granted_email(project_member.real_source_type, project_member.id).deliver_later end @@ -249,6 +265,9 @@ class NotificationService end def decline_group_invite(group_member) + # always send this one, since it's a response to the user's own + # action + mailer.member_invite_declined_email( group_member.real_source_type, group_member.group.id, @@ -258,15 +277,19 @@ class NotificationService end def new_group_member(group_member) + return true unless group_member.notifiable?(:mention) + mailer.member_access_granted_email(group_member.real_source_type, group_member.id).deliver_later end def update_group_member(group_member) + return true unless group_member.notifiable?(:mention) + mailer.member_access_granted_email(group_member.real_source_type, group_member.id).deliver_later end def project_was_moved(project, old_path_with_namespace) - recipients = NotificationRecipientService.notifiable_users(project.team.members, :mention, project: project) + recipients = notifiable_users(project.team.members, :mention, project: project) recipients.each do |recipient| mailer.project_was_moved_email( @@ -288,10 +311,14 @@ class NotificationService end def project_exported(project, current_user) + return true unless notifiable?(current_user, :mention, project: project) + mailer.project_was_exported_email(current_user, project).deliver_later end def project_not_exported(project, current_user, errors) + return true unless notifiable?(current_user, :mention, project: project) + mailer.project_was_not_exported_email(current_user, project, errors).deliver_later end @@ -300,7 +327,7 @@ class NotificationService return unless mailer.respond_to?(email_template) - recipients ||= NotificationRecipientService.notifiable_users( + recipients ||= notifiable_users( [pipeline.user], :watch, custom_action: :"#{pipeline.status}_pipeline", target: pipeline @@ -369,7 +396,7 @@ class NotificationService def relabeled_resource_email(target, labels, current_user, method) recipients = labels.flat_map { |l| l.subscribers(target.project) } - recipients = NotificationRecipientService.notifiable_users( + recipients = notifiable_users( recipients, :subscription, target: target, acting_user: current_user @@ -401,4 +428,14 @@ class NotificationService object.previous_changes[attribute].first end end + + private + + def notifiable?(*args) + NotificationRecipientService.notifiable?(*args) + end + + def notifiable_users(*args) + NotificationRecipientService.notifiable_users(*args) + end end diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml index a4f49d3f6d7..8bf6556079b 100644 --- a/app/views/admin/application_settings/_form.html.haml +++ b/app/views/admin/application_settings/_form.html.haml @@ -48,6 +48,12 @@ = select(:application_setting, :enabled_git_access_protocol, [['Both SSH and HTTP(S)', nil], ['Only SSH', 'ssh'], ['Only HTTP(S)', 'http']], {}, class: 'form-control') %span.help-block#clone-protocol-help Allow only the selected protocols to be used for Git access. + .form-group + .col-sm-offset-2.col-sm-10 + .checkbox + = f.label :project_export_enabled do + = f.check_box :project_export_enabled + Project export enabled %fieldset %legend Account and Limit Settings diff --git a/app/views/projects/_export.html.haml b/app/views/projects/_export.html.haml new file mode 100644 index 00000000000..623d3bc91c6 --- /dev/null +++ b/app/views/projects/_export.html.haml @@ -0,0 +1,41 @@ +- return unless current_application_settings.project_export_enabled? + +- project = local_assigns.fetch(:project) +- expanded = Rails.env.test? + +%section.settings + .settings-header + %h4 + Export project + %button.btn.js-settings-toggle + = expanded ? 'Collapse' : 'Expand' + %p + Export this project with all its related data in order to move your project to a new GitLab instance. Once the export is finished, you can import the file from the "New Project" page. + .settings-content.no-animate{ class: ('expanded' if expanded) } + .bs-callout.bs-callout-info + %p.append-bottom-0 + %p + The following items will be exported: + %ul + %li Project and wiki repositories + %li Project uploads + %li Project configuration including web hooks and services + %li Issues with comments, merge requests with diffs and comments, labels, milestones, snippets, and other project entities + %p + The following items will NOT be exported: + %ul + %li Job traces and artifacts + %li LFS objects + %li Container registry images + %li CI variables + %li Any encrypted tokens + %p + Once the exported file is ready, you will receive a notification email with a download link. + - if project.export_project_path + = link_to 'Download export', download_export_project_path(project), + rel: 'nofollow', download: '', method: :get, class: "btn btn-default" + = link_to 'Generate new export', generate_new_export_project_path(project), + method: :post, class: "btn btn-default" + - else + = link_to 'Export project', export_project_path(project), + method: :post, class: "btn btn-default" diff --git a/app/views/projects/_md_preview.html.haml b/app/views/projects/_md_preview.html.haml index 6e13bf47ff6..97041b87c48 100644 --- a/app/views/projects/_md_preview.html.haml +++ b/app/views/projects/_md_preview.html.haml @@ -1,11 +1,9 @@ - referenced_users = local_assigns.fetch(:referenced_users, nil) - if defined?(@issue) && @issue.confidential? - %li.confidential-issue-warning + .confidential-issue-warning = confidential_icon(@issue) %span This is a confidential issue. Your comment will not be visible to the public. -- else - %li.confidential-issue-warning.not-confidential .md-area .md-header diff --git a/app/views/projects/edit.html.haml b/app/views/projects/edit.html.haml index c2794f8aaa8..6178abe9160 100644 --- a/app/views/projects/edit.html.haml +++ b/app/views/projects/edit.html.haml @@ -161,42 +161,7 @@ = render 'merge_request_settings', form: f = f.submit 'Save changes', class: "btn btn-save" - %section.settings - .settings-header - %h4 - Export project - %button.btn.js-settings-toggle - = expanded ? 'Collapse' : 'Expand' - %p - Export this project with all its related data in order to move your project to a new GitLab instance. Once the export is finished, you can import the file from the "New Project" page. - .settings-content.no-animate{ class: ('expanded' if expanded) } - .bs-callout.bs-callout-info - %p.append-bottom-0 - %p - The following items will be exported: - %ul - %li Project and wiki repositories - %li Project uploads - %li Project configuration including web hooks and services - %li Issues with comments, merge requests with diffs and comments, labels, milestones, snippets, and other project entities - %p - The following items will NOT be exported: - %ul - %li Job traces and artifacts - %li LFS objects - %li Container registry images - %li CI variables - %li Any encrypted tokens - %p - Once the exported file is ready, you will receive a notification email with a download link. - - if @project.export_project_path - = link_to 'Download export', download_export_project_path(@project), - rel: 'nofollow', download: '', method: :get, class: "btn btn-default" - = link_to 'Generate new export', generate_new_export_project_path(@project), - method: :post, class: "btn btn-default" - - else - = link_to 'Export project', export_project_path(@project), - method: :post, class: "btn btn-default" + = render 'export', project: @project %section.settings.advanced-settings .settings-header diff --git a/changelogs/unreleased/13325-bugfix-silence-on-disabled-notifications.yml b/changelogs/unreleased/13325-bugfix-silence-on-disabled-notifications.yml new file mode 100644 index 00000000000..90b169390d2 --- /dev/null +++ b/changelogs/unreleased/13325-bugfix-silence-on-disabled-notifications.yml @@ -0,0 +1,6 @@ +--- +title: disabling notifications globally now properly turns off group/project added + emails +merge_request: 13325 +author: @jneen +type: fixed diff --git a/changelogs/unreleased/35435-pending-delete-project-error-in-admin-interface-fix.yml b/changelogs/unreleased/35435-pending-delete-project-error-in-admin-interface-fix.yml new file mode 100644 index 00000000000..8539615faac --- /dev/null +++ b/changelogs/unreleased/35435-pending-delete-project-error-in-admin-interface-fix.yml @@ -0,0 +1,4 @@ +--- +title: Project pending delete no longer return 500 error in admins projects view +merge_request: 13389 +author: diff --git a/changelogs/unreleased/36213-return-is_admin-in-users-api-when-current_user-is-admin.yml b/changelogs/unreleased/36213-return-is_admin-in-users-api-when-current_user-is-admin.yml new file mode 100644 index 00000000000..b51b5e58b39 --- /dev/null +++ b/changelogs/unreleased/36213-return-is_admin-in-users-api-when-current_user-is-admin.yml @@ -0,0 +1,6 @@ +--- +title: Include the `is_admin` field in the `GET /users/:id` API when current user + is an admin +merge_request: +author: +type: fixed diff --git a/changelogs/unreleased/broadcast-messages-cache.yml b/changelogs/unreleased/broadcast-messages-cache.yml new file mode 100644 index 00000000000..a3c9e1ff465 --- /dev/null +++ b/changelogs/unreleased/broadcast-messages-cache.yml @@ -0,0 +1,4 @@ +--- +title: Better caching and indexing of broadcast messages +merge_request: +author: diff --git a/changelogs/unreleased/disable-project-export.yml b/changelogs/unreleased/disable-project-export.yml new file mode 100644 index 00000000000..d7ca9f46193 --- /dev/null +++ b/changelogs/unreleased/disable-project-export.yml @@ -0,0 +1,4 @@ +--- +title: Add option to disable project export on instance +merge_request: 13211 +author: Robin Bobbitt diff --git a/db/migrate/20170809133343_add_broadcast_messages_index.rb b/db/migrate/20170809133343_add_broadcast_messages_index.rb new file mode 100644 index 00000000000..4ab2ddb059d --- /dev/null +++ b/db/migrate/20170809133343_add_broadcast_messages_index.rb @@ -0,0 +1,21 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddBroadcastMessagesIndex < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + disable_ddl_transaction! + + COLUMNS = %i[starts_at ends_at id].freeze + + def up + add_concurrent_index :broadcast_messages, COLUMNS + end + + def down + remove_concurrent_index :broadcast_messages, COLUMNS + end +end diff --git a/db/migrate/20170809134534_add_broadcast_message_not_null_constraints.rb b/db/migrate/20170809134534_add_broadcast_message_not_null_constraints.rb new file mode 100644 index 00000000000..13e8ef52f22 --- /dev/null +++ b/db/migrate/20170809134534_add_broadcast_message_not_null_constraints.rb @@ -0,0 +1,17 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddBroadcastMessageNotNullConstraints < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + COLUMNS = %i[starts_at ends_at created_at updated_at message_html] + + def change + COLUMNS.each do |column| + change_column_null :broadcast_messages, column, false + end + end +end diff --git a/db/migrate/20170809161910_add_project_export_enabled_to_application_settings.rb b/db/migrate/20170809161910_add_project_export_enabled_to_application_settings.rb new file mode 100644 index 00000000000..4baba1ade6d --- /dev/null +++ b/db/migrate/20170809161910_add_project_export_enabled_to_application_settings.rb @@ -0,0 +1,14 @@ +class AddProjectExportEnabledToApplicationSettings < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + disable_ddl_transaction! + + DOWNTIME = false + + def up + add_column_with_default(:application_settings, :project_export_enabled, :boolean, default: true) + end + + def down + remove_column(:application_settings, :project_export_enabled) + end +end diff --git a/db/schema.rb b/db/schema.rb index 65afe37a21c..3206e106552 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170809142252) do +ActiveRecord::Schema.define(version: 20170809161910) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -127,6 +127,7 @@ ActiveRecord::Schema.define(version: 20170809142252) do t.string "help_page_support_url" t.integer "performance_bar_allowed_group_id" t.boolean "password_authentication_enabled" + t.boolean "project_export_enabled", default: true, null: false end create_table "audit_events", force: :cascade do |t| @@ -163,16 +164,18 @@ ActiveRecord::Schema.define(version: 20170809142252) do create_table "broadcast_messages", force: :cascade do |t| t.text "message", null: false - t.datetime "starts_at" - t.datetime "ends_at" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "starts_at", null: false + t.datetime "ends_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "color" t.string "font" - t.text "message_html" + t.text "message_html", null: false t.integer "cached_markdown_version" end + add_index "broadcast_messages", ["starts_at", "ends_at", "id"], name: "index_broadcast_messages_on_starts_at_and_ends_at_and_id", using: :btree + create_table "chat_names", force: :cascade do |t| t.integer "user_id", null: false t.integer "service_id", null: false diff --git a/doc/development/testing.md b/doc/development/testing.md index ac1865f6682..c7eac3cf40c 100644 --- a/doc/development/testing.md +++ b/doc/development/testing.md @@ -157,8 +157,9 @@ trade-off: - Unit tests are usually cheap, and you should consider them like the basement of your house: you need them to be confident that your code is behaving - correctly. However if you run only unit tests without integration / system tests, you might [miss] the [big] [picture]! -- Integration tests are a bit more expensive, but don't abuse them. A feature test + correctly. However if you run only unit tests without integration / system + tests, you might [miss] the [big] [picture]! +- Integration tests are a bit more expensive, but don't abuse them. A system test is often better than an integration test that is stubbing a lot of internals. - System tests are expensive (compared to unit tests), even more if they require a JavaScript driver. Make sure to follow the guidelines in the [Speed](#test-speed) @@ -195,11 +196,27 @@ Please consult the [dedicated "Frontend testing" guide](./fe_guide/testing.md). - Try to match the ordering of tests to the ordering within the class. - Try to follow the [Four-Phase Test][four-phase-test] pattern, using newlines to separate phases. -- Try to use `Gitlab.config.gitlab.host` rather than hard coding `'localhost'` +- Use `Gitlab.config.gitlab.host` rather than hard coding `'localhost'` +- Don't assert against the absolute value of a sequence-generated attribute (see + [Gotchas](gotchas.md#dont-assert-against-the-absolute-value-of-a-sequence-generated-attribute)). +- Don't supply the `:each` argument to hooks since it's the default. - On `before` and `after` hooks, prefer it scoped to `:context` over `:all` [four-phase-test]: https://robots.thoughtbot.com/four-phase-test +### Automatic retries and flaky tests detection + +On our CI, we use [rspec-retry] to automatically retry a failing example a few +times (see [`spec/spec_helper.rb`] for the precise retries count). + +We also use a home-made `RspecFlaky::Listener` listener which records flaky +examples in a JSON report file on `master` (`retrieve-tests-metadata` and `update-tests-metadata` jobs), and warns when a new flaky example +is detected in any other branch (`flaky-examples-check` job). In the future, the +`flaky-examples-check` job will not be allowed to fail. + +[rspec-retry]: https://github.com/NoRedInk/rspec-retry +[`spec/spec_helper.rb`]: https://gitlab.com/gitlab-org/gitlab-ce/blob/master/spec/spec_helper.rb + ### `let` variables GitLab's RSpec suite has made extensive use of `let` variables to reduce diff --git a/doc/install/requirements.md b/doc/install/requirements.md index 141df55f6bc..175dfc62096 100644 --- a/doc/install/requirements.md +++ b/doc/install/requirements.md @@ -104,6 +104,10 @@ features of GitLab work with MySQL/MariaDB: See [issue #30472][30472] for more information. 1. GitLab Geo does [not support MySQL](https://docs.gitlab.com/ee/gitlab-geo/database.html#mysql-replication). 1. [Zero downtime migrations][zero] do not work with MySQL +1. GitLab [optimizes the loading of dashboard events](https://gitlab.com/gitlab-org/gitlab-ce/issues/31806) using [PostgreSQL LATERAL JOINs](https://blog.heapanalytics.com/postgresqls-powerful-new-join-type-lateral/). +1. In general, SQL optimized for PostgreSQL may run much slower in MySQL due to + differences in query planners. For example, subqueries that work well in PostgreSQL + may not be [performant in MySQL](https://dev.mysql.com/doc/refman/5.7/en/optimizing-subqueries.html) 1. We expect this list to grow over time. Existing users using GitLab with MySQL/MariaDB are advised to diff --git a/doc/update/patch_versions.md b/doc/update/patch_versions.md index 12408123158..30107360446 100644 --- a/doc/update/patch_versions.md +++ b/doc/update/patch_versions.md @@ -56,21 +56,17 @@ sudo -u git -H bundle clean # Run database migrations sudo -u git -H bundle exec rake db:migrate RAILS_ENV=production -### 4. Compile GetText PO files - -Internationalization was added in `v9.2.0` so these commands are only -required for versions equal or major to it. - -```bash +# Compile GetText PO files +# Internationalization was added in `v9.2.0` so these commands are only +# required for versions equal or major to it. sudo -u git -H bundle exec rake gettext:pack RAILS_ENV=production sudo -u git -H bundle exec rake gettext:po_to_json RAILS_ENV=production -``` # Clean up assets and cache sudo -u git -H bundle exec rake yarn:install gitlab:assets:clean gitlab:assets:compile cache:clear RAILS_ENV=production NODE_ENV=production ``` -### 5. Update gitlab-workhorse to the corresponding version +### 4. Update gitlab-workhorse to the corresponding version ```bash cd /home/git/gitlab @@ -78,7 +74,7 @@ cd /home/git/gitlab sudo -u git -H bundle exec rake "gitlab:workhorse:install[/home/git/gitlab-workhorse]" RAILS_ENV=production ``` -### 6. Update gitlab-shell to the corresponding version +### 5. Update gitlab-shell to the corresponding version ```bash cd /home/git/gitlab-shell @@ -88,14 +84,14 @@ sudo -u git -H git checkout v`cat /home/git/gitlab/GITLAB_SHELL_VERSION` -b v`ca sudo -u git -H sh -c 'if [ -x bin/compile ]; then bin/compile; fi' ``` -### 7. Start application +### 6. Start application ```bash sudo service gitlab start sudo service nginx restart ``` -### 8. Check application status +### 7. Check application status Check if GitLab and its environment are configured correctly: diff --git a/doc/user/project/settings/import_export.md b/doc/user/project/settings/import_export.md index 35960ade3d4..97cca3007b1 100644 --- a/doc/user/project/settings/import_export.md +++ b/doc/user/project/settings/import_export.md @@ -9,6 +9,9 @@ > application settings (`/admin/application_settings`) under 'Import sources'. > Ask your administrator if you don't see the **GitLab export** button when > creating a new project. +> - Starting with GitLab 10.0, administrators can disable the project export option +> on the GitLab instance in application settings (`/admin/application_settings`) +> under 'Visibility and Access Controls'. > - You can find some useful raketasks if you are an administrator in the > [import_export](../../../administration/raketasks/project_import_export.md) > raketask. diff --git a/lib/api/settings.rb b/lib/api/settings.rb index d55a61fa638..667ba468ce6 100644 --- a/lib/api/settings.rb +++ b/lib/api/settings.rb @@ -29,6 +29,7 @@ module API desc: 'Enabled sources for code import during project creation. OmniAuth must be configured for GitHub, Bitbucket, and GitLab.com' optional :disabled_oauth_sign_in_sources, type: Array[String], desc: 'Disable certain OAuth sign-in sources' optional :enabled_git_access_protocol, type: String, values: %w[ssh http nil], desc: 'Allow only the selected protocols to be used for Git access.' + optional :project_export_enabled, type: Boolean, desc: 'Enable project export' optional :gravatar_enabled, type: Boolean, desc: 'Flag indicating if the Gravatar service is enabled' optional :default_projects_limit, type: Integer, desc: 'The maximum number of personal projects' optional :max_attachment_size, type: Integer, desc: 'Maximum attachment size in MB' diff --git a/lib/api/users.rb b/lib/api/users.rb index a590f2692a2..e2019d6d512 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -79,22 +79,17 @@ module API end desc 'Get a single user' do - success Entities::UserBasic + success Entities::User end params do requires :id, type: Integer, desc: 'The ID of the user' end get ":id" do user = User.find_by(id: params[:id]) - not_found!('User') unless user + not_found!('User') unless user && can?(current_user, :read_user, user) - if current_user && current_user.admin? - present user, with: Entities::UserPublic - elsif can?(current_user, :read_user, user) - present user, with: Entities::User - else - render_api_error!("User not found.", 404) - end + opts = current_user&.admin? ? { with: Entities::UserWithAdmin } : {} + present user, opts end desc 'Create a user. Available only for admins.' do diff --git a/lib/file_streamer.rb b/lib/file_streamer.rb deleted file mode 100644 index 4e3c6d3c773..00000000000 --- a/lib/file_streamer.rb +++ /dev/null @@ -1,16 +0,0 @@ -class FileStreamer #:nodoc: - attr_reader :to_path - - def initialize(path) - @to_path = path - end - - # Stream the file's contents if Rack::Sendfile isn't present. - def each - File.open(to_path, 'rb') do |file| - while chunk = file.read(16384) - yield chunk - end - end - end -end diff --git a/lib/gitlab/checks/force_push.rb b/lib/gitlab/checks/force_push.rb index 1e73f89158d..714464fd5e7 100644 --- a/lib/gitlab/checks/force_push.rb +++ b/lib/gitlab/checks/force_push.rb @@ -5,12 +5,19 @@ module Gitlab return false if project.empty_repo? # Created or deleted branch - if Gitlab::Git.blank_ref?(oldrev) || Gitlab::Git.blank_ref?(newrev) - false - else - Gitlab::Git::RevList.new( - path_to_repo: project.repository.path_to_repo, - oldrev: oldrev, newrev: newrev).missed_ref.present? + return false if Gitlab::Git.blank_ref?(oldrev) || Gitlab::Git.blank_ref?(newrev) + + GitalyClient.migrate(:force_push) do |is_enabled| + if is_enabled + !project + .repository + .gitaly_commit_client + .is_ancestor(oldrev, newrev) + else + Gitlab::Git::RevList.new( + path_to_repo: project.repository.path_to_repo, + oldrev: oldrev, newrev: newrev).missed_ref.present? + end end end end diff --git a/lib/gitlab/gitaly_client/util.rb b/lib/gitlab/gitaly_client/util.rb index f5a4c5493ef..8fc937496af 100644 --- a/lib/gitlab/gitaly_client/util.rb +++ b/lib/gitlab/gitaly_client/util.rb @@ -5,7 +5,9 @@ module Gitlab def repository(repository_storage, relative_path) Gitaly::Repository.new( storage_name: repository_storage, - relative_path: relative_path + relative_path: relative_path, + git_object_directory: Gitlab::Git::Env['GIT_OBJECT_DIRECTORY'].to_s, + git_alternate_object_directories: Array.wrap(Gitlab::Git::Env['GIT_ALTERNATE_OBJECT_DIRECTORIES']) ) end end diff --git a/lib/gitlab/middleware/webpack_proxy.rb b/lib/gitlab/middleware/webpack_proxy.rb index 6105d165810..6aecf63231f 100644 --- a/lib/gitlab/middleware/webpack_proxy.rb +++ b/lib/gitlab/middleware/webpack_proxy.rb @@ -1,6 +1,7 @@ # This Rack middleware is intended to proxy the webpack assets directory to the # webpack-dev-server. It is only intended for use in development. +# :nocov: module Gitlab module Middleware class WebpackProxy < Rack::Proxy @@ -22,3 +23,4 @@ module Gitlab end end end +# :nocov: diff --git a/lib/gitlab/o_auth/session.rb b/lib/gitlab/o_auth/session.rb index f33bfd0bd0e..30739f2a2c5 100644 --- a/lib/gitlab/o_auth/session.rb +++ b/lib/gitlab/o_auth/session.rb @@ -1,3 +1,4 @@ +# :nocov: module Gitlab module OAuth module Session @@ -15,3 +16,4 @@ module Gitlab end end end +# :nocov: diff --git a/lib/gitlab/seeder.rb b/lib/gitlab/seeder.rb index 823f697f51c..f9ab9bd466f 100644 --- a/lib/gitlab/seeder.rb +++ b/lib/gitlab/seeder.rb @@ -1,3 +1,4 @@ +# :nocov: module DeliverNever def deliver_later self @@ -21,3 +22,4 @@ module Gitlab end end end +# :nocov: diff --git a/lib/rspec_flaky/example.rb b/lib/rspec_flaky/example.rb new file mode 100644 index 00000000000..b6e790cbbab --- /dev/null +++ b/lib/rspec_flaky/example.rb @@ -0,0 +1,46 @@ +module RspecFlaky + # This is a wrapper class for RSpec::Core::Example + class Example + delegate :status, :exception, to: :execution_result + + def initialize(rspec_example) + @rspec_example = rspec_example.try(:example) || rspec_example + end + + def uid + @uid ||= Digest::MD5.hexdigest("#{description}-#{file}") + end + + def example_id + rspec_example.id + end + + def file + metadata[:file_path] + end + + def line + metadata[:line_number] + end + + def description + metadata[:full_description] + end + + def attempts + rspec_example.try(:attempts) || 1 + end + + private + + attr_reader :rspec_example + + def metadata + rspec_example.metadata + end + + def execution_result + rspec_example.execution_result + end + end +end diff --git a/lib/rspec_flaky/flaky_example.rb b/lib/rspec_flaky/flaky_example.rb new file mode 100644 index 00000000000..f81fb90e870 --- /dev/null +++ b/lib/rspec_flaky/flaky_example.rb @@ -0,0 +1,39 @@ +module RspecFlaky + # This represents a flaky RSpec example and is mainly meant to be saved in a JSON file + class FlakyExample < OpenStruct + def initialize(example) + if example.respond_to?(:example_id) + super( + example_id: example.example_id, + file: example.file, + line: example.line, + description: example.description, + last_attempts_count: example.attempts, + flaky_reports: 1) + else + super + end + end + + def first_flaky_at + self[:first_flaky_at] || Time.now + end + + def last_flaky_at + Time.now + end + + def last_flaky_job + return unless ENV['CI_PROJECT_URL'] && ENV['CI_JOB_ID'] + + "#{ENV['CI_PROJECT_URL']}/-/jobs/#{ENV['CI_JOB_ID']}" + end + + def to_h + super.merge( + first_flaky_at: first_flaky_at, + last_flaky_at: last_flaky_at, + last_flaky_job: last_flaky_job) + end + end +end diff --git a/lib/rspec_flaky/listener.rb b/lib/rspec_flaky/listener.rb new file mode 100644 index 00000000000..ec2fbd9e36c --- /dev/null +++ b/lib/rspec_flaky/listener.rb @@ -0,0 +1,75 @@ +require 'json' + +module RspecFlaky + class Listener + attr_reader :all_flaky_examples, :new_flaky_examples + + def initialize + @new_flaky_examples = {} + @all_flaky_examples = init_all_flaky_examples + end + + def example_passed(notification) + current_example = RspecFlaky::Example.new(notification.example) + + return unless current_example.attempts > 1 + + flaky_example_hash = all_flaky_examples[current_example.uid] + + all_flaky_examples[current_example.uid] = + if flaky_example_hash + FlakyExample.new(flaky_example_hash).tap do |ex| + ex.last_attempts_count = current_example.attempts + ex.flaky_reports += 1 + end + else + FlakyExample.new(current_example).tap do |ex| + new_flaky_examples[current_example.uid] = ex + end + end + end + + def dump_summary(_) + write_report_file(all_flaky_examples, all_flaky_examples_report_path) + + if new_flaky_examples.any? + Rails.logger.warn "\nNew flaky examples detected:\n" + Rails.logger.warn JSON.pretty_generate(to_report(new_flaky_examples)) + + write_report_file(new_flaky_examples, new_flaky_examples_report_path) + end + end + + def to_report(examples) + Hash[examples.map { |k, ex| [k, ex.to_h] }] + end + + private + + def init_all_flaky_examples + return {} unless File.exist?(all_flaky_examples_report_path) + + all_flaky_examples = JSON.parse(File.read(all_flaky_examples_report_path)) + + Hash[(all_flaky_examples || {}).map { |k, ex| [k, FlakyExample.new(ex)] }] + end + + def write_report_file(examples, file_path) + return unless ENV['FLAKY_RSPEC_GENERATE_REPORT'] == 'true' + + report_path_dir = File.dirname(file_path) + FileUtils.mkdir_p(report_path_dir) unless Dir.exist?(report_path_dir) + File.write(file_path, JSON.pretty_generate(to_report(examples))) + end + + def all_flaky_examples_report_path + @all_flaky_examples_report_path ||= ENV['ALL_FLAKY_RSPEC_REPORT_PATH'] || + Rails.root.join("rspec_flaky/all-report.json") + end + + def new_flaky_examples_report_path + @new_flaky_examples_report_path ||= ENV['NEW_FLAKY_RSPEC_REPORT_PATH'] || + Rails.root.join("rspec_flaky/new-report.json") + end + end +end diff --git a/scripts/detect-new-flaky-examples b/scripts/detect-new-flaky-examples new file mode 100755 index 00000000000..3bee4f9a34b --- /dev/null +++ b/scripts/detect-new-flaky-examples @@ -0,0 +1,21 @@ +#!/usr/bin/env ruby + +require 'json' + +report_file = ARGV.shift +unless report_file + puts 'usage: detect-new-flaky-examples <report-file>' + exit 1 +end + +puts "Loading #{report_file}..." +report = JSON.parse(File.read(report_file)) + +if report.any? + puts "New flaky examples were detected!\n" + puts JSON.pretty_generate(report) + exit 1 +else + puts "No new flaky examples detected.\n" + exit 0 +end diff --git a/scripts/merge-reports b/scripts/merge-reports index aad76bcc327..3a421f1f1fc 100755 --- a/scripts/merge-reports +++ b/scripts/merge-reports @@ -4,7 +4,7 @@ require 'json' main_report_file = ARGV.shift unless main_report_file - puts 'usage: merge_reports <main-report> [extra reports...]' + puts 'usage: merge-reports <main-report> [extra reports...]' exit 1 end diff --git a/spec/controllers/admin/projects_controller_spec.rb b/spec/controllers/admin/projects_controller_spec.rb index 65587064eb1..373260b3978 100644 --- a/spec/controllers/admin/projects_controller_spec.rb +++ b/spec/controllers/admin/projects_controller_spec.rb @@ -12,12 +12,24 @@ describe Admin::ProjectsController do it 'retrieves the project for the given visibility level' do get :index, visibility_level: [Gitlab::VisibilityLevel::PUBLIC] + expect(response.body).to match(project.name) end it 'does not retrieve the project' do get :index, visibility_level: [Gitlab::VisibilityLevel::INTERNAL] + expect(response.body).not_to match(project.name) end + + it 'does not respond with projects pending deletion' do + pending_delete_project = create(:project, pending_delete: true) + + get :index + + expect(response).to have_http_status(200) + expect(response.body).not_to match(pending_delete_project.name) + expect(response.body).to match(project.name) + end end end diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 8ecd8b6ca71..c0e48046937 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -578,6 +578,118 @@ describe ProjectsController do end end + describe '#export' do + before do + sign_in(user) + + project.add_master(user) + end + + context 'when project export is enabled' do + it 'returns 302' do + get :export, namespace_id: project.namespace, id: project + + expect(response).to have_http_status(302) + end + end + + context 'when project export is disabled' do + before do + stub_application_setting(project_export_enabled?: false) + end + + it 'returns 404' do + get :export, namespace_id: project.namespace, id: project + + expect(response).to have_http_status(404) + end + end + end + + describe '#download_export' do + before do + sign_in(user) + + project.add_master(user) + end + + context 'when project export is enabled' do + it 'returns 302' do + get :download_export, namespace_id: project.namespace, id: project + + expect(response).to have_http_status(302) + end + end + + context 'when project export is disabled' do + before do + stub_application_setting(project_export_enabled?: false) + end + + it 'returns 404' do + get :download_export, namespace_id: project.namespace, id: project + + expect(response).to have_http_status(404) + end + end + end + + describe '#remove_export' do + before do + sign_in(user) + + project.add_master(user) + end + + context 'when project export is enabled' do + it 'returns 302' do + post :remove_export, namespace_id: project.namespace, id: project + + expect(response).to have_http_status(302) + end + end + + context 'when project export is disabled' do + before do + stub_application_setting(project_export_enabled?: false) + end + + it 'returns 404' do + post :remove_export, namespace_id: project.namespace, id: project + + expect(response).to have_http_status(404) + end + end + end + + describe '#generate_new_export' do + before do + sign_in(user) + + project.add_master(user) + end + + context 'when project export is enabled' do + it 'returns 302' do + post :generate_new_export, namespace_id: project.namespace, id: project + + expect(response).to have_http_status(302) + end + end + + context 'when project export is disabled' do + before do + stub_application_setting(project_export_enabled?: false) + end + + it 'returns 404' do + post :generate_new_export, namespace_id: project.namespace, id: project + + expect(response).to have_http_status(404) + end + end + end + def project_moved_message(redirect_route, project) "Project '#{redirect_route.path}' was moved to '#{project.full_path}'. Please update any links and bookmarks that may still have the old path." end diff --git a/spec/features/admin/admin_settings_spec.rb b/spec/features/admin/admin_settings_spec.rb index c9591a7d854..5db42175c15 100644 --- a/spec/features/admin/admin_settings_spec.rb +++ b/spec/features/admin/admin_settings_spec.rb @@ -35,6 +35,7 @@ feature 'Admin updates settings' do fill_in 'Help page text', with: 'Example text' check 'Hide marketing-related entries from help' fill_in 'Support page URL', with: 'http://example.com/help' + uncheck 'Project export enabled' click_button 'Save' expect(current_application_settings.gravatar_enabled).to be_falsey @@ -42,6 +43,7 @@ feature 'Admin updates settings' do expect(current_application_settings.help_page_text).to eq "Example text" expect(current_application_settings.help_page_hide_commercial_content).to be_truthy expect(current_application_settings.help_page_support_url).to eq "http://example.com/help" + expect(current_application_settings.project_export_enabled).to be_falsey expect(page).to have_content "Application settings saved successfully" end diff --git a/spec/features/boards/sidebar_spec.rb b/spec/features/boards/sidebar_spec.rb index 8d3d4ff8773..c3bf50ef9d1 100644 --- a/spec/features/boards/sidebar_spec.rb +++ b/spec/features/boards/sidebar_spec.rb @@ -15,10 +15,12 @@ describe 'Issue Boards', js: true do let!(:list) { create(:list, board: board, label: development, position: 0) } let(:card) { find('.board:nth-child(2)').first('.card') } - before do - Timecop.freeze + around do |example| + Timecop.freeze { example.run } + end - project.team << [user, :master] + before do + project.add_master(user) sign_in(user) @@ -26,10 +28,6 @@ describe 'Issue Boards', js: true do wait_for_requests end - after do - Timecop.return - end - it 'shows sidebar when clicking issue' do click_card(card) diff --git a/spec/features/groups/milestone_spec.rb b/spec/features/groups/milestone_spec.rb index 574bbe0e0e1..32b3e13c624 100644 --- a/spec/features/groups/milestone_spec.rb +++ b/spec/features/groups/milestone_spec.rb @@ -5,14 +5,12 @@ feature 'Group milestones', :js do let!(:project) { create(:project_empty_repo, group: group) } let(:user) { create(:group_member, :master, user: create(:user), group: group ).user } - before do - Timecop.freeze - - sign_in(user) + around do |example| + Timecop.freeze { example.run } end - after do - Timecop.return + before do + sign_in(user) end context 'create a milestone' do diff --git a/spec/features/issues_spec.rb b/spec/features/issues_spec.rb index a5bb642221c..3c8e37ff920 100644 --- a/spec/features/issues_spec.rb +++ b/spec/features/issues_spec.rb @@ -729,7 +729,6 @@ describe 'Issues' do visit project_issue_path(project, issue) expect(page).not_to have_css('.is-confidential') - expect(page).to have_css('.is-not-confidential') end end end diff --git a/spec/finders/admin/projects_finder_spec.rb b/spec/finders/admin/projects_finder_spec.rb index 4e367d39cf3..28e36330029 100644 --- a/spec/finders/admin/projects_finder_spec.rb +++ b/spec/finders/admin/projects_finder_spec.rb @@ -38,6 +38,12 @@ describe Admin::ProjectsFinder do it { is_expected.to match_array([shared_project, public_project, internal_project, private_project]) } end + context 'with pending delete project' do + let!(:pending_delete_project) { create(:project, pending_delete: true) } + + it { is_expected.not_to include(pending_delete_project) } + end + context 'filter by namespace_id' do let(:namespace) { create(:namespace) } let!(:project_in_namespace) { create(:project, namespace: namespace) } diff --git a/spec/lib/gitlab/checks/force_push_spec.rb b/spec/lib/gitlab/checks/force_push_spec.rb index 6c4cfa1203e..f8c8b83a3ac 100644 --- a/spec/lib/gitlab/checks/force_push_spec.rb +++ b/spec/lib/gitlab/checks/force_push_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Gitlab::Checks::ForcePush do let(:project) { create(:project, :repository) } - context "exit code checking" do + context "exit code checking", skip_gitaly_mock: true do it "does not raise a runtime error if the `popen` call to git returns a zero exit code" do allow(Gitlab::Popen).to receive(:popen).and_return(['normal output', 0]) diff --git a/spec/lib/gitlab/git/storage/circuit_breaker_spec.rb b/spec/lib/gitlab/git/storage/circuit_breaker_spec.rb index 7256402b010..9d1763b96ad 100644 --- a/spec/lib/gitlab/git/storage/circuit_breaker_spec.rb +++ b/spec/lib/gitlab/git/storage/circuit_breaker_spec.rb @@ -175,11 +175,7 @@ describe Gitlab::Git::Storage::CircuitBreaker, clean_gitlab_redis_shared_state: describe '#track_storage_inaccessible' do around do |example| - Timecop.freeze - - example.run - - Timecop.return + Timecop.freeze { example.run } end it 'records the failure time in redis' do diff --git a/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb b/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb index a0e5e401359..f5c9680bf59 100644 --- a/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb +++ b/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb @@ -106,12 +106,6 @@ describe Gitlab::HealthChecks::FsShardsCheck do }.with_indifferent_access end - # Unsolved intermittent failure in CI https://gitlab.com/gitlab-org/gitlab-ce/issues/31128 - around do |example| # rubocop:disable RSpec/AroundBlock - times_to_try = ENV['CI'] ? 4 : 1 - example.run_with_retry retry: times_to_try - end - it 'provides metrics' do metrics = described_class.metrics diff --git a/spec/lib/gitlab/metrics/requests_rack_middleware_spec.rb b/spec/lib/gitlab/metrics/requests_rack_middleware_spec.rb index 461b1e4182a..ebe66948a91 100644 --- a/spec/lib/gitlab/metrics/requests_rack_middleware_spec.rb +++ b/spec/lib/gitlab/metrics/requests_rack_middleware_spec.rb @@ -4,10 +4,6 @@ describe Gitlab::Metrics::RequestsRackMiddleware do let(:app) { double('app') } subject { described_class.new(app) } - around do |example| - Timecop.freeze { example.run } - end - describe '#call' do let(:status) { 100 } let(:env) { { 'REQUEST_METHOD' => 'GET' } } @@ -28,16 +24,14 @@ describe Gitlab::Metrics::RequestsRackMiddleware do subject.call(env) end - it 'measures execution time' do - execution_time = 10 - allow(app).to receive(:call) do |*args| - Timecop.freeze(execution_time.seconds) - [200, nil, nil] - end + RSpec::Matchers.define :a_positive_execution_time do + match { |actual| actual > 0 } + end - expect(described_class).to receive_message_chain(:http_request_duration_seconds, :observe).with({ status: 200, method: 'get' }, execution_time) + it 'measures execution time' do + expect(described_class).to receive_message_chain(:http_request_duration_seconds, :observe).with({ status: 200, method: 'get' }, a_positive_execution_time) - subject.call(env) + Timecop.scale(3600) { subject.call(env) } end end diff --git a/spec/lib/gitlab/workhorse_spec.rb b/spec/lib/gitlab/workhorse_spec.rb index 654397ccffb..e78892d4232 100644 --- a/spec/lib/gitlab/workhorse_spec.rb +++ b/spec/lib/gitlab/workhorse_spec.rb @@ -217,7 +217,9 @@ describe Gitlab::Workhorse do it 'includes a Repository param' do repo_param = { Repository: { storage_name: 'default', - relative_path: project.full_path + '.git' + relative_path: project.full_path + '.git', + git_object_directory: '', + git_alternate_object_directories: [] } } expect(subject).to include(repo_param) diff --git a/spec/lib/rspec_flaky/example_spec.rb b/spec/lib/rspec_flaky/example_spec.rb new file mode 100644 index 00000000000..5b4fd5ddf3e --- /dev/null +++ b/spec/lib/rspec_flaky/example_spec.rb @@ -0,0 +1,89 @@ +require 'spec_helper' + +describe RspecFlaky::Example do + let(:example_attrs) do + { + id: 'spec/foo/bar_spec.rb:2', + metadata: { + file_path: 'spec/foo/bar_spec.rb', + line_number: 2, + full_description: 'hello world' + }, + execution_result: double(status: 'passed', exception: 'BOOM!'), + attempts: 1 + } + end + let(:rspec_example) { double(example_attrs) } + + describe '#initialize' do + shared_examples 'a valid Example instance' do + it 'returns valid attributes' do + example = described_class.new(args) + + expect(example.example_id).to eq(example_attrs[:id]) + end + end + + context 'when given an Rspec::Core::Example that responds to #example' do + let(:args) { double(example: rspec_example) } + + it_behaves_like 'a valid Example instance' + end + + context 'when given an Rspec::Core::Example that does not respond to #example' do + let(:args) { rspec_example } + + it_behaves_like 'a valid Example instance' + end + end + + subject { described_class.new(rspec_example) } + + describe '#uid' do + it 'returns a hash of the full description' do + expect(subject.uid).to eq(Digest::MD5.hexdigest("#{subject.description}-#{subject.file}")) + end + end + + describe '#example_id' do + it 'returns the ID of the RSpec::Core::Example' do + expect(subject.example_id).to eq(rspec_example.id) + end + end + + describe '#attempts' do + it 'returns the attempts of the RSpec::Core::Example' do + expect(subject.attempts).to eq(rspec_example.attempts) + end + end + + describe '#file' do + it 'returns the metadata[:file_path] of the RSpec::Core::Example' do + expect(subject.file).to eq(rspec_example.metadata[:file_path]) + end + end + + describe '#line' do + it 'returns the metadata[:line_number] of the RSpec::Core::Example' do + expect(subject.line).to eq(rspec_example.metadata[:line_number]) + end + end + + describe '#description' do + it 'returns the metadata[:full_description] of the RSpec::Core::Example' do + expect(subject.description).to eq(rspec_example.metadata[:full_description]) + end + end + + describe '#status' do + it 'returns the execution_result.status of the RSpec::Core::Example' do + expect(subject.status).to eq(rspec_example.execution_result.status) + end + end + + describe '#exception' do + it 'returns the execution_result.exception of the RSpec::Core::Example' do + expect(subject.exception).to eq(rspec_example.execution_result.exception) + end + end +end diff --git a/spec/lib/rspec_flaky/flaky_example_spec.rb b/spec/lib/rspec_flaky/flaky_example_spec.rb new file mode 100644 index 00000000000..cbfc1e538ab --- /dev/null +++ b/spec/lib/rspec_flaky/flaky_example_spec.rb @@ -0,0 +1,104 @@ +require 'spec_helper' + +describe RspecFlaky::FlakyExample do + let(:flaky_example_attrs) do + { + example_id: 'spec/foo/bar_spec.rb:2', + file: 'spec/foo/bar_spec.rb', + line: 2, + description: 'hello world', + first_flaky_at: 1234, + last_flaky_at: 2345, + last_attempts_count: 2, + flaky_reports: 1 + } + end + let(:example_attrs) do + { + uid: 'abc123', + example_id: flaky_example_attrs[:example_id], + file: flaky_example_attrs[:file], + line: flaky_example_attrs[:line], + description: flaky_example_attrs[:description], + status: 'passed', + exception: 'BOOM!', + attempts: flaky_example_attrs[:last_attempts_count] + } + end + let(:example) { double(example_attrs) } + + describe '#initialize' do + shared_examples 'a valid FlakyExample instance' do + it 'returns valid attributes' do + flaky_example = described_class.new(args) + + expect(flaky_example.uid).to eq(flaky_example_attrs[:uid]) + expect(flaky_example.example_id).to eq(flaky_example_attrs[:example_id]) + end + end + + context 'when given an Rspec::Example' do + let(:args) { example } + + it_behaves_like 'a valid FlakyExample instance' + end + + context 'when given a hash' do + let(:args) { flaky_example_attrs } + + it_behaves_like 'a valid FlakyExample instance' + end + end + + describe '#to_h' do + before do + # Stub these env variables otherwise specs don't behave the same on the CI + stub_env('CI_PROJECT_URL', nil) + stub_env('CI_JOB_ID', nil) + end + + shared_examples 'a valid FlakyExample hash' do + let(:additional_attrs) { {} } + + it 'returns a valid hash' do + flaky_example = described_class.new(args) + final_hash = flaky_example_attrs + .merge(last_flaky_at: instance_of(Time), last_flaky_job: nil) + .merge(additional_attrs) + + expect(flaky_example.to_h).to match(hash_including(final_hash)) + end + end + + context 'when given an Rspec::Example' do + let(:args) { example } + + context 'when run locally' do + it_behaves_like 'a valid FlakyExample hash' do + let(:additional_attrs) do + { first_flaky_at: instance_of(Time) } + end + end + end + + context 'when run on the CI' do + before do + stub_env('CI_PROJECT_URL', 'https://gitlab.com/gitlab-org/gitlab-ce') + stub_env('CI_JOB_ID', 42) + end + + it_behaves_like 'a valid FlakyExample hash' do + let(:additional_attrs) do + { first_flaky_at: instance_of(Time), last_flaky_job: "https://gitlab.com/gitlab-org/gitlab-ce/-/jobs/42" } + end + end + end + end + + context 'when given a hash' do + let(:args) { flaky_example_attrs } + + it_behaves_like 'a valid FlakyExample hash' + end + end +end diff --git a/spec/lib/rspec_flaky/listener_spec.rb b/spec/lib/rspec_flaky/listener_spec.rb new file mode 100644 index 00000000000..0e193bf408b --- /dev/null +++ b/spec/lib/rspec_flaky/listener_spec.rb @@ -0,0 +1,178 @@ +require 'spec_helper' + +describe RspecFlaky::Listener do + let(:flaky_example_report) do + { + 'abc123' => { + example_id: 'spec/foo/bar_spec.rb:2', + file: 'spec/foo/bar_spec.rb', + line: 2, + description: 'hello world', + first_flaky_at: 1234, + last_flaky_at: instance_of(Time), + last_attempts_count: 2, + flaky_reports: 1, + last_flaky_job: nil + } + } + end + let(:example_attrs) do + { + id: 'spec/foo/baz_spec.rb:3', + metadata: { + file_path: 'spec/foo/baz_spec.rb', + line_number: 3, + full_description: 'hello GitLab' + }, + execution_result: double(status: 'passed', exception: nil) + } + end + + before do + # Stub these env variables otherwise specs don't behave the same on the CI + stub_env('CI_PROJECT_URL', nil) + stub_env('CI_JOB_ID', nil) + end + + describe '#initialize' do + shared_examples 'a valid Listener instance' do + let(:expected_all_flaky_examples) { {} } + + it 'returns a valid Listener instance' do + listener = described_class.new + + expect(listener.to_report(listener.all_flaky_examples)) + .to match(hash_including(expected_all_flaky_examples)) + expect(listener.new_flaky_examples).to eq({}) + end + end + + context 'when no report file exists' do + it_behaves_like 'a valid Listener instance' + end + + context 'when a report file exists and set by ALL_FLAKY_RSPEC_REPORT_PATH' do + let(:report_file) do + Tempfile.new(%w[rspec_flaky_report .json]).tap do |f| + f.write(JSON.pretty_generate(flaky_example_report)) + f.rewind + end + end + + before do + stub_env('ALL_FLAKY_RSPEC_REPORT_PATH', report_file.path) + end + + after do + report_file.close + report_file.unlink + end + + it_behaves_like 'a valid Listener instance' do + let(:expected_all_flaky_examples) { flaky_example_report } + end + end + end + + describe '#example_passed' do + let(:rspec_example) { double(example_attrs) } + let(:notification) { double(example: rspec_example) } + + shared_examples 'a non-flaky example' do + it 'does not change the flaky examples hash' do + expect { subject.example_passed(notification) } + .not_to change { subject.all_flaky_examples } + end + end + + describe 'when the RSpec example does not respond to attempts' do + it_behaves_like 'a non-flaky example' + end + + describe 'when the RSpec example has 1 attempt' do + let(:rspec_example) { double(example_attrs.merge(attempts: 1)) } + + it_behaves_like 'a non-flaky example' + end + + describe 'when the RSpec example has 2 attempts' do + let(:rspec_example) { double(example_attrs.merge(attempts: 2)) } + let(:expected_new_flaky_example) do + { + example_id: 'spec/foo/baz_spec.rb:3', + file: 'spec/foo/baz_spec.rb', + line: 3, + description: 'hello GitLab', + first_flaky_at: instance_of(Time), + last_flaky_at: instance_of(Time), + last_attempts_count: 2, + flaky_reports: 1, + last_flaky_job: nil + } + end + + it 'does not change the flaky examples hash' do + expect { subject.example_passed(notification) } + .to change { subject.all_flaky_examples } + + new_example = RspecFlaky::Example.new(rspec_example) + + expect(subject.all_flaky_examples[new_example.uid].to_h) + .to match(hash_including(expected_new_flaky_example)) + end + end + end + + describe '#dump_summary' do + let(:rspec_example) { double(example_attrs) } + let(:notification) { double(example: rspec_example) } + + context 'when a report file path is set by ALL_FLAKY_RSPEC_REPORT_PATH' do + let(:report_file_path) { Rails.root.join('tmp', 'rspec_flaky_report.json') } + + before do + stub_env('ALL_FLAKY_RSPEC_REPORT_PATH', report_file_path) + FileUtils.rm(report_file_path) if File.exist?(report_file_path) + end + + after do + FileUtils.rm(report_file_path) if File.exist?(report_file_path) + end + + context 'when FLAKY_RSPEC_GENERATE_REPORT == "false"' do + before do + stub_env('FLAKY_RSPEC_GENERATE_REPORT', 'false') + end + + it 'does not write the report file' do + subject.example_passed(notification) + + subject.dump_summary(nil) + + expect(File.exist?(report_file_path)).to be(false) + end + end + + context 'when FLAKY_RSPEC_GENERATE_REPORT == "true"' do + before do + stub_env('FLAKY_RSPEC_GENERATE_REPORT', 'true') + end + + it 'writes the report file' do + subject.example_passed(notification) + + subject.dump_summary(nil) + + expect(File.exist?(report_file_path)).to be(true) + end + end + end + end + + describe '#to_report' do + it 'transforms the internal hash to a JSON-ready hash' do + expect(subject.to_report('abc123' => RspecFlaky::FlakyExample.new(flaky_example_report['abc123']))) + .to match(hash_including(flaky_example_report)) + end + end +end diff --git a/spec/models/broadcast_message_spec.rb b/spec/models/broadcast_message_spec.rb index a8ca1d110e4..3369aef1d3e 100644 --- a/spec/models/broadcast_message_spec.rb +++ b/spec/models/broadcast_message_spec.rb @@ -20,7 +20,7 @@ describe BroadcastMessage do it { is_expected.not_to allow_value('000').for(:font) } end - describe '.current' do + describe '.current', :use_clean_rails_memory_store_caching do it 'returns message if time match' do message = create(:broadcast_message) @@ -45,6 +45,14 @@ describe BroadcastMessage do expect(described_class.current).to be_empty end + + it 'caches the output of the query' do + create(:broadcast_message) + + expect(described_class).to receive(:where).and_call_original.once + + 2.times { described_class.current } + end end describe '#active?' do @@ -102,4 +110,14 @@ describe BroadcastMessage do end end end + + describe '#flush_redis_cache' do + it 'flushes the Redis cache' do + message = create(:broadcast_message) + + expect(Rails.cache).to receive(:delete).with(described_class::CACHE_KEY) + + message.flush_redis_cache + end + end end diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 6d825ba68d1..9203f6562f2 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -57,18 +57,14 @@ describe Issue do end describe '#closed_at' do - after do - Timecop.return - end - - let!(:now) { Timecop.freeze(Time.now) } - it 'sets closed_at to Time.now when issue is closed' do issue = create(:issue, state: 'opened') + expect(issue.closed_at).to be_nil + issue.close - expect(issue.closed_at).to eq(now) + expect(issue.closed_at).to be_present end end diff --git a/spec/requests/api/internal_spec.rb b/spec/requests/api/internal_spec.rb index 8a2de23716f..e9c30dba8d4 100644 --- a/spec/requests/api/internal_spec.rb +++ b/spec/requests/api/internal_spec.rb @@ -181,13 +181,12 @@ describe API::Internal do describe "POST /internal/allowed", :clean_gitlab_redis_shared_state do context "access granted" do - before do - project.team << [user, :developer] - Timecop.freeze + around do |example| + Timecop.freeze { example.run } end - after do - Timecop.return + before do + project.team << [user, :developer] end context 'with env passed as a JSON' do diff --git a/spec/requests/api/settings_spec.rb b/spec/requests/api/settings_spec.rb index c3ed5cd8ece..97275b80d03 100644 --- a/spec/requests/api/settings_spec.rb +++ b/spec/requests/api/settings_spec.rb @@ -43,7 +43,9 @@ describe API::Settings, 'Settings' do default_artifacts_expire_in: '2 days', help_page_text: 'custom help text', help_page_hide_commercial_content: true, - help_page_support_url: 'http://example.com/help' + help_page_support_url: 'http://example.com/help', + project_export_enabled: false + expect(response).to have_http_status(200) expect(json_response['default_projects_limit']).to eq(3) expect(json_response['password_authentication_enabled']).to be_falsey @@ -58,6 +60,7 @@ describe API::Settings, 'Settings' do expect(json_response['help_page_text']).to eq('custom help text') expect(json_response['help_page_hide_commercial_content']).to be_truthy expect(json_response['help_page_support_url']).to eq('http://example.com/help') + expect(json_response['project_export_enabled']).to be_falsey end end diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index 2dc7be22f8f..49739a1601a 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -217,9 +217,19 @@ describe API::Users do it "does not return the user's `is_admin` flag" do get api("/users/#{user.id}", user) + expect(response).to have_http_status(200) expect(json_response['is_admin']).to be_nil end + context 'when authenticated as admin' do + it 'includes the `is_admin` field' do + get api("/users/#{user.id}", admin) + + expect(response).to have_http_status(200) + expect(json_response['is_admin']).to be(false) + end + end + context 'for an anonymous user' do it "returns a user by id" do get api("/users/#{user.id}") diff --git a/spec/serializers/analytics_build_entity_spec.rb b/spec/serializers/analytics_build_entity_spec.rb index 9f26d5cd09a..1ff4908972a 100644 --- a/spec/serializers/analytics_build_entity_spec.rb +++ b/spec/serializers/analytics_build_entity_spec.rb @@ -13,12 +13,8 @@ describe AnalyticsBuildEntity do subject { entity.as_json } - before do - Timecop.freeze - end - - after do - Timecop.return + around do |example| + Timecop.freeze { example.run } end it 'contains the URL' do diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index 64981c199e4..44b2d28d1d4 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -80,12 +80,16 @@ describe NotificationService, :mailer do describe 'Keys' do describe '#new_key' do - let!(:key) { create(:personal_key) } + let(:key_options) { {} } + let!(:key) { create(:personal_key, key_options) } it { expect(notification.new_key(key)).to be_truthy } + it { should_email(key.user) } - it 'sends email to key owner' do - expect { notification.new_key(key) }.to change { ActionMailer::Base.deliveries.size }.by(1) + describe 'never emails the ghost user' do + let(:key_options) { { user: User.ghost } } + + it { should_not_email_anyone } end end end @@ -1173,19 +1177,39 @@ describe NotificationService, :mailer do end end - describe '#project_exported' do - it do - notification.project_exported(project, @u_disabled) + context 'user with notifications disabled' do + describe '#project_exported' do + it do + notification.project_exported(project, @u_disabled) + + should_not_email_anyone + end + end + + describe '#project_not_exported' do + it do + notification.project_not_exported(project, @u_disabled, ['error']) - should_only_email(@u_disabled) + should_not_email_anyone + end end end - describe '#project_not_exported' do - it do - notification.project_not_exported(project, @u_disabled, ['error']) + context 'user with notifications enabled' do + describe '#project_exported' do + it do + notification.project_exported(project, @u_participating) - should_only_email(@u_disabled) + should_only_email(@u_participating) + end + end + + describe '#project_not_exported' do + it do + notification.project_not_exported(project, @u_participating, ['error']) + + should_only_email(@u_participating) + end end end end @@ -1209,6 +1233,35 @@ describe NotificationService, :mailer do end.to change { ActionMailer::Base.deliveries.size }.by(1) end end + + describe '#new_group_member' do + let(:group) { create(:group) } + let(:added_user) { create(:user) } + + def create_member! + GroupMember.create( + group: group, + user: added_user, + access_level: Gitlab::Access::GUEST + ) + end + + it 'sends a notification' do + create_member! + should_only_email(added_user) + end + + describe 'when notifications are disabled' do + before do + create_global_setting_for(added_user, :disabled) + end + + it 'does not send a notification' do + create_member! + should_not_email_anyone + end + end + end end describe 'ProjectMember' do @@ -1228,6 +1281,31 @@ describe NotificationService, :mailer do end.to change { ActionMailer::Base.deliveries.size }.by(1) end end + + describe '#new_project_member' do + let(:project) { create(:project) } + let(:added_user) { create(:user) } + + def create_member! + create(:project_member, user: added_user, project: project) + end + + it do + create_member! + should_only_email(added_user) + end + + describe 'when notifications are disabled' do + before do + create_global_setting_for(added_user, :disabled) + end + + it do + create_member! + should_not_email_anyone + end + end + end end context 'guest user in private project' do diff --git a/spec/simplecov_env.rb b/spec/simplecov_env.rb index ac2c89b3ff9..25ddf932d42 100644 --- a/spec/simplecov_env.rb +++ b/spec/simplecov_env.rb @@ -36,18 +36,25 @@ module SimpleCovEnv track_files '{app,lib}/**/*.rb' add_filter '/vendor/ruby/' + add_filter 'app/controllers/sherlock/' add_filter 'config/initializers/' + add_filter 'db/fixtures/' + add_filter 'lib/gitlab/sidekiq_middleware/' + add_filter 'lib/system_check/' add_group 'Controllers', 'app/controllers' - add_group 'Models', 'app/models' - add_group 'Mailers', 'app/mailers' - add_group 'Helpers', 'app/helpers' - add_group 'Workers', %w(app/jobs app/workers) - add_group 'Libraries', 'lib' - add_group 'Services', 'app/services' - add_group 'Finders', 'app/finders' - add_group 'Uploaders', 'app/uploaders' - add_group 'Validators', 'app/validators' + add_group 'Finders', 'app/finders' + add_group 'Helpers', 'app/helpers' + add_group 'Libraries', 'lib' + add_group 'Mailers', 'app/mailers' + add_group 'Models', 'app/models' + add_group 'Policies', 'app/policies' + add_group 'Presenters', 'app/presenters' + add_group 'Serializers', 'app/serializers' + add_group 'Services', 'app/services' + add_group 'Uploaders', 'app/uploaders' + add_group 'Validators', 'app/validators' + add_group 'Workers', %w(app/jobs app/workers) merge_timeout 365.days end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0ba6ed56314..0cddbe89833 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -69,7 +69,14 @@ RSpec.configure do |config| config.raise_errors_for_deprecations! + if ENV['CI'] + # This includes the first try, i.e. tests will be run 4 times before failing. + config.default_retry_count = 4 + config.reporter.register_listener(RspecFlaky::Listener.new, :example_passed, :dump_summary) + end + config.before(:suite) do + Timecop.safe_mode = true TestEnv.init end @@ -97,12 +104,6 @@ RSpec.configure do |config| reset_delivered_emails! end - if ENV['CI'] - config.around(:each) do |ex| - ex.run_with_retry retry: 2 - end - end - config.around(:each, :use_clean_rails_memory_store_caching) do |example| caching_store = Rails.cache Rails.cache = ActiveSupport::Cache::MemoryStore.new diff --git a/spec/views/projects/edit.html.haml_spec.rb b/spec/views/projects/edit.html.haml_spec.rb index 94899e26292..1af422941d7 100644 --- a/spec/views/projects/edit.html.haml_spec.rb +++ b/spec/views/projects/edit.html.haml_spec.rb @@ -11,14 +11,26 @@ describe 'projects/edit' do allow(controller).to receive(:current_user).and_return(user) allow(view).to receive_messages(current_user: user, can?: true) - allow(Gitlab.config.lfs).to receive(:enabled).and_return(true) end context 'LFS enabled setting' do it 'displays the correct elements' do + allow(Gitlab.config.lfs).to receive(:enabled).and_return(true) + render + expect(rendered).to have_select('project_lfs_enabled') expect(rendered).to have_content('Git Large File Storage') end end + + context 'project export disabled' do + it 'does not display the project export option' do + stub_application_setting(project_export_enabled?: false) + + render + + expect(rendered).not_to have_content('Export project') + end + end end |