Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
592076654ffd
Commit
59207665
authored
May 22, 2013
by
Dmitriy Zaporozhets
Browse files
Make service code more abstract
parent
3ab22223ec4d
Changes
8
Hide whitespace changes
Inline
Side-by-side
app/controllers/services_controller.rb
View file @
59207665
class
ServicesController
<
ProjectResourceController
# Authorize
before_filter
:authorize_admin_project!
before_filter
:service
,
only:
[
:edit
,
:update
,
:test
]
respond_to
:html
def
index
...
...
@@ -4,8 +5,9 @@
respond_to
:html
def
index
@gitlab_ci_service
=
@project
.
gitlab_ci_service
@project
.
build_missing_services
@services
=
@project
.
services
end
def
edit
...
...
@@ -9,10 +11,6 @@
end
def
edit
@service
=
@project
.
gitlab_ci_service
# Create if missing
@service
=
@project
.
create_gitlab_ci_service
unless
@service
end
def
update
...
...
@@ -16,6 +14,4 @@
end
def
update
@service
=
@project
.
gitlab_ci_service
if
@service
.
update_attributes
(
params
[
:service
])
...
...
@@ -21,5 +17,5 @@
if
@service
.
update_attributes
(
params
[
:service
])
redirect_to
edit_project_service_path
(
@project
,
:gitlab_ci
)
redirect_to
edit_project_service_path
(
@project
,
@service
.
to_param
)
else
render
'edit'
end
...
...
@@ -28,8 +24,7 @@
def
test
data
=
GitPushService
.
new
.
sample_data
(
project
,
current_user
)
@service
=
project
.
gitlab_ci_service
@service
.
execute
(
data
)
redirect_to
:back
end
...
...
@@ -32,5 +27,11 @@
@service
.
execute
(
data
)
redirect_to
:back
end
private
def
service
@service
||=
@project
.
services
.
find
{
|
service
|
service
.
to_param
==
params
[
:id
]
}
end
end
app/models/gitlab_ci_service.rb
View file @
59207665
...
...
@@ -54,4 +54,23 @@
def
status_img_path
project_url
+
"/status.png?ref="
+
project
.
default_branch
end
def
title
'GitLab CI'
end
def
description
'Continuous integration server from GitLab'
end
def
to_param
'gitlab_ci'
end
def
fields
[
{
type:
'text'
,
name:
'token'
,
placeholder:
'GitLab CI project specific token'
},
{
type:
'text'
,
name:
'project_url'
,
placeholder:
'http://ci.gitlabhq.com/projects/3'
}
]
end
end
app/models/project.rb
View file @
59207665
...
...
@@ -48,6 +48,7 @@
has_one
:forked_project_link
,
dependent: :destroy
,
foreign_key:
"forked_to_project_id"
has_one
:forked_from_project
,
through: :forked_project_link
has_many
:services
,
dependent: :destroy
has_many
:events
,
dependent: :destroy
has_many
:merge_requests
,
dependent: :destroy
has_many
:issues
,
dependent: :destroy
,
order:
"state DESC, created_at DESC"
...
...
@@ -223,8 +224,18 @@
self
.
issues_enabled
&&
!
self
.
used_default_issues_tracker?
end
def
services
[
gitlab_ci_service
].
compact
def
build_missing_services
available_services_names
.
each
do
|
service_name
|
service
=
services
.
find
{
|
service
|
service
.
to_param
==
service_name
}
# If service is available but missing in db
# we should create an instance. Ex `create_gitlab_ci_service`
service
=
self
.
send
:"create_
#{
service_name
}
_service"
if
service
.
nil?
end
end
def
available_services_names
%w(gitlab_ci)
end
def
gitlab_ci?
...
...
app/models/service.rb
View file @
59207665
...
...
@@ -13,6 +13,8 @@
# project_url :string(255)
#
# To add new service you should build a class inherited from Service
# and implement a set of methods
class
Service
<
ActiveRecord
::
Base
attr_accessible
:title
,
:token
,
:type
,
:active
...
...
@@ -24,4 +26,17 @@
def
activated?
active
end
def
title
end
def
description
end
def
to_param
end
def
fields
[]
end
end
app/views/services/_form.html.haml
0 → 100644
View file @
59207665
%h3
.page_title
-
if
@service
.
activated?
%span
.cgreen
%i
.icon-circle
-
else
%span
.cgray
%i
.icon-circle-blank
=
@service
.
title
%p
=
@service
.
description
.back_link
=
link_to
project_services_path
(
@project
)
do
←
to services
%hr
=
form_for
(
@service
,
as: :service
,
url:
project_service_path
(
@project
,
@service
.
to_param
),
method: :put
)
do
|
f
|
-
if
@service
.
errors
.
any?
.alert.alert-error
%ul
-
@service
.
errors
.
full_messages
.
each
do
|
msg
|
%li
=
msg
.control-group
=
f
.
label
:active
,
"Active"
,
class:
"control-label"
.controls
=
f
.
check_box
:active
-
@service
.
fields
.
each
do
|
field
|
-
name
=
field
[
:name
]
-
type
=
field
[
:type
]
-
placeholder
=
field
[
:placeholder
]
.control-group
=
f
.
label
name
,
class:
"control-label"
.controls
-
if
type
==
'text'
=
f
.
text_field
name
,
class:
"input-xlarge"
,
placeholder:
placeholder
-
elsif
type
==
'checkbox'
=
f
.
check_box
name
.form-actions
=
f
.
submit
'Save'
,
class:
'btn btn-save'
-
if
@service
.
valid?
&&
@service
.
activated?
=
link_to
'Test settings'
,
test_project_service_path
(
@project
,
@service
.
to_param
),
class:
'btn btn-small'
app/views/services/_gitlab_ci.html.haml
deleted
100644 → 0
View file @
3ab22223
%h3
.page_title
GitLab CI
%small
Continuous integration server from GitLab
.pull-right
-
if
@service
.
active
%small
.cgreen
Enabled
-
else
%small
.cgray
Disabled
.back_link
=
link_to
project_services_path
(
@project
)
do
←
to services
%hr
=
form_for
(
@service
,
:as
=>
:service
,
:url
=>
project_service_path
(
@project
,
:gitlab_ci
),
:method
=>
:put
)
do
|
f
|
-
if
@service
.
errors
.
any?
.alert.alert-error
%ul
-
@service
.
errors
.
full_messages
.
each
do
|
msg
|
%li
=
msg
.control-group
=
f
.
label
:active
,
"Active"
,
class:
"control-label"
.controls
=
f
.
check_box
:active
.control-group
=
f
.
label
:project_url
,
"Project URL"
,
class:
"control-label"
.controls
=
f
.
text_field
:project_url
,
class:
"input-xlarge"
,
placeholder:
"http://ci.gitlabhq.com/projects/3"
.control-group
=
f
.
label
:token
,
class:
"control-label"
do
CI Project token
.controls
=
f
.
text_field
:token
,
class:
"input-xlarge"
,
placeholder:
"GitLab CI project specific token"
.form-actions
=
f
.
submit
'Save'
,
class:
'btn btn-save'
-
if
@service
.
valid?
&&
@service
.
active
=
link_to
'Test settings'
,
test_project_service_path
(
@project
),
class:
'btn btn-small'
app/views/services/edit.html.haml
View file @
59207665
=
render
"projects/settings_nav"
=
render
'
gitlab_ci
'
=
render
'
form
'
app/views/services/index.html.haml
View file @
59207665
...
...
@@ -3,15 +3,11 @@
%h3
.page_title
Services
%br
%ul
.ui-box.well-list
%li
%h4
.cgreen
=
link_to
edit_project_service_path
(
@project
,
:gitlab_ci
)
do
GitLab CI
%small
Continuous integration server from GitLab
.pull-right
-
if
@gitlab_ci_service
.
try
(
:active
)
%small
.cgreen
%i
.icon-ok
Enabled
%ul
.bordered-list
-
@services
.
each
do
|
service
|
%li
%h4
-
if
service
.
activated?
%span
.cgreen
%i
.icon-circle
-
else
...
...
@@ -17,16 +13,6 @@
-
else
%small
.cgray
%i
.icon-off
Disabled
%li
.disabled
%h4
Jenkins CI
%small
An extendable open source continuous integration server
.pull-right
%small
Not implemented yet
%li
.disabled
%h4
Campfire
%small
Web-based group chat tool
.pull-right
%small
Not implemented yet
%span
.cgray
%i
.icon-circle-blank
=
link_to
edit_project_service_path
(
@project
,
service
.
to_param
)
do
=
service
.
title
%p
=
service
.
description
Write
Preview
Supports
Markdown
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