Commit 7a4b288e authored by Peter Leitzen's avatar Peter Leitzen

Create a system note after tagging a commit

parent d6eaf38b
...@@ -15,7 +15,7 @@ class SystemNoteMetadata < ActiveRecord::Base ...@@ -15,7 +15,7 @@ class SystemNoteMetadata < ActiveRecord::Base
commit description merge confidential visible label assignee cross_reference commit description merge confidential visible label assignee cross_reference
title time_tracking branch milestone discussion task moved title time_tracking branch milestone discussion task moved
opened closed merged duplicate locked unlocked opened closed merged duplicate locked unlocked
outdated outdated tag
].freeze ].freeze
validates :note, presence: true validates :note, presence: true
......
...@@ -20,7 +20,8 @@ module Commits ...@@ -20,7 +20,8 @@ module Commits
.new(commit.project, current_user) .new(commit.project, current_user)
.execute(tag_name, commit.sha, message, release_description) .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 commit
end end
end end
......
...@@ -32,6 +32,20 @@ module SystemNoteService ...@@ -32,6 +32,20 @@ module SystemNoteService
create_note(NoteSummary.new(noteable, project, author, body, action: 'commit', commit_count: total_count)) create_note(NoteSummary.new(noteable, project, author, body, action: 'commit', commit_count: total_count))
end 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 # Called when the assignee of a Noteable is changed or removed
# #
# noteable - Noteable object # noteable - Noteable object
......
...@@ -22,11 +22,26 @@ describe Commits::UpdateService do ...@@ -22,11 +22,26 @@ describe Commits::UpdateService do
end end
it 'tags a commit' do it 'tags a commit' do
tag_double = double(name: opts[:tag_name])
tag_stub = instance_double(Tags::CreateService) tag_stub = instance_double(Tags::CreateService)
allow(Tags::CreateService).to receive(:new).and_return(tag_stub) allow(Tags::CreateService).to receive(:new).and_return(tag_stub)
allow(tag_stub).to receive(:execute) allow(tag_stub).to receive(:execute)
.with(opts[:tag_name], commit.sha, opts[:tag_message], nil) .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) service.execute(commit)
end end
...@@ -39,6 +54,7 @@ describe Commits::UpdateService do ...@@ -39,6 +54,7 @@ describe Commits::UpdateService do
it 'does not call the tag create service' do it 'does not call the tag create service' do
expect(Tags::CreateService).not_to receive(:new) expect(Tags::CreateService).not_to receive(:new)
expect(SystemNoteService).not_to receive(:tag_commit)
service.execute(commit) service.execute(commit)
end end
......
...@@ -108,6 +108,23 @@ describe SystemNoteService do ...@@ -108,6 +108,23 @@ describe SystemNoteService do
end end
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 describe '.change_assignee' do
subject { described_class.change_assignee(noteable, project, author, assignee) } subject { described_class.change_assignee(noteable, project, author, assignee) }
......
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