Commit b859506b authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'enable-ci-on-push' into 'master'

Enable CI for gitlab when .gitlab-ci.yml is pushed 

Make enabling CI as easy as pushing file. 

Should be merged after !1402. 

Fixes #2650. Part of #2594 and internal issue https://dev.gitlab.org/gitlab/gitlabhq/issues/2528

See merge request !1403
parents 32cb9d21 0a57c3f6
......@@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 8.1.0 (unreleased)
- Show CI status on all pages where commits list is rendered
- Automatically enable CI when push .gitlab-ci.yml file to repository
v 8.0.1
- Improve CI migration procedure and documentation
......
......@@ -739,4 +739,14 @@ class Project < ActiveRecord::Base
def ci_commit(sha)
gitlab_ci_project.commits.find_by(sha: sha) if gitlab_ci?
end
def enable_ci(user)
# Enable service
service = gitlab_ci_service || create_gitlab_ci_service
service.active = true
service.save
# Create Ci::Project
Ci::CreateProjectService.new.execute(user, self)
end
end
......@@ -55,6 +55,12 @@ class GitPushService
@push_data = build_push_data(oldrev, newrev, ref)
# If CI was disabled but .gitlab-ci.yml file was pushed
# we enable CI automatically
if !project.gitlab_ci? && gitlab_ci_yaml?(newrev)
project.enable_ci(user)
end
EventCreateService.new.push(project, user, @push_data)
project.execute_hooks(@push_data.dup, :push_hooks)
project.execute_services(@push_data.dup, :push_hooks)
......@@ -143,4 +149,10 @@ class GitPushService
def commit_user(commit)
commit.author || user
end
def gitlab_ci_yaml?(sha)
@project.repository.blob_at(sha, '.gitlab-ci.yml')
rescue Rugged::ReferenceError
nil
end
end
......@@ -411,4 +411,14 @@ describe Project do
it { expect(project.ci_commit(commit.sha)).to eq(commit) }
end
describe :enable_ci do
let(:project) { create :project }
let(:user) { create :user }
before { project.enable_ci(user) }
it { expect(project.gitlab_ci?).to be_truthy }
it { expect(project.gitlab_ci_project).to be_a(Ci::Project) }
end
end
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