Commit 27859f7e authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'ci-commit-status-skipped' into 'master'

Don't create CI status for refs that doesn't have .gitlab-ci.yml, even if the builds are enabled

Fixes #3827 
Fixes #4157

/cc @grzesiek @dblessing 

See merge request !2139
parents 3ca78f01 742089ae
...@@ -26,6 +26,7 @@ v 8.3.0 (unreleased) ...@@ -26,6 +26,7 @@ v 8.3.0 (unreleased)
- Migrate all CI::Services and CI::WebHooks to Services and WebHooks - Migrate all CI::Services and CI::WebHooks to Services and WebHooks
- Don't show project fork event as "imported" - Don't show project fork event as "imported"
- Add API endpoint to fetch merge request commits list - Add API endpoint to fetch merge request commits list
- Don't create CI status for refs that doesn't have .gitlab-ci.yml, even if the builds are enabled
- Expose events API with comment information and author info - Expose events API with comment information and author info
- Fix: Ensure "Remove Source Branch" button is not shown when branch is being deleted. #3583 - Fix: Ensure "Remove Source Branch" button is not shown when branch is being deleted. #3583
- Run custom Git hooks when branch is created or deleted. - Run custom Git hooks when branch is created or deleted.
......
...@@ -218,16 +218,6 @@ module Ci ...@@ -218,16 +218,6 @@ module Ci
update!(committed_at: DateTime.now) update!(committed_at: DateTime.now)
end end
##
# This method checks if build status should be displayed.
#
# Build status should be available only if builds are enabled
# on project level and `.gitlab-ci.yml` file is present.
#
def show_build_status?
project.builds_enabled? && ci_yaml_file
end
private private
def save_yaml_error(error) def save_yaml_error(error)
......
...@@ -16,9 +16,23 @@ class CreateCommitBuildsService ...@@ -16,9 +16,23 @@ class CreateCommitBuildsService
return false return false
end end
tag = Gitlab::Git.tag_ref?(origin_ref) commit = project.ci_commit(sha)
commit = project.ensure_ci_commit(sha) unless commit
commit = project.ci_commits.new(sha: sha)
# Skip creating ci_commit when no gitlab-ci.yml is found
unless commit.ci_yaml_file
return false
end
# Create a new ci_commit
commit.save!
end
# Skip creating builds for commits that have [ci skip]
unless commit.skip_ci? unless commit.skip_ci?
# Create builds for commit
tag = Gitlab::Git.tag_ref?(origin_ref)
commit.update_committed! commit.update_committed!
commit.create_builds(ref, tag, user) commit.create_builds(ref, tag, user)
end end
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
- @commit.parents.each do |parent| - @commit.parents.each do |parent|
= link_to parent.short_id, namespace_project_commit_path(@project.namespace, @project, parent), class: "monospace" = link_to parent.short_id, namespace_project_commit_path(@project.namespace, @project, parent), class: "monospace"
- if @ci_commit && @ci_commit.show_build_status? - if @ci_commit
.pull-right .pull-right
= link_to ci_status_path(@ci_commit), class: "ci-status ci-#{@ci_commit.status}" do = link_to ci_status_path(@ci_commit), class: "ci-status ci-#{@ci_commit.status}" do
= ci_status_icon(@ci_commit) = ci_status_icon(@ci_commit)
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
%a.text-expander.js-toggle-button ... %a.text-expander.js-toggle-button ...
.pull-right .pull-right
- if ci_commit && ci_commit.show_build_status? - if ci_commit
= render_ci_status(ci_commit) = render_ci_status(ci_commit)
   
