Commit 404ea472 authored by Peter Leitzen's avatar Peter Leitzen Committed by Sean McGivern

Implement the `tag` commands

parent f26c4354
......@@ -583,6 +583,23 @@ module QuickActions
@updates[:confidential] = true
end
desc 'Tag this commit.'
explanation do |(tag_name), _|
"Tags this commit to #{tag_name}."
end
params 'v1.2.3 <message>'
parse_params do |tag_name_and_message|
tag_name_and_message.split(' ', 2)
end
condition do
issuable.is_a?(Commit)
# TODO authorize
end
command :tag do |(tag_name, message)|
@updates[:tag_name] = tag_name
@updates[:tag_message] = message
end
def extract_users(params)
return [] if params.nil?
......
......@@ -7,6 +7,7 @@ describe QuickActions::InterpretService do
let(:developer2) { create(:user) }
let(:issue) { create(:issue, project: project) }
let(:milestone) { create(:milestone, project: project, title: '9.10') }
let(:commit) { create(:commit, project: project) }
let(:inprogress) { create(:label, project: project, title: 'In Progress') }
let(:bug) { create(:label, project: project, title: 'Bug') }
let(:note) { build(:note, commit_id: merge_request.diff_head_sha) }
......@@ -367,6 +368,14 @@ describe QuickActions::InterpretService do
end
end
shared_examples 'tag command' do
it 'tags a commit' do
_, updates = service.execute(content, issuable)
expect(updates).to eq(tag_name: tag_name, tag_message: tag_message)
end
end
it_behaves_like 'reopen command' do
let(:content) { '/reopen' }
let(:issuable) { issue }
......@@ -1179,6 +1188,32 @@ describe QuickActions::InterpretService do
it_behaves_like 'empty command'
end
end
context '/tag command' do
let(:issuable) { commit }
context 'ignores command with no argument' do
it_behaves_like 'empty command' do
let(:content) { '/tag' }
end
end
context 'tags a commit with a tag name' do
it_behaves_like 'tag command' do
let(:tag_name) { 'v1.2.3' }
let(:tag_message) { nil }
let(:content) { "/tag #{tag_name}" }
end
end
context 'tags a commit with a tag name and message' do
it_behaves_like 'tag command' do
let(:tag_name) { 'v1.2.3' }
let(:tag_message) { 'Stable release' }
let(:content) { "/tag #{tag_name} #{tag_message}" }
end
end
end
end
describe '#explain' do
......@@ -1397,6 +1432,16 @@ describe QuickActions::InterpretService do
end
end
describe 'tag a commit' do
let(:content) { '/tag 1.2.3 some message' }
it 'includes the tag name' do
_, explanations = service.explain(content, commit)
expect(explanations).to eq(["Tags this commit to 1.2.3."])
end
end
# EE-specific tests
describe 'weight command' 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