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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
b694bf6f
Commit
b694bf6f
authored
Oct 08, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7545 from buildbox/buildbox-service
Buildbox Service Integration
parents
d30e1f5c
f013973d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
209 additions
and
6 deletions
+209
-6
app/models/project.rb
app/models/project.rb
+2
-1
app/models/project_services/buildbox_service.rb
app/models/project_services/buildbox_service.rb
+121
-0
app/views/projects/show.html.haml
app/views/projects/show.html.haml
+8
-5
spec/models/buildbox_service_spec.rb
spec/models/buildbox_service_spec.rb
+78
-0
No files found.
app/models/project.rb
View file @
b694bf6f
...
@@ -64,6 +64,7 @@ class Project < ActiveRecord::Base
...
@@ -64,6 +64,7 @@ class Project < ActiveRecord::Base
has_one
:assembla_service
,
dependent: :destroy
has_one
:assembla_service
,
dependent: :destroy
has_one
:gemnasium_service
,
dependent: :destroy
has_one
:gemnasium_service
,
dependent: :destroy
has_one
:slack_service
,
dependent: :destroy
has_one
:slack_service
,
dependent: :destroy
has_one
:buildbox_service
,
dependent: :destroy
has_one
:pushover_service
,
dependent: :destroy
has_one
:pushover_service
,
dependent: :destroy
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
...
@@ -312,7 +313,7 @@ class Project < ActiveRecord::Base
...
@@ -312,7 +313,7 @@ class Project < ActiveRecord::Base
end
end
def
available_services_names
def
available_services_names
%w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla emails_on_push gemnasium slack pushover)
%w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla emails_on_push gemnasium slack pushover
buildbox
)
end
end
def
gitlab_ci?
def
gitlab_ci?
...
...
app/models/project_services/buildbox_service.rb
0 → 100644
View file @
b694bf6f
# == Schema Information
#
# Table name: services
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# project_id :integer not null
# created_at :datetime
# updated_at :datetime
# active :boolean default(FALSE), not null
# property :text
#
class
BuildboxService
<
CiService
prop_accessor
:project_url
,
:token
validates
:project_url
,
presence:
true
,
if: :activated?
validates
:token
,
presence:
true
,
if: :activated?
after_save
:compose_service_hook
,
if: :activated?
def
webhook_url
"
#{
buildbox_endpoint
(
'webhook'
)
}
/deliver/
#{
webhook_token
}
"
end
def
compose_service_hook
hook
=
service_hook
||
build_service_hook
hook
.
url
=
webhook_url
hook
.
save
end
def
execute
(
data
)
service_hook
.
execute
(
data
)
end
def
commit_status
(
sha
)
response
=
HTTParty
.
get
(
commit_status_path
(
sha
),
verify:
false
)
if
response
.
code
==
200
&&
response
[
'status'
]
response
[
'status'
]
else
:error
end
end
def
commit_status_path
(
sha
)
"
#{
buildbox_endpoint
(
'gitlab'
)
}
/status/
#{
status_token
}
.json?commit=
#{
sha
}
"
end
def
build_page
(
sha
)
"
#{
project_url
}
/builds?commit=
#{
sha
}
"
end
def
builds_path
"
#{
project_url
}
/builds?branch=
#{
project
.
default_branch
}
"
end
def
status_img_path
"
#{
buildbox_endpoint
(
'badge'
)
}
/
#{
status_token
}
.svg"
end
def
title
'Buildbox'
end
def
description
'Continuous integration and deployments'
end
def
to_param
'buildbox'
end
def
fields
[
{
type:
'text'
,
name:
'token'
,
placeholder:
'Buildbox project GitLab token'
},
{
type:
'text'
,
name:
'project_url'
,
placeholder:
'https://buildbox.io/example/project'
}
]
end
private
def
webhook_token
token_parts
.
first
end
def
status_token
token_parts
.
second
end
def
token_parts
if
token
.
present?
token
.
split
(
':'
)
else
[]
end
end
def
buildbox_endpoint
(
subdomain
=
nil
)
endpoint
=
'https://buildbox.io'
if
subdomain
.
present?
uri
=
Addressable
::
URI
.
parse
(
endpoint
)
new_endpoint
=
"
#{
uri
.
scheme
||
'http'
}
://
#{
subdomain
}
.
#{
uri
.
host
}
"
if
uri
.
port
.
present?
"
#{
new_endpoint
}
:
#{
uri
.
port
}
"
else
new_endpoint
end
else
endpoint
end
end
end
app/views/projects/show.html.haml
View file @
b694bf6f
...
@@ -62,11 +62,14 @@
...
@@ -62,11 +62,14 @@
-
else
-
else
#{
link_to
@project
.
owner_name
,
@project
.
owner
}
#{
link_to
@project
.
owner_name
,
@project
.
owner
}
-
@project
.
ci_services
.
each
do
|
ci_service
|
-
if
@project
.
gitlab_ci?
-
if
ci_service
.
active?
&&
ci_service
.
respond_to?
(
:builds_path
)
%hr
-
if
ci_service
.
respond_to?
(
:status_img_path
)
=
link_to
@project
.
gitlab_ci_service
.
builds_path
do
=
link_to
ci_service
.
builds_path
do
=
image_tag
@project
.
gitlab_ci_service
.
status_img_path
,
alt:
"build status"
=
image_tag
ci_service
.
status_img_path
,
alt:
"build status"
-
else
%span
.light
CI provided by
=
link_to
ci_service
.
title
,
ci_service
.
builds_path
-
if
readme
-
if
readme
.tab-pane
#tab-readme
.tab-pane
#tab-readme
...
...
spec/models/buildbox_service_spec.rb
0 → 100644
View file @
b694bf6f
# == Schema Information
#
# Table name: services
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# token :string(255)
# project_id :integer not null
# created_at :datetime
# updated_at :datetime
# active :boolean default(FALSE), not null
# project_url :string(255)
# subdomain :string(255)
# room :string(255)
# recipients :text
# api_key :string(255)
#
require
'spec_helper'
describe
BuildboxService
do
describe
'Associations'
do
it
{
should
belong_to
:project
}
it
{
should
have_one
:service_hook
}
end
describe
'commits methods'
do
before
do
@project
=
Project
.
new
@project
.
stub
(
default_branch:
'default-brancho'
)
@service
=
BuildboxService
.
new
@service
.
stub
(
project:
@project
,
service_hook:
true
,
project_url:
'https://buildbox.io/account-name/example-project'
,
token:
'secret-sauce-webhook-token:secret-sauce-status-token'
)
end
describe
:webhook_url
do
it
'returns the webhook url'
do
@service
.
webhook_url
.
should
==
'https://webhook.buildbox.io/deliver/secret-sauce-webhook-token'
end
end
describe
:commit_status_path
do
it
'returns the correct status page'
do
@service
.
commit_status_path
(
'2ab7834c'
).
should
==
'https://gitlab.buildbox.io/status/secret-sauce-status-token.json?commit=2ab7834c'
end
end
describe
:build_page
do
it
'returns the correct build page'
do
@service
.
build_page
(
'2ab7834c'
).
should
==
'https://buildbox.io/account-name/example-project/builds?commit=2ab7834c'
end
end
describe
:builds_page
do
it
'returns the correct path to the builds page'
do
@service
.
builds_path
.
should
==
'https://buildbox.io/account-name/example-project/builds?branch=default-brancho'
end
end
describe
:status_img_path
do
it
'returns the correct path to the status image'
do
@service
.
status_img_path
.
should
==
'https://badge.buildbox.io/secret-sauce-status-token.svg'
end
end
end
end
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