circleci-cli 0.6.3 → 1.0.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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +21 -19
  4. data/bin/circle +2 -2
  5. data/bin/console +1 -1
  6. data/{circler.gemspec → circleci-cli.gemspec} +3 -3
  7. data/exe/{circle → circleci-cli} +2 -2
  8. data/lib/circleci/cli.rb +77 -0
  9. data/lib/circleci/cli/command.rb +16 -0
  10. data/lib/circleci/cli/command/base_command.rb +45 -0
  11. data/lib/circleci/cli/command/browse_command.rb +24 -0
  12. data/lib/circleci/cli/command/build_command.rb +19 -0
  13. data/lib/circleci/cli/command/builds_command.rb +25 -0
  14. data/lib/circleci/cli/command/cancel_command.rb +23 -0
  15. data/lib/circleci/cli/command/projects_command.rb +16 -0
  16. data/lib/circleci/cli/command/retry_command.rb +23 -0
  17. data/lib/circleci/cli/command/watch_command.rb +77 -0
  18. data/lib/circleci/cli/networking.rb +9 -0
  19. data/lib/circleci/cli/networking/pusher_client.rb +62 -0
  20. data/lib/circleci/cli/printer.rb +11 -0
  21. data/lib/circleci/cli/printer/build_printer.rb +63 -0
  22. data/lib/circleci/cli/printer/project_printer.rb +37 -0
  23. data/lib/circleci/cli/printer/step_printer.rb +57 -0
  24. data/lib/circleci/cli/response.rb +13 -0
  25. data/lib/circleci/cli/response/account.rb +21 -0
  26. data/lib/circleci/cli/response/action.rb +39 -0
  27. data/lib/circleci/cli/response/build.rb +104 -0
  28. data/lib/circleci/cli/response/project.rb +21 -0
  29. data/lib/circleci/cli/response/step.rb +22 -0
  30. data/lib/circleci/cli/version.rb +7 -0
  31. data/lib/circleci_cli.rb +7 -0
  32. metadata +29 -25
  33. data/lib/circler.rb +0 -6
  34. data/lib/circler/cli.rb +0 -88
  35. data/lib/circler/command/base_command.rb +0 -41
  36. data/lib/circler/command/browse_command.rb +0 -20
  37. data/lib/circler/command/build_command.rb +0 -15
  38. data/lib/circler/command/builds_command.rb +0 -21
  39. data/lib/circler/command/cancel_command.rb +0 -19
  40. data/lib/circler/command/projects_command.rb +0 -12
  41. data/lib/circler/command/retry_command.rb +0 -19
  42. data/lib/circler/command/watch_command.rb +0 -73
  43. data/lib/circler/networking/pusher_client.rb +0 -56
  44. data/lib/circler/printer/build_printer.rb +0 -59
  45. data/lib/circler/printer/project_printer.rb +0 -33
  46. data/lib/circler/printer/step_printer.rb +0 -53
  47. data/lib/circler/response/account.rb +0 -17
  48. data/lib/circler/response/action.rb +0 -35
  49. data/lib/circler/response/build.rb +0 -100
  50. data/lib/circler/response/project.rb +0 -17
  51. data/lib/circler/response/step.rb +0 -18
  52. data/lib/circler/version.rb +0 -5
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CircleCI
4
+ module CLI
5
+ module Response
6
+ class Step
7
+ attr_reader :type
8
+ attr_reader :status
9
+
10
+ def initialize(type, hash)
11
+ @type = type
12
+ @status = hash['status']
13
+ @hash = hash
14
+ end
15
+
16
+ def actions
17
+ @hash['actions'].map { |a| Action.new(a) }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CircleCI
4
+ module CLI
5
+ VERSION = '1.0.0'
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'circleci/cli'
4
+
5
+ module CircleCI
6
+ module CLI; end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circleci-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - unhappychoice
@@ -298,7 +298,7 @@ description: A command line tool for CircleCI
298
298
  email:
299
299
  - unhappychoice@gmail.com
300
300
  executables:
301
- - circle
301
+ - circleci-cli
302
302
  extensions: []
303
303
  extra_rdoc_files: []
304
304
  files:
@@ -314,30 +314,34 @@ files:
314
314
  - bin/circle
315
315
  - bin/console
316
316
  - bin/setup
