2014-09-02 18:07:02 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
describe Git::TagPushService do
|
2015-04-26 12:48:37 +05:30
|
|
|
include RepoHelpers
|
2018-12-05 23:21:45 +05:30
|
|
|
include GitHelpers
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :repository) }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:service) { described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref) }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:oldrev) { Gitlab::Git::BLANK_SHA }
|
|
|
|
let(:newrev) { "8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b" } # gitlab-test: git rev-parse refs/tags/v1.1.0
|
|
|
|
let(:ref) { 'refs/tags/v1.1.0' }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe "Push tags" do
|
|
|
|
subject do
|
|
|
|
service.execute
|
|
|
|
service
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'flushes general cached data' do
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(project.repository).to receive(:before_push_tag)
|
2016-08-24 12:49:21 +05:30
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'flushes the tags cache' do
|
|
|
|
expect(project.repository).to receive(:expire_tags_cache)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
describe 'System Hooks' do
|
|
|
|
let!(:push_data) { service.tap(&:execute).push_data }
|
|
|
|
|
|
|
|
it "executes system hooks after pushing a tag" do
|
|
|
|
expect_next_instance_of(SystemHooksService) do |system_hooks_service|
|
|
|
|
expect(system_hooks_service)
|
|
|
|
.to receive(:execute_hooks)
|
|
|
|
.with(push_data, :tag_push_hooks)
|
|
|
|
end
|
|
|
|
|
|
|
|
service.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe "Pipelines" do
|
|
|
|
subject { service.execute }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_ci_pipeline_to_return_yaml_file
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_developer(user)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a new pipeline" do
|
2018-03-17 18:26:18 +05:30
|
|
|
expect { subject }.to change { Ci::Pipeline.count }
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(Ci::Pipeline.last).to be_push
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
describe "Git Tag Push Data" do
|
2014-09-02 18:07:02 +05:30
|
|
|
subject { @push_data }
|
2016-11-24 13:41:30 +05:30
|
|
|
let(:tag) { project.repository.find_tag(tag_name) }
|
|
|
|
let(:commit) { tag.dereferenced_target }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-11-24 13:41:30 +05:30
|
|
|
context 'annotated tag' do
|
|
|
|
let(:tag_name) { Gitlab::Git.ref_name(ref) }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-11-24 13:41:30 +05:30
|
|
|
before do
|
|
|
|
service.execute
|
|
|
|
@push_data = service.push_data
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-11-24 13:41:30 +05:30
|
|
|
it { is_expected.to include(object_kind: 'tag_push') }
|
|
|
|
it { is_expected.to include(ref: ref) }
|
|
|
|
it { is_expected.to include(before: oldrev) }
|
|
|
|
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_name: user.name) }
|
|
|
|
it { is_expected.to include(project_id: project.id) }
|
|
|
|
|
|
|
|
context "with repository data" do
|
|
|
|
subject { @push_data[:repository] }
|
|
|
|
|
|
|
|
it { is_expected.to include(name: project.name) }
|
|
|
|
it { is_expected.to include(url: project.url_to_repo) }
|
|
|
|
it { is_expected.to include(description: project.description) }
|
|
|
|
it { is_expected.to include(homepage: project.web_url) }
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2016-11-24 13:41:30 +05:30
|
|
|
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
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2016-11-24 13:41:30 +05:30
|
|
|
end
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-11-24 13:41:30 +05:30
|
|
|
context 'lightweight tag' do
|
|
|
|
let(:tag_name) { 'light-tag' }
|
|
|
|
let(:newrev) { '5937ac0a7beb003549fc5fd26fc247adbce4a52e' }
|
|
|
|
let(:ref) { "refs/tags/light-tag" }
|
|
|
|
|
|
|
|
before do
|
|
|
|
# Create the lightweight tag
|
2018-12-05 23:21:45 +05:30
|
|
|
rugged_repo(project.repository).tags.create(tag_name, newrev)
|
2016-11-24 13:41:30 +05:30
|
|
|
|
|
|
|
# Clear tag list cache
|
|
|
|
project.repository.expire_tags_cache
|
|
|
|
|
|
|
|
service.execute
|
|
|
|
@push_data = service.push_data
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to include(object_kind: 'tag_push') }
|
|
|
|
it { is_expected.to include(ref: ref) }
|
|
|
|
it { is_expected.to include(before: oldrev) }
|
|
|
|
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_name: user.name) }
|
|
|
|
it { is_expected.to include(project_id: project.id) }
|
|
|
|
|
|
|
|
context "with repository data" do
|
|
|
|
subject { @push_data[:repository] }
|
|
|
|
|
|
|
|
it { is_expected.to include(name: project.name) }
|
|
|
|
it { is_expected.to include(url: project.url_to_repo) }
|
|
|
|
it { is_expected.to include(description: project.description) }
|
|
|
|
it { is_expected.to include(homepage: project.web_url) }
|
|
|
|
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
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-11-24 13:41:30 +05:30
|
|
|
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
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
describe "Webhooks" do
|
|
|
|
context "execute webhooks" do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:service) { described_class.new(project, user, oldrev: 'oldrev', newrev: 'newrev', ref: 'refs/tags/v1.0.0') }
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
it "when pushing tags" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(project).to receive(:execute_hooks)
|
2016-06-02 11:05:42 +05:30
|
|
|
service.execute
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|