command_proposal 1.0.4 → 1.0.8

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: 4d0b2ef7f0cf5f9044adaab75cb1b28b762086ff77ce659d461b976dd0533e3d
4
- data.tar.gz: c4c50205f7e2260a9d7659e7c6938808366c07aa00f0e85511fd1269de768e95
3
+ metadata.gz: 36c34ec1bf4f4ad80708120c0f2add544b8bb576c1087fc34b0ea7bc537c07ae
4
+ data.tar.gz: 86877f325b5eb60d7949d6145304229a1da644a87109b8fc8fdf0961a5b484cb
5
5
  SHA512:
6
- metadata.gz: 9ee3a6d919ea22545e62488fc0291d476b168b26412433288b6acde185d96bba8e4f9df313d13596faf508f7faabcea1d5d8539e7794a47d897eb117d4fe70e1
7
- data.tar.gz: faca82d2f612e2a0ec8b78ac09655d794b9e04b108b93b075b2097aff0dd0959dc75c21410fa7a6be4d71fac93f52428d0e497298a66c71b4b7caa6d6930329a
6
+ metadata.gz: 642066c9c9c36200f1ee0873b8017c501aa3950a4d880d94ef5adfd959841775ea74c4beeedc96f9212e346ea067868f8c33656524e962c9cae8d33d17ae4565
7
+ data.tar.gz: 8d4bc91c68b050bbd6d79433aa5aaadd824e00ebdb7e2fe9c73a54fff31f339fa3b248f88b0dcaec259492c3319406a731b7561e6aceaaa25fd1a099c94cc59e
@@ -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
@@ -21,9 +21,13 @@ module CommandProposal
21
21
  args << { host: host, port: nil } if host.present?
22
22
 
23
23
  begin
24
- command_proposal_engine.url_for(args.compact)
24
+ engine.url_for(args.compact)
25
25
  rescue NoMethodError => e
26
- 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
27
31
  end
28
32
  end
29
33
 
@@ -40,24 +44,31 @@ module CommandProposal
40
44
  end
41
45
 
42
46
  def string_path(*args)
43
- [command_proposal_engine.command_proposal_tasks_url + args.shift, args.to_param.presence].compact.join("?")
47
+ [engine.command_proposal_tasks_url + args.shift, args.to_param.presence].compact.join("?")
48
+ end
49
+
50
+ def engine
51
+ @engine ||= begin
52
+ name = `rails routes | grep command_proposal_engine`[/\w*command_proposal_engine/]
53
+ send(name)
54
+ end
44
55
  end
45
56
 
46
57
  # Runner controller doesn't map to a model, so needs special handling
47
58
  def runner_path(task, iteration=nil)
48
59
  if iteration.present?
49
- command_proposal_engine.command_proposal_task_runner_path(task, iteration)
60
+ engine.command_proposal_task_runner_path(task, iteration)
50
61
  else
51
- command_proposal_engine.command_proposal_task_runner_index_path(task)
62
+ engine.command_proposal_task_runner_index_path(task)
52
63
  end
53
64
  end
54
65
 
55
66
  # Runner controller doesn't map to a model, so needs special handling
56
67
  def runner_url(task, iteration=nil)
57
68
  if iteration.present?
58
- command_proposal_engine.command_proposal_task_runner_url(task, iteration)
69
+ engine.command_proposal_task_runner_url(task, iteration)
59
70
  else
60
- command_proposal_engine.command_proposal_task_runner_index_url(task)
71
+ engine.command_proposal_task_runner_index_url(task)
61
72
  end
62
73
  end
63
74
  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
@@ -1,4 +1,4 @@
1
1
  <% if lines.blank? && !(skip_empty ||= false) -%><div class="line"></div><% end
2
- -%><% lines.split("\n").each do |line|
2
+ -%><% lines&.split("\n").each do |line|
3
3
  -%><div class="line"><%= line -%></div><%
4
4
  end -%>
@@ -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
@@ -86,7 +88,11 @@ module CommandProposal
86
88
  check_can_command?
87
89
  return unless @iteration.task.console?
88
90
 
89
- @task.first_iteration.update(status: :success, completed_at: Time.current)
91
+ if ::CommandProposal.sessions.key?("task:#{@task.id}")
92
+ @task.first_iteration.update(status: :success, completed_at: Time.current)
93
+ else
94
+ @task.first_iteration.update(status: :terminated, completed_at: Time.current)
95
+ end
90
96
  ::CommandProposal.sessions.delete("task:#{@task.id}")
91
97
  end
92
98
 
@@ -125,7 +125,8 @@ module CommandProposal
125
125
 
126
126
  def results_from_exception(exc)
127
127
  klass = exc.class
128
- msg = exc.try(:message) || exc.try(:body) || exc.to_s
128
+ # Dup to avoid frozen string errors
129
+ msg = (exc.try(:message) || exc.try(:body) || exc.to_s).dup
129
130
  # Remove proposal context
130
131
  msg.gsub!(/ for \#\<CommandProposal.*/, "")
131
132
  msg.gsub!(/(::)?CommandProposal::Services::Runner(::)?/, "")
@@ -142,7 +143,7 @@ module CommandProposal
142
143
 
143
144
  eval_trace = backtrace.select { |row| row.include?("(eval)") }.presence || []
144
145
  eval_trace = eval_trace.map do |row|
145
- eval_row_number = row[/\(eval\)\:\d+/].to_s[7..-1]
146
+ eval_row_number = row[/\(eval\)\:\d+/].to_s.dup[7..-1]
146
147
  next if eval_row_number.blank?
147
148
 
148
149
  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.4'
2
+ VERSION = "1.0.8"
8
3
  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.4
4
+ version: 1.0.8
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-08-28 00:00:00.000000000 Z
11
+ date: 2021-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -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: []