diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-12-17 16:21:36 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-12-17 16:33:47 +0100 |
commit | 58a56a03967a407bf376f960809d3398a3153645 (patch) | |
tree | e76fcc3719ab30f96043e5de0b646229ea1a7452 | |
parent | b2c593dac513c0e12153e0aa786759c4ebc996bc (diff) | |
download | gitlab-ce-58a56a03967a407bf376f960809d3398a3153645.tar.gz |
Don't create CI status for refs that doesn't have .gitlab-ci.yml, even if the builds are enabled
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/models/ci/commit.rb | 10 | ||||
-rw-r--r-- | app/services/create_commit_builds_service.rb | 18 | ||||
-rw-r--r-- | app/views/projects/commit/_commit_box.html.haml | 2 | ||||
-rw-r--r-- | app/views/projects/commits/_commit.html.haml | 2 | ||||
-rw-r--r-- | spec/services/create_commit_builds_service_spec.rb | 17 |
6 files changed, 30 insertions, 20 deletions
diff --git a/CHANGELOG b/CHANGELOG index 53aa970d45c..f98615ebd6a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -26,6 +26,7 @@ v 8.3.0 (unreleased) - Migrate all CI::Services and CI::WebHooks to Services and WebHooks - Don't show project fork event as "imported" - 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 - 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. diff --git a/app/models/ci/commit.rb b/app/models/ci/commit.rb index 6bf596e5d3e..d2a29236942 100644 --- a/app/models/ci/commit.rb +++ b/app/models/ci/commit.rb @@ -218,16 +218,6 @@ module Ci update!(committed_at: DateTime.now) 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 def save_yaml_error(error) diff --git a/app/services/create_commit_builds_service.rb b/app/services/create_commit_builds_service.rb index 759c334ebe9..31b407efeb1 100644 --- a/app/services/create_commit_builds_service.rb +++ b/app/services/create_commit_builds_service.rb @@ -16,9 +16,23 @@ class CreateCommitBuildsService return false end - tag = Gitlab::Git.tag_ref?(origin_ref) - commit = project.ensure_ci_commit(sha) + commit = project.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? + # Create builds for commit + tag = Gitlab::Git.tag_ref?(origin_ref) commit.update_committed! commit.create_builds(ref, tag, user) end diff --git a/app/views/projects/commit/_commit_box.html.haml b/app/views/projects/commit/_commit_box.html.haml index cd40bfafcc2..ddb77fd796b 100644 --- a/app/views/projects/commit/_commit_box.html.haml +++ b/app/views/projects/commit/_commit_box.html.haml @@ -40,7 +40,7 @@ - @commit.parents.each do |parent| = 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 = link_to ci_status_path(@ci_commit), class: "ci-status ci-#{@ci_commit.status}" do = ci_status_icon(@ci_commit) diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index 1303b27c4f3..28b82dd31f3 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -17,7 +17,7 @@ %a.text-expander.js-toggle-button ... .pull-right - - if ci_commit && ci_commit.show_build_status? + - if ci_commit = render_ci_status(ci_commit) = clipboard_button(clipboard_text: commit.id) diff --git a/spec/services/create_commit_builds_service_spec.rb b/spec/services/create_commit_builds_service_spec.rb index 40ba6549e1f..ea5dcfa068a 100644 --- a/spec/services/create_commit_builds_service_spec.rb +++ b/spec/services/create_commit_builds_service_spec.rb @@ -52,7 +52,7 @@ describe CreateCommitBuildsService, services: true do 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) result = service.execute(project, user, ref: 'refs/heads/0_1', @@ -60,13 +60,11 @@ describe CreateCommitBuildsService, services: true do after: '31das312', commits: [{ message: 'Message' }] ) - expect(result).to be_persisted - expect(result.builds.any?).to be_falsey - expect(result.status).to eq('skipped') - expect(result.yaml_errors).to be_nil + expect(result).to be_falsey + expect(Ci::Commit.count).to eq(0) end - it 'skips commits if yaml is invalid' do + it 'fails commits if yaml is invalid' do message = 'message' allow_any_instance_of(Ci::Commit).to receive(:git_commit_message) { message } stub_ci_commit_yaml_file('invalid: file: file') @@ -77,6 +75,7 @@ describe CreateCommitBuildsService, services: true do after: '31das312', commits: commits ) + expect(commit).to be_persisted expect(commit.builds.any?).to be false expect(commit.status).to eq('failed') expect(commit.yaml_errors).to_not be_nil @@ -97,6 +96,7 @@ describe CreateCommitBuildsService, services: true do after: '31das312', commits: commits ) + expect(commit).to be_persisted expect(commit.builds.any?).to be false expect(commit.status).to eq("skipped") end @@ -112,6 +112,7 @@ describe CreateCommitBuildsService, services: true do commits: commits ) + expect(commit).to be_persisted expect(commit.builds.first.name).to eq("staging") end @@ -124,6 +125,7 @@ describe CreateCommitBuildsService, services: true do after: '31das312', commits: commits ) + expect(commit).to be_persisted expect(commit.builds.any?).to be false expect(commit.status).to eq("skipped") expect(commit.yaml_errors).to be_nil @@ -140,6 +142,7 @@ describe CreateCommitBuildsService, services: true do after: '31das312', commits: commits ) + expect(commit).to be_persisted expect(commit.builds.count(:all)).to eq(2) commit = service.execute(project, user, @@ -148,6 +151,7 @@ describe CreateCommitBuildsService, services: true do after: '31das312', commits: commits ) + expect(commit).to be_persisted expect(commit.builds.count(:all)).to eq(2) end @@ -163,6 +167,7 @@ describe CreateCommitBuildsService, services: true do commits: commits ) + expect(commit).to be_persisted expect(commit.status).to eq("failed") expect(commit.builds.any?).to be false end |