Commit 916d7da4 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'fix-gitlab-ci-yml' into 'master'

Look for .gitlab-ci.yml only if checkout_sha is present

Fixes https://dev.gitlab.org/gitlab/gitlabhq/issues/2396

cc @vsizov

See merge request !818
parent cbeaa57a
...@@ -40,10 +40,14 @@ class GitlabCiService < CiService ...@@ -40,10 +40,14 @@ class GitlabCiService < CiService
def execute(data) def execute(data)
return unless supported_events.include?(data[:object_kind]) return unless supported_events.include?(data[:object_kind])
ci_yaml_file = ci_yaml_file(data) sha = data[:checkout_sha]
if ci_yaml_file if sha.present?
data.merge!(ci_yaml_file: ci_yaml_file) file = ci_yaml_file(sha)
if file && file.data
data.merge!(ci_yaml_file: file.data)
end
end end
service_hook.execute(data) service_hook.execute(data)
...@@ -129,15 +133,15 @@ class GitlabCiService < CiService ...@@ -129,15 +133,15 @@ class GitlabCiService < CiService
private private
def ci_yaml_file(data) def ci_yaml_file(sha)
ref = data[:checkout_sha] repository.blob_at(sha, '.gitlab-ci.yml')
repo = project.repository
commit = repo.commit(ref)
blob = Gitlab::Git::Blob.find(repo, commit.id, ".gitlab-ci.yml")
blob && blob.data
end end
def fork_registration_path def fork_registration_path
project_url.sub(/projects\/\d*/, "#{API_PREFIX}/forks") project_url.sub(/projects\/\d*/, "#{API_PREFIX}/forks")
end end
def repository
project.repository
end
end end
...@@ -27,7 +27,7 @@ module Gitlab ...@@ -27,7 +27,7 @@ module Gitlab
# Get latest 20 commits ASC # Get latest 20 commits ASC
commits_limited = commits.last(20) commits_limited = commits.last(20)
# For performance purposes maximum 20 latest commits # For performance purposes maximum 20 latest commits
# will be passed as post receive hook data. # will be passed as post receive hook data.
commit_attrs = commits_limited.map(&:hook_attrs) commit_attrs = commits_limited.map(&:hook_attrs)
...@@ -70,8 +70,11 @@ module Gitlab ...@@ -70,8 +70,11 @@ module Gitlab
end end
def checkout_sha(repository, newrev, ref) def checkout_sha(repository, newrev, ref)
# Checkout sha is nil when we remove branch or tag
return if Gitlab::Git.blank_ref?(newrev)
# Find sha for tag, except when it was deleted. # Find sha for tag, except when it was deleted.
if Gitlab::Git.tag_ref?(ref) && !Gitlab::Git.blank_ref?(newrev) if Gitlab::Git.tag_ref?(ref)
tag_name = Gitlab::Git.ref_name(ref) tag_name = Gitlab::Git.ref_name(ref)
tag = repository.find_tag(tag_name) tag = repository.find_tag(tag_name)
......
...@@ -58,7 +58,7 @@ describe GitlabCiService do ...@@ -58,7 +58,7 @@ describe GitlabCiService do
service_hook = double service_hook = double
service_hook.should_receive(:execute) service_hook.should_receive(:execute)
@service.should_receive(:service_hook).and_return(service_hook) @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) @service.execute(push_sample_data)
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