jiminy 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c2d7c5c5ca5c253b2c1c9962f4d2c846a1bf2ebb9ecbcfa4d5a254832dae2ec
4
- data.tar.gz: 77f60976535c54d0e42205aedbca82067164b15956d1b0b7a44a49791a7d4de5
3
+ metadata.gz: c6d04e4d260d197712f1b3772110fd5ef1026ab903838746a7e97b229815c0b3
4
+ data.tar.gz: afafff4e148443368dc94297beecc151708ecae6f6e4f008b9fb70226d68b3b7
5
5
  SHA512:
6
- metadata.gz: 8ee0316e181e196a2a091e68aedbfded41f0a4834f7c71370a71ba7fcaa512380a58d300aa79fae33e8302c13b7c1dd4796dce0027a3218ef25722d5c7983135
7
- data.tar.gz: f15f0f87a0b1bdd97eed27e250f23b51c72049b8b86fcd9468a226b559a379d10ef0cc30deb7697dfe9c62b86b3e6a009984a7e698e4f4607dd99800566126d7
6
+ metadata.gz: 385cc76c40a7954e820d5f3f55a187407fb65934d378b487d0cf22a5efea2a1d56b8082930779332cd4e8e86b4a8c6353535cfba11cdfb97b804d4570ee15bd0
7
+ data.tar.gz: faa1fc3009eab77ee0237ad42326e1cc86c0ff26441bedcbd299107245299fd1380948a2b98db2968f01e256645482e94eba8e84e3e6548b70b276e6c0270c21
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jiminy (0.2.0)
4
+ jiminy (0.3.0)
5
5
  octokit (>= 4)
6
6
  prosopite (>= 1)
7
7
  rspec
@@ -0,0 +1,11 @@
1
+ module Jiminy
2
+ class CLI
3
+ module ExitCodes
4
+ Base = Struct.new(:message, :value) do
5
+ def to_s
6
+ message
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Jiminy
2
+ class CLI
3
+ module ExitCodes
4
+ class PipelineNotFound < Base
5
+ def initialize(git_revision:)
6
+ super("No such Pipeline with commit SHA #{git_revision}", 1)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Jiminy
2
+ class CLI
3
+ module ExitCodes
4
+ class ProcessTimeout < Base
5
+ def initialize(start_time:)
6
+ super("Process timed out after #{Time.now - start_time} seconds", 1)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Jiminy
2
+ class CLI
3
+ module ExitCodes
4
+ class Success < Base
5
+ def initialize
6
+ super("Reported N+1s successfully", 0)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Jiminy
2
+ class CLI
3
+ module ExitCodes
4
+ class WorkflowNotFound < Base
5
+ def initialize(pipeline_id:, workflow_name:)
6
+ super("Unable to find workflow called '#{workflow_name}' in Pipeline #{pipeline_id}", 1)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Jiminy
2
+ class CLI
3
+ module ExitCodes
4
+ class WorkflowNotSuccess < Base
5
+ def initialize(status:)
6
+ super("Workflow #{status}—aborting...", 0)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ require_relative "exit_codes/base"
2
+ require_relative "exit_codes/pipeline_not_found"
3
+ require_relative "exit_codes/process_timeout"
4
+ require_relative "exit_codes/success"
5
+ require_relative "exit_codes/workflow_not_found"
6
+ require_relative "exit_codes/workflow_not_success"
data/lib/jiminy/cli.rb CHANGED
@@ -4,6 +4,8 @@ module Jiminy
4
4
  require "thor"
5
5
  class CLI < Thor
6
6
  require "jiminy/reporting/ci_providers/circle_ci"
7
+ require "jiminy/cli/exit_codes"
8
+
7
9
  include Thor::Actions
8
10
  include Jiminy::Reporting::CIProviders
9
11
 
@@ -41,8 +43,7 @@ module Jiminy
41
43
  pr_number: options[:pr_number],
42
44
  dry_run: options[:dry_run])
43
45
 
44
- $stdout.puts "Reported N+1s successfully"
45
- exit(0)
46
+ finish(ExitCodes::Success)
46
47
  end
47
48
 
48
49
  desc "Install Jiminy", "Installs jiminy configuration files in your app"
@@ -54,6 +55,16 @@ module Jiminy
54
55
  no_tasks do
55
56
  attr_accessor :start_time
56
57
 
58
+ def finish(exit_code_klass, *args, **kwargs)
59
+ exit_code = exit_code_klass.new(*args, **kwargs)
60
+ if exit_code.value == 0
61
+ puts exit_code
62
+ else
63
+ warn exit_code
64
+ end
65
+ exit(exit_code.value)
66
+ end
67
+
57
68
  def poll_interval
58
69
  options[:poll_interval] || POLL_INTERVAL_SECONDS
59
70
  end
@@ -80,7 +91,7 @@ module Jiminy
80
91
 
81
92
  def pipeline
82
93
  @_pipeline ||= CircleCI::Pipeline.find_by_revision(git_revision: git_revision, pr_number: pr_number) or
83
- abort("No such Pipeline with commit SHA #{git_revision}")
94
+ finish(ExitCodes::PipelineNotFound, git_revision: git_revision)
84
95
  end
85
96
 
86
97
  def missing_options
@@ -95,14 +106,18 @@ module Jiminy
95
106
  @_workflow ||= begin
96
107
  result = CircleCI::Workflow.find(pipeline_id: pipeline.id, workflow_name: Jiminy.config.ci_workflow_name)
97
108
  if result.nil?
98
- abort("Unable to find workflow called '#{Jiminy.config.ci_workflow_name}' in Pipeline #{pipeline.id}")
109
+ finish(ExitCodes::WorkflowNotFound,
110
+ workflow_name: Jiminy.config.ci_workflow_name,
111
+ pipeline_id: pipeline.id)
99
112
  end
100
113
 
101
114
  if result.not_run? || result.running?
102
115
  $stdout.puts "Workflow still running..."
103
116
  raise(WorkflowStillRunningError)
104
117
  end
105
- abort("Workflow #{result.status}—aborting...") unless result.success?
118
+ unless result.success?
119
+ finish(ExitCodes::WorkflowNotSuccess, status: result.status)
120
+ end
106
121
 
107
122
  result
108
123
  rescue WorkflowStillRunningError
@@ -110,7 +125,7 @@ module Jiminy
110
125
  $stdout.puts "Retrying..."
111
126
  retry unless timed_out?
112
127
 
113
- abort("Process timed out after #{Time.now - start_time} seconds")
128
+ finish(ExitCodes::ProcessTimeout, start_time: start_time)
114
129
  end
115
130
  end
116
131
  # rubocop:enable Metrics/AbcSize
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jiminy
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jiminy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bodacious
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-16 00:00:00.000000000 Z
11
+ date: 2022-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -149,6 +149,13 @@ files:
149
149
  - jiminy.gemspec
150
150
  - lib/jiminy.rb
151
151
  - lib/jiminy/cli.rb
152
+ - lib/jiminy/cli/exit_codes.rb
153
+ - lib/jiminy/cli/exit_codes/base.rb
154
+ - lib/jiminy/cli/exit_codes/pipeline_not_found.rb
155
+ - lib/jiminy/cli/exit_codes/process_timeout.rb
156
+ - lib/jiminy/cli/exit_codes/success.rb
157
+ - lib/jiminy/cli/exit_codes/workflow_not_found.rb
158
+ - lib/jiminy/cli/exit_codes/workflow_not_success.rb
152
159
  - lib/jiminy/configuration.rb
153
160
  - lib/jiminy/github_apiable.rb
154
161
  - lib/jiminy/recording.rb