summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-05-19 13:48:57 -0500
committerKamil Trzcinski <ayufan@ayufan.eu>2016-05-19 13:49:15 -0500
commitf88fce3bea67eca935b050a3b3bd08a0f2695cee (patch)
tree958f3f87352c5848bb6e8e79188210644165062b
parent86b22b4f153610993008e5f6fa65bca1fb57b659 (diff)
downloadgitlab-ce-fix-ci-commit-creation.tar.gz
Fix creation of Ci::Commit object which can lead to pending, failed in some scenariosfix-ci-commit-creation
-rw-r--r--CHANGELOG1
-rw-r--r--app/services/create_commit_builds_service.rb27
-rw-r--r--spec/workers/post_receive_spec.rb16
3 files changed, 29 insertions, 15 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 9613332774f..d0f3d037325 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -8,6 +8,7 @@ v 8.8.0 (unreleased)
- Toggle sign-up confirmation emails in application settings
- Project#open_branches has been cleaned up and no longer loads entire records into memory.
- Escape HTML in commit titles in system note messages
+ - Fix creation of Ci::Commit object which can lead to pending, failed in some scenarios
- Improve multiple branch push performance by memoizing permission checking
- Log to application.log when an admin starts and stops impersonating a user
- Changing the confidentiality of an issue now creates a new system note (Alex Moore-Niemi)
diff --git a/app/services/create_commit_builds_service.rb b/app/services/create_commit_builds_service.rb
index 0d2aa1ff03d..98006e7ccc1 100644
--- a/app/services/create_commit_builds_service.rb
+++ b/app/services/create_commit_builds_service.rb
@@ -18,24 +18,21 @@ class CreateCommitBuildsService
return false
end
- commit = project.ci_commit(sha, ref)
- unless commit
- commit = project.ci_commits.new(sha: sha, ref: ref, before_sha: before_sha, tag: tag)
+ commit = Ci::Commit.new(project: project, sha: sha, ref: ref, before_sha: before_sha, tag: tag)
- # 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!
+ # Skip creating ci_commit when no gitlab-ci.yml is found
+ unless commit.ci_yaml_file
+ return false
end
- # Skip creating builds for commits that have [ci skip]
- unless commit.skip_ci?
- # Create builds for commit
- commit.create_builds(user)
- end
+ # Create a new ci_commit
+ commit.save!
+
+ # # Skip creating builds for commits that have [ci skip]
+ # unless commit.skip_ci?
+ # # Create builds for commit
+ # commit.create_builds(user)
+ # end
commit.touch
commit
diff --git a/spec/workers/post_receive_spec.rb b/spec/workers/post_receive_spec.rb
index 94ff3457902..463f3d93c0a 100644
--- a/spec/workers/post_receive_spec.rb
+++ b/spec/workers/post_receive_spec.rb
@@ -48,6 +48,22 @@ describe PostReceive do
PostReceive.new.perform(pwd(project), key_id, base64_changes)
end
end
+
+ context "gitlab-ci.yml" do
+ subject { PostReceive.new.perform(pwd(project), key_id, base64_changes) }
+
+ context "should create a Ci::Commit for every change" do
+ before { stub_ci_commit_to_return_yaml_file }
+
+ it { expect{ subject }.to change{ Ci::Commit.count }.by(2) }
+ end
+
+ context "should not create a Ci::Commit" do
+ before { stub_ci_commit_yaml_file(nil) }
+
+ it { expect{ subject }.to_not change{ Ci::Commit.count } }
+ end
+ end
end
context "webhook" do