command_proposal 1.0.6 → 1.0.10

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: a04686b93a2ae3d6583de7e04ea894d5a57076dec286cbb9897ccb1ae2740a10
4
- data.tar.gz: 1fae20a33afea09026f2c4ea195370a9fcc58a0b62a27dae1da930dd6260e755
3
+ metadata.gz: ab98adfd455b086e6e9837ebabb3461fadfe73e95060b7061e61e05c4eae374a
4
+ data.tar.gz: 8449a6b67001d913bd5cf8a9e89bb8a3fe730dc384449fb51957a8eb018c53af
5
5
  SHA512:
6
- metadata.gz: ba73213cb6457ff53adc8990eed6b2787d9fe92577b63da6538d195ed41969d77e9591c77176da00698526c63a65ae95e25f9bf6b1424a3f8601fa439b0cd6a5
7
- data.tar.gz: 1a5c1661b379c469f6bbf47d544b66be9d91fc417adc067dcc7126db4c17279b75017a6f2245f083b5b250b2de3e93a05e54d0068aff1e86607d56f4c934fdd0
6
+ metadata.gz: 277d11f925f481a5c5a8f53a4f17dce9725305964f04473cebd92693f0684335e5d77161966186444f29e5fcb113571feb029662bb4b3d82a7182bee38ea89ff
7
+ data.tar.gz: 02c2e3f743f0dd76bbabe43c3fe0f22d332af4d03a5d9561ee1a459e62f185b515f8961ee8a2f96d3ce0424c1153f10769759daed07f38441c8d41abe4eb4f4b
@@ -48,7 +48,7 @@ class ::CommandProposal::IterationsController < ::CommandProposal::EngineControl
48
48
  begin
49
49
  alter_command if params.dig(:command_proposal_iteration, :command).present?
50
50
  rescue ::CommandProposal::Services::CommandInterpreter::Error => e
51
- return redirect_to cmd_path(:tasks, :error), alert: e.message
51
+ return redirect_to cmd_path(:error, :tasks), alert: e.message
52
52
  end
53
53
 
54
54
  sleep 0.2
@@ -19,13 +19,15 @@ module CommandProposal
19
19
  end
20
20
  }
21
21
  args << { host: host, port: nil } if host.present?
22
- # args << {host: nil}
23
22
 
24
23
  begin
25
24
  engine.url_for(args.compact)
26
25
  rescue NoMethodError => e
27
- puts "\e[33m[LOGIT]#{e.inspect}\e[0m"
28
- raise "Error generating route! Please make sure `config.action_mailer.default_url_options` are set."
26
+ if e.message.match?(/\_(url|path)\'/)
27
+ raise e
28
+ else
29
+ raise "Error generating route! Please make sure `config.action_mailer.default_url_options` are set."
30
+ end
29
31
  end
30
32
  end
31
33
 
@@ -46,10 +48,7 @@ module CommandProposal
46
48
  end
47
49
 
48
50
  def engine
49
- @engine ||= begin
50
- name = `rails routes | grep command_proposal_engine`[/\w*command_proposal_engine/]
51
- send(name)
52
- end
51
+ @engine ||= send(::CommandProposal.engine_name)
53
52
  end
54
53
 
55
54
  # Runner controller doesn't map to a model, so needs special handling
@@ -1,4 +1,7 @@
1
1
  module CommandProposal
2
2
  class ApplicationJob < ActiveJob::Base
3
+ rescue_from(StandardError) do |exception|
4
+ Rails.logger.error "[#{self.class.name}] Job failed and will not retry: #{exception.to_s}"
5
+ end
3
6
  end
4
7
  end
@@ -42,7 +42,7 @@ class ::CommandProposal::Iteration < ApplicationRecord
42
42
  delegate :session_type, to: :task
43
43
 
44
44
  def params
45
- code.scan(/params\[[:\"\'](.*?)[\'\"]?\]/).flatten
45
+ code.scan(/params\[[:\"\'](.*?)[\'\"]?\]/).flatten.uniq
46
46
  end
47
47
 
48
48
  def brings
@@ -18,8 +18,8 @@
18
18
  <% end %>
19
19
  </td>
20
20
  <td><%= iteration.status.capitalize %></td>
21
- <!-- <td><%= iteration.comments.count %></td> -->
22
- <!-- <td><%= link_to "Diff", cmd_path(@task, iteration: @iteration.id, diff: iteration.id) %></td> -->
21
+ <!-- <td><%#= iteration.comments.count %></td> -->
22
+ <!-- <td><%#= link_to "Diff", cmd_path(@task, iteration: @iteration.id, diff: iteration.id) %></td> -->
23
23
  </tr>
24
24
  <% end %>
25
25
  </tbody>
@@ -10,6 +10,7 @@ module CommandProposal
10
10
  :approval_required,
11
11
  # Optional
12
12
  :proposal_callback,
13
+ :approval_callback,
13
14
  :success_callback,
14
15
  :failed_callback,
15
16
  )
@@ -26,6 +27,7 @@ module CommandProposal
26
27
 
27
28
  # Optional
28
29
  @proposal_callback = nil
30
+ @approval_callback = nil
29
31
  @success_callback = nil
30
32
  @failed_callback = nil
31
33
  end
@@ -56,6 +56,8 @@ module CommandProposal
56
56
  check_can_command? && check_can_approve?
57
57
 
58
58
  @iteration.update(status: :approved, approver: @user, approved_at: Time.current)
59
+ proposal = ::CommandProposal::Service::ProposalPresenter.new(@iteration)
60
+ ::CommandProposal.configuration.approval_callback&.call(proposal)
59
61
  end
60
62
 
61
63
  def command_run
@@ -10,6 +10,15 @@ module CommandProposal
10
10
  new.execute(task.primary_iteration)
11
11
  end
12
12
 
13
+ def self.command(friendly_id, user, params={})
14
+ ::CommandProposal::Services::CommandInterpreter.command(
15
+ ::CommandProposal::Task.find_by!(friendly_id: friendly_id).primary_iteration,
16
+ :run,
17
+ user,
18
+ params.except(:action, :controller)
19
+ )
20
+ end
21
+
13
22
  def initialize
14
23
  @session = session
15
24
  end
@@ -125,7 +134,8 @@ module CommandProposal
125
134
 
126
135
  def results_from_exception(exc)
127
136
  klass = exc.class
128
- msg = exc.try(:message) || exc.try(:body) || exc.to_s
137
+ # Dup to avoid frozen string errors
138
+ msg = (exc.try(:message) || exc.try(:body) || exc.to_s).dup
129
139
  # Remove proposal context
130
140
  msg.gsub!(/ for \#\<CommandProposal.*/, "")
131
141
  msg.gsub!(/(::)?CommandProposal::Services::Runner(::)?/, "")
@@ -142,7 +152,7 @@ module CommandProposal
142
152
 
143
153
  eval_trace = backtrace.select { |row| row.include?("(eval)") }.presence || []
144
154
  eval_trace = eval_trace.map do |row|
145
- eval_row_number = row[/\(eval\)\:\d+/].to_s[7..-1]
155
+ eval_row_number = row[/\(eval\)\:\d+/].to_s.dup[7..-1]
146
156
  next if eval_row_number.blank?
147
157
 
148
158
  error_line = @iteration.code.split("\n")[eval_row_number.to_i - 1]
@@ -1,8 +1,3 @@
1
- # gem build command_proposal.gemspec
2
- # gam "Built version __ of gem."
3
- # gpo
4
- # gem push command_proposal-__.gem
5
-
6
1
  module CommandProposal
7
- VERSION = '1.0.6'
2
+ VERSION = "1.0.10"
8
3
  end
@@ -22,6 +22,12 @@ module CommandProposal
22
22
  @configuration = ::CommandProposal::Configuration.new
23
23
  end
24
24
 
25
+ def self.engine_name
26
+ @engine_name ||= begin
27
+ `rails routes | grep command_proposal_engine`[/\w*command_proposal_engine/]
28
+ end
29
+ end
30
+
25
31
  def self.configure
26
32
  yield(configuration)
27
33
  end
@@ -43,6 +43,10 @@
43
43
  config.proposal_callback = Proc.new { |proposal|
44
44
  # Slack.notify("#{proposal.requester} has proposed #{proposal.name}.\n<#{proposal.url}|Click Here> to view this proposal and approve.")
45
45
  }
46
+ # Called when a command is approved
47
+ config.approval_callback = Proc.new { |proposal|
48
+ # Slack.notify("The task #{proposal.name} has been approved and is now ready to run.\n<#{proposal.url}|Click Here> to view.")
49
+ }
46
50
  # Called when a command runs and completes successfully
47
51
  config.success_callback = Proc.new { |proposal|
48
52
  # Slack.notify("The task #{proposal.name} has completed in #{proposal.duration}s.\n<#{proposal.url}|Click Here> to view the results.")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command_proposal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rocco Nicholls
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-01 00:00:00.000000000 Z
11
+ date: 2021-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: 5.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
26
+ version: 5.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: font-awesome-rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -147,7 +147,7 @@ metadata:
147
147
  homepage_uri: https://github.com/Rockster160/command_proposal
148
148
  source_code_uri: https://github.com/Rockster160/command_proposal
149
149
  changelog_uri: https://github.com/Rockster160/command_proposal/blob/master/README.md
150
- post_install_message:
150
+ post_install_message:
151
151
  rdoc_options: []
152
152
  require_paths:
153
153
  - lib
@@ -162,8 +162,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  - !ruby/object:Gem::Version
163
163
  version: '0'
164
164
  requirements: []
165
- rubygems_version: 3.1.4
166
- signing_key:
165
+ rubygems_version: 3.2.22
166
+ signing_key:
167
167
  specification_version: 4
168
168
  summary: Gives the ability to run approved commands through a UI in your browser
169
169
  test_files: []