redmine-reporting 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: ac501589d0737e31a91a96268028b61dbc16e021
4
- data.tar.gz: a14f692beba30c48642f1dbf5a81142cfaa2ed5d
3
+ metadata.gz: f59676859d1dd31152d7b49246ce7b0d86cae104
4
+ data.tar.gz: 802fff1d7124b72fcd2486902204807f803bc6bc
5
5
  SHA512:
6
- metadata.gz: 17643533787ea69e2f4fb34752b312eef4ad187c3f9af8d2d0826274987bcd852c3cba13927e1dfc333b74dd8ca20ac13e33828853dd52381389ec14b82da260
7
- data.tar.gz: d970eba7db83d58045d09840b81f2ef498ce901fcbadead4b8e82406165456b75fd84bb6ddd0a483f58efdbb02378467bfa05c5d9d670cd912ccff9776eafbd8
6
+ metadata.gz: a1af6b987a35f7cc93a03cdcbce7677cc6b4ff0b188116d04bb3afcd64e58d6a9b727b6b47b377bc89d739fd3aac95683cb5421c245f7cca8c5e122960d03042
7
+ data.tar.gz: 91e782b6b0f44629ad8e4f63661aef46a72678c522d9de2203c43f185035936774912e4dc928d4bad0919223162215c387e47b13eabf9d79d8e8d9a8d05cc48b
@@ -19,6 +19,19 @@ module Redmine
19
19
  @http_options[:http_proxyuser] = username
20
20
  @http_options[:http_proxypass] = password
21
21
  end
22
+
23
+ def to_hash
24
+ {
25
+ base_url: self.base_url,
26
+ api_key: self.api_key,
27
+ project: self.project,
28
+ tracker: self.tracker,
29
+ category: self.category,
30
+ http_options: self.http_options
31
+ }
32
+ end
33
+
34
+ alias :to_h :to_hash
22
35
  end
23
36
  end
24
37
  end
@@ -23,36 +23,26 @@ module Redmine
23
23
 
24
24
  # This method should be used for sending manual notifications while you are still
25
25
  # inside the controller. Otherwise it works like Redmine::Reporting.report.
26
- def redmine_report(subject_or_exception, &block)
27
- #unless redmine_reporting_local_request?
28
- env['redmine_reporting.reference_id'] = Redmine::Reporting.report(subject_or_exception, &block)
29
- #end
26
+ def redmine_report(subject_or_exception, options={}, &block)
27
+ unless redmine_reporting_local_request?
28
+ @redmine_reporting_reference_id = env['redmine_reporting.reference_id'] = Redmine::Reporting.report(subject_or_exception, options, &block)
29
+ end
30
30
  end
31
31
 
32
32
  def redmine_report_reference_id
33
- env['redmine_reporting.reference_id']
33
+ @redmine_reporting_reference_id || env['redmine_reporting.reference_id']
34
34
  end
35
35
 
36
36
  private
37
37
 
38
38
  def redmine_reporting_local_request?
39
- if defined?(::Rails.application.config)
40
- ::Rails.application.config.consider_all_requests_local || (request.local? && (!request.env["HTTP_X_FORWARDED_FOR"]))
41
- else
42
- consider_all_requests_local || (local_request? && (!request.env["HTTP_X_FORWARDED_FOR"]))
43
- end
39
+ ::Rails.application.config.consider_all_requests_local || (request.local? && (!request.env["HTTP_X_FORWARDED_FOR"]))
44
40
  end
45
41
 
46
42
  def redmine_reporting_filter_hash(hash)
47
43
  return hash if ! hash.is_a?(Hash)
48
44
 
49
- if respond_to?(:filter_parameters) # Rails 2
50
- filter_parameters(hash)
51
- elsif defined?(ActionDispatch::Http::ParameterFilter) # Rails 3
52
- ActionDispatch::Http::ParameterFilter.new(::Rails.application.config.filter_parameters).filter(hash)
53
- else
54
- hash
55
- end rescue hash
45
+ ActionDispatch::Http::ParameterFilter.new(::Rails.application.config.filter_parameters).filter(hash)
56
46
  end
57
47
 
58
48
  def redmine_reporting_request_url
@@ -28,13 +28,9 @@ module Redmine
28
28
  def redmine_report(env, exception)
29
29
  return unless desc = env["action_controller.instance"].try(:redmine_reporting_request_data)
30
30
 
31
- Redmine::Reporting.report(exception.message) do
32
- description do
33
- section(exception.message) do
34
- output("<pre>#{exception.backtrace.join("\n")}</pre>")
35
- end unless exception.nil?
36
- end
31
+ Redmine::Reporting.report(exception) do
37
32
  notes do
33
+ section("URL: #{desc[:url]}", '')
38
34
  section('Parameters') do
39
35
  output(desc[:params].collect{|k,v| "* #{k}: #{v}"}.join("\n"))
40
36
  end
@@ -7,6 +7,10 @@ module Redmine
7
7
  module Reporting
8
8
  class Report
9
9
 
10
+ def initialize(options)
11
+ @options = options.dup.freeze
12
+ end
13
+
10
14
  def subject(s)
11
15
  @subject = s
12
16
  end
@@ -24,40 +28,36 @@ module Redmine
24
28
  end
25
29
 
26
30
  def commit
27
- config = Redmine::Reporting.configuration
28
-
29
- options = (config.http_options || {}).merge({
31
+ options = (config[:http_options] || {}).merge({
30
32
  headers: {
31
33
  'Content-type' => 'application/json',
32
- 'X-Redmine-API-Key' => config.api_key
34
+ 'X-Redmine-API-Key' => config[:api_key]
33
35
  }
34
36
  })
35
37
 
36
38
  if issue_id.nil?
37
- resp = HTTParty.post("#{config.base_url}/issues.json", options.merge({
39
+ resp = HTTParty.post("#{config[:base_url]}/issues.json", options.merge({
38
40
  body: {
39
41
  issue: {
40
42
  subject: @subject.strip,
41
- project_id: config.project,
43
+ project_id: config[:project],
42
44
  description: @description.strip,
43
- tracker_id: config.tracker,
44
- category_id: config.category
45
+ tracker_id: config[:tracker],
46
+ category_id: config[:category]
45
47
  }
46
48
  }.to_json
47
49
  }))
48
50
 
49
- issue_id = resp['issue']['id'] rescue nil
51
+ iid = resp['issue']['id'] rescue nil
50
52
 
51
- unless issue_id.nil?
52
- File.open(issue_id_file, File::CREAT|File::TRUNC|File::RDWR, 0600) {|f| f.write(issue_id.to_s)}
53
- end
53
+ File.open(issue_id_file, File::CREAT|File::TRUNC|File::RDWR, 0600) {|f| f.write(iid.to_s)} unless iid.nil?
54
54
  end
55
55
 
56
56
  return false if issue_id.nil?
57
57
 
58
58
  reference_id = "#{Zlib.crc32(Time.now.to_f.to_s).to_s(16)}#{Zlib.crc32(@subject).to_s(16)}#{Zlib.crc32(@description).to_s(16)}"
59
59
 
60
- resp = HTTParty.put("#{config.base_url}/issues/#{issue_id}.json", options.merge({
60
+ resp = HTTParty.put("#{config[:base_url]}/issues/#{issue_id}.json", options.merge({
61
61
  body: {
62
62
  issue: {
63
63
  notes: "h1. #{reference_id}\n\n#{@notes}".strip
@@ -104,10 +104,12 @@ module Redmine
104
104
  nil
105
105
  end
106
106
 
107
- def issue_hash
108
- config = Redmine::Reporting.configuration
107
+ def config
108
+ @c ||= Redmine::Reporting.configuration.to_h.merge(@options)
109
+ end
109
110
 
110
- Digest::SHA1.hexdigest([config.base_url, config.project, @subject.strip, @description.strip].join('//'))
111
+ def issue_hash
112
+ Digest::SHA1.hexdigest([config[:base_url], config[:project], @subject.strip, @description.strip].join('//'))
111
113
  end
112
114
 
113
115
  def issue_id_file
@@ -1,5 +1,5 @@
1
1
  module Redmine
2
2
  module Reporting
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
@@ -15,13 +15,13 @@ module Redmine
15
15
  @configuration ||= Configuration.new
16
16
  end
17
17
 
18
- def report(subject_or_exception=nil, &block)
19
- r = Report.new
18
+ def report(subject_or_exception=nil, options={}, &block)
19
+ r = Report.new(options)
20
20
 
21
21
  if subject_or_exception.is_a?(Exception)
22
22
  r.subject(subject_or_exception.message)
23
23
  r.description do
24
- section(subject_or_exception.message) do
24
+ section("#{subject_or_exception.class}: #{subject_or_exception.message}") do
25
25
  output("<pre>#{subject_or_exception.backtrace.join("\n")}</pre>")
26
26
  end
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmine-reporting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Schwab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-25 00:00:00.000000000 Z
11
+ date: 2013-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler