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
23659c52
Commit
23659c52
authored
Feb 27, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'mock-ci-service' into 'master'
Add Mock CI service/integration See merge request !9250
parents
0599ced1
1c85d86d
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
155 additions
and
3 deletions
+155
-3
app/controllers/concerns/service_params.rb
app/controllers/concerns/service_params.rb
+1
-0
app/models/project_services/mock_ci_service.rb
app/models/project_services/mock_ci_service.rb
+82
-0
app/models/service.rb
app/models/service.rb
+4
-1
changelogs/unreleased/mock-ci-service.yml
changelogs/unreleased/mock-ci-service.yml
+4
-0
doc/api/services.md
doc/api/services.md
+35
-0
doc/development/ci_setup.md
doc/development/ci_setup.md
+2
-1
doc/user/project/integrations/mock_ci.md
doc/user/project/integrations/mock_ci.md
+13
-0
lib/api/services.rb
lib/api/services.rb
+14
-1
No files found.
app/controllers/concerns/service_params.rb
View file @
23659c52
...
@@ -33,6 +33,7 @@ module ServiceParams
...
@@ -33,6 +33,7 @@ module ServiceParams
:issues_url
,
:issues_url
,
:jira_issue_transition_id
,
:jira_issue_transition_id
,
:merge_requests_events
,
:merge_requests_events
,
:mock_service_url
,
:namespace
,
:namespace
,
:new_issue_url
,
:new_issue_url
,
:notify
,
:notify
,
...
...
app/models/project_services/mock_ci_service.rb
0 → 100644
View file @
23659c52
# For an example companion mocking service, see https://gitlab.com/gitlab-org/gitlab-mock-ci-service
class
MockCiService
<
CiService
ALLOWED_STATES
=
%w[failed canceled running pending success success_with_warnings skipped not_found]
.
freeze
prop_accessor
:mock_service_url
validates
:mock_service_url
,
presence:
true
,
url:
true
,
if: :activated?
def
title
'MockCI'
end
def
description
'Mock an external CI'
end
def
self
.
to_param
'mock_ci'
end
def
fields
[
{
type:
'text'
,
name:
'mock_service_url'
,
placeholder:
'http://localhost:4004'
},
]
end
# Return complete url to build page
#
# Ex.
# http://jenkins.example.com:8888/job/test1/scm/bySHA1/12d65c
#
def
build_page
(
sha
,
ref
)
url
=
[
mock_service_url
,
"
#{
project
.
namespace
.
path
}
/
#{
project
.
path
}
/status/
#{
sha
}
"
]
URI
.
join
(
*
url
).
to_s
end
# Return string with build status or :error symbol
#
# Allowed states: 'success', 'failed', 'running', 'pending', 'skipped'
#
#
# Ex.
# @service.commit_status('13be4ac', 'master')
# # => 'success'
#
# @service.commit_status('2abe4ac', 'dev')
# # => 'running'
#
#
def
commit_status
(
sha
,
ref
)
response
=
HTTParty
.
get
(
commit_status_path
(
sha
),
verify:
false
)
read_commit_status
(
response
)
rescue
Errno
::
ECONNREFUSED
:error
end
def
commit_status_path
(
sha
)
url
=
[
mock_service_url
,
"
#{
project
.
namespace
.
path
}
/
#{
project
.
path
}
/status/
#{
sha
}
.json"
]
URI
.
join
(
*
url
).
to_s
end
def
read_commit_status
(
response
)
return
:error
unless
response
.
code
==
200
||
response
.
code
==
404
status
=
if
response
.
code
==
404
'pending'
else
response
[
'status'
]
end
if
status
.
present?
&&
ALLOWED_STATES
.
include?
(
status
)
status
else
:error
end
end
end
app/models/service.rb
View file @
23659c52
...
@@ -210,7 +210,7 @@ class Service < ActiveRecord::Base
...
@@ -210,7 +210,7 @@ class Service < ActiveRecord::Base
end
end
def
self
.
available_services_names
def
self
.
available_services_names
%w[
service_names
=
%w[
asana
asana
assembla
assembla
bamboo
bamboo
...
@@ -238,6 +238,9 @@ class Service < ActiveRecord::Base
...
@@ -238,6 +238,9 @@ class Service < ActiveRecord::Base
slack
slack
teamcity
teamcity
]
]
service_names
<<
'mock_ci'
if
Rails
.
env
.
development?
service_names
.
sort_by
(
&
:downcase
)
end
end
def
self
.
build_from_template
(
project_id
,
template
)
def
self
.
build_from_template
(
project_id
,
template
)
...
...
changelogs/unreleased/mock-ci-service.yml
0 → 100644
View file @
23659c52
---
title
:
Add Mock CI service/integration for development
merge_request
:
author
:
doc/api/services.md
View file @
23659c52
...
@@ -810,3 +810,38 @@ GET /projects/:id/services/teamcity
...
@@ -810,3 +810,38 @@ GET /projects/:id/services/teamcity
[
jira-doc
]:
../user/project/integrations/jira.md
[
jira-doc
]:
../user/project/integrations/jira.md
[
old-jira-api
]:
https://gitlab.com/gitlab-org/gitlab-ce/blob/8-13-stable/doc/api/services.md#jira
[
old-jira-api
]:
https://gitlab.com/gitlab-org/gitlab-ce/blob/8-13-stable/doc/api/services.md#jira
## MockCI
Mock an external CI. See
[
`gitlab-org/gitlab-mock-ci-service`
](
https://gitlab.com/gitlab-org/gitlab-mock-ci-service
)
for an example of a companion mock service.
This service is only available when your environment is set to development.
### Create/Edit MockCI service
Set MockCI service for a project.
```
PUT /projects/:id/services/mock-ci
```
Parameters:
-
`mock_service_url`
(
**required**
) - http://localhost:4004
### Delete MockCI service
Delete MockCI service for a project.
```
DELETE /projects/:id/services/mock-ci
```
### Get MockCI service settings
Get MockCI service settings for a project.
```
GET /projects/:id/services/mock-ci
```
doc/development/ci_setup.md
View file @
23659c52
...
@@ -2,11 +2,12 @@
...
@@ -2,11 +2,12 @@
This document describes what services we use for testing GitLab and GitLab CI.
This document describes what services we use for testing GitLab and GitLab CI.
We currently use
three
CI services to test GitLab:
We currently use
four
CI services to test GitLab:
1.
GitLab CI on
[
GitHost.io
](
https://gitlab-ce.githost.io/projects/4/
)
for the
[
GitLab.com repo
](
https://gitlab.com/gitlab-org/gitlab-ce
)
1.
GitLab CI on
[
GitHost.io
](
https://gitlab-ce.githost.io/projects/4/
)
for the
[
GitLab.com repo
](
https://gitlab.com/gitlab-org/gitlab-ce
)
2.
GitLab CI at ci.gitlab.org to test the private GitLab B.V. repo at dev.gitlab.org
2.
GitLab CI at ci.gitlab.org to test the private GitLab B.V. repo at dev.gitlab.org
3.
[
Semephore
](
https://semaphoreapp.com/gitlabhq/gitlabhq/
)
for
[
GitHub.com repo
](
https://github.com/gitlabhq/gitlabhq
)
3.
[
Semephore
](
https://semaphoreapp.com/gitlabhq/gitlabhq/
)
for
[
GitHub.com repo
](
https://github.com/gitlabhq/gitlabhq
)
4.
[
Mock CI Service
](
user/project/integrations/mock_ci.md
)
for local development
| Software @ configuration being tested | GitLab CI (ci.gitlab.org) | GitLab CI (GitHost.io) | Semaphore |
| Software @ configuration being tested | GitLab CI (ci.gitlab.org) | GitLab CI (GitHost.io) | Semaphore |
|---------------------------------------|---------------------------|---------------------------------------------------------------------------|-----------|
|---------------------------------------|---------------------------|---------------------------------------------------------------------------|-----------|
...
...
doc/user/project/integrations/mock_ci.md
0 → 100644
View file @
23659c52
# Mock CI Service
**NB: This service is only listed if you are in a development environment!**
To setup the mock CI service server, respond to the following endpoints
-
`commit_status`
:
`#{project.namespace.path}/#{project.path}/status/#{sha}.json`
-
Have your service return
`200 { status: ['failed'|'canceled'|'running'|'pending'|'success'|'success_with_warnings'|'skipped'|'not_found'] }`
-
If the service returns a 404, it is interpreted as
`pending`
-
`build_page`
:
`#{project.namespace.path}/#{project.path}/status/#{sha}`
-
Just where the build is linked to, doesn't matter if implemented
For an example of a mock CI server, see
[
`gitlab-org/gitlab-mock-ci-service`
](
https://gitlab.com/gitlab-org/gitlab-mock-ci-service
)
lib/api/services.rb
View file @
23659c52
...
@@ -563,7 +563,20 @@ module API
...
@@ -563,7 +563,20 @@ module API
SlackService
,
SlackService
,
MattermostService
,
MattermostService
,
TeamcityService
,
TeamcityService
,
].
freeze
]
if
Rails
.
env
.
development?
services
[
'mock-ci'
]
=
[
{
required:
true
,
name: :mock_service_url
,
type:
String
,
desc:
'URL to the mock service'
}
]
service_classes
<<
MockCiService
end
trigger_services
=
{
trigger_services
=
{
'mattermost-slash-commands'
=>
[
'mattermost-slash-commands'
=>
[
...
...
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