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
Hide 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
end
def
create
result
=
CreateBranchService
.
new
.
execute
(
project
,
params
[
:branch_name
],
params
[
:ref
],
current_user
)
result
=
CreateBranchService
.
new
(
project
,
current_user
).
execute
(
params
[
:branch_name
],
params
[
:ref
])
if
result
[
:status
]
==
:success
@branch
=
result
[
:branch
]
redirect_to
project_tree_path
(
@project
,
@branch
.
name
)
...
...
@@ -31,7 +29,7 @@ class Projects::BranchesController < Projects::ApplicationController
end
def
destroy
DeleteBranchService
.
new
.
execute
(
project
,
params
[
:id
],
current_user
)
DeleteBranchService
.
new
(
project
,
current_user
).
execute
(
params
[
:id
]
)
@branch_name
=
params
[
:id
]
respond_to
do
|
format
|
...
...
app/controllers/projects/edit_tree_controller.rb
View file @
ad47993a
...
...
@@ -10,7 +10,8 @@ class Projects::EditTreeController < Projects::BaseTreeController
end
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
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
end
def
create
result
=
CreateTagService
.
new
.
execute
(
@project
,
params
[
:tag_name
],
params
[
:ref
],
params
[
:message
],
current_user
)
result
=
CreateTagService
.
new
(
@project
,
current_user
).
execute
(
params
[
:tag_name
],
params
[
:ref
],
params
[
:message
])
if
result
[
:status
]
==
:success
@tag
=
result
[
:tag
]
redirect_to
project_tags_path
(
@project
)
...
...
app/services/base_service.rb
View file @
ad47993a
class
BaseService
attr_accessor
:project
,
:current_user
,
:params
def
initialize
(
project
,
user
,
params
)
def
initialize
(
project
,
user
,
params
=
{}
)
@project
,
@current_user
,
@params
=
project
,
user
,
params
.
dup
end
...
...
@@ -32,4 +32,19 @@ class BaseService
def
system_hook_service
SystemHooksService
.
new
end
private
def
error
(
message
)
{
message:
message
,
status: :error
}
end
def
success
{
status: :success
}
end
end
app/services/create_branch_service.rb
View file @
ad47993a
class
CreateBranchService
def
execute
(
project
,
branch_name
,
ref
,
current_user
)
require_relative
'base_service'
class
CreateBranchService
<
BaseService
def
execute
(
branch_name
,
ref
)
valid_branch
=
Gitlab
::
GitRefValidator
.
validate
(
branch_name
)
if
valid_branch
==
false
return
error
(
'Branch name invalid'
)
...
...
@@ -22,17 +24,9 @@ class CreateBranchService
end
end
def
error
(
message
)
{
message:
message
,
status: :error
}
end
def
success
(
branch
)
{
branch:
branch
,
status: :success
}
out
=
super
()
out
[
:branch
]
=
branch
out
end
end
app/services/create_tag_service.rb
View file @
ad47993a
class
CreateTagService
def
execute
(
project
,
tag_name
,
ref
,
message
,
current_user
)
require_relative
'base_service'
class
CreateTagService
<
BaseService
def
execute
(
tag_name
,
ref
,
message
)
valid_tag
=
Gitlab
::
GitRefValidator
.
validate
(
tag_name
)
if
valid_tag
==
false
return
error
(
'Tag name invalid'
)
...
...
@@ -26,17 +28,9 @@ class CreateTagService
end
end
def
error
(
message
)
{
message:
message
,
status: :error
}
end
def
success
(
branch
)
{
tag:
branch
,
status: :success
}
out
=
super
()
out
[
:tag
]
=
branch
out
end
end
app/services/delete_branch_service.rb
View file @
ad47993a
class
DeleteBranchService
def
execute
(
project
,
branch_name
,
current_user
)
require_relative
'base_service'
class
DeleteBranchService
<
BaseService
def
execute
(
branch_name
)
repository
=
project
.
repository
branch
=
repository
.
find_branch
(
branch_name
)
...
...
@@ -31,17 +33,14 @@ class DeleteBranchService
end
def
error
(
message
,
return_code
=
400
)
{
message:
message
,
return_code:
return_code
,
state: :error
}
out
=
super
(
message
)
out
[
:return_code
]
=
return_code
out
end
def
success
(
message
)
{
message:
message
,
state: :success
}
out
=
super
()
out
[
:message
]
=
message
out
end
end
app/services/files/base_service.rb
View file @
ad47993a
...
...
@@ -10,18 +10,10 @@ module Files
private
def
error
(
message
)
{
error:
message
,
status: :error
}
end
def
success
{
error:
''
,
status: :success
}
out
=
super
()
out
[
:error
]
=
''
out
end
def
repository
...
...
lib/api/branches.rb
View file @
ad47993a
...
...
@@ -80,10 +80,8 @@ module API
# POST /projects/:id/repository/branches
post
":id/repository/branches"
do
authorize_push_project
result
=
CreateBranchService
.
new
.
execute
(
user_project
,
params
[
:branch_name
],
params
[
:ref
],
current_user
)
result
=
CreateBranchService
.
new
(
user_project
,
current_user
).
execute
(
params
[
:branch_name
],
params
[
:ref
])
if
result
[
:status
]
==
:success
present
result
[
:branch
],
with:
Entities
::
RepoObject
,
...
...
@@ -102,9 +100,10 @@ module API
# DELETE /projects/:id/repository/branches/:branch
delete
":id/repository/branches/:branch"
do
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
else
render_api_error!
(
result
[
:message
],
result
[
:return_code
])
...
...
lib/api/repositories.rb
View file @
ad47993a
...
...
@@ -38,9 +38,8 @@ module API
post
':id/repository/tags'
do
authorize_push_project
message
=
params
[
:message
]
||
nil
result
=
CreateTagService
.
new
.
execute
(
user_project
,
params
[
:tag_name
],
params
[
:ref
],
message
,
current_user
)
result
=
CreateTagService
.
new
(
user_project
,
current_user
).
execute
(
params
[
:tag_name
],
params
[
:ref
],
message
)
if
result
[
:status
]
==
:success
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