forked from bitbucket-rest-api/bitbucket
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from codeship/create_status
Adding create_status call
- Loading branch information
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# encoding: utf-8 | ||
|
||
module BitBucket | ||
class Repos::Statuses < API | ||
|
||
# Add build status to commit | ||
# | ||
# = Parameters | ||
# <tt>:user_name</tt> - Required string. The account of the repository owner. | ||
# <tt>:repo_name</tt> - Required string. The repository name. | ||
# <tt>:sha</tt> - Requrired string. The SHA1 value for the commit where you want to add the build status. | ||
# <tt>:state</tt> - Required String. An indication of the status of the commit: (INPROGRESS, SUCCESSFUL, or FAILED) | ||
# <tt>:key</tt> - Required String. A key that the vendor or build system supplies to identify the submitted build status. | ||
# <tt>:url</tt> - Required String. The URL for the vendor or system that produces the build. | ||
# <tt>:options</tt> Optional hash. Containing the following optional parameters: | ||
# * <tt>description</tt> - A user-defined description of the build. For example, 4 out of 128 tests passed. | ||
# * <tt>name<tt> - The name of the build. Your build system may provide the name, which will also appear in Bitbucket. For example, Unit Tests. | ||
# | ||
# = Examples | ||
# bitbucket = BitBucket.new | ||
# bitbucket.repos.create_status(client.repos.statuses.create('homer', | ||
# 'monorail', | ||
# 'e14caad7c501e0ae52daef24b26aa2625b7534e6', | ||
# 'SUCCESSFUL', | ||
# 'BAMBOO-PROJECT-X', | ||
# 'https://example.com/path/to/build/info', | ||
# 'name' => 'this is covered by build_concurrency_spec', | ||
# 'description' => 'Changes by John Doe') | ||
# | ||
def create(user_name, repo_name, sha, state, key, url, options = {}) | ||
_update_user_repo_params(user_name, repo_name) | ||
_validate_user_repo_params(user, repo) unless user? && repo? | ||
_validate_presence_of(sha, state, key, url) | ||
|
||
build_options = options.merge({ | ||
"state" => state, | ||
"key" => key, | ||
"url" => url | ||
}) | ||
|
||
post_request("/2.0/repositories/#{user}/#{sanitize_repository_name(repo)}/commit/#{sha}/statuses/build", | ||
build_options, | ||
json: true) | ||
end | ||
end # Repos::Statuses | ||
end # BitBucket |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'bitbucket_rest_api' | ||
|
||
describe BitBucket::Repos::Statuses do | ||
let(:repo_name) { 'wrath' } | ||
let(:sha) { '123456' } | ||
let(:state) { 'FAILED' } | ||
let(:key) { 'my-build-key' } | ||
let(:url) { 'http://somewhere/build' } | ||
|
||
let(:statuses) { described_class.new } | ||
|
||
before { allow(statuses).to receive(:post_request) } | ||
|
||
subject(:status_create) do | ||
statuses.create('khan', repo_name, sha, state, key, url, { 'extra-stuff' => 'hello'}) | ||
end | ||
|
||
describe 'create' do | ||
it 'should send request if parameters are valid' do | ||
expect(statuses).to receive(:post_request).with("/2.0/repositories/khan/wrath/commit/123456/statuses/build", | ||
{ | ||
"extra-stuff"=>"hello", | ||
"state"=> state, | ||
"key"=> key, | ||
"url"=> url | ||
}, | ||
{json: true}) | ||
|
||
status_create | ||
end | ||
|
||
it 'should sanitize_repository_name' do | ||
expect(statuses).to receive(:sanitize_repository_name).with(repo_name) { 'radio-edit' } | ||
expect(statuses).to receive(:post_request).with("/2.0/repositories/khan/radio-edit/commit/123456/statuses/build", | ||
anything, | ||
anything) | ||
|
||
status_create | ||
end | ||
|
||
it 'should validate presence of sha, state, key, url' do | ||
expect(statuses).to receive(:_validate_presence_of).with(sha, state, key, url) | ||
|
||
status_create | ||
end | ||
|
||
end | ||
end |