= clipboard_button(clipboard_text: commit.id) = clipboard_button(clipboard_text: commit.id)
......
...@@ -19,8 +19,6 @@ describe 'Commits' do ...@@ -19,8 +19,6 @@ describe 'Commits' do
let!(:build) { FactoryGirl.create :ci_build, commit: commit } let!(:build) { FactoryGirl.create :ci_build, commit: commit }
describe 'Project commits' do describe 'Project commits' do
context 'builds enabled' do
context '.gitlab-ci.yml found' do
before do before do
visit namespace_project_commits_path(project.namespace, project, :master) visit namespace_project_commits_path(project.namespace, project, :master)
end end
...@@ -32,21 +30,6 @@ describe 'Commits' do ...@@ -32,21 +30,6 @@ describe 'Commits' do
end end
end end
context 'no .gitlab-ci.yml found' do
before do
stub_ci_commit_yaml_file(nil)
visit namespace_project_commits_path(project.namespace, project, :master)
end
it 'should not show build status' do
page.within("//li[@id='commit-#{commit.short_sha}']") do
expect(page).to have_no_css(".ci-status-link")
end
end
end
end
end
describe 'Commit builds' do describe 'Commit builds' do
before do before do
visit ci_status_path(commit) visit ci_status_path(commit)
......
...@@ -52,7 +52,7 @@ describe CreateCommitBuildsService, services: true do ...@@ -52,7 +52,7 @@ describe CreateCommitBuildsService, services: true do
end end
end end
it 'skips commits without .gitlab-ci.yml' do it 'skips creating ci_commit for refs without .gitlab-ci.yml' do
stub_ci_commit_yaml_file(nil) stub_ci_commit_yaml_file(nil)
result = service.execute(project, user, result = service.execute(project, user,
ref: 'refs/heads/0_1', ref: 'refs/heads/0_1',
...@@ -60,13 +60,11 @@ describe CreateCommitBuildsService, services: true do ...@@ -60,13 +60,11 @@ describe CreateCommitBuildsService, services: true do
after: '31das312', after: '31das312',
commits: [{ message: 'Message' }] commits: [{ message: 'Message' }]
) )
expect(result).to be_persisted expect(result).to be_falsey
expect(result.builds.any?).to be_falsey expect(Ci::Commit.count).to eq(0)
expect(result.status).to eq('skipped')
expect(result.yaml_errors).to be_nil
end end
it 'skips commits if yaml is invalid' do it 'fails commits if yaml is invalid' do
message = 'message' message = 'message'
allow_any_instance_of(Ci::Commit).to receive(:git_commit_message) { message } allow_any_instance_of(Ci::Commit).to receive(:git_commit_message) { message }
stub_ci_commit_yaml_file('invalid: file: file') stub_ci_commit_yaml_file('invalid: file: file')
...@@ -77,6 +75,7 @@ describe CreateCommitBuildsService, services: true do ...@@ -77,6 +75,7 @@ describe CreateCommitBuildsService, services: true do
after: '31das312', after: '31das312',
commits: commits commits: commits
) )
expect(commit).to be_persisted
expect(commit.builds.any?).to be false expect(commit.builds.any?).to be false
expect(commit.status).to eq('failed') expect(commit.status).to eq('failed')
expect(commit.yaml_errors).to_not be_nil expect(commit.yaml_errors).to_not be_nil
...@@ -97,6 +96,7 @@ describe CreateCommitBuildsService, services: true do ...@@ -97,6 +96,7 @@ describe CreateCommitBuildsService, services: true do
after: '31das312', after: '31das312',
commits: commits commits: commits
) )
expect(commit).to be_persisted
expect(commit.builds.any?).to be false expect(commit.builds.any?).to be false
expect(commit.status).to eq("skipped") expect(commit.status).to eq("skipped")
end end
...@@ -112,6 +112,7 @@ describe CreateCommitBuildsService, services: true do ...@@ -112,6 +112,7 @@ describe CreateCommitBuildsService, services: true do
commits: commits commits: commits
) )
expect(commit).to be_persisted
expect(commit.builds.first.name).to eq("staging") expect(commit.builds.first.name).to eq("staging")
end end
...@@ -124,6 +125,7 @@ describe CreateCommitBuildsService, services: true do ...@@ -124,6 +125,7 @@ describe CreateCommitBuildsService, services: true do
after: '31das312', after: '31das312',
commits: commits commits: commits
) )
expect(commit).to be_persisted
expect(commit.builds.any?).to be false expect(commit.builds.any?).to be false
expect(commit.status).to eq("skipped") expect(commit.status).to eq("skipped")
expect(commit.yaml_errors).to be_nil expect(commit.yaml_errors).to be_nil
...@@ -140,6 +142,7 @@ describe CreateCommitBuildsService, services: true do ...@@ -140,6 +142,7 @@ describe CreateCommitBuildsService, services: true do
after: '31das312', after: '31das312',
commits: commits commits: commits
) )
expect(commit).to be_persisted
expect(commit.builds.count(:all)).to eq(2) expect(commit.builds.count(:all)).to eq(2)
commit = service.execute(project, user, commit = service.execute(project, user,
...@@ -148,6 +151,7 @@ describe CreateCommitBuildsService, services: true do ...@@ -148,6 +151,7 @@ describe CreateCommitBuildsService, services: true do
after: '31das312', after: '31das312',
commits: commits commits: commits
) )
expect(commit).to be_persisted
expect(commit.builds.count(:all)).to eq(2) expect(commit.builds.count(:all)).to eq(2)
end end
...@@ -163,6 +167,7 @@ describe CreateCommitBuildsService, services: true do ...@@ -163,6 +167,7 @@ describe CreateCommitBuildsService, services: true do
commits: commits commits: commits
) )
expect(commit).to be_persisted
expect(commit.status).to eq("failed") expect(commit.status).to eq("failed")
expect(commit.builds.any?).to be false expect(commit.builds.any?).to be false
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