v3: allow filtering builds by event_type, state and previous_state
This commit is contained in:
parent
cc346ce165
commit
73ec1d496e
|
@ -1,11 +1,16 @@
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Queries::Builds < Query
|
class Queries::Builds < Query
|
||||||
|
params :state, :event_type, :previous_state, prefix: :build
|
||||||
|
|
||||||
def find(repository)
|
def find(repository)
|
||||||
filter(repository.builds)
|
filter(repository.builds)
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter(list)
|
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(:commit).includes(branch: :last_build).includes(:repository)
|
||||||
list = list.includes(branch: { last_build: :commit }) if includes? 'build.commit'.freeze
|
list = list.includes(branch: { last_build: :commit }) if includes? 'build.commit'.freeze
|
||||||
list
|
list
|
||||||
|
|
|
@ -51,6 +51,10 @@ module Travis::API::V3
|
||||||
!!value
|
!!value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def list(value)
|
||||||
|
value.split(?,.freeze)
|
||||||
|
end
|
||||||
|
|
||||||
def user_condition(value)
|
def user_condition(value)
|
||||||
case value
|
case value
|
||||||
when String then { login: value }
|
when String then { login: value }
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Services::Builds::Find < Service
|
class Services::Builds::Find < Service
|
||||||
|
params :state, :event_type, :previous_state, prefix: :build
|
||||||
paginate
|
paginate
|
||||||
|
|
||||||
def run!
|
def run!
|
||||||
|
|
Loading…
Reference in New Issue
Block a user