Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Leitzen <pl@neopoly.de>2018-07-21 15:57:52 +0300
committerPeter Leitzen <pl@neopoly.de>2018-08-10 17:45:11 +0300
commit7a4b288ec96e64bd9eaf1296d319a39401901df4 (patch)
treee8b488873903d3ec07a5dd0df0cdf006efcde088
parentd6eaf38be4fa1785b6e47eeb76f4ca2cb20a144d (diff)
Create a system note after tagging a commit
-rw-r--r--app/models/system_note_metadata.rb2
-rw-r--r--app/services/commits/update_service.rb3
-rw-r--r--app/services/system_note_service.rb14
-rw-r--r--spec/services/commits/update_service_spec.rb18
-rw-r--r--spec/services/system_note_service_spec.rb17
5 files changed, 51 insertions, 3 deletions
diff --git a/app/models/system_note_metadata.rb b/app/models/system_note_metadata.rb
index c5c77bc8333..376ef673ca8 100644
--- a/app/models/system_note_metadata.rb
+++ b/app/models/system_note_metadata.rb
@@ -15,7 +15,7 @@ class SystemNoteMetadata < ActiveRecord::Base
commit description merge confidential visible label assignee cross_reference
title time_tracking branch milestone discussion task moved
opened closed merged duplicate locked unlocked
- outdated
+ outdated tag
].freeze
validates :note, presence: true
diff --git a/app/services/commits/update_service.rb b/app/services/commits/update_service.rb
index 7ec678ff1cf..45c971d153a 100644
--- a/app/services/commits/update_service.rb
+++ b/app/services/commits/update_service.rb
@@ -20,7 +20,8 @@ module Commits
.new(commit.project, current_user)
.execute(tag_name, commit.sha, message, release_description)
- if result[:status]
+ if result[:status] == :success && (tag = result[:tag])
+ SystemNoteService.tag_commit(commit, commit.project, current_user, tag.name)
commit
end
end
diff --git a/app/services/system_note_service.rb b/app/services/system_note_service.rb
index 77494295f14..452b80b1bfa 100644
--- a/app/services/system_note_service.rb
+++ b/app/services/system_note_service.rb
@@ -32,6 +32,20 @@ module SystemNoteService
create_note(NoteSummary.new(noteable, project, author, body, action: 'commit', commit_count: total_count))
end
+ # Called when a commit was tagged
+ #
+ # noteable - Noteable object
+ # project - Project owning noteable
+ # author - User performing the tag
+ # tag_name - The created tag name
+ #
+ # Returns the created Note object
+ def tag_commit(noteable, project, author, tag_name)
+ body = "tagged commit #{noteable.sha} to `#{tag_name}`"
+
+ create_note(NoteSummary.new(noteable, project, author, body, action: 'tag'))
+ end
+
# Called when the assignee of a Noteable is changed or removed
#
# noteable - Noteable object
diff --git a/spec/services/commits/update_service_spec.rb b/spec/services/commits/update_service_spec.rb
index cfca3a85236..05d1e4ec254 100644
--- a/spec/services/commits/update_service_spec.rb
+++ b/spec/services/commits/update_service_spec.rb
@@ -22,11 +22,26 @@ describe Commits::UpdateService do
end
it 'tags a commit' do
+ tag_double = double(name: opts[:tag_name])
tag_stub = instance_double(Tags::CreateService)
allow(Tags::CreateService).to receive(:new).and_return(tag_stub)
allow(tag_stub).to receive(:execute)
.with(opts[:tag_name], commit.sha, opts[:tag_message], nil)
- .and_return({ status: :success })
+ .and_return({ status: :success, tag: tag_double })
+
+ expect(SystemNoteService).to receive(:tag_commit).with(commit, project, user, opts[:tag_name])
+
+ service.execute(commit)
+ end
+
+ it 'fails to tag the commit' do
+ tag_stub = instance_double(Tags::CreateService)
+ allow(Tags::CreateService).to receive(:new).and_return(tag_stub)
+ allow(tag_stub).to receive(:execute)
+ .with(opts[:tag_name], commit.sha, opts[:tag_message], nil)
+ .and_return({ status: :error })
+
+ expect(SystemNoteService).not_to receive(:tag_commit)
service.execute(commit)
end
@@ -39,6 +54,7 @@ describe Commits::UpdateService do
it 'does not call the tag create service' do
expect(Tags::CreateService).not_to receive(:new)
+ expect(SystemNoteService).not_to receive(:tag_commit)
service.execute(commit)
end
diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb
index 57d081cffb3..cbe5668cf08 100644
--- a/spec/services/system_note_service_spec.rb
+++ b/spec/services/system_note_service_spec.rb
@@ -108,6 +108,23 @@ describe SystemNoteService do
end
end
+ describe '.tag_commit' do
+ let(:noteable) do
+ project.commit
+ end
+ let(:tag_name) { '1.2.3' }
+
+ subject { described_class.tag_commit(noteable, project, author, tag_name) }
+
+ it_behaves_like 'a system note' do
+ let(:action) { 'tag' }
+ end
+
+ it 'sets the note text' do
+ expect(subject.note).to eq "tagged commit #{noteable.sha} to `#{tag_name}`"
+ end
+ end
+
describe '.change_assignee' do
subject { described_class.change_assignee(noteable, project, author, assignee) }