Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
ad47993a
Commit
ad47993a
authored
Sep 21, 2014
by
Ciro Santilli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor error and success methods from services.
parent
fda61a04
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
57 additions
and
67 deletions
+57
-67
app/controllers/projects/branches_controller.rb
app/controllers/projects/branches_controller.rb
+3
-5
app/controllers/projects/edit_tree_controller.rb
app/controllers/projects/edit_tree_controller.rb
+2
-1
app/controllers/projects/tags_controller.rb
app/controllers/projects/tags_controller.rb
+2
-3
app/services/base_service.rb
app/services/base_service.rb
+16
-1
app/services/create_branch_service.rb
app/services/create_branch_service.rb
+7
-13
app/services/create_tag_service.rb
app/services/create_tag_service.rb
+7
-13
app/services/delete_branch_service.rb
app/services/delete_branch_service.rb
+10
-11
app/services/files/base_service.rb
app/services/files/base_service.rb
+3
-11
lib/api/branches.rb
lib/api/branches.rb
+5
-6
lib/api/repositories.rb
lib/api/repositories.rb
+2
-3
No files found.
app/controllers/projects/branches_controller.rb
View file @
ad47993a
...
@@ -17,10 +17,8 @@ class Projects::BranchesController < Projects::ApplicationController
...
@@ -17,10 +17,8 @@ class Projects::BranchesController < Projects::ApplicationController
end
end
def
create
def
create
result
=
CreateBranchService
.
new
.
execute
(
project
,
result
=
CreateBranchService
.
new
(
project
,
current_user
).
params
[
:branch_name
],
execute
(
params
[
:branch_name
],
params
[
:ref
])
params
[
:ref
],
current_user
)
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
@branch
=
result
[
:branch
]
@branch
=
result
[
:branch
]
redirect_to
project_tree_path
(
@project
,
@branch
.
name
)
redirect_to
project_tree_path
(
@project
,
@branch
.
name
)
...
@@ -31,7 +29,7 @@ class Projects::BranchesController < Projects::ApplicationController
...
@@ -31,7 +29,7 @@ class Projects::BranchesController < Projects::ApplicationController
end
end
def
destroy
def
destroy
DeleteBranchService
.
new
.
execute
(
project
,
params
[
:id
],
current_user
)
DeleteBranchService
.
new
(
project
,
current_user
).
execute
(
params
[
:id
]
)
@branch_name
=
params
[
:id
]
@branch_name
=
params
[
:id
]
respond_to
do
|
format
|
respond_to
do
|
format
|
...
...
app/controllers/projects/edit_tree_controller.rb
View file @
ad47993a
...
@@ -10,7 +10,8 @@ class Projects::EditTreeController < Projects::BaseTreeController
...
@@ -10,7 +10,8 @@ class Projects::EditTreeController < Projects::BaseTreeController
end
end
def
update
def
update
result
=
Files
::
UpdateService
.
new
(
@project
,
current_user
,
params
,
@ref
,
@path
).
execute
result
=
Files
::
UpdateService
.
new
(
@project
,
current_user
,
params
,
@ref
,
@path
).
execute
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
flash
[
:notice
]
=
"Your changes have been successfully committed"
flash
[
:notice
]
=
"Your changes have been successfully committed"
...
...
app/controllers/projects/tags_controller.rb
View file @
ad47993a
...
@@ -13,9 +13,8 @@ class Projects::TagsController < Projects::ApplicationController
...
@@ -13,9 +13,8 @@ class Projects::TagsController < Projects::ApplicationController
end
end
def
create
def
create
result
=
CreateTagService
.
new
.
execute
(
@project
,
params
[
:tag_name
],
result
=
CreateTagService
.
new
(
@project
,
current_user
).
params
[
:ref
],
params
[
:message
],
execute
(
params
[
:tag_name
],
params
[
:ref
],
params
[
:message
])
current_user
)
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
@tag
=
result
[
:tag
]
@tag
=
result
[
:tag
]
redirect_to
project_tags_path
(
@project
)
redirect_to
project_tags_path
(
@project
)
...
...
app/services/base_service.rb
View file @
ad47993a
class
BaseService
class
BaseService
attr_accessor
:project
,
:current_user
,
:params
attr_accessor
:project
,
:current_user
,
:params
def
initialize
(
project
,
user
,
params
)
def
initialize
(
project
,
user
,
params
=
{}
)
@project
,
@current_user
,
@params
=
project
,
user
,
params
.
dup
@project
,
@current_user
,
@params
=
project
,
user
,
params
.
dup
end
end
...
@@ -32,4 +32,19 @@ class BaseService
...
@@ -32,4 +32,19 @@ class BaseService
def
system_hook_service
def
system_hook_service
SystemHooksService
.
new
SystemHooksService
.
new
end
end
private
def
error
(
message
)
{
message:
message
,
status: :error
}
end
def
success
{
status: :success
}
end
end
end
app/services/create_branch_service.rb
View file @
ad47993a
class
CreateBranchService
require_relative
'base_service'
def
execute
(
project
,
branch_name
,
ref
,
current_user
)
class
CreateBranchService
<
BaseService
def
execute
(
branch_name
,
ref
)
valid_branch
=
Gitlab
::
GitRefValidator
.
validate
(
branch_name
)
valid_branch
=
Gitlab
::
GitRefValidator
.
validate
(
branch_name
)
if
valid_branch
==
false
if
valid_branch
==
false
return
error
(
'Branch name invalid'
)
return
error
(
'Branch name invalid'
)
...
@@ -22,17 +24,9 @@ class CreateBranchService
...
@@ -22,17 +24,9 @@ class CreateBranchService
end
end
end
end
def
error
(
message
)
{
message:
message
,
status: :error
}
end
def
success
(
branch
)
def
success
(
branch
)
{
out
=
super
()
branch:
branch
,
out
[
:branch
]
=
branch
status: :success
out
}
end
end
end
end
app/services/create_tag_service.rb
View file @
ad47993a
class
CreateTagService
require_relative
'base_service'
def
execute
(
project
,
tag_name
,
ref
,
message
,
current_user
)
class
CreateTagService
<
BaseService
def
execute
(
tag_name
,
ref
,
message
)
valid_tag
=
Gitlab
::
GitRefValidator
.
validate
(
tag_name
)
valid_tag
=
Gitlab
::
GitRefValidator
.
validate
(
tag_name
)
if
valid_tag
==
false
if
valid_tag
==
false
return
error
(
'Tag name invalid'
)
return
error
(
'Tag name invalid'
)
...
@@ -26,17 +28,9 @@ class CreateTagService
...
@@ -26,17 +28,9 @@ class CreateTagService
end
end
end
end
def
error
(
message
)
{
message:
message
,
status: :error
}
end
def
success
(
branch
)
def
success
(
branch
)
{
out
=
super
()
tag:
branch
,
out
[
:tag
]
=
branch
status: :success
out
}
end
end
end
end
app/services/delete_branch_service.rb
View file @
ad47993a
class
DeleteBranchService
require_relative
'base_service'
def
execute
(
project
,
branch_name
,
current_user
)
class
DeleteBranchService
<
BaseService
def
execute
(
branch_name
)
repository
=
project
.
repository
repository
=
project
.
repository
branch
=
repository
.
find_branch
(
branch_name
)
branch
=
repository
.
find_branch
(
branch_name
)
...
@@ -31,17 +33,14 @@ class DeleteBranchService
...
@@ -31,17 +33,14 @@ class DeleteBranchService
end
end
def
error
(
message
,
return_code
=
400
)
def
error
(
message
,
return_code
=
400
)
{
out
=
super
(
message
)
message:
message
,
out
[
:return_code
]
=
return_code
return_code:
return_code
,
out
state: :error
}
end
end
def
success
(
message
)
def
success
(
message
)
{
out
=
super
()
message:
message
,
out
[
:message
]
=
message
state: :success
out
}
end
end
end
end
app/services/files/base_service.rb
View file @
ad47993a
...
@@ -10,18 +10,10 @@ module Files
...
@@ -10,18 +10,10 @@ module Files
private
private
def
error
(
message
)
{
error:
message
,
status: :error
}
end
def
success
def
success
{
out
=
super
()
error:
''
,
out
[
:error
]
=
''
status: :success
out
}
end
end
def
repository
def
repository
...
...
lib/api/branches.rb
View file @
ad47993a
...
@@ -80,10 +80,8 @@ module API
...
@@ -80,10 +80,8 @@ module API
# POST /projects/:id/repository/branches
# POST /projects/:id/repository/branches
post
":id/repository/branches"
do
post
":id/repository/branches"
do
authorize_push_project
authorize_push_project
result
=
CreateBranchService
.
new
.
execute
(
user_project
,
result
=
CreateBranchService
.
new
(
user_project
,
current_user
).
params
[
:branch_name
],
execute
(
params
[
:branch_name
],
params
[
:ref
])
params
[
:ref
],
current_user
)
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
present
result
[
:branch
],
present
result
[
:branch
],
with:
Entities
::
RepoObject
,
with:
Entities
::
RepoObject
,
...
@@ -102,9 +100,10 @@ module API
...
@@ -102,9 +100,10 @@ module API
# DELETE /projects/:id/repository/branches/:branch
# DELETE /projects/:id/repository/branches/:branch
delete
":id/repository/branches/:branch"
do
delete
":id/repository/branches/:branch"
do
authorize_push_project
authorize_push_project
result
=
DeleteBranchService
.
new
.
execute
(
user_project
,
params
[
:branch
],
current_user
)
result
=
DeleteBranchService
.
new
(
user_project
,
current_user
).
execute
(
params
[
:branch
])
if
result
[
:stat
e
]
==
:success
if
result
[
:stat
us
]
==
:success
true
true
else
else
render_api_error!
(
result
[
:message
],
result
[
:return_code
])
render_api_error!
(
result
[
:message
],
result
[
:return_code
])
...
...
lib/api/repositories.rb
View file @
ad47993a
...
@@ -38,9 +38,8 @@ module API
...
@@ -38,9 +38,8 @@ module API
post
':id/repository/tags'
do
post
':id/repository/tags'
do
authorize_push_project
authorize_push_project
message
=
params
[
:message
]
||
nil
message
=
params
[
:message
]
||
nil
result
=
CreateTagService
.
new
.
execute
(
user_project
,
params
[
:tag_name
],
result
=
CreateTagService
.
new
(
user_project
,
current_user
).
params
[
:ref
],
message
,
execute
(
params
[
:tag_name
],
params
[
:ref
],
message
)
current_user
)
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
present
result
[
:tag
],
present
result
[
:tag
],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment