Commit 1e6766f9edb2a9bda18e89acef64ee03e8d3b2e4
1 parent
3e1853c5
Exists in
spb-stable
and in
2 other branches
Add CreateTagService. Use new service to allow tag creation through API.
Showing
2 changed files
with
29 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +class CreateTagService | ||
2 | + def execute(project, tag_name, ref, current_user) | ||
3 | + repository = project.repository | ||
4 | + repository.add_tag(tag_name, ref) | ||
5 | + new_tag = repository.find_tag(tag_name) | ||
6 | + | ||
7 | + if new_tag | ||
8 | + Event.create_ref_event(project, current_user, new_tag, 'add', 'refs/tags') | ||
9 | + end | ||
10 | + | ||
11 | + new_tag | ||
12 | + end | ||
13 | +end |
lib/api/repositories.rb
@@ -25,6 +25,22 @@ module API | @@ -25,6 +25,22 @@ module API | ||
25 | present user_project.repo.tags.sort_by(&:name).reverse, with: Entities::RepoObject, project: user_project | 25 | present user_project.repo.tags.sort_by(&:name).reverse, with: Entities::RepoObject, project: user_project |
26 | end | 26 | end |
27 | 27 | ||
28 | + # Create tag | ||
29 | + # | ||
30 | + # Parameters: | ||
31 | + # id (required) - The ID of a project | ||
32 | + # tag_name (required) - The name of the tag | ||
33 | + # ref (required) - Create tag from commit sha or branch | ||
34 | + # Example Request: | ||
35 | + # POST /projects/:id/repository/tags | ||
36 | + post ':id/repository/tags' do | ||
37 | + authorize_push_project | ||
38 | + @tag = CreateTagService.new.execute(user_project, params[:tag_name], | ||
39 | + params[:ref], current_user) | ||
40 | + | ||
41 | + present @tag, with: Entities::RepoObject, project: user_project | ||
42 | + end | ||
43 | + | ||
28 | # Get a project repository tree | 44 | # Get a project repository tree |
29 | # | 45 | # |
30 | # Parameters: | 46 | # Parameters: |