317
- - circler.gemspec
318
- - exe/circle
319
- - lib/circler.rb
320
- - lib/circler/cli.rb
321
- - lib/circler/command/base_command.rb
322
- - lib/circler/command/browse_command.rb
323
- - lib/circler/command/build_command.rb
324
- - lib/circler/command/builds_command.rb
325
- - lib/circler/command/cancel_command.rb
326
- - lib/circler/command/projects_command.rb
327
- - lib/circler/command/retry_command.rb
328
- - lib/circler/command/watch_command.rb
329
- - lib/circler/networking/pusher_client.rb
330
- - lib/circler/printer/build_printer.rb
331
- - lib/circler/printer/project_printer.rb
332
- - lib/circler/printer/step_printer.rb
333
- - lib/circler/response/account.rb
334
- - lib/circler/response/action.rb
335
- - lib/circler/response/build.rb
336
- - lib/circler/response/project.rb
337
- - lib/circler/response/step.rb
338
- - lib/circler/version.rb
317
+ - circleci-cli.gemspec
318
+ - exe/circleci-cli
319
+ - lib/circleci/cli.rb
320
+ - lib/circleci/cli/command.rb
321
+ - lib/circleci/cli/command/base_command.rb
322
+ - lib/circleci/cli/command/browse_command.rb
323
+ - lib/circleci/cli/command/build_command.rb
324
+ - lib/circleci/cli/command/builds_command.rb
325
+ - lib/circleci/cli/command/cancel_command.rb
326
+ - lib/circleci/cli/command/projects_command.rb
327
+ - lib/circleci/cli/command/retry_command.rb
328
+ - lib/circleci/cli/command/watch_command.rb
329
+ - lib/circleci/cli/networking.rb
330
+ - lib/circleci/cli/networking/pusher_client.rb
331
+ - lib/circleci/cli/printer.rb
332
+ - lib/circleci/cli/printer/build_printer.rb
333
+ - lib/circleci/cli/printer/project_printer.rb
334
+ - lib/circleci/cli/printer/step_printer.rb
335
+ - lib/circleci/cli/response.rb
336
+ - lib/circleci/cli/response/account.rb
337
+ - lib/circleci/cli/response/action.rb
338
+ - lib/circleci/cli/response/build.rb
339
+ - lib/circleci/cli/response/project.rb
340
+ - lib/circleci/cli/response/step.rb
341
+ - lib/circleci/cli/version.rb
342
+ - lib/circleci_cli.rb
339
343
  - movie/rec.gif
340
- homepage: https://github.com/unhappychoice/circler
344
+ homepage: https://github.com/unhappychoice/circleci-cli
341
345
  licenses:
342
346
  - MIT
343
347
  metadata: {}
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'circler/cli'
4
-
5
- module Circler
6
- end
@@ -1,88 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'thor'
4
- require 'faraday'
5
- require 'launchy'
6
- require 'terminal-table'
7
- require 'highline/import'
8
- require 'colorize'
9
- require 'rugged'
10
- require 'circleci'
11
- require 'terminal-notifier'
12
- require 'circler'
13
- require 'circler/version'
14
- require 'circler/command/base_command'
15
- require 'circler/command/projects_command'
16
- require 'circler/command/builds_command'
17
- require 'circler/command/build_command'
18
- require 'circler/command/browse_command'
19
- require 'circler/command/watch_command'
20
- require 'circler/command/retry_command'
21
- require 'circler/command/cancel_command'
22
- require 'circler/response/account'
23
- require 'circler/response/project'
24
- require 'circler/response/build'
25
- require 'circler/response/step'
26
- require 'circler/response/action'
27
- require 'circler/printer/project_printer'
28
- require 'circler/printer/build_printer'
29
- require 'circler/printer/step_printer'
30
- require 'circler/networking/pusher_client'
31
-
32
- module Circler
33
- class CLI < Thor
34
- desc 'projects', 'list projects'
35
- method_option :format, aliases: 'f', type: :string, banner: 'pretty/simple'
36
- def projects
37
- ProjectsCommand.run(options)
38
- end
39
-
40
- desc 'builds', 'list builds'
41
- method_option :project, aliases: 'p', type: :string, banner: 'user/project'
42
- method_option :branch, aliases: 'b', type: :string, banner: 'some-branch'
43
- method_option :format, aliases: 'f', type: :string, banner: 'pretty/simple'
44
- def builds
45
- BuildsCommand.run(options)
46
- end
47
-
48
- desc 'build', 'show build description'
49
- method_option :project, aliases: 'p', type: :string, banner: 'user/project'
50
- method_option :build, aliases: 'n', type: :numeric, banner: 'build-number'
51
- def build
52
- BuildCommand.run(options)
53
- end
54
-
55
- desc 'browse', 'open circle ci website'
56
- method_option :project, aliases: 'p', type: :string, banner: 'user/project'
57
- method_option :build, aliases: 'n', type: :numeric, banner: 'build-number'
58
- def browse
59
- BrowseCommand.run(options)
60
- end
61
-
62
- desc 'retry', 'retry a build'
63
- method_option :project, aliases: 'p', type: :string, banner: 'user/project'
64
- method_option :build, aliases: 'n', type: :numeric, banner: 'build-number'
65
- def retry
66
- RetryCommand.run(options)
67
- end
68
-
69
- desc 'cancel', 'cancel a build'
70
- method_option :project, aliases: 'p', type: :string, banner: 'user/project'
71
- method_option :build, aliases: 'n', type: :numeric, banner: 'build-number'
72
- def cancel
73
- CancelCommand.run(options)
74
- end
75
-
76
- desc 'watch', 'watch a build in real time'
77
- method_option :project, aliases: 'p', type: :string, banner: 'user/project'
78
- method_option :build, aliases: 'n', type: :numeric, banner: 'build-number'
79
- def watch
80
- WatchCommand.run(options)
81
- end
82
-
83
- desc 'version', 'show gem version'
84
- def version
85
- say Circler::VERSION
86
- end
87
- end
88
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Circler
4
- class BaseCommand
5
- class << self
6
- def setup_token
7
- CircleCi.configure do |config|
8
- config.token = ENV['CIRCLE_CI_TOKEN'] || ask('Circle CI token ? :')
9
- end
10
- end
11
-
12
- def project_name(options)
13
- if options.project
14
- options.project
15
- elsif reponame
16
- reponame
17
- else
18
- say ProjectPrinter.new(Project.all).to_s
19
- ask('Input user-name/project-name :')
20
- end
21
- end
22
-
23
- def reponame
24
- repository = Rugged::Repository.new('.')
25
- origin = repository.remotes.find { |r| r.name == 'origin' }
26
- regexp = %r{git@github.com(?::|/)([\w_-]+/[\w_-]+)(?:\.git)*}
27
- return Regexp.last_match(1) if origin.url =~ regexp
28
-
29
- nil
30
- end
31
-
32
- def build_number(options)
33
- options.build || ask('Input build number')
34
- end
35
-
36
- def should_be_pretty(options)
37
- options['format'] != 'simple'
38
- end
39
- end
40
- end
41
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Circler
4
- class BrowseCommand < BaseCommand
5
- class << self
6
- def run(options)
7
- setup_token
8
- project = project_name(options)
9
- number = options.build
10
- Launchy.open url(project, number)
11
- end
12
-
13
- def url(project, number)
14
- return "https://circleci.com/gh/#{project}" unless number
15
-
16
- "https://circleci.com/gh/#{project}/#{number}"
17
- end
18
- end
19
- end
20
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Circler
4
- class BuildCommand < BaseCommand
5
- class << self
6
- def run(options)
7
- setup_token
8
- username, reponame = project_name(options).split('/')
9
- number = build_number(options)
10
- build = Build.get(username, reponame, number)
11
- say StepPrinter.new(build.steps).to_s
12
- end
13
- end
14
- end
15
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Circler
4
- class BuildsCommand < BaseCommand
5
- class << self
6
- def run(options)
7
- setup_token
8
- username, reponame = project_name(options).split('/')
9
-
10
- builds =
11
- if options.branch
12
- Build.branch(username, reponame, options.branch)
13
- else
14
- Build.all(username, reponame)
15
- end
16
-
17
- say BuildPrinter.new(builds, pretty: should_be_pretty(options)).to_s
18
- end
19
- end
20
- end
21
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Circler
4
- class CancelCommand < BaseCommand
5
- class << self
6
- def run(options)
7
- setup_token
8
- username, reponame = project_name(options).split('/')
9
- number = build_number(options)
10
- build = Build.cancel(username, reponame, number)
11
- if build.username
12
- say "build #{build.project_name} #{build.build_number} is canceled."
13
- else
14
- say "failed to cancel #{username}/#{reponame} #{number}."
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Circler
4
- class ProjectsCommand < BaseCommand
5
- class << self
6
- def run(options)
7
- setup_token
8
- say ProjectPrinter.new(Project.all, pretty: should_be_pretty(options)).to_s
9
- end
10
- end
11
- end
12
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Circler
4
- class RetryCommand < BaseCommand
5
- class << self
6
- def run(options)
7
- setup_token
8
- username, reponame = project_name(options).split('/')
9
- number = build_number(options)
10
- build = Build.retry(username, reponame, number)
11
- if build.username
12
- say "build #{username}/#{reponame} #{build.build_number} is triggered"
13
- else
14
- say "failed to trigger #{username}/#{reponame} #{number}"
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Circler
4
- class WatchCommand < BaseCommand
5
- class << self
6
- def run(options)
7
- setup_token
8
- setup_client
9
-
10
- build = get_build(options)
11
-
12
- if build&.running?
13
- start_watch(build)
14
- wait_until_finish
15
- finalize(build, build.channel_name)
16
- else
17
- say 'The build is not running'
18
- end
19
- end
20
-
21
- private
22
-
23
- def setup_client
24
- @client = CirclerPusherClient.new
25
- @client.connect
26
- end
27
-
28
- def get_build(options)
29
- username, reponame = project_name(options).split('/')
30
- number = build_number options
31
- Build.get(username, reponame, number)
32
- end
33
-
34
- def start_watch(build)
35
- @running = true
36
- text = "Start watching #{build.project_name} ##{build.build_number}"
37
- print_bordered text
38
- TerminalNotifier.notify text
39
-
40
- bind_event_handling build.channel_name
41
- end
42
-
43
- def bind_event_handling(channel)
44
- @client.bind_event_json(channel, 'newAction') do |json|
45
- print_bordered json['log']['name'].green
46
- end
47
-
48
- @client.bind_event_json(channel, 'appendAction') do |json|
49
- say json['out']['message']
50
- end
51
-
52
- @client.bind_event_json(channel, 'updateAction') do |json|
53
- @running = json['log']['name'] != 'Disable SSH'
54
- end
55
- end
56
-
57
- def wait_until_finish
58
- sleep(1) while @running
59
- end
60
-
61
- def finalize(build, channel)
62
- @client.unsubscribe(channel)
63
- text = "Finish watching #{build.project_name} ##{build.build_number}"
64
- print_bordered text.blue
65
- TerminalNotifier.notify text
66
- end
67
-
68
- def print_bordered(text)
69
- say Terminal::Table.new(rows: [[text]], style: { width: 120 }).to_s
70
- end
71
- end
72
- end
73
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'pusher-client'
4
-
5
- class CirclerPusherClient
6
- def connect
7
- PusherClient.logger.level = Logger::ERROR
8
- @socket = PusherClient::Socket.new(app_key, pusher_options)
9
- @socket.connect(true)
10
- end
11
-
12
- def bind(channel, event)
13
- @socket.subscribe(channel)
14
- @socket[channel].bind(event) do |data|
15
- yield data
16
- end
17
- end
18
-
19
- def bind_event_json(channel, event)
20
- bind(channel, event) do |data|
21
- JSON.parse(data).each { |json| yield(json) }
22
- end
23
- end
24
-
25
- def unsubscribe(channel)
26
- @socket.unsubscribe(channel)
27
- end
28
-
29
- private
30
-
31
- def app_key
32
- '1cf6e0e755e419d2ac9a'
33
- end
34
-
35
- def pusher_options
36
- {
37
- secure: true,
38
- auth_method: proc { |a, b| auth(a, b) },
39
- logger: Logger.new('/dev/null')
40
- }
41
- end
42
-
43
- def auth(socket_id, channel)
44
- data = { socket_id: socket_id, channel_name: channel.name }
45
- token = ENV['CIRCLE_CI_TOKEN'] || ask('Circle CI token ? :')
46
- res = connection.post("/auth/pusher?circle-token=#{token}", data)
47
- JSON.parse(res.body)['auth']
48
- end
49
-
50
- def connection
51
- Faraday.new(url: 'https://circleci.com') do |f|
52
- f.request :url_encoded
53
- f.adapter Faraday.default_adapter
54
- end
55
- end
56
- end