forked from gitlabhq/gitlabhq
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate tag-names and references in WebUI, API
- Loading branch information
Showing
9 changed files
with
152 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,38 @@ | ||
class CreateTagService | ||
def execute(project, tag_name, ref, current_user) | ||
valid_tag = Gitlab::GitRefValidator.validate(tag_name) | ||
if valid_tag == false | ||
return error('Tag name invalid') | ||
end | ||
|
||
repository = project.repository | ||
existing_tag = repository.find_tag(tag_name) | ||
if existing_tag | ||
return error('Tag already exists') | ||
end | ||
|
||
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') | ||
return success(new_tag) | ||
else | ||
return error('Invalid reference name') | ||
end | ||
end | ||
|
||
def error(message) | ||
{ | ||
message: message, | ||
status: :error | ||
} | ||
end | ||
|
||
new_tag | ||
def success(branch) | ||
{ | ||
tag: branch, | ||
status: :success | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters