Skip to content

Commit

Permalink
Merge pull request #64 from mtchavez/61-project-recent-builds
Browse files Browse the repository at this point in the history
Project recent builds params
  • Loading branch information
mtchavez committed Mar 13, 2016
2 parents 9208e91 + f1b34c1 commit 1034d9d
Show file tree
Hide file tree
Showing 6 changed files with 298 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* CircleCi::RecentBuilds#get - Replaces old CircleCi#organization endpoint to return all recent builds
* Remove CircleCi#organization for CircleCi::RecentBuilds#get
* CircleCi::Project#recent_builds - Takes params to supply limit, offset, and filter query params

# Version 0.2.2 - (2016-02-26)

Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ end
* [Get Checkout Key](#get_checkout_key)
* [List Checkout Keys](#list_checkout_keys)
* [New Checkout Key](#new_checkout_key)
* [Recent Builds](#recent_builds)
* [Recent Builds](#project_recent_builds)
* [Recent Builds Branch](#recent_builds_branch)
* [Settings](#settings)
* [Set Envvar](#set_envvar)
Expand Down Expand Up @@ -517,14 +517,21 @@ Example response
}
```

#### [recent_builds](#recent_builds)
#### [recent_builds](#project_recent_builds)

Endpoint: `/project/:username/:repository`

Build summary for each of the last 30 recent builds, ordered by build_num.

```ruby
res = CircleCi::Project.recent_builds 'username', 'reponame'

# Use params to filter by status
# res = CircleCi::Project.recent_builds 'username', 'reponame', filter: 'failed'

# Use params to limit and give an offset
# res = CircleCi::Project.recent_builds 'username', 'reponame', limit: 10, offset: 50

res.success?
res.body
```
Expand Down
5 changes: 3 additions & 2 deletions lib/circleci/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ def self.new_checkout_key(username, project, type)
#
# @param username [String] - User or org name who owns project
# @param project [String] - Name of project
# @param params [Hash] - Parameters for builds (limit, offset, filter)
# @return [CircleCi::Response] - Response object

def self.recent_builds(username, project)
CircleCi.http.get "/project/#{username}/#{project}"
def self.recent_builds(username, project, params = {})
CircleCi.http.get "/project/#{username}/#{project}", params
end

##
Expand Down
294 changes: 266 additions & 28 deletions spec/cassettes/project/recent_builds/success.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions spec/circleci/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,24 @@
user['is_user'].should be
user['login'].should eql 'mtchavez'
end

describe 'params' do
context 'limit' do
let(:res) { CircleCi::Project.recent_builds 'mtchavez', 'circleci', limit: 5 }
it 'returns correct total of builds' do
res.body.size.should eql 5
end
end

context 'filter' do
let(:res) { CircleCi::Project.recent_builds 'mtchavez', 'circleci', limit: 5, filter: 'failed' }
it 'returns builds filtered by status' do
builds = res.body
statuses = builds.map { |build| build['status'] }
statuses.each { |status| status.should eql 'failed' }
end
end
end
end

context 'non-utf8 encoding', vcr: { cassette_name: 'project/recent_builds/encoding', serialize_with: :json, record: :none } do
Expand Down
2 changes: 1 addition & 1 deletion spec/circleci/recent_builds_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe CircleCi::Build do
describe CircleCi::RecentBuilds do
describe 'get' do
context 'successfully', vcr: { cassette_name: 'recent_builds/get/success', record: :none } do
let(:res) { CircleCi::RecentBuilds.get }
Expand Down

0 comments on commit 1034d9d

Please sign in to comment.