2014-05-22 01:46:01 +00:00
|
|
|
class CreateTagService
|
|
|
|
def execute(project, tag_name, ref, current_user)
|
2014-07-27 17:56:33 +00:00
|
|
|
valid_tag = Gitlab::GitRefValidator.validate(tag_name)
|
|
|
|
if valid_tag == false
|
|
|
|
return error('Tag name invalid')
|
|
|
|
end
|
|
|
|
|
2014-05-22 01:46:01 +00:00
|
|
|
repository = project.repository
|
2014-07-27 17:56:33 +00:00
|
|
|
existing_tag = repository.find_tag(tag_name)
|
|
|
|
if existing_tag
|
|
|
|
return error('Tag already exists')
|
|
|
|
end
|
|
|
|
|
2014-05-22 01:46:01 +00:00
|
|
|
repository.add_tag(tag_name, ref)
|
|
|
|
new_tag = repository.find_tag(tag_name)
|
|
|
|
|
|
|
|
if new_tag
|
|
|
|
Event.create_ref_event(project, current_user, new_tag, 'add', 'refs/tags')
|
2014-07-27 17:56:33 +00:00
|
|
|
return success(new_tag)
|
|
|
|
else
|
|
|
|
return error('Invalid reference name')
|
2014-05-22 01:46:01 +00:00
|
|
|
end
|
2014-07-27 17:56:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def error(message)
|
|
|
|
{
|
|
|
|
message: message,
|
|
|
|
status: :error
|
|
|
|
}
|
|
|
|
end
|
2014-05-22 01:46:01 +00:00
|
|
|
|
2014-07-27 17:56:33 +00:00
|
|
|
def success(branch)
|
|
|
|
{
|
|
|
|
tag: branch,
|
|
|
|
status: :success
|
|
|
|
}
|
2014-05-22 01:46:01 +00:00
|
|
|
end
|
|
|
|
end
|