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
Léo-Paul Géneau
gitlab-ce
Commits
3a22631d
Commit
3a22631d
authored
May 22, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make service code more abstract
parent
576ad445
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
118 additions
and
38 deletions
+118
-38
app/controllers/services_controller.rb
app/controllers/services_controller.rb
+10
-9
app/models/gitlab_ci_service.rb
app/models/gitlab_ci_service.rb
+19
-0
app/models/project.rb
app/models/project.rb
+13
-2
app/models/service.rb
app/models/service.rb
+15
-0
app/views/services/_form.html.haml
app/views/services/_form.html.haml
+48
-0
app/views/services/edit.html.haml
app/views/services/edit.html.haml
+1
-1
app/views/services/index.html.haml
app/views/services/index.html.haml
+12
-26
No files found.
app/controllers/services_controller.rb
View file @
3a22631d
class
ServicesController
<
ProjectResourceController
class
ServicesController
<
ProjectResourceController
# Authorize
# Authorize
before_filter
:authorize_admin_project!
before_filter
:authorize_admin_project!
before_filter
:service
,
only:
[
:edit
,
:update
,
:test
]
respond_to
:html
respond_to
:html
def
index
def
index
@gitlab_ci_service
=
@project
.
gitlab_ci_service
@project
.
build_missing_services
@services
=
@project
.
services
end
end
def
edit
def
edit
@service
=
@project
.
gitlab_ci_service
# Create if missing
@service
=
@project
.
create_gitlab_ci_service
unless
@service
end
end
def
update
def
update
@service
=
@project
.
gitlab_ci_service
if
@service
.
update_attributes
(
params
[
:service
])
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
else
render
'edit'
render
'edit'
end
end
...
@@ -28,9 +24,14 @@ class ServicesController < ProjectResourceController
...
@@ -28,9 +24,14 @@ class ServicesController < ProjectResourceController
def
test
def
test
data
=
GitPushService
.
new
.
sample_data
(
project
,
current_user
)
data
=
GitPushService
.
new
.
sample_data
(
project
,
current_user
)
@service
=
project
.
gitlab_ci_service
@service
.
execute
(
data
)
@service
.
execute
(
data
)
redirect_to
:back
redirect_to
:back
end
end
private
def
service
@service
||=
@project
.
services
.
find
{
|
service
|
service
.
to_param
==
params
[
:id
]
}
end
end
end
app/models/gitlab_ci_service.rb
View file @
3a22631d
...
@@ -54,4 +54,23 @@ class GitlabCiService < Service
...
@@ -54,4 +54,23 @@ class GitlabCiService < Service
def
status_img_path
def
status_img_path
project_url
+
"/status.png?ref="
+
project
.
default_branch
project_url
+
"/status.png?ref="
+
project
.
default_branch
end
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
end
app/models/project.rb
View file @
3a22631d
...
@@ -48,6 +48,7 @@ class Project < ActiveRecord::Base
...
@@ -48,6 +48,7 @@ class Project < ActiveRecord::Base
has_one
:forked_project_link
,
dependent: :destroy
,
foreign_key:
"forked_to_project_id"
has_one
:forked_project_link
,
dependent: :destroy
,
foreign_key:
"forked_to_project_id"
has_one
:forked_from_project
,
through: :forked_project_link
has_one
:forked_from_project
,
through: :forked_project_link
has_many
:services
,
dependent: :destroy
has_many
:events
,
dependent: :destroy
has_many
:events
,
dependent: :destroy
has_many
:merge_requests
,
dependent: :destroy
has_many
:merge_requests
,
dependent: :destroy
has_many
:issues
,
dependent: :destroy
,
order:
"state DESC, created_at DESC"
has_many
:issues
,
dependent: :destroy
,
order:
"state DESC, created_at DESC"
...
@@ -223,8 +224,18 @@ class Project < ActiveRecord::Base
...
@@ -223,8 +224,18 @@ class Project < ActiveRecord::Base
self
.
issues_enabled
&&
!
self
.
used_default_issues_tracker?
self
.
issues_enabled
&&
!
self
.
used_default_issues_tracker?
end
end
def
services
def
build_missing_services
[
gitlab_ci_service
].
compact
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
end
def
gitlab_ci?
def
gitlab_ci?
...
...
app/models/service.rb
View file @
3a22631d
...
@@ -13,6 +13,8 @@
...
@@ -13,6 +13,8 @@
# project_url :string(255)
# 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
class
Service
<
ActiveRecord
::
Base
attr_accessible
:title
,
:token
,
:type
,
:active
attr_accessible
:title
,
:token
,
:type
,
:active
...
@@ -24,4 +26,17 @@ class Service < ActiveRecord::Base
...
@@ -24,4 +26,17 @@ class Service < ActiveRecord::Base
def
activated?
def
activated?
active
active
end
end
def
title
end
def
description
end
def
to_param
end
def
fields
[]
end
end
end
app/views/services/_
gitlab_ci
.html.haml
→
app/views/services/_
form
.html.haml
View file @
3a22631d
%h3
.page_title
%h3
.page_title
GitLab CI
-
if
@service
.
activated?
%small
Continuous integration server from GitLab
%span
.cgreen
.pull-right
%i
.icon-circle
-
if
@service
.
active
-
else
%small
.cgreen
Enabled
%span
.cgray
-
else
%i
.icon-circle-blank
%small
.cgray
Disabled
=
@service
.
title
%p
=
@service
.
description
.back_link
.back_link
=
link_to
project_services_path
(
@project
)
do
=
link_to
project_services_path
(
@project
)
do
←
to services
←
to services
%hr
%hr
=
form_for
(
@service
,
:as
=>
:service
,
:url
=>
project_service_path
(
@project
,
:gitlab_ci
),
:method
=>
:put
)
do
|
f
|
=
form_for
(
@service
,
as: :service
,
url:
project_service_path
(
@project
,
@service
.
to_param
),
method: :put
)
do
|
f
|
-
if
@service
.
errors
.
any?
-
if
@service
.
errors
.
any?
.alert.alert-error
.alert.alert-error
%ul
%ul
...
@@ -27,20 +28,21 @@
...
@@ -27,20 +28,21 @@
.controls
.controls
=
f
.
check_box
:active
=
f
.
check_box
:active
.control-group
-
@service
.
fields
.
each
do
|
field
|
=
f
.
label
:project_url
,
"Project URL"
,
class:
"control-label"
-
name
=
field
[
:name
]
.controls
-
type
=
field
[
:type
]
=
f
.
text_field
:project_url
,
class:
"input-xlarge"
,
placeholder:
"http://ci.gitlabhq.com/projects/3"
-
placeholder
=
field
[
:placeholder
]
.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"
.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
.form-actions
=
f
.
submit
'Save'
,
class:
'btn btn-save'
=
f
.
submit
'Save'
,
class:
'btn btn-save'
-
if
@service
.
valid?
&&
@service
.
activ
e
-
if
@service
.
valid?
&&
@service
.
activ
ated?
=
link_to
'Test settings'
,
test_project_service_path
(
@project
),
class:
'btn btn-small'
=
link_to
'Test settings'
,
test_project_service_path
(
@project
,
@service
.
to_param
),
class:
'btn btn-small'
app/views/services/edit.html.haml
View file @
3a22631d
=
render
"projects/settings_nav"
=
render
"projects/settings_nav"
=
render
'
gitlab_ci
'
=
render
'
form
'
app/views/services/index.html.haml
View file @
3a22631d
...
@@ -3,30 +3,16 @@
...
@@ -3,30 +3,16 @@
%h3
.page_title
Services
%h3
.page_title
Services
%br
%br
%ul
.ui-box.well-list
%ul
.bordered-list
%li
-
@services
.
each
do
|
service
|
%h4
.cgreen
%li
=
link_to
edit_project_service_path
(
@project
,
:gitlab_ci
)
do
%h4
GitLab CI
-
if
service
.
activated?
%small
Continuous integration server from GitLab
%span
.cgreen
.pull-right
%i
.icon-circle
-
if
@gitlab_ci_service
.
try
(
:active
)
%small
.cgreen
%i
.icon-ok
Enabled
-
else
-
else
%small
.cgray
%span
.cgray
%i
.icon-off
%i
.icon-circle-blank
Disabled
=
link_to
edit_project_service_path
(
@project
,
service
.
to_param
)
do
%li
.disabled
=
service
.
title
%h4
%p
=
service
.
description
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
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