circler 0.2.1 → 0.3.0

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: 04a84c2140e10bf2aa03f7d965432158ef882c8b
4
- data.tar.gz: 108e7f83fc13da7fec212cfa1870d88b0e86e7ac
3
+ metadata.gz: 7a0bff5698706e6bf37040feab3422d9cf523cb6
4
+ data.tar.gz: 21df7ada83e50eab7532a1b4a7b632615ef253a0
5
5
  SHA512:
6
- metadata.gz: 202f45afbaba993cd9d2bc8417ad8cedf7dc5c5476c0edbd9e38802d16463987b7a2386e4aadfcb70586565d449c7a3d6bd0462e5aff431c9ac9c9b8789ea97c
7
- data.tar.gz: 0ae2698e134b57bdf11b5f7f25be10b5546ca6ae969d7e3d7a4515c41db2f8449a0719364ecd94ad324670119127ca75fdcb31f3aedba875d20b2721d72e2c1a
6
+ metadata.gz: a1d436af72afa90fdf030ac44bf3680c2087180ecb538ac4567b48b82c9dde1a69aa6804740bc6a844459a0f55931926eb86816dda9574c145f80b85e82de1e1
7
+ data.tar.gz: d5763b8b7ebed54276d14d60448b010be05afe27b1d2eab6297778013aeb9925fe83d3c7aa89edd80164ab80753fd1379a2dc2fab258ef40682a24667687bd51
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- circler (0.2.1)
4
+ circler (0.3.0)
5
5
  circleci (~> 0.2.0)
6
6
  colorize (~> 0.7.7)
7
7
  faraday (~> 0.9.2)
8
8
  highline (~> 1.7.8)
9
9
  launchy (~> 2.4.3)
10
+ pusher-client (~> 0.6.2)
10
11
  rugged (~> 0.24.0b11)
11
12
  terminal-table (~> 1.5.2)
12
13
  thor (~> 0.19.1)
@@ -15,22 +16,26 @@ GEM
15
16
  remote: https://rubygems.org/
16
17
  specs:
17
18
  addressable (2.4.0)
18
- circleci (0.2.1)
19
+ circleci (0.2.2)
19
20
  rest-client (~> 1.8)
20
21
  colorize (0.7.7)
21
22
  diff-lcs (1.2.5)
22
- domain_name (0.5.20160128)
23
+ domain_name (0.5.20160216)
23
24
  unf (>= 0.0.5, < 1.0.0)
24
25
  faraday (0.9.2)
25
26
  multipart-post (>= 1.2, < 3)
26
27
  highline (1.7.8)
27
28
  http-cookie (1.0.2)
28
29
  domain_name (~> 0.5)
30
+ json (1.8.3)
29
31
  launchy (2.4.3)
30
32
  addressable (~> 2.3)
31
33
  mime-types (2.99.1)
32
34
  multipart-post (2.0.0)
33
35
  netrc (0.11.0)
36
+ pusher-client (0.6.2)
37
+ json
38
+ websocket (~> 1.0)
34
39
  rake (10.5.0)
35
40
  rest-client (1.8.0)
36
41
  http-cookie (>= 1.0.2, < 2.0)
@@ -49,12 +54,13 @@ GEM
49
54
  diff-lcs (>= 1.2.0, < 2.0)
50
55
  rspec-support (~> 3.4.0)
51
56
  rspec-support (3.4.1)
52
- rugged (0.24.0b13)
57
+ rugged (0.24.0)
53
58
  terminal-table (1.5.2)
54
59
  thor (0.19.1)
55
60
  unf (0.1.4)
56
61
  unf_ext
57
62
  unf_ext (0.0.7.2)
63
+ websocket (1.2.2)
58
64
 
59
65
  PLATFORMS
60
66
  ruby
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Circler
2
2
 
3
- [![Circle CI](https://circleci.com/gh/unhappychoice/circle.svg?style=svg)](https://circleci.com/gh/unhappychoice/circle)
3
+ [![Circle CI](https://circleci.com/gh/unhappychoice/circler.svg?style=svg)](https://circleci.com/gh/unhappychoice/circler)
4
4
 
5
5
  Circler is a CLI tool for [Circle CI](https://circleci.com).
6
6
 
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  # Production
22
+ spec.add_dependency 'pusher-client', '~> 0.6.2'
22
23
  spec.add_dependency 'thor', '~> 0.19.1'
23
24
  spec.add_dependency 'faraday', '~> 0.9.2'
24
25
  spec.add_dependency 'launchy', '~> 2.4.3'
@@ -12,6 +12,8 @@ require 'circler/command/projects_command'
12
12
  require 'circler/command/builds_command'
13
13
  require 'circler/command/build_command'
14
14
  require 'circler/command/browse_command'
15
+ require 'circler/command/watch_command'
16
+ require 'circler/response/account'
15
17
  require 'circler/response/project'
16
18
  require 'circler/response/build'
17
19
  require 'circler/response/step'
@@ -19,6 +21,7 @@ require 'circler/response/action'
19
21
  require 'circler/printer/project_printer'
20
22
  require 'circler/printer/build_printer'
21
23
  require 'circler/printer/step_printer'
24
+ require 'circler/networking/pusher_client'
22
25
 
23
26
  module Circler
24
27
  class CLI < Thor
@@ -48,6 +51,13 @@ module Circler
48
51
  BrowseCommand.run(options)
49
52
  end
50
53
 
54
+ desc 'watch', 'watch a build in real time'
55
+ method_option :project, aliases: 'p', type: :string, banner: 'user/project'
56
+ method_option :build, aliases: 'n', type: :numeric, banner: 'build-number'
57
+ def watch
58
+ WatchCommand.run(options)
59
+ end
60
+
51
61
  desc 'version', 'show gem version'
52
62
  def version
53
63
  say Circler::VERSION
@@ -2,6 +2,7 @@ module Circler
2
2
  class BrowseCommand < BaseCommand
3
3
  class << self
4
4
  def run(options)
5
+ setup_token
5
6
  project = project_name(options)
6
7
  number = options.build
7
8
  Launchy.open url(project, number)
@@ -0,0 +1,86 @@
1
+ module Circler
2
+ class WatchCommand < BaseCommand
3
+ class << self
4
+ def run(options)
5
+ setup_token
6
+ say 'Connecting to pusher'.blue
7
+
8
+ update_builds(options)
9
+ setup_client(options)
10
+
11
+ say 'Connected'.blue
12
+
13
+ loop do
14
+ start_watch(@@builds.first) if !@@builds.empty? && !@@running
15
+ sleep 1
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def setup_client(options)
22
+ @@running = false
23
+ @@client = CirclerPusherClient.new
24
+ @@client.connect
25
+ @@client.bind("private-#{Account.me.user_name}", 'call') do
26
+ @@running = false
27
+ update_builds(options)
28
+ end
29
+ end
30
+
31
+ def update_builds(options)
32
+ username, reponame = project_name(options).split('/')
33
+ @@builds = Build
34
+ .all(username, reponame)
35
+ .select { |b| b.status == 'running' }
36
+ end
37
+
38
+ def start_watch(build)
39
+ @@running = true
40
+ print_bordered "Start watching #{build.username}/#{build.reponame} build ##{build.build_number}".blue
41
+
42
+ bind_event_handling(build.channel_name)
43
+ wait_until_finish
44
+ finalize(build, build.channel_name)
45
+ end
46
+
47
+ def bind_event_handling(channel)
48
+ @@client.bind(channel, 'newAction') do |data|
49
+ JSON.parse(data).each do |d|
50
+ print_bordered d['log']['name'].green
51
+ end
52
+ end
53
+
54
+ @@client.bind(channel, 'appendAction') do |data|
55
+ JSON.parse(data).each { |d| say d['out']['message'] }
56
+ end
57
+
58
+ @@client.bind(channel, 'updateAction') do |data|
59
+ JSON.parse(data).each do |d|
60
+ @@running = d['log']['name'] != 'Disable SSH'
61
+ end
62
+ end
63
+ end
64
+
65
+ def wait_until_finish
66
+ while @@running
67
+ sleep(1)
68
+ end
69
+ end
70
+
71
+ def finalize(build, channel)
72
+ @@builds = @@builds.select { |b| b.build_number != build.build_number }
73
+ @@client.unsubscribe(channel)
74
+
75
+ print_bordered "Finish watching #{build.username}/#{build.reponame} build ##{build.build_number}".blue
76
+ end
77
+
78
+ def print_bordered(text)
79
+ say Terminal::Table.new(
80
+ rows: [[text]],
81
+ style: { width: 120 }
82
+ ).to_s
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,48 @@
1
+ require 'pusher-client'
2
+
3
+ class CirclerPusherClient
4
+ def connect
5
+ PusherClient.logger.level = Logger::ERROR
6
+ @socket = PusherClient::Socket.new(app_key, pusher_options)
7
+ @socket.connect(true)
8
+ end
9
+
10
+ def bind(channel, event)
11
+ @socket.subscribe(channel)
12
+ @socket[channel].bind(event) do |data|
13
+ yield data
14
+ end
15
+ end
16
+
17
+ def unsubscribe(channel)
18
+ @socket.unsubscribe(channel)
19
+ end
20
+
21
+ private
22
+
23
+ def app_key
24
+ '1cf6e0e755e419d2ac9a'
25
+ end
26
+
27
+ def pusher_options
28
+ {
29
+ secure: true,
30
+ auth_method: Proc.new { |a, b| auth(a, b) },
31
+ logger: Logger.new('/dev/null')
32
+ }
33
+ end
34
+
35
+ def auth(socket_id, channel)
36
+ data = { socket_id: socket_id, channel_name: channel.name }
37
+ token = ENV['CIRCLE_CI_TOKEN'] || ask('Circle CI token ? :')
38
+ res = connection.post("/auth/pusher?circle-token=#{token}", data)
39
+ JSON.parse(res.body)['auth']
40
+ end
41
+
42
+ def connection
43
+ Faraday.new(url: 'https://circleci.com') do |f|
44
+ f.request :url_encoded
45
+ f.adapter Faraday.default_adapter
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,15 @@
1
+ module Circler
2
+ class Account
3
+ def initialize(hash)
4
+ @hash = hash
5
+ end
6
+
7
+ def user_name
8
+ @hash['name']
9
+ end
10
+
11
+ def self.me
12
+ Account.new(CircleCi::User.me.body)
13
+ end
14
+ end
15
+ end
@@ -1,4 +1,3 @@
1
- require 'pp'
2
1
  module Circler
3
2
  class Action
4
3
  attr_reader :name, :status, :run_time_millis
@@ -30,6 +30,18 @@ module Circler
30
30
  @hash['reponame']
31
31
  end
32
32
 
33
+ def status
34
+ @hash['status']
35
+ end
36
+
37
+ def build_number
38
+ @hash['build_num']
39
+ end
40
+
41
+ def channel_name
42
+ "private-#{username}@#{reponame}@#{build_number}@vcs-github"
43
+ end
44
+
33
45
  def information
34
46
  [
35
47
  @hash['build_num'],
@@ -1,3 +1,3 @@
1
1
  module Circler
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - unhappychoice
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-24 00:00:00.000000000 Z
11
+ date: 2016-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pusher-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.2
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: thor
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -190,9 +204,12 @@ files:
190
204
  - lib/circler/command/build_command.rb
191
205
  - lib/circler/command/builds_command.rb
192
206
  - lib/circler/command/projects_command.rb
207
+ - lib/circler/command/watch_command.rb
208
+ - lib/circler/networking/pusher_client.rb
193
209
  - lib/circler/printer/build_printer.rb
194
210
  - lib/circler/printer/project_printer.rb
195
211
  - lib/circler/printer/step_printer.rb
212
+ - lib/circler/response/account.rb
196
213
  - lib/circler/response/action.rb
197
214
  - lib/circler/response/build.rb
198
215
  - lib/circler/response/project.rb