Send checkout sha for web hooks and services
This commit is contained in:
parent
1e0f36b42a
commit
a0d4235c04
2 changed files with 70 additions and 52 deletions
|
@ -1,5 +1,9 @@
|
||||||
module Gitlab
|
module Gitlab
|
||||||
module Git
|
module Git
|
||||||
BLANK_SHA = '0' * 40
|
BLANK_SHA = '0' * 40
|
||||||
|
|
||||||
|
def self.extract_ref_name(ref)
|
||||||
|
ref.gsub(/\Arefs\/(tags|heads)\//, '')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
module Gitlab
|
module Gitlab
|
||||||
class PushDataBuilder
|
class PushDataBuilder
|
||||||
|
class << self
|
||||||
# Produce a hash of post-receive data
|
# Produce a hash of post-receive data
|
||||||
#
|
#
|
||||||
# data = {
|
# data = {
|
||||||
|
@ -19,7 +20,7 @@ module Gitlab
|
||||||
# total_commits_count: Fixnum
|
# total_commits_count: Fixnum
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
def self.build(project, user, oldrev, newrev, ref, commits = [])
|
def build(project, user, oldrev, newrev, ref, commits = [])
|
||||||
# Total commits count
|
# Total commits count
|
||||||
commits_count = commits.size
|
commits_count = commits.size
|
||||||
|
|
||||||
|
@ -31,6 +32,7 @@ module Gitlab
|
||||||
before: oldrev,
|
before: oldrev,
|
||||||
after: newrev,
|
after: newrev,
|
||||||
ref: ref,
|
ref: ref,
|
||||||
|
checkout_sha: checkout_sha(project.repository, newrev, ref),
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
user_name: user.name,
|
user_name: user.name,
|
||||||
project_id: project.id,
|
project_id: project.id,
|
||||||
|
@ -55,9 +57,21 @@ module Gitlab
|
||||||
|
|
||||||
# This method provide a sample data generated with
|
# This method provide a sample data generated with
|
||||||
# existing project and commits to test web hooks
|
# existing project and commits to test web hooks
|
||||||
def self.build_sample(project, user)
|
def build_sample(project, user)
|
||||||
commits = project.repository.commits(project.default_branch, nil, 3)
|
commits = project.repository.commits(project.default_branch, nil, 3)
|
||||||
build(project, user, commits.last.id, commits.first.id, "refs/heads/#{project.default_branch}", commits)
|
build(project, user, commits.last.id, commits.first.id, "refs/heads/#{project.default_branch}", commits)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def checkout_sha(repository, newrev, ref)
|
||||||
|
if newrev != Gitlab::Git::BLANK_SHA && ref.start_with?('refs/tags/')
|
||||||
|
tag_name = Gitlab::Git.extract_ref_name(ref)
|
||||||
|
tag = repository.find_tag(tag_name)
|
||||||
|
commit = repository.commit(tag.target)
|
||||||
|
commit.try(:sha)
|
||||||
|
else
|
||||||
|
newrev
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue