Commit 23520789 authored by Stan Hu's avatar Stan Hu

Merge branch 'fix-jenkins-service-test-button' into 'master'

Fix JenkinsService test button

When clicking the "Test" button on the JenkinsCI Service, the following error occurs:

```
We tried to send a request to the provided URL but an error occurred: undefined method `message' for [200, ""]:Array 
```

!374 changed the implementation to call the `WebHook`, which returns [status, message], instead of the return value of `HTTParty#post`.

Closes #637

See merge request !476
parents cda8de63 a68bcce7
Please view this file on the master branch, on stable branches it's out of date.
v 8.9.0 (unreleased)
- Fix JenkinsService test button
- Fix nil user handling in UpdateMirrorService
- Allow LDAP to mark users as external based on their group membership. !432
- Forbid MR authors from approving their own MRs
......
......@@ -53,14 +53,13 @@ class JenkinsService < CiService
def test(data)
begin
result = execute(data)
message = result.message || result unless result.nil?
return { success: false, result: message } if result.code != 200
code, message = execute(data)
return { success: false, result: message } if code != 200
rescue StandardError => error
return { success: false, result: error }
end
{ success: true, result: result }
{ success: true, result: message }
end
def auth
......
......@@ -25,6 +25,16 @@ describe JenkinsService do
it { is_expected.to have_one :service_hook }
end
let(:project) { create(:project) }
let(:jenkins_params) do
{
active: true,
project: project,
properties: {
jenkins_url: 'http://jenkins.example.com/',
project_name: 'my_project'
}
}
end
describe 'username validation' do
before do
......@@ -74,19 +84,26 @@ describe JenkinsService do
end
end
describe '#test' do
it 'returns the right status' do
user = create(:user, username: 'username')
project = create(:project, name: 'project')
push_sample_data = Gitlab::PushDataBuilder.build_sample(project, user)
jenkins_service = described_class.create(jenkins_params)
stub_request(:post, jenkins_service.hook_url)
result = jenkins_service.test(push_sample_data)
expect(result).to eq({ success: true, result: '' })
end
end
describe '#execute' do
it 'adds default web hook headers to the request' do
user = create(:user, username: 'username')
project = create(:project, name: 'project')
push_sample_data = Gitlab::PushDataBuilder.build_sample(project, user)
jenkins_service = described_class.create(
active: true,
project: project,
properties: {
jenkins_url: 'http://jenkins.example.com/',
project_name: 'my_project'
}
)
jenkins_service = described_class.create(jenkins_params)
stub_request(:post, jenkins_service.hook_url)
jenkins_service.execute(push_sample_data)
......
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