Commit 598d2b20 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'fix/gb/update-commit-status-api' into 'master'

Fix updaing commit status when using optional attributes

Closes #28656 and #25784

See merge request !9618
parents d77bf0ed e19687b2
---
title: Fix updaing commit status when using optional attributes
merge_request: 9618
author:
......@@ -72,14 +72,15 @@ module API
status = GenericCommitStatus.running_or_pending.find_or_initialize_by(
project: @project,
pipeline: pipeline,
user: current_user,
name: name,
ref: ref,
target_url: params[:target_url],
description: params[:description],
coverage: params[:coverage]
user: current_user
)
optional_attributes =
attributes_for_keys(%w[target_url description coverage])
status.update(optional_attributes) if optional_attributes.any?
render_validation_error!(status) if status.invalid?
begin
......
......@@ -151,18 +151,17 @@ describe API::CommitStatuses, api: true do
end
context 'with all optional parameters' do
before do
optional_params = { state: 'success',
context 'when creating a commit status' do
it 'creates commit status' do
post api(post_url, developer), {
state: 'success',
context: 'coverage',
ref: 'develop',
description: 'test',
coverage: 80.0,
target_url: 'http://gitlab.com/status' }
post api(post_url, developer), optional_params
end
target_url: 'http://gitlab.com/status'
}
it 'creates commit status' do
expect(response).to have_http_status(201)
expect(json_response['sha']).to eq(commit.id)
expect(json_response['status']).to eq('success')
......@@ -174,6 +173,43 @@ describe API::CommitStatuses, api: true do
end
end
context 'when updatig a commit status' do
before do
post api(post_url, developer), {
state: 'running',
context: 'coverage',
ref: 'develop',
description: 'coverage test',
coverage: 0.0,
target_url: 'http://gitlab.com/status'
}
post api(post_url, developer), {
state: 'success',
name: 'coverage',
ref: 'develop',
description: 'new description',
coverage: 90.0
}
end
it 'updates a commit status' do
expect(response).to have_http_status(201)
expect(json_response['sha']).to eq(commit.id)
expect(json_response['status']).to eq('success')
expect(json_response['name']).to eq('coverage')
expect(json_response['ref']).to eq('develop')
expect(json_response['coverage']).to eq(90.0)
expect(json_response['description']).to eq('new description')
expect(json_response['target_url']).to eq('http://gitlab.com/status')
end
it 'does not create a new commit status' do
expect(CommitStatus.count).to eq 1
end
end
end
context 'when status is invalid' do
before { post api(post_url, developer), state: 'invalid' }
......
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