Commit 23659c52 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'mock-ci-service' into 'master'

Add Mock CI service/integration

See merge request !9250
parents 0599ced1 1c85d86d
......@@ -33,6 +33,7 @@ module ServiceParams
:issues_url,
:jira_issue_transition_id,
:merge_requests_events,
:mock_service_url,
:namespace,
:new_issue_url,
:notify,
......
# 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
......@@ -210,7 +210,7 @@ class Service < ActiveRecord::Base
end
def self.available_services_names
%w[
service_names = %w[
asana
assembla
bamboo
......@@ -238,6 +238,9 @@ class Service < ActiveRecord::Base
slack
teamcity
]
service_names << 'mock_ci' if Rails.env.development?
service_names.sort_by(&:downcase)
end
def self.build_from_template(project_id, template)
......
---
title: Add Mock CI service/integration for development
merge_request:
author:
......@@ -810,3 +810,38 @@ GET /projects/:id/services/teamcity
[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
## 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
```
......@@ -2,11 +2,12 @@
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)
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)
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 |
|---------------------------------------|---------------------------|---------------------------------------------------------------------------|-----------|
......
# 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)
......@@ -563,7 +563,20 @@ module API
SlackService,
MattermostService,
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 = {
'mattermost-slash-commands' => [
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment