Unverified Commit 5de0b078 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Prevent creating 2 Ci::Project entities when enable CI


Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 21e9cc2a494b
...@@ -751,13 +751,9 @@ def ensure_gitlab_ci_project ...@@ -751,13 +751,9 @@ def ensure_gitlab_ci_project
gitlab_ci_project || create_gitlab_ci_project gitlab_ci_project || create_gitlab_ci_project
end end
def enable_ci(user) def enable_ci
# Enable service
service = gitlab_ci_service || create_gitlab_ci_service service = gitlab_ci_service || create_gitlab_ci_service
service.active = true service.active = true
service.save service.save
# Create Ci::Project
Ci::CreateProjectService.new.execute(user, self)
end end
end end
...@@ -58,7 +58,7 @@ def execute(project, user, oldrev, newrev, ref) ...@@ -58,7 +58,7 @@ def execute(project, user, oldrev, newrev, ref)
# If CI was disabled but .gitlab-ci.yml file was pushed # If CI was disabled but .gitlab-ci.yml file was pushed
# we enable CI automatically # we enable CI automatically
if !project.gitlab_ci? && gitlab_ci_yaml?(newrev) if !project.gitlab_ci? && gitlab_ci_yaml?(newrev)
project.enable_ci(user) project.enable_ci
end end
EventCreateService.new.push(project, user, @push_data) EventCreateService.new.push(project, user, @push_data)
......
...@@ -103,7 +103,7 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps ...@@ -103,7 +103,7 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps
end end
step 'commit has ci status' do step 'commit has ci status' do
@project.enable_ci(@user) @project.enable_ci
create :ci_commit, gl_project: @project, sha: sample_commit.id create :ci_commit, gl_project: @project, sha: sample_commit.id
end end
......
...@@ -199,7 +199,7 @@ def current_project ...@@ -199,7 +199,7 @@ def current_project
step 'project "Shop" has CI enabled' do step 'project "Shop" has CI enabled' do
project = Project.find_by(name: "Shop") project = Project.find_by(name: "Shop")
project.enable_ci(@user) project.enable_ci
end end
step 'project "Shop" has CI build' do step 'project "Shop" has CI build' do
......
...@@ -417,9 +417,8 @@ ...@@ -417,9 +417,8 @@
describe :enable_ci do describe :enable_ci do
let(:project) { create :project } let(:project) { create :project }
let(:user) { create :user }
before { project.enable_ci(user) } before { project.enable_ci }
it { expect(project.gitlab_ci?).to be_truthy } it { expect(project.gitlab_ci?).to be_truthy }
it { expect(project.gitlab_ci_project).to be_a(Ci::Project) } it { expect(project.gitlab_ci_project).to be_a(Ci::Project) }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment