jiminy 0.1.0 → 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
  SHA256:
3
- metadata.gz: 26a3afee95d97458dce74ea14893726e5edb8111c2db4bb362c557536fb3be44
4
- data.tar.gz: 034cb7891aee6949d476dd8b519cca22764ff09623e92f10d0e576cef5b42753
3
+ metadata.gz: c6d04e4d260d197712f1b3772110fd5ef1026ab903838746a7e97b229815c0b3
4
+ data.tar.gz: afafff4e148443368dc94297beecc151708ecae6f6e4f008b9fb70226d68b3b7
5
5
  SHA512:
6
- metadata.gz: 75ead9773e96336b05bf9fc72fa1757efc3860215b4fd585948bc3fa17df5cc9ea46f273b5cab66cbce951e7796641695c5be94444db145ca507008bea70cb4f
7
- data.tar.gz: a0857f6f144d878d86f04eba20f040919eef944cb3bfcbbab698b2e32953410bccb627235f45b38f97613a1cb6bfca461682d56c066bd3f49cdff009d7839598
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.1.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
@@ -6,24 +6,26 @@ module Jiminy
6
6
  class TmpFileRecorder
7
7
  require_relative "../n_plus_one"
8
8
 
9
+ # rubocop:disable Metrics/AbcSize
9
10
  def record(location:, queries:)
10
11
  yaml_content = File.read(Jiminy.config.temp_file_location)
11
12
  array = YAML.safe_load(yaml_content)
12
13
  n_plus_one = NPlusOne.new(location: location, queries: queries)
13
14
 
14
15
  if filepath_ignored?(n_plus_one.file)
15
- Jiminy.logger.debug("Ignoring n+1 instance #{n_plus_one}")
16
+ Jiminy.logger.debug { "Ignoring n+1 instance #{n_plus_one}" }
16
17
  return
17
18
  end
18
19
 
19
20
  if location_in_array?(location, array)
20
- Jiminy.logger.debug("Already reported n+1 instance #{n_plus_one}")
21
+ Jiminy.logger.debug { "Already reported n+1 instance #{n_plus_one}" }
21
22
  return
22
23
  end
23
24
 
24
25
  array << n_plus_one.to_h
25
26
  File.write(Jiminy.config.temp_file_location, array.to_yaml)
26
27
  end
28
+ # rubocop:enable Metrics/AbcSize
27
29
 
28
30
  private
29
31
 
@@ -14,7 +14,7 @@ module Jiminy
14
14
  end
15
15
 
16
16
  def perform!
17
- Jiminy.logger.debug("API request: #@url")
17
+ Jiminy.logger.debug { "API request: #@url" }
18
18
  response
19
19
  end
20
20
 
@@ -21,6 +21,9 @@ module Jiminy
21
21
  comment_content = yaml_files.map do |yaml_file|
22
22
  YAMLFileCommentPresenter.new(source_filepath: yaml_file, pr_number: options[:pr_number]).to_s
23
23
  end.join(LINE_SEPARATOR)
24
+
25
+ return if comment_content.strip.empty?
26
+
24
27
  if options[:dry_run]
25
28
  Reporters::DryRunReporter.new(header: COMMENT_HEADER, body: comment_content).report!
26
29
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jiminy
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/jiminy.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative "jiminy/version"
4
4
  require_relative "jiminy/setup"
5
5
  require_relative "jiminy/recording" if defined?(Rails)
6
+ require_relative "jiminy/rspec" if defined?(Rspec) && ENV["RAILS_ENV"] == "test"
6
7
 
7
8
  module Jiminy
8
9
  module_function
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.1.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-09 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