Class: Drone::Builds

Inherits:
Object
  • Object
show all
Defined in:
lib/drone/builds.rb,
lib/drone/builds/version.rb

Defined Under Namespace

Classes: Cli, Parser

Constant Summary collapse

MAX_LIMIT =
30
DEFAULT_LIMIT =
10
DEFAULT_JOB_ID =
1
VERSION =
'0.7.1'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token:, domain:, owner:, name:, job_id: nil, protocol: nil) ⇒ Builds

Returns a new instance of Builds.



14
15
16
17
18
19
20
21
# File 'lib/drone/builds.rb', line 14

def initialize(token:, domain:, owner:, name:, job_id: nil, protocol: nil)
  @token = token
  @domain = domain
  @owner = owner
  @name = name
  @job_id = job_id || DEFAULT_JOB_ID
  @protocol = protocol || 'http'
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



8
9
10
# File 'lib/drone/builds.rb', line 8

def domain
  @domain
end

#job_idObject (readonly)

Returns the value of attribute job_id.



8
9
10
# File 'lib/drone/builds.rb', line 8

def job_id
  @job_id
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/drone/builds.rb', line 8

def name
  @name
end

#ownerObject (readonly)

Returns the value of attribute owner.



8
9
10
# File 'lib/drone/builds.rb', line 8

def owner
  @owner
end

#protocolObject (readonly)

Returns the value of attribute protocol.



8
9
10
# File 'lib/drone/builds.rb', line 8

def protocol
  @protocol
end

#tokenObject (readonly)

Returns the value of attribute token.



8
9
10
# File 'lib/drone/builds.rb', line 8

def token
  @token
end

Instance Method Details

#kill(build_number) ⇒ Object



39
40
41
# File 'lib/drone/builds.rb', line 39

def kill(build_number)
  delete_api(job_url(build_number))
end

#list(limit: nil, ref: nil, status: nil) ⇒ Object



23
24
25
26
27
# File 'lib/drone/builds.rb', line 23

def list(limit: nil, ref: nil, status: nil)
  json_api(builds_url).select do |b|
    (!ref || b['ref'] == ref) && (!status || b['status'] == status)
  end.first(limit || DEFAULT_LIMIT).reverse
end

#restart(build_number) ⇒ Object



43
44
45
# File 'lib/drone/builds.rb', line 43

def restart(build_number)
  post_api(build_url(build_number))
end

#show(build_number, filter: nil, context: nil) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/drone/builds.rb', line 29

def show(build_number, filter: nil, context: nil)
  text_api(logs_url(build_number)).lines.each do |l|
    yield l if show_line(l, filter: filter, context: context)
  end
rescue OpenURI::HTTPError
  stream_api(stream_url(build_number)) do |l|
    yield l if show_line(l, filter: filter, context: context)
  end
end