summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-12-31 12:05:11 +0900
committerShinya Maeda <shinya@gitlab.com>2018-12-31 14:34:15 +0900
commit54df1a570186c6e1851b98f268121d9d92c2de8a (patch)
tree8dbaf4cb0bdad6aee09bfb86f09898b666805847 /app/services
parent8f1e96c89bd3ffe6ae47c275df2d1e919d42c39a (diff)
downloadgitlab-ce-54df1a570186c6e1851b98f268121d9d92c2de8a.tar.gz
Resolve a Cognitive Complexity of 12
Diffstat (limited to 'app/services')
-rw-r--r--app/services/releases/create_service.rb30
1 files changed, 18 insertions, 12 deletions
diff --git a/app/services/releases/create_service.rb b/app/services/releases/create_service.rb
index 210bdfbc699..73fcebf79af 100644
--- a/app/services/releases/create_service.rb
+++ b/app/services/releases/create_service.rb
@@ -8,24 +8,30 @@ module Releases
return error('Access Denied', 403) unless allowed?
return error('Release already exists', 409) if release
- new_tag = nil
+ tag = ensure_tag
- unless tag_exist?
- return error('Ref is not specified', 422) unless ref
+ return tag unless tag.is_a?(Gitlab::Git::Tag)
- result = Tags::CreateService
- .new(project, current_user)
- .execute(tag_name, ref, nil)
-
- return result unless result[:status] == :success
+ create_release(tag)
+ end
- new_tag = result[:tag]
- end
+ private
- create_release(existing_tag || new_tag)
+ def ensure_tag
+ existing_tag || create_tag
end
- private
+ def create_tag
+ return error('Ref is not specified', 422) unless ref
+
+ result = Tags::CreateService
+ .new(project, current_user)
+ .execute(tag_name, ref, nil)
+
+ return result unless result[:status] == :success
+
+ result[:tag]
+ end
def allowed?
Ability.allowed?(current_user, :create_release, project)