v3: allow filtering builds by event_type, state and previous_state

This commit is contained in:
Konstantin Haase 2015-08-21 18:46:42 +02:00
parent cc346ce165
commit 73ec1d496e
3 changed files with 11 additions and 1 deletions

View File

@ -1,11 +1,16 @@
module Travis::API::V3
class Queries::Builds < Query
params :state, :event_type, :previous_state, prefix: :build
def find(repository)
filter(repository.builds)
end
def filter(list)
# filtering by branch, type, etc would go here
list = list.where(state: list(state)) if state
list = list.where(previous_state: list(previous_state)) if previous_state
list = list.where(event_type: list(state)) if event_type
list = list.includes(:commit).includes(branch: :last_build).includes(:repository)
list = list.includes(branch: { last_build: :commit }) if includes? 'build.commit'.freeze
list

View File

@ -51,6 +51,10 @@ module Travis::API::V3
!!value
end
def list(value)
value.split(?,.freeze)
end
def user_condition(value)
case value
when String then { login: value }

View File

@ -1,5 +1,6 @@
module Travis::API::V3
class Services::Builds::Find < Service
params :state, :event_type, :previous_state, prefix: :build
paginate
def run!