Commit 100c2e1d authored by Thong Kuah's avatar Thong Kuah

Merge branch 'ci/update-buildkite' into 'master'

CI: Update Buildkite service

See merge request gitlab-org/gitlab!33697
parents fb798aa1 42ee3081
...@@ -8,13 +8,32 @@ class BuildkiteService < CiService ...@@ -8,13 +8,32 @@ class BuildkiteService < CiService
ENDPOINT = "https://buildkite.com" ENDPOINT = "https://buildkite.com"
prop_accessor :project_url, :token prop_accessor :project_url, :token
boolean_accessor :enable_ssl_verification
validates :project_url, presence: true, public_url: true, if: :activated? validates :project_url, presence: true, public_url: true, if: :activated?
validates :token, presence: true, if: :activated? validates :token, presence: true, if: :activated?
after_save :compose_service_hook, if: :activated? after_save :compose_service_hook, if: :activated?
def self.supported_events
%w(push merge_request tag_push)
end
# This is a stub method to work with deprecated API response
# TODO: remove enable_ssl_verification after 14.0
# https://gitlab.com/gitlab-org/gitlab/-/issues/222808
def enable_ssl_verification
true
end
# Since SSL verification will always be enabled for Buildkite,
# we no longer needs to store the boolean.
# This is a stub method to work with deprecated API param.
# TODO: remove enable_ssl_verification after 14.0
# https://gitlab.com/gitlab-org/gitlab/-/issues/222808
def enable_ssl_verification=(_value)
self.properties.delete('enable_ssl_verification') # Remove unused key
end
def webhook_url def webhook_url
"#{buildkite_endpoint('webhook')}/deliver/#{webhook_token}" "#{buildkite_endpoint('webhook')}/deliver/#{webhook_token}"
end end
...@@ -22,7 +41,7 @@ class BuildkiteService < CiService ...@@ -22,7 +41,7 @@ class BuildkiteService < CiService
def compose_service_hook def compose_service_hook
hook = service_hook || build_service_hook hook = service_hook || build_service_hook
hook.url = webhook_url hook.url = webhook_url
hook.enable_ssl_verification = !!enable_ssl_verification hook.enable_ssl_verification = true
hook.save hook.save
end end
...@@ -49,7 +68,7 @@ class BuildkiteService < CiService ...@@ -49,7 +68,7 @@ class BuildkiteService < CiService
end end
def description def description
'Continuous integration and deployments' 'Buildkite is a platform for running fast, secure, and scalable continuous integration pipelines on your own infrastructure'
end end
def self.to_param def self.to_param
...@@ -60,15 +79,15 @@ class BuildkiteService < CiService ...@@ -60,15 +79,15 @@ class BuildkiteService < CiService
[ [
{ type: 'text', { type: 'text',
name: 'token', name: 'token',
placeholder: 'Buildkite project GitLab token', required: true }, title: 'Integration Token',
help: 'This token will be provided when you create a Buildkite pipeline with a GitLab repository',
required: true },
{ type: 'text', { type: 'text',
name: 'project_url', name: 'project_url',
placeholder: "#{ENDPOINT}/example/project", required: true }, title: 'Pipeline URL',
placeholder: "#{ENDPOINT}/acme-inc/test-pipeline",
{ type: 'checkbox', required: true }
name: 'enable_ssl_verification',
title: "Enable SSL verification" }
] ]
end end
......
---
title: "Update Buildkite Service for supported events, fields, and always verify SSL"
merge_request: 33697
author: "Juanito Fatas"
type: changed
...@@ -229,8 +229,8 @@ Parameters: ...@@ -229,8 +229,8 @@ Parameters:
| Parameter | Type | Required | Description | | Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `token` | string | true | Buildkite project GitLab token | | `token` | string | true | Buildkite project GitLab token |
| `project_url` | string | true | `https://buildkite.com/example/project` | | `project_url` | string | true | Pipeline URL. For example, `https://buildkite.com/example/pipeline` |
| `enable_ssl_verification` | boolean | false | Enable SSL verification | | `enable_ssl_verification` | boolean | false | DEPRECATED: This parameter has no effect since SSL verification will always be enabled |
| `push_events` | boolean | false | Enable notifications for push events | | `push_events` | boolean | false | Enable notifications for push events |
### Delete Buildkite service ### Delete Buildkite service
......
...@@ -247,13 +247,13 @@ module API ...@@ -247,13 +247,13 @@ module API
required: true, required: true,
name: :project_url, name: :project_url,
type: String, type: String,
desc: 'The buildkite project URL' desc: 'The Buildkite pipeline URL'
}, },
{ {
required: false, required: false,
name: :enable_ssl_verification, name: :enable_ssl_verification,
type: Boolean, type: Boolean,
desc: 'Enable SSL verification for communication' desc: 'DEPRECATED: This parameter has no effect since SSL verification will always be enabled'
} }
], ],
'campfire' => [ 'campfire' => [
......
...@@ -82,7 +82,7 @@ RSpec.describe Projects::ServicesController do ...@@ -82,7 +82,7 @@ RSpec.describe Projects::ServicesController do
'active' => '1', 'active' => '1',
'push_events' => '1', 'push_events' => '1',
'token' => 'token', 'token' => 'token',
'project_url' => 'http://test.com' 'project_url' => 'https://buildkite.com/organization/pipeline'
} }
end end
......
...@@ -13,7 +13,7 @@ RSpec.describe BuildkiteService, :use_clean_rails_memory_store_caching do ...@@ -13,7 +13,7 @@ RSpec.describe BuildkiteService, :use_clean_rails_memory_store_caching do
project: project, project: project,
properties: { properties: {
service_hook: true, service_hook: true,
project_url: 'https://buildkite.com/account-name/example-project', project_url: 'https://buildkite.com/organization-name/example-pipeline',
token: 'secret-sauce-webhook-token:secret-sauce-status-token' token: 'secret-sauce-webhook-token:secret-sauce-status-token'
} }
) )
...@@ -45,11 +45,27 @@ RSpec.describe BuildkiteService, :use_clean_rails_memory_store_caching do ...@@ -45,11 +45,27 @@ RSpec.describe BuildkiteService, :use_clean_rails_memory_store_caching do
end end
end end
describe '.supported_events' do
it 'supports push, merge_request, and tag_push events' do
expect(service.supported_events).to eq %w(push merge_request tag_push)
end
end
describe 'commits methods' do describe 'commits methods' do
before do before do
allow(project).to receive(:default_branch).and_return('default-brancho') allow(project).to receive(:default_branch).and_return('default-brancho')
end end
it 'always activates SSL verification after saved' do
service.create_service_hook(enable_ssl_verification: false)
service.enable_ssl_verification = false
service.active = true
expect { service.save! }
.to change { service.service_hook.enable_ssl_verification }.from(false).to(true)
end
describe '#webhook_url' do describe '#webhook_url' do
it 'returns the webhook url' do it 'returns the webhook url' do
expect(service.webhook_url).to eq( expect(service.webhook_url).to eq(
...@@ -69,7 +85,7 @@ RSpec.describe BuildkiteService, :use_clean_rails_memory_store_caching do ...@@ -69,7 +85,7 @@ RSpec.describe BuildkiteService, :use_clean_rails_memory_store_caching do
describe '#build_page' do describe '#build_page' do
it 'returns the correct build page' do it 'returns the correct build page' do
expect(service.build_page('2ab7834c', nil)).to eq( expect(service.build_page('2ab7834c', nil)).to eq(
'https://buildkite.com/account-name/example-project/builds?commit=2ab7834c' 'https://buildkite.com/organization-name/example-pipeline/builds?commit=2ab7834c'
) )
end end
end end
......
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