Commit fad1c2e7 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'topic/push_tag_events_for_ci' of...

Merge branch 'topic/push_tag_events_for_ci' of https://github.com/ayufan/gitlabhq into ayufan-topic/push_tag_events_for_ci
parents 63da396f 5b432e76
...@@ -18,6 +18,7 @@ v 7.10.0 (unreleased) ...@@ -18,6 +18,7 @@ v 7.10.0 (unreleased)
- Add location field to user profile - Add location field to user profile
- Fix print view for markdown files and wiki pages - Fix print view for markdown files and wiki pages
- Improve GitLab performance when working with git repositories - Improve GitLab performance when working with git repositories
- Add tag message and last commit to tag hook (Kamil Trzciński)
v 7.9.0 (unreleased) v 7.9.0 (unreleased)
- Add HipChat integration documentation (Stan Hu) - Add HipChat integration documentation (Stan Hu)
......
...@@ -40,7 +40,8 @@ class CreateTagService < BaseService ...@@ -40,7 +40,8 @@ class CreateTagService < BaseService
end end
def create_push_data(project, user, tag) def create_push_data(project, user, tag)
commits = [project.repository.commit(tag.target)].compact
Gitlab::PushDataBuilder. Gitlab::PushDataBuilder.
build(project, user, Gitlab::Git::BLANK_SHA, tag.target, "#{Gitlab::Git::TAG_REF_PREFIX}#{tag.name}", []) build(project, user, Gitlab::Git::BLANK_SHA, tag.target, "#{Gitlab::Git::TAG_REF_PREFIX}#{tag.name}", commits, tag.message)
end end
end end
...@@ -23,7 +23,6 @@ class GitPushService ...@@ -23,7 +23,6 @@ class GitPushService
project.repository.expire_cache project.repository.expire_cache
project.update_repository_size project.update_repository_size
if push_to_branch?(ref)
if push_remove_branch?(ref, newrev) if push_remove_branch?(ref, newrev)
@push_commits = [] @push_commits = []
elsif push_to_new_branch?(ref, oldrev) elsif push_to_new_branch?(ref, oldrev)
...@@ -59,7 +58,6 @@ class GitPushService ...@@ -59,7 +58,6 @@ class GitPushService
project.execute_hooks(@push_data.dup, :push_hooks) project.execute_hooks(@push_data.dup, :push_hooks)
project.execute_services(@push_data.dup, :push_hooks) project.execute_services(@push_data.dup, :push_hooks)
end end
end
protected protected
......
...@@ -18,6 +18,20 @@ class GitTagPushService ...@@ -18,6 +18,20 @@ class GitTagPushService
private private
def build_push_data(oldrev, newrev, ref) def build_push_data(oldrev, newrev, ref)
Gitlab::PushDataBuilder.build(project, user, oldrev, newrev, ref, []) commits = []
message = nil
if !Gitlab::Git.blank_ref?(newrev)
tag_name = Gitlab::Git.ref_name(ref)
tag = project.repository.find_tag(tag_name)
if tag && tag.target == newrev
commit = project.repository.commit(tag.target)
commits = [commit].compact
message = tag.message
end
end
Gitlab::PushDataBuilder.
build(project, user, oldrev, newrev, ref, commits, message)
end end
end end
...@@ -21,7 +21,7 @@ module Gitlab ...@@ -21,7 +21,7 @@ module Gitlab
# total_commits_count: Fixnum # total_commits_count: Fixnum
# } # }
# #
def build(project, user, oldrev, newrev, ref, commits = []) def build(project, user, oldrev, newrev, ref, commits = [], message = nil)
# Total commits count # Total commits count
commits_count = commits.size commits_count = commits.size
...@@ -42,6 +42,7 @@ module Gitlab ...@@ -42,6 +42,7 @@ module Gitlab
after: newrev, after: newrev,
ref: ref, ref: ref,
checkout_sha: checkout_sha(project.repository, newrev, ref), checkout_sha: checkout_sha(project.repository, newrev, ref),
message: message,
user_id: user.id, user_id: user.id,
user_name: user.name, user_name: user.name,
user_email: user.email, user_email: user.email,
......
...@@ -145,11 +145,6 @@ describe GitPushService do ...@@ -145,11 +145,6 @@ describe GitPushService do
expect(project).to receive(:execute_hooks) expect(project).to receive(:execute_hooks)
service.execute(project, user, 'oldrev', 'newrev', 'refs/heads/master') service.execute(project, user, 'oldrev', 'newrev', 'refs/heads/master')
end end
it "when pushing tags" do
expect(project).not_to receive(:execute_hooks)
service.execute(project, user, 'newrev', 'newrev', 'refs/tags/v1.0.0')
end
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe GitTagPushService do describe GitTagPushService do
include RepoHelpers
let (:user) { create :user } let (:user) { create :user }
let (:project) { create :project } let (:project) { create :project }
let (:service) { GitTagPushService.new } let (:service) { GitTagPushService.new }
before do before do
@ref = 'refs/tags/super-tag' @oldrev = Gitlab::Git::BLANK_SHA
@oldrev = 'b98a310def241a6fd9c9a9a3e7934c48e498fe81' @newrev = "8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b" # gitlab-test: git rev-parse refs/tags/v1.1.0
@newrev = 'b19a04f53caeebf4fe5ec2327cb83e9253dc91bb' @ref = 'refs/tags/v1.1.0'
end end
describe 'Git Tag Push Data' do describe "Git Tag Push Data" do
before do before do
service.execute(project, user, @oldrev, @newrev, @ref) service.execute(project, user, @oldrev, @newrev, @ref)
@push_data = service.push_data @push_data = service.push_data
@tag_name = Gitlab::Git.ref_name(@ref)
@tag = project.repository.find_tag(@tag_name)
@commit = project.repository.commit(@tag.target)
end end
subject { @push_data } subject { @push_data }
it { is_expected.to include(object_kind: 'tag_push') }
it { is_expected.to include(ref: @ref) } it { is_expected.to include(ref: @ref) }
it { is_expected.to include(before: @oldrev) } it { is_expected.to include(before: @oldrev) }
it { is_expected.to include(after: @newrev) } it { is_expected.to include(after: @newrev) }
it { is_expected.to include(message: @tag.message) }
it { is_expected.to include(user_id: user.id) } it { is_expected.to include(user_id: user.id) }
it { is_expected.to include(user_name: user.name) } it { is_expected.to include(user_name: user.name) }
it { is_expected.to include(project_id: project.id) } it { is_expected.to include(project_id: project.id) }
context 'With repository data' do context "with repository data" do
subject { @push_data[:repository] } subject { @push_data[:repository] }
it { is_expected.to include(name: project.name) } it { is_expected.to include(name: project.name) }
...@@ -34,6 +41,41 @@ describe GitTagPushService do ...@@ -34,6 +41,41 @@ describe GitTagPushService do
it { is_expected.to include(description: project.description) } it { is_expected.to include(description: project.description) }
it { is_expected.to include(homepage: project.web_url) } it { is_expected.to include(homepage: project.web_url) }
end end
context "with commits" do
subject { @push_data[:commits] }
it { is_expected.to be_an(Array) }
it 'has 1 element' do
expect(subject.size).to eq(1)
end
context "the commit" do
subject { @push_data[:commits].first }
it { is_expected.to include(id: @commit.id) }
it { is_expected.to include(message: @commit.safe_message) }
it { is_expected.to include(timestamp: @commit.date.xmlschema) }
it do
is_expected.to include(
url: [
Gitlab.config.gitlab.url,
project.namespace.to_param,
project.to_param,
'commit',
@commit.id
].join('/')
)
end
context "with a author" do
subject { @push_data[:commits].first[:author] }
it { is_expected.to include(name: @commit.author_name) }
it { is_expected.to include(email: @commit.author_email) }
end
end
end
end end
describe "Web Hooks" do describe "Web Hooks" do
......
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