drone-builds 0.2.2 → 0.2.3
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 +4 -4
- data/Rakefile +2 -2
- data/bin/console +3 -3
- data/drone-builds.gemspec +17 -17
- data/exe/drone-builds +0 -1
- data/lib/drone/builds.rb +8 -8
- data/lib/drone/builds/cli.rb +16 -15
- data/lib/drone/builds/parser.rb +7 -7
- data/lib/drone/builds/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebc202d5e431628b68d6b18139e09ab8017e3611
|
4
|
+
data.tar.gz: 14748c8228a690c14644404a517737845886f633
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6ad38567302652d0e020b9de47da175ff04003d0413be8438004d5a696abab90674e54a7efb1ccff6c94660d3d494d96329e9e483ee2557835978b50adf3ced
|
7
|
+
data.tar.gz: 0eed21a1d304959e6a9f55fa27d432f715ee5b87fbcc3db67754b913afc0d7c9ee1f9bae85aef10682e6e257d16ff1ef092be8e80a15ef0a4910b24ae0e786b7
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'drone/builds'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "drone/builds"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
data/drone-builds.gemspec
CHANGED
@@ -5,29 +5,29 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
require 'drone/builds/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name =
|
8
|
+
spec.name = 'drone-builds'
|
9
9
|
spec.version = Drone::Builds::VERSION
|
10
|
-
spec.authors = [
|
11
|
-
spec.email = [
|
10
|
+
spec.authors = ['Dorian Marié']
|
11
|
+
spec.email = ['dorian@doma.io']
|
12
12
|
|
13
|
-
spec.summary =
|
14
|
-
spec.description =
|
15
|
-
spec.homepage =
|
16
|
-
spec.license =
|
13
|
+
spec.summary = 'Command line interface to Drone'
|
14
|
+
spec.description = 'List builds, print realtime output, view previous outputs, filter outputs'
|
15
|
+
spec.homepage = 'https://github.com/Dorian/drone-builds'
|
16
|
+
spec.license = 'MIT'
|
17
17
|
|
18
18
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
19
|
f.match(%r{^(test|spec|features)/})
|
20
20
|
end
|
21
|
-
spec.bindir =
|
21
|
+
spec.bindir = 'exe'
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
-
spec.require_paths = [
|
23
|
+
spec.require_paths = ['lib']
|
24
24
|
|
25
|
-
spec.add_runtime_dependency
|
26
|
-
spec.add_runtime_dependency
|
27
|
-
spec.add_runtime_dependency
|
28
|
-
spec.add_runtime_dependency
|
29
|
-
spec.add_runtime_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
25
|
+
spec.add_runtime_dependency 'colorize', '~> 0'
|
26
|
+
spec.add_runtime_dependency 'home-dotenv', '~> 0'
|
27
|
+
spec.add_runtime_dependency 'json', '~> 2'
|
28
|
+
spec.add_runtime_dependency 'terminal-table', '~> 1'
|
29
|
+
spec.add_runtime_dependency 'thor', '~> 0'
|
30
|
+
spec.add_development_dependency 'bundler', '~> 1'
|
31
|
+
spec.add_development_dependency 'rake', '~> 12'
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3'
|
33
33
|
end
|
data/exe/drone-builds
CHANGED
data/lib/drone/builds.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'drone/builds/version'
|
2
2
|
require 'open-uri'
|
3
3
|
require 'net/http'
|
4
4
|
require 'json'
|
@@ -11,7 +11,6 @@ module Drone
|
|
11
11
|
DEFAULT_JOB_ID = 1
|
12
12
|
|
13
13
|
def initialize(token:, domain:, owner:, name:, job_id: nil, protocol: nil)
|
14
|
-
@protocol
|
15
14
|
@token = token
|
16
15
|
@domain = domain
|
17
16
|
@owner = owner
|
@@ -60,13 +59,9 @@ module Drone
|
|
60
59
|
uri = URI(full_url(url))
|
61
60
|
|
62
61
|
Net::HTTP.start(uri.host, uri.port) do |http|
|
63
|
-
request
|
64
|
-
|
65
|
-
http.request request do |response|
|
62
|
+
http.request(Net::HTTP::Get.new(uri)) do |response|
|
66
63
|
response.read_body do |chunk|
|
67
|
-
|
68
|
-
output = lines.map(&:strip).compact.join("\n")
|
69
|
-
yield output
|
64
|
+
yield clean_stream_data(chunk)
|
70
65
|
end
|
71
66
|
end
|
72
67
|
end
|
@@ -80,4 +75,9 @@ module Drone
|
|
80
75
|
open(full_url(url)).read
|
81
76
|
end
|
82
77
|
end
|
78
|
+
|
79
|
+
def clean_stream_data(data)
|
80
|
+
lines = data.lines.grep(/^data:/).map { |l| l.gsub(/^data:/, '') }
|
81
|
+
lines.map(&:strip).compact.join("\n")
|
82
|
+
end
|
83
83
|
end
|
data/lib/drone/builds/cli.rb
CHANGED
@@ -2,35 +2,36 @@ require 'home-dotenv/load'
|
|
2
2
|
require 'thor'
|
3
3
|
require 'drone/builds/parser'
|
4
4
|
|
5
|
+
# Command-line interface configuration
|
5
6
|
class Drone::Builds::Cli < Thor
|
6
|
-
package_name
|
7
|
+
package_name 'drone-builds'
|
7
8
|
|
8
|
-
map
|
9
|
-
map
|
9
|
+
map 'l' => :list
|
10
|
+
map 's' => :show
|
10
11
|
|
11
|
-
desc
|
12
|
+
desc 'list', 'list last builds'
|
12
13
|
method_option :limit,
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
type: :numeric,
|
15
|
+
default: Drone::Builds::DEFAULT_LIMIT,
|
16
|
+
aliases: '-l',
|
17
|
+
desc: 'number of builds shown'
|
17
18
|
def list
|
18
19
|
puts self.class.parser.table(
|
19
20
|
self.class.parser.parse_builds(self.class.client.list(limit: options[:limit])),
|
20
|
-
%i
|
21
|
+
%i[id status ref message]
|
21
22
|
)
|
22
23
|
end
|
23
24
|
|
24
|
-
desc
|
25
|
-
method_option :filter, type: :string, aliases:
|
26
|
-
method_option :last, type: :numeric, default: 1, aliases:
|
25
|
+
desc 'show', 'show a build'
|
26
|
+
method_option :filter, type: :string, aliases: '-f', desc: 'filter builds output lines'
|
27
|
+
method_option :last, type: :numeric, default: 1, aliases: '-l', desc: 'show nth last build'
|
27
28
|
def show(id = nil)
|
28
|
-
if id.nil?
|
29
|
+
if id.nil? || id == 'l' || id == 'last'
|
29
30
|
last = self.class.client.list(limit: options[:last])[0]
|
30
|
-
id = last[
|
31
|
+
id = last['id'] if last
|
31
32
|
end
|
32
33
|
|
33
|
-
abort
|
34
|
+
abort 'id is required' if id.to_s.empty?
|
34
35
|
|
35
36
|
self.class.client.show(id, filter: options[:filter]) { |line| puts line }
|
36
37
|
end
|
data/lib/drone/builds/parser.rb
CHANGED
@@ -10,7 +10,7 @@ class Drone::Builds::Parser
|
|
10
10
|
failure: :red,
|
11
11
|
killed: :white,
|
12
12
|
pending: :yellow
|
13
|
-
}
|
13
|
+
}.freeze
|
14
14
|
|
15
15
|
def initialize(client)
|
16
16
|
@client = client
|
@@ -22,10 +22,10 @@ class Drone::Builds::Parser
|
|
22
22
|
|
23
23
|
def parse_build(build)
|
24
24
|
{
|
25
|
-
id: parse_id(build[
|
26
|
-
status: parse_status(build[
|
27
|
-
ref: parse_ref(build[
|
28
|
-
message: parse_message(build[
|
25
|
+
id: parse_id(build['id']),
|
26
|
+
status: parse_status(build['status']),
|
27
|
+
ref: parse_ref(build['ref']),
|
28
|
+
message: parse_message(build['message'])
|
29
29
|
}
|
30
30
|
end
|
31
31
|
|
@@ -38,11 +38,11 @@ class Drone::Builds::Parser
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def parse_ref(ref)
|
41
|
-
ref.gsub(
|
41
|
+
ref.gsub('refs/heads/', '').gsub('/head', '').gsub('refs/pull/', '#')
|
42
42
|
end
|
43
43
|
|
44
44
|
def parse_message(message)
|
45
|
-
message.to_s.lines.first.to_s.gsub("of github.com:#{client.owner}/#{client.name}",
|
45
|
+
message.to_s.lines.first.to_s.gsub("of github.com:#{client.owner}/#{client.name}", '')[0..50]
|
46
46
|
end
|
47
47
|
|
48
48
|
def table(data, fields)
|
data/lib/drone/builds/version.rb
CHANGED