Commit a892b235 authored by Peter Leitzen's avatar Peter Leitzen

Tag a commit via `/tag 1.2.3 message`

parent cc1aecdb
......@@ -3,7 +3,26 @@
module Commits
class UpdateService < BaseService
def execute(commit)
# TODO authorize user
tag_commit(commit)
end
private
def tag_commit(commit)
# TODO authorize
return unless params[:tag_name]
tag_name = params[:tag_name]
message = params[:tag_message]
release_description = nil
result = Tags::CreateService
.new(commit.project, current_user)
.execute(tag_name, commit.sha, message, release_description)
if result[:status]
commit
end
end
end
end
require 'spec_helper'
describe Commits::UpdateService do
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let(:commit) { create(:commit, project: project) }
before do
project.add_maintainer(user)
end
describe 'execute' do
let(:service) { described_class.new(project, user, opts) }
context 'valid params' do
let(:opts) do
{
tag_name: '1.2.3',
tag_message: 'Release'
}
end
it 'tags a 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: :success })
service.execute(commit)
end
end
context 'invalid params' do
let(:opts) do
{}
end
it 'does not call the tag create service' do
expect(Tags::CreateService).not_to receive(:new)
service.execute(commit)
end
end
end
end
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