summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-06-15 17:54:42 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-06-15 17:54:42 +0200
commit0674bf2339131c104b233cb9c7ffeeb025f2b461 (patch)
treebbe89762e5a9c8e1785997a1d92431eb0b3fa0f4
parentfe51fa26a777f239dc4a09f531b54162f9f949fc (diff)
downloadgitlab-ce-fix-gitlab-ci-yml.tar.gz
Look for .gitlab-ci.yml only if checkout_sha is presentfix-gitlab-ci-yml
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/models/project_services/gitlab_ci_service.rb22
-rw-r--r--spec/models/project_services/gitlab_ci_service_spec.rb2
2 files changed, 14 insertions, 10 deletions
diff --git a/app/models/project_services/gitlab_ci_service.rb b/app/models/project_services/gitlab_ci_service.rb
index a9354754686..19b5859d5c9 100644
--- a/app/models/project_services/gitlab_ci_service.rb
+++ b/app/models/project_services/gitlab_ci_service.rb
@@ -40,10 +40,14 @@ class GitlabCiService < CiService
def execute(data)
return unless supported_events.include?(data[:object_kind])
- ci_yaml_file = ci_yaml_file(data)
+ sha = data[:checkout_sha]
- if ci_yaml_file
- data.merge!(ci_yaml_file: ci_yaml_file)
+ if sha.present?
+ file = ci_yaml_file(sha)
+
+ if file && file.data
+ data.merge!(ci_yaml_file: file.data)
+ end
end
service_hook.execute(data)
@@ -129,15 +133,15 @@ class GitlabCiService < CiService
private
- def ci_yaml_file(data)
- ref = data[:checkout_sha]
- repo = project.repository
- commit = repo.commit(ref)
- blob = Gitlab::Git::Blob.find(repo, commit.id, ".gitlab-ci.yml")
- blob && blob.data
+ def ci_yaml_file(sha)
+ repository.blob_at(sha, '.gitlab-ci.yml')
end
def fork_registration_path
project_url.sub(/projects\/\d*/, "#{API_PREFIX}/forks")
end
+
+ def repository
+ project.repository
+ end
end
diff --git a/spec/models/project_services/gitlab_ci_service_spec.rb b/spec/models/project_services/gitlab_ci_service_spec.rb
index ebd8b545aa7..c92cf3cdae6 100644
--- a/spec/models/project_services/gitlab_ci_service_spec.rb
+++ b/spec/models/project_services/gitlab_ci_service_spec.rb
@@ -58,7 +58,7 @@ describe GitlabCiService do
service_hook = double
service_hook.should_receive(:execute)
@service.should_receive(:service_hook).and_return(service_hook)
- @service.should_receive(:ci_yaml_file).with(push_sample_data)
+ @service.should_receive(:ci_yaml_file).with(push_sample_data[:checkout_sha])
@service.execute(push_sample_data)
end