drone-builds 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 573c8e1088e883fea7522342bd5abc2ec5f3014c
4
- data.tar.gz: c1c00080331b2014bac34bca4450639fa0ca8405
3
+ metadata.gz: 7669c5cd94aadf34b8c0ffc3abdec4bd96667a98
4
+ data.tar.gz: e19d1a73b9d8f02372816aabb9db20843b1ffb17
5
5
  SHA512:
6
- metadata.gz: 470076dc1140d472d310cb086d9c1fdcb2dcbbf72588a6095f8f297f7234492d404431984e2002843c875a971ab7bdc8ac90613571c7f56e13aca33819bb4380
7
- data.tar.gz: 93697e8e362b24e2161a0480c2af5cd877a654d3d762144ba25e4a6e7b06fd85024f3c75408663554431e4dc19f4460377021a8a444ba4d777d7aef2855a8268
6
+ metadata.gz: 23bb8201340113d18b5f85948bcd3951ee83a65763403e538701c86a4fe51a9a0117e34f8097b33282d38de4426ec70b70e9b2853d7162d6de3d3ea0cd24e9d7
7
+ data.tar.gz: c7173aab373a38ded30d8a9ec9064ca1e5f5671ae5350ae3fd84de3ca9c0f813fb3c40886a9573188981d473218d699236ccb0ba24419c4e95f0609e331bf494
@@ -15,31 +15,31 @@ class Drone::Builds::Cli < Thor
15
15
  desc 'list', 'list last builds'
16
16
  method_option :limit, type: :numeric, default: LIMIT, aliases: '-l', desc: 'number of builds shown'
17
17
  method_option :pull, type: :numeric, aliases: '-p', desc: 'pull request ID on GitHub'
18
+ method_option :branch, type: :string, aliases: '-b', desc: 'builds on that branch'
18
19
  def list
19
- limit = options[:pull] ? Drone::Builds::MAX_LIMIT : options[:limit]
20
+ ref = self.class.options_to_ref(options)
20
21
 
21
- builds = self.class.parser.parse_builds(self.class.client.list(limit: limit))
22
+ builds = self.class.parser.parse_builds(self.class.client.list(limit: options[:limit], ref: ref))
22
23
 
23
- builds = builds.select { |build| build[:ref] == "##{options[:pull]}" } if options[:pull]
24
-
25
- puts self.class.parser.table(builds.last(options[:limit]], %i[id status ref message])
24
+ puts self.class.parser.table(builds, %i[id status ref message])
26
25
  end
27
26
 
28
27
  desc 'show', 'show a build'
29
28
  method_option :filter, type: :string, aliases: '-f', desc: 'filter builds output lines'
30
29
  method_option :context, type: :numeric, aliases: '-c', desc: 'number of lines after filter match'
31
30
  method_option :last, type: :numeric, default: 1, aliases: '-l', desc: 'show nth last build'
31
+ method_option :pull, type: :numeric, aliases: '-p', desc: 'show last build from pull request ID'
32
+ method_option :branch, type: :string, aliases: '-b', desc: 'builds on that branch'
32
33
  def show(id = nil)
33
- if id.nil? || id == 'l' || id == 'last'
34
- last = self.class.client.list(limit: options[:last].abs)[0]
35
- id = last['id'] if last
36
- end
34
+ ref = self.class.options_to_ref(options)
37
35
 
38
- abort 'id is required' if id.to_s.empty?
36
+ id = self.class.client.list(limit: options[:last].abs, ref: ref)[0]['id'] if id.to_i.to_s != id
39
37
 
40
38
  self.class.client.show(id, filter: options[:filter], context: options[:context]) do |line|
41
39
  puts line
42
40
  end
41
+ rescue
42
+ abort "No build found for options: #{options}"
43
43
  end
44
44
 
45
45
  desc 'version', 'version used'
@@ -63,4 +63,12 @@ class Drone::Builds::Cli < Thor
63
63
  job_id: HOME_ENV[:DRONECI_JOB_ID]
64
64
  )
65
65
  end
66
+
67
+
68
+ def self.options_to_ref(options)
69
+ ref = nil
70
+ ref = "refs/heads/#{options[:branch]}" if options[:branch]
71
+ ref = "refs/pull/#{options[:pull]}/head" if options[:pull]
72
+ ref
73
+ end
66
74
  end
@@ -1,5 +1,5 @@
1
1
  module Drone
2
2
  class Builds
3
- VERSION = '0.3.0'.freeze
3
+ VERSION = '0.3.1'.freeze
4
4
  end
5
5
  end
data/lib/drone/builds.rb CHANGED
@@ -20,8 +20,8 @@ module Drone
20
20
  @protocol = protocol || 'http'
21
21
  end
22
22
 
23
- def list(limit: nil)
24
- json_api(builds_url).first(limit || DEFAULT_LIMIT).reverse
23
+ def list(limit: nil, ref: nil)
24
+ json_api(builds_url).select { |b| !ref || b["ref"] == ref }.first(limit || DEFAULT_LIMIT).reverse
25
25
  end
26
26
 
27
27
  def show(id, filter: nil, context: nil)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drone-builds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié