diff options
25 files changed, 247 insertions, 157 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index df3458b47dd..4e6fcab3808 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: "dev.gitlab.org:5005/gitlab/gitlab-build-images:ruby-2.3.3-git-2.7-phantomjs-2.1-node-7.1" +image: "dev.gitlab.org:5005/gitlab/gitlab-build-images:ruby-2.3.3-golang-1.8-git-2.7-phantomjs-2.1-node-7.1" cache: key: "ruby-233" diff --git a/Gemfile.lock b/Gemfile.lock index d7e3f7343d0..965c888ca79 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -330,7 +330,7 @@ GEM grape-entity (0.6.0) activesupport multi_json (>= 1.3.2) - grpc (1.1.2) + grpc (1.2.2) google-protobuf (~> 3.1) googleauth (~> 0.5.1) haml (4.0.7) diff --git a/app/controllers/projects/hooks_controller.rb b/app/controllers/projects/hooks_controller.rb index b668a9331e7..1e41f980f31 100644 --- a/app/controllers/projects/hooks_controller.rb +++ b/app/controllers/projects/hooks_controller.rb @@ -10,7 +10,7 @@ class Projects::HooksController < Projects::ApplicationController @hook = @project.hooks.new(hook_params) @hook.save - unless @hook.valid? + unless @hook.valid? @hooks = @project.hooks.select(&:persisted?) flash[:alert] = @hook.errors.full_messages.join.html_safe end @@ -49,7 +49,7 @@ class Projects::HooksController < Projects::ApplicationController def hook_params params.require(:hook).permit( - :build_events, + :job_events, :pipeline_events, :enable_ssl_verification, :issues_events, diff --git a/app/models/commit.rb b/app/models/commit.rb index 5c452f78546..8b8b3f00202 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -326,14 +326,13 @@ class Commit end def raw_diffs(*args) - use_gitaly = Gitlab::GitalyClient.feature_enabled?(:commit_raw_diffs) - deltas_only = args.last.is_a?(Hash) && args.last[:deltas_only] - - if use_gitaly && !deltas_only - Gitlab::GitalyClient::Commit.diff_from_parent(self, *args) - else - raw.diffs(*args) - end + # NOTE: This feature is intentionally disabled until + # https://gitlab.com/gitlab-org/gitaly/issues/178 is resolved + # if Gitlab::GitalyClient.feature_enabled?(:commit_raw_diffs) + # Gitlab::GitalyClient::Commit.diff_from_parent(self, *args) + # else + raw.diffs(*args) + # end end def diffs(diff_options = nil) diff --git a/app/models/note.rb b/app/models/note.rb index c85692c5aec..630d0adbece 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -96,6 +96,7 @@ class Note < ActiveRecord::Base before_validation :set_discussion_id, on: :create after_save :keep_around_commit, unless: :for_personal_snippet? after_save :expire_etag_cache + after_destroy :expire_etag_cache class << self def model_name diff --git a/app/models/repository.rb b/app/models/repository.rb index 526ab1e77a7..2b11ed6128e 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -963,13 +963,15 @@ class Repository end def is_ancestor?(ancestor_id, descendant_id) - Gitlab::GitalyClient.migrate(:is_ancestor) do |is_enabled| - if is_enabled - raw_repository.is_ancestor?(ancestor_id, descendant_id) - else - merge_base_commit(ancestor_id, descendant_id) == ancestor_id - end - end + # NOTE: This feature is intentionally disabled until + # https://gitlab.com/gitlab-org/gitlab-ce/issues/30586 is resolved + # Gitlab::GitalyClient.migrate(:is_ancestor) do |is_enabled| + # if is_enabled + # raw_repository.is_ancestor?(ancestor_id, descendant_id) + # else + merge_base_commit(ancestor_id, descendant_id) == ancestor_id + # end + # end end def empty_repo? diff --git a/app/policies/group_policy.rb b/app/policies/group_policy.rb index cb58c115d54..87398303c68 100644 --- a/app/policies/group_policy.rb +++ b/app/policies/group_policy.rb @@ -28,6 +28,7 @@ class GroupPolicy < BasePolicy can! :admin_namespace can! :admin_group_member can! :change_visibility_level + can! :create_subgroup if @user.can_create_group end if globally_viewable && @subject.request_access_enabled && !member diff --git a/app/views/groups/subgroups.html.haml b/app/views/groups/subgroups.html.haml index be809083139..8f0724c0677 100644 --- a/app/views/groups/subgroups.html.haml +++ b/app/views/groups/subgroups.html.haml @@ -9,7 +9,7 @@ .nav-controls = form_tag request.path, method: :get do |f| = search_field_tag :filter_groups, params[:filter_groups], placeholder: 'Filter by name', class: 'form-control', spellcheck: false - - if can? current_user, :admin_group, @group + - if can?(current_user, :create_subgroup, @group) = link_to new_group_path(parent_id: @group.id), class: 'btn btn-new pull-right' do New Subgroup diff --git a/changelogs/unreleased/30457-expire-note-destroy.yml b/changelogs/unreleased/30457-expire-note-destroy.yml new file mode 100644 index 00000000000..f5c89da68a9 --- /dev/null +++ b/changelogs/unreleased/30457-expire-note-destroy.yml @@ -0,0 +1,4 @@ +--- +title: Fix issue's note cache expiration after delete +merge_request: +author: mhasbini diff --git a/changelogs/unreleased/siemens-gitlab-ce-fix-subgroup-hide-button.yml b/changelogs/unreleased/siemens-gitlab-ce-fix-subgroup-hide-button.yml new file mode 100644 index 00000000000..716311c7582 --- /dev/null +++ b/changelogs/unreleased/siemens-gitlab-ce-fix-subgroup-hide-button.yml @@ -0,0 +1,4 @@ +--- +title: Hide new subgroup button if user has no permission to create one +merge_request: 10627 +author: diff --git a/changelogs/unreleased/zj-api-fix-build-events.yml b/changelogs/unreleased/zj-api-fix-build-events.yml new file mode 100644 index 00000000000..7700d8dcd22 --- /dev/null +++ b/changelogs/unreleased/zj-api-fix-build-events.yml @@ -0,0 +1,4 @@ +--- +title: "Bugfix: POST /projects/:id/hooks and PUT /projects/:id/hook/:hook_id no longer ignore the the job_events param in the V4 API" +merge_request: 10586 +author: diff --git a/config/gitlab.yml.example b/config/gitlab.yml.example index 3c70f35b9d0..06c9f734c2a 100644 --- a/config/gitlab.yml.example +++ b/config/gitlab.yml.example @@ -579,9 +579,9 @@ test: storages: default: path: tmp/tests/repositories/ - gitaly_address: unix:<%= Rails.root.join('tmp/sockets/private/gitaly.socket') %> + gitaly_address: unix:tmp/tests/gitaly/gitaly.socket gitaly: - enabled: false + enabled: true backup: path: tmp/tests/backups gitlab_shell: diff --git a/lib/api/project_hooks.rb b/lib/api/project_hooks.rb index 53791166c33..87dfd1573a4 100644 --- a/lib/api/project_hooks.rb +++ b/lib/api/project_hooks.rb @@ -13,7 +13,7 @@ module API optional :merge_requests_events, type: Boolean, desc: "Trigger hook on merge request events" optional :tag_push_events, type: Boolean, desc: "Trigger hook on tag push events" optional :note_events, type: Boolean, desc: "Trigger hook on note(comment) events" - optional :build_events, type: Boolean, desc: "Trigger hook on build events" + optional :job_events, type: Boolean, desc: "Trigger hook on job events" optional :pipeline_events, type: Boolean, desc: "Trigger hook on pipeline events" optional :wiki_page_events, type: Boolean, desc: "Trigger hook on wiki events" optional :enable_ssl_verification, type: Boolean, desc: "Do SSL verification when triggering the hook" @@ -53,7 +53,10 @@ module API use :project_hook_properties end post ":id/hooks" do - hook = user_project.hooks.new(declared_params(include_missing: false)) + hook_params = declared_params(include_missing: false) + hook_params[:build_events] = hook_params.delete(:job_events) { false } + + hook = user_project.hooks.new(hook_params) if hook.save present hook, with: Entities::ProjectHook @@ -74,7 +77,10 @@ module API put ":id/hooks/:hook_id" do hook = user_project.hooks.find(params.delete(:hook_id)) - if hook.update_attributes(declared_params(include_missing: false)) + update_params = declared_params(include_missing: false) + update_params[:build_events] = update_params.delete(:job_events) if update_params[:job_events] + + if hook.update_attributes(update_params) present hook, with: Entities::ProjectHook else error!("Invalid url given", 422) if hook.errors[:url].present? diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 41ab73abb56..d7dac9f6149 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -45,13 +45,15 @@ module Gitlab # Default branch in the repository def root_ref - @root_ref ||= Gitlab::GitalyClient.migrate(:root_ref) do |is_enabled| - if is_enabled - gitaly_ref_client.default_branch_name - else - discover_default_branch - end - end + # NOTE: This feature is intentionally disabled until + # https://gitlab.com/gitlab-org/gitaly/issues/179 is resolved + # @root_ref ||= Gitlab::GitalyClient.migrate(:root_ref) do |is_enabled| + # if is_enabled + # gitaly_ref_client.default_branch_name + # else + @root_ref ||= discover_default_branch + # end + # end rescue GRPC::BadStatus => e raise CommandError.new(e) end @@ -70,13 +72,15 @@ module Gitlab # Returns an Array of branch names # sorted by name ASC def branch_names - Gitlab::GitalyClient.migrate(:branch_names) do |is_enabled| - if is_enabled - gitaly_ref_client.branch_names - else - branches.map(&:name) - end - end + # Gitlab::GitalyClient.migrate(:branch_names) do |is_enabled| + # NOTE: This feature is intentionally disabled until + # https://gitlab.com/gitlab-org/gitaly/issues/179 is resolved + # if is_enabled + # gitaly_ref_client.branch_names + # else + branches.map(&:name) + # end + # end rescue GRPC::BadStatus => e raise CommandError.new(e) end @@ -131,13 +135,15 @@ module Gitlab # Returns an Array of tag names def tag_names - Gitlab::GitalyClient.migrate(:tag_names) do |is_enabled| - if is_enabled - gitaly_ref_client.tag_names - else - rugged.tags.map { |t| t.name } - end - end + # Gitlab::GitalyClient.migrate(:tag_names) do |is_enabled| + # NOTE: This feature is intentionally disabled until + # https://gitlab.com/gitlab-org/gitaly/issues/179 is resolved + # if is_enabled + # gitaly_ref_client.tag_names + # else + rugged.tags.map { |t| t.name } + # end + # end rescue GRPC::BadStatus => e raise CommandError.new(e) end @@ -458,17 +464,19 @@ module Gitlab # Returns a RefName for a given SHA def ref_name_for_sha(ref_path, sha) - Gitlab::GitalyClient.migrate(:find_ref_name) do |is_enabled| - if is_enabled - gitaly_ref_client.find_ref_name(sha, ref_path) - else - args = %W(#{Gitlab.config.git.bin_path} for-each-ref --count=1 #{ref_path} --contains #{sha}) - - # Not found -> ["", 0] - # Found -> ["b8d95eb4969eefacb0a58f6a28f6803f8070e7b9 commit\trefs/environments/production/77\n", 0] - Gitlab::Popen.popen(args, @path).first.split.last - end - end + # NOTE: This feature is intentionally disabled until + # https://gitlab.com/gitlab-org/gitaly/issues/180 is resolved + # Gitlab::GitalyClient.migrate(:find_ref_name) do |is_enabled| + # if is_enabled + # gitaly_ref_client.find_ref_name(sha, ref_path) + # else + args = %W(#{Gitlab.config.git.bin_path} for-each-ref --count=1 #{ref_path} --contains #{sha}) + + # Not found -> ["", 0] + # Found -> ["b8d95eb4969eefacb0a58f6a28f6803f8070e7b9 commit\trefs/environments/production/77\n", 0] + Gitlab::Popen.popen(args, @path).first.split.last + # end + # end end # Returns commits collection diff --git a/qa/qa/page/main/menu.rb b/qa/qa/page/main/menu.rb index 45db7a92fa4..7ce4e9009f5 100644 --- a/qa/qa/page/main/menu.rb +++ b/qa/qa/page/main/menu.rb @@ -11,7 +11,7 @@ module QA end def go_to_admin_area - within_user_menu { click_link 'Admin Area' } + within_user_menu { click_link 'Admin area' } end def sign_out diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 690f604db5e..3d6d7292b42 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -24,20 +24,21 @@ describe Gitlab::Git::Repository, seed_helper: true do end end - context 'with gitaly enabled' do - before { stub_gitaly } - - it 'gets the branch name from GitalyClient' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name) - repository.root_ref - end - - it 'wraps GRPC exceptions' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name). - and_raise(GRPC::Unknown) - expect { repository.root_ref }.to raise_error(Gitlab::Git::CommandError) - end - end + # TODO: Uncomment when feature is reenabled + # context 'with gitaly enabled' do + # before { stub_gitaly } + # + # it 'gets the branch name from GitalyClient' do + # expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name) + # repository.root_ref + # end + # + # it 'wraps GRPC exceptions' do + # expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name). + # and_raise(GRPC::Unknown) + # expect { repository.root_ref }.to raise_error(Gitlab::Git::CommandError) + # end + # end end describe "#rugged" do @@ -112,20 +113,21 @@ describe Gitlab::Git::Repository, seed_helper: true do it { is_expected.to include("master") } it { is_expected.not_to include("branch-from-space") } - context 'with gitaly enabled' do - before { stub_gitaly } - - it 'gets the branch names from GitalyClient' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names) - subject - end - - it 'wraps GRPC exceptions' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names). - and_raise(GRPC::Unknown) - expect { subject }.to raise_error(Gitlab::Git::CommandError) - end - end + # TODO: Uncomment when feature is reenabled + # context 'with gitaly enabled' do + # before { stub_gitaly } + # + # it 'gets the branch names from GitalyClient' do + # expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names) + # subject + # end + # + # it 'wraps GRPC exceptions' do + # expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names). + # and_raise(GRPC::Unknown) + # expect { subject }.to raise_error(Gitlab::Git::CommandError) + # end + # end end describe '#tag_names' do @@ -143,20 +145,21 @@ describe Gitlab::Git::Repository, seed_helper: true do it { is_expected.to include("v1.0.0") } it { is_expected.not_to include("v5.0.0") } - context 'with gitaly enabled' do - before { stub_gitaly } - - it 'gets the tag names from GitalyClient' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names) - subject - end - - it 'wraps GRPC exceptions' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names). - and_raise(GRPC::Unknown) - expect { subject }.to raise_error(Gitlab::Git::CommandError) - end - end + # TODO: Uncomment when feature is reenabled + # context 'with gitaly enabled' do + # before { stub_gitaly } + # + # it 'gets the tag names from GitalyClient' do + # expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names) + # subject + # end + # + # it 'wraps GRPC exceptions' do + # expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names). + # and_raise(GRPC::Unknown) + # expect { subject }.to raise_error(Gitlab::Git::CommandError) + # end + # end end shared_examples 'archive check' do |extenstion| diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb index 980a1b70ef5..ce31c8ed94c 100644 --- a/spec/models/commit_spec.rb +++ b/spec/models/commit_spec.rb @@ -389,31 +389,32 @@ eos end end - describe '#raw_diffs' do - context 'Gitaly commit_raw_diffs feature enabled' do - before do - allow(Gitlab::GitalyClient).to receive(:feature_enabled?).with(:commit_raw_diffs).and_return(true) - end - - context 'when a truthy deltas_only is not passed to args' do - it 'fetches diffs from Gitaly server' do - expect(Gitlab::GitalyClient::Commit).to receive(:diff_from_parent). - with(commit) - - commit.raw_diffs - end - end - - context 'when a truthy deltas_only is passed to args' do - it 'fetches diffs using Rugged' do - opts = { deltas_only: true } - - expect(Gitlab::GitalyClient::Commit).not_to receive(:diff_from_parent) - expect(commit.raw).to receive(:diffs).with(opts) - - commit.raw_diffs(opts) - end - end - end - end + # describe '#raw_diffs' do + # TODO: Uncomment when feature is reenabled + # context 'Gitaly commit_raw_diffs feature enabled' do + # before do + # allow(Gitlab::GitalyClient).to receive(:feature_enabled?).with(:commit_raw_diffs).and_return(true) + # end + # + # context 'when a truthy deltas_only is not passed to args' do + # it 'fetches diffs from Gitaly server' do + # expect(Gitlab::GitalyClient::Commit).to receive(:diff_from_parent). + # with(commit) + # + # commit.raw_diffs + # end + # end + # + # context 'when a truthy deltas_only is passed to args' do + # it 'fetches diffs using Rugged' do + # opts = { deltas_only: true } + # + # expect(Gitlab::GitalyClient::Commit).not_to receive(:diff_from_parent) + # expect(commit.raw).to receive(:diffs).with(opts) + # + # commit.raw_diffs(opts) + # end + # end + # end + # end end diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index af7753caba6..070716e859a 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -110,17 +110,18 @@ describe Environment, models: true do end end - context 'Gitaly find_ref_name feature enabled' do - before do - allow(Gitlab::GitalyClient).to receive(:feature_enabled?).with(:find_ref_name).and_return(true) - end - - it 'calls GitalyClient' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:find_ref_name) - - environment.first_deployment_for(commit) - end - end + # TODO: Uncomment when feature is reenabled + # context 'Gitaly find_ref_name feature enabled' do + # before do + # allow(Gitlab::GitalyClient).to receive(:feature_enabled?).with(:find_ref_name).and_return(true) + # end + # + # it 'calls GitalyClient' do + # expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:find_ref_name) + # + # environment.first_deployment_for(commit) + # end + # end end describe '#environment_type' do diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 3c4bf3f4ddb..557ea97b008 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -622,12 +622,22 @@ describe Note, models: true do describe 'expiring ETag cache' do let(:note) { build(:note_on_issue) } - it "expires cache for note's issue when note is saved" do + def expect_expiration(note) expect_any_instance_of(Gitlab::EtagCaching::Store) .to receive(:touch) .with("/#{note.project.namespace.to_param}/#{note.project.to_param}/noteable/issue/#{note.noteable.id}/notes") + end + + it "expires cache for note's issue when note is saved" do + expect_expiration(note) note.save! end + + it "expires cache for note's issue when note is destroyed" do + expect_expiration(note) + + note.destroy! + end end end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 8bd436558cb..5e5c2b016b6 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -1829,16 +1829,17 @@ describe Repository, models: true do end end - describe '#is_ancestor?' do - context 'Gitaly is_ancestor feature enabled' do - it 'asks Gitaly server if it\'s an ancestor' do - commit = repository.commit - allow(Gitlab::GitalyClient).to receive(:feature_enabled?).with(:is_ancestor).and_return(true) - expect(Gitlab::GitalyClient::Commit).to receive(:is_ancestor). - with(repository.raw_repository, commit.id, commit.id).and_return(true) - - expect(repository.is_ancestor?(commit.id, commit.id)).to be true - end - end - end + # TODO: Uncomment when feature is reenabled + # describe '#is_ancestor?' do + # context 'Gitaly is_ancestor feature enabled' do + # it 'asks Gitaly server if it\'s an ancestor' do + # commit = repository.commit + # allow(Gitlab::GitalyClient).to receive(:feature_enabled?).with(:is_ancestor).and_return(true) + # expect(Gitlab::GitalyClient::Commit).to receive(:is_ancestor). + # with(repository.raw_repository, commit.id, commit.id).and_return(true) + # + # expect(repository.is_ancestor?(commit.id, commit.id)).to be true + # end + # end + # end end diff --git a/spec/policies/group_policy_spec.rb b/spec/policies/group_policy_spec.rb index 5c34ff04152..2077c14ff7a 100644 --- a/spec/policies/group_policy_spec.rb +++ b/spec/policies/group_policy_spec.rb @@ -22,7 +22,8 @@ describe GroupPolicy, models: true do :admin_group, :admin_namespace, :admin_group_member, - :change_visibility_level + :change_visibility_level, + :create_subgroup ] end diff --git a/spec/requests/api/project_hooks_spec.rb b/spec/requests/api/project_hooks_spec.rb index b1f8c249092..b1603233f9e 100644 --- a/spec/requests/api/project_hooks_spec.rb +++ b/spec/requests/api/project_hooks_spec.rb @@ -22,8 +22,8 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do context "authorized user" do it "returns project hooks" do get api("/projects/#{project.id}/hooks", user) - expect(response).to have_http_status(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(response).to include_pagination_headers expect(json_response.count).to eq(1) @@ -43,6 +43,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do context "unauthorized user" do it "does not access project hooks" do get api("/projects/#{project.id}/hooks", user3) + expect(response).to have_http_status(403) end end @@ -52,6 +53,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do context "authorized user" do it "returns a project hook" do get api("/projects/#{project.id}/hooks/#{hook.id}", user) + expect(response).to have_http_status(200) expect(json_response['url']).to eq(hook.url) expect(json_response['issues_events']).to eq(hook.issues_events) @@ -67,6 +69,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do it "returns a 404 error if hook id is not available" do get api("/projects/#{project.id}/hooks/1234", user) + expect(response).to have_http_status(404) end end @@ -88,7 +91,8 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do it "adds hook to project" do expect do post api("/projects/#{project.id}/hooks", user), - url: "http://example.com", issues_events: true, wiki_page_events: true + url: "http://example.com", issues_events: true, wiki_page_events: true, + job_events: true end.to change {project.hooks.count}.by(1) expect(response).to have_http_status(201) @@ -98,7 +102,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do expect(json_response['merge_requests_events']).to eq(false) expect(json_response['tag_push_events']).to eq(false) expect(json_response['note_events']).to eq(false) - expect(json_response['job_events']).to eq(false) + expect(json_response['job_events']).to eq(true) expect(json_response['pipeline_events']).to eq(false) expect(json_response['wiki_page_events']).to eq(true) expect(json_response['enable_ssl_verification']).to eq(true) @@ -136,7 +140,8 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do describe "PUT /projects/:id/hooks/:hook_id" do it "updates an existing project hook" do put api("/projects/#{project.id}/hooks/#{hook.id}", user), - url: 'http://example.org', push_events: false + url: 'http://example.org', push_events: false, job_events: true + expect(response).to have_http_status(200) expect(json_response['url']).to eq('http://example.org') expect(json_response['issues_events']).to eq(hook.issues_events) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4eb5b150af5..a3665795452 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -59,6 +59,10 @@ RSpec.configure do |config| TestEnv.init end + config.after(:suite) do + TestEnv.cleanup + end + if ENV['CI'] # Retry only on feature specs that use JS config.around :each, :js do |ex| diff --git a/spec/support/gitaly.rb b/spec/support/gitaly.rb new file mode 100644 index 00000000000..7aca902fc61 --- /dev/null +++ b/spec/support/gitaly.rb @@ -0,0 +1,7 @@ +if Gitlab::GitalyClient.enabled? + RSpec.configure do |config| + config.before(:each) do + allow(Gitlab::GitalyClient).to receive(:feature_enabled?).and_return(true) + end + end +end diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index 1b5cb71a6b0..60c2096a126 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -64,6 +64,8 @@ module TestEnv # Setup GitLab shell for test instance setup_gitlab_shell + setup_gitaly if Gitlab::GitalyClient.enabled? + # Create repository for FactoryGirl.create(:project) setup_factory_repo @@ -71,6 +73,10 @@ module TestEnv setup_forked_repo end + def cleanup + stop_gitaly + end + def disable_mailer allow_any_instance_of(NotificationService).to receive(:mailer). and_return(double.as_null_object) @@ -92,7 +98,7 @@ module TestEnv tmp_test_path = Rails.root.join('tmp', 'tests', '**') Dir[tmp_test_path].each do |entry| - unless File.basename(entry) =~ /\Agitlab-(shell|test|test_bare|test-fork|test-fork_bare)\z/ + unless File.basename(entry) =~ /\A(gitaly|gitlab-(shell|test|test_bare|test-fork|test-fork_bare))\z/ FileUtils.rm_rf(entry) end end @@ -110,6 +116,28 @@ module TestEnv end end + def setup_gitaly + socket_path = Gitlab::GitalyClient.get_address('default').sub(/\Aunix:/, '') + gitaly_dir = File.dirname(socket_path) + + unless File.directory?(gitaly_dir) || system('rake', "gitlab:gitaly:install[#{gitaly_dir}]") + raise "Can't clone gitaly" + end + + start_gitaly(gitaly_dir, socket_path) + end + + def start_gitaly(gitaly_dir, socket_path) + gitaly_exec = File.join(gitaly_dir, 'gitaly') + @gitaly_pid = spawn({ "GITALY_SOCKET_PATH" => socket_path }, gitaly_exec, [:out, :err] => '/dev/null') + end + + def stop_gitaly + return unless @gitaly_pid + + Process.kill('KILL', @gitaly_pid) + end + def setup_factory_repo setup_repo(factory_repo_path, factory_repo_path_bare, factory_repo_name, BRANCH_SHA) |