v3: allow filtering builds by branch
This commit is contained in:
parent
4eb89ab141
commit
462b2aed0d
|
@ -1,6 +1,7 @@
|
|||
module Travis::API::V3
|
||||
class Queries::Builds < Query
|
||||
params :state, :event_type, :previous_state, prefix: :build
|
||||
params :name, prefix: :branch, method_name: :branch_name
|
||||
|
||||
def find(repository)
|
||||
filter(repository.builds)
|
||||
|
@ -9,7 +10,8 @@ module Travis::API::V3
|
|||
def filter(list)
|
||||
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.where(event_type: list(event_type)) if event_type
|
||||
list = list.where(branch: list(branch_name)) if branch_name
|
||||
|
||||
list = list.includes(:commit).includes(branch: :last_build).includes(:repository)
|
||||
list = list.includes(branch: { last_build: :commit }) if includes? 'build.commit'.freeze
|
||||
|
|
|
@ -4,26 +4,35 @@ module Travis::API::V3
|
|||
|
||||
# generate from eval to avoid additional string allocations on every params access
|
||||
@@params_accessor = <<-RUBY
|
||||
attr_writer :%<name>s
|
||||
attr_writer :%<method_name>s
|
||||
|
||||
def %<name>s
|
||||
return @%<name>s if defined? @%<name>s
|
||||
return @%<name>s = @params['%<prefix>s.%<name>s'.freeze] if @params.include? '%<prefix>s.%<name>s'.freeze
|
||||
return @%<name>s = @params['%<prefix>s'.freeze]['%<name>s'.freeze] if @params.include? '%<prefix>s'.freeze and @params['%<prefix>s'.freeze].is_a? Hash
|
||||
return @%<name>s = @params['%<name>s'.freeze] if (@params['@type'.freeze] || @main_type) == '%<prefix>s'.freeze
|
||||
return @%<name>s = @params['%<name>s'.freeze] if %<check_type>p and (@params['@type'.freeze] || @main_type) == '%<type>s'.freeze
|
||||
@%<name>s = nil
|
||||
def %<method_name>s
|
||||
return @%<method_name>s if defined? @%<method_name>s
|
||||
return @%<method_name>s = @params['%<prefix>s.%<name>s'.freeze] if @params.include? '%<prefix>s.%<name>s'.freeze
|
||||
return @%<method_name>s = @params['%<prefix>s'.freeze]['%<name>s'.freeze] if @params.include? '%<prefix>s'.freeze and @params['%<prefix>s'.freeze].is_a? Hash
|
||||
return @%<method_name>s = @params['%<name>s'.freeze] if (@params['@type'.freeze] || @main_type) == '%<prefix>s'.freeze
|
||||
return @%<method_name>s = @params['%<name>s'.freeze] if %<check_type>p and (@params['@type'.freeze] || @main_type) == '%<type>s'.freeze
|
||||
@%<method_name>s = nil
|
||||
end
|
||||
|
||||
def %<name>s!
|
||||
%<name>s or raise WrongParams, 'missing %<prefix>s.%<name>s'.freeze
|
||||
def %<method_name>s!
|
||||
%<method_name>s or raise WrongParams, 'missing %<prefix>s.%<name>s'.freeze
|
||||
end
|
||||
RUBY
|
||||
|
||||
def self.params(*list, prefix: nil)
|
||||
type = name[/[^:]+$/].underscore
|
||||
prefix ||= type.to_s
|
||||
list.each { |e| class_eval(@@params_accessor % { name: e, prefix: prefix, type: type, check_type: type != prefix }) }
|
||||
def self.params(*list, prefix: nil, method_name: nil)
|
||||
type = name[/[^:]+$/].underscore
|
||||
prefix ||= type.to_s
|
||||
check_type = method_name.nil? and type != prefix
|
||||
list.each do |entry|
|
||||
class_eval(@@params_accessor % {
|
||||
name: entry,
|
||||
prefix: prefix,
|
||||
type: type,
|
||||
method_name: method_name || entry,
|
||||
check_type: check_type
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :params, :main_type
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
module Travis::API::V3
|
||||
class Services::Builds::Find < Service
|
||||
params :state, :event_type, :previous_state, prefix: :build
|
||||
params "branch.name"
|
||||
paginate
|
||||
|
||||
def run!
|
||||
|
|
Loading…
Reference in New Issue
Block a user