redmine_airbrake_backend 1.2.2 → 1.2.3

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: 78d324b14146a054ed7f62573df24493843ebccc846a1a8936348fff51228098
4
- data.tar.gz: 6225ac96f31412e899d0ab2f06e869f22761d4af19583dda20cdfefc1e00d416
3
+ metadata.gz: 37936f35cac6d9858dd65014e0e9592a794990c08990b4b7918ae5cab3c92c8e
4
+ data.tar.gz: 42e2e65994e3302da7e71cd910aac5fefb6ac6d4bbf0f22b091fa1cb2e796894
5
5
  SHA512:
6
- metadata.gz: 366e346434ea2a82047ff0d1a7c6314ff2782e5e4056cdf3f2563e2ebfe0f958265d727a1e87dd47eddb001c61b3d832dd3fa20ee4e6f8eb9973e2aba3a59801
7
- data.tar.gz: abb59d8c978611fa973c20a3de001904a1bfade5c30d910739ad2285cccc7a024a0e0951e57f4fb1da429d9fae0d2b61ebcb16c6fab24f94a97cd40fd763e18a
6
+ metadata.gz: fb04ff49d11b6471db9c9f33fd4882344847dabbaa3ba0708087aa6d4d74cd97516f8ce8392e0064eb3a6304c01af86d8e86c09e550664e815eb168c1247bbaa
7
+ data.tar.gz: 6d461674d8bc48dc7b22ae4ea1da383ab903b115ec0661843aad58805f98de7ebfb7c171c5840190f53823d8355e44bea25b8608f3be1a85a13c2a6dd1310b73
@@ -1,5 +1,6 @@
1
1
  stages:
2
2
  - build
3
+ - test
3
4
  - codequality
4
5
  - security
5
6
 
@@ -7,17 +8,25 @@ build:
7
8
  stage: build
8
9
  image: ruby:2.5
9
10
  script:
10
- - gem install bundler --no-ri --no-rdoc
11
+ - gem install bundler --no-document
11
12
  - bundle update
12
13
  artifacts:
13
14
  paths:
14
15
  - Gemfile.lock
15
16
 
17
+ test:
18
+ stage: test
19
+ image: ruby:2.5
20
+ script:
21
+ - gem install bundler --no-document
22
+ - bundle update
23
+ - rake test
24
+
16
25
  rubocop:
17
26
  stage: codequality
18
27
  image: ruby:2.5
19
28
  script:
20
- - gem install rubocop --no-ri --no-rdoc
29
+ - gem install rubocop --no-document
21
30
  - rubocop
22
31
 
23
32
  dependency_scanning:
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.3 (2019-01-27)
4
+ ### Fixes
5
+ - Fix reopen of issues
6
+
3
7
  ## 1.2.2 (2018-11-03)
4
8
  ### Fixes
5
9
  - Fix finding repository if no filename is for backtrace element
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Handling for creating / updating issues
4
+ module AirbrakeIssueFinding
5
+ extend ActiveSupport::Concern
6
+ include AirbrakeAttachments
7
+
8
+ private
9
+
10
+ # Load or initialize issue by project, tracker and airbrake hash or similarity
11
+ def find_or_initialize_issue(notice)
12
+ find_issue_by_airbrake_id(notice) || initialize_issue(notice)
13
+ end
14
+
15
+ def find_issue_by_airbrake_id(notice)
16
+ issue_ids = CustomValue
17
+ .where(customized_type: Issue.name, custom_field_id: notice_hash_field.id, value: notice.id)
18
+ .pluck(:customized_id)
19
+
20
+ Issue.find_by(id: issue_ids, project_id: @project.id, tracker_id: @tracker.id)
21
+ end
22
+
23
+ def initialize_issue(notice)
24
+ issue = Issue.new(
25
+ subject: notice.subject,
26
+ project: @project,
27
+ tracker: @tracker,
28
+ author: User.current,
29
+ category: @category,
30
+ priority: @priority,
31
+ description: render_description(notice),
32
+ assigned_to: @assignee
33
+ )
34
+
35
+ add_attachments_to_issue(issue, notice)
36
+
37
+ issue
38
+ end
39
+ end
@@ -5,6 +5,7 @@ require 'tempfile'
5
5
  # Handling for creating / updating issues
6
6
  module AirbrakeIssueHandling
7
7
  extend ActiveSupport::Concern
8
+ include AirbrakeIssueFinding
8
9
  include AirbrakeAttachments
9
10
 
10
11
  private
@@ -30,36 +31,6 @@ module AirbrakeIssueHandling
30
31
  @issue = nil unless @issue.save
31
32
  end
32
33
 
33
- # Load or initialize issue by project, tracker and airbrake hash
34
- def find_or_initialize_issue(notice)
35
- issue_ids = CustomValue
36
- .where(customized_type: Issue.name, custom_field_id: notice_hash_field.id, value: notice.id)
37
- .pluck(:customized_id)
38
-
39
- issue = Issue.find_by(id: issue_ids, project_id: @project.id, tracker_id: @tracker.id)
40
-
41
- return issue if issue.present?
42
-
43
- initialize_issue(notice)
44
- end
45
-
46
- def initialize_issue(notice)
47
- issue = Issue.new(
48
- subject: notice.subject,
49
- project: @project,
50
- tracker: @tracker,
51
- author: User.current,
52
- category: @category,
53
- priority: @priority,
54
- description: render_description(notice),
55
- assigned_to: @assignee
56
- )
57
-
58
- add_attachments_to_issue(issue, notice)
59
-
60
- issue
61
- end
62
-
63
34
  def update_occurrences(issue, custom_field_values)
64
35
  return if occurrences_field.blank?
65
36
 
@@ -97,8 +68,8 @@ module AirbrakeIssueHandling
97
68
  def reopen_issue(issue, notice)
98
69
  return if notice.environment_name.blank?
99
70
 
100
- desc = "*Issue reopened after occurring again in _#{notice.environment_name}_ environment.*"
101
- desc << "\n\n#{render_description(notice)}" if issue_reopen_repeat_description?
71
+ desc = "*Issue reopened after occurring again in _#{notice.environment_name}_ environment.*"
72
+ desc += "\n\n#{render_description(notice)}" if issue_reopen_repeat_description?
102
73
 
103
74
  issue.status = issue.tracker.default_status
104
75
 
@@ -11,4 +11,8 @@ module RedmineAirbrakeBackend
11
11
  def self.filter_hex_values(value)
12
12
  value.gsub(/0x[0-9a-f]+/, '')
13
13
  end
14
+
15
+ def self.filter(value)
16
+ filter_hex_values(value)
17
+ end
14
18
  end
@@ -32,7 +32,7 @@ module RedmineAirbrakeBackend
32
32
  .downcase
33
33
  .gsub(/([\d_]+$)?/, '') # ruby blocks
34
34
 
35
- RedmineAirbrakeBackend.filter_hex_values(name)
35
+ RedmineAirbrakeBackend.filter(name)
36
36
  end
37
37
  end
38
38
  end
@@ -26,9 +26,9 @@ module RedmineAirbrakeBackend
26
26
 
27
27
  def generate_id
28
28
  h = []
29
- h << RedmineAirbrakeBackend.filter_hex_values(@type)
30
- h << RedmineAirbrakeBackend.filter_hex_values(@message)
31
- h += @backtrace.map(&:checksum).compact
29
+ h << RedmineAirbrakeBackend.filter(@type)
30
+ h << RedmineAirbrakeBackend.filter(@message)
31
+ h += @backtrace.map(&:checksum)
32
32
 
33
33
  Digest::MD5.hexdigest(h.compact.join("\n"))
34
34
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module RedmineAirbrakeBackend
4
4
  # Version of this gem
5
- VERSION = '1.2.2'
5
+ VERSION = '1.2.3'
6
6
  end
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.homepage = 'https://gitlab.com/ydkn/redmine_airbrake_backend'
17
17
  spec.license = 'MIT'
18
18
 
19
- spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
19
+ spec.files = `git ls-files`.split("\n")
20
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
21
  spec.require_paths = ['lib']
22
22
 
@@ -1 +1,6 @@
1
- require File.expand_path('./test/test_helper')
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+
3
+ require 'rails'
4
+ require 'rails/test_help'
5
+
6
+ Bundler.require(*Rails.groups)
@@ -1,52 +1,72 @@
1
- require File.expand_path('../test_helper', __dir__)
1
+ require_relative '../test_helper'
2
2
 
3
- class NoticeTest < ActiveSupport::TestCase
4
- test 'parse' do
5
- api_key = {
6
- api_key: 'foobar',
7
- project: 'foo'
8
- }.to_json
9
- xml_data = <<-EOS
10
- <?xml version="1.0" encoding="UTF-8"?>
11
- <notice version="2.4">
12
- <api-key>#{api_key}</api-key>
13
- <notifier>
14
- <name>Airbrake Notifier</name>
15
- <version>3.1.6</version>
16
- <url>http://api.airbrake.io</url>
17
- </notifier>
18
- <error>
19
- <class>RuntimeError</class>
20
- <message>RuntimeError: I've made a huge mistake</message>
21
- <backtrace>
22
- <line method="public" file="/testapp/app/models/user.rb" number="53"/>
23
- <line method="index" file="/testapp/app/controllers/users_controller.rb" number="14"/>
24
- </backtrace>
25
- </error>
26
- <request>
27
- <url>http://example.com</url>
28
- <component/>
29
- <action/>
30
- <cgi-data>
31
- <var key="SERVER_NAME">example.org</var>
32
- <var key="HTTP_USER_AGENT">Mozilla</var>
33
- </cgi-data>
34
- </request>
35
- <server-environment>
36
- <project-root>/testapp</project-root>
37
- <environment-name>production</environment-name>
38
- <app-version>1.0.0</app-version>
39
- </server-environment>
40
- </notice>
41
- EOS
3
+ require 'redmine_airbrake_backend/notice'
42
4
 
43
- notice = RedmineAirbrakeBackend::Notice.parse(prepare_xml(xml_data))
44
- assert notice
45
- end
5
+ class NoticeTest < ActiveSupport::TestCase
6
+ test 'parse notice request' do
7
+ params = {
8
+ "errors" => [{
9
+ "type" => "OpenURI::HTTPError",
10
+ "message" => "404 Not Found",
11
+ "backtrace" => [{
12
+ "file" => "/usr/local/lib/ruby/2.5.0/open-uri.rb",
13
+ "line" => 377,
14
+ "function" => "open_http"
15
+ }, {
16
+ "file" => "/usr/local/lib/ruby/2.5.0/open-uri.rb",
17
+ "line" => 755,
18
+ "function" => "buffer_open"
19
+ }, {
20
+ "file" => "/GEM_ROOT/gems/activesupport-5.2.1/lib/active_support/dependencies.rb",
21
+ "line" => 287,
22
+ "function" => "block in require"
23
+ }, {
24
+ "file" => "/GEM_ROOT/gems/activesupport-5.2.1/lib/active_support/dependencies.rb",
25
+ "line" => 253,
26
+ "function" => "load_dependency"
27
+ }, {
28
+ "file" => "/GEM_ROOT/gems/activesupport-5.2.1/lib/active_support/dependencies.rb",
29
+ "line" => 287,
30
+ "function" => "require"
31
+ }, {
32
+ "file" => "bin/rails",
33
+ "line" => 4,
34
+ "function" => "<main>"
35
+ }]
36
+ }],
37
+ "context" => {
38
+ "rootDirectory" => "/app",
39
+ "environment" => "production",
40
+ "hostname" => "foobar.fail",
41
+ "severity" => "error",
42
+ "os" => "x86_64-linux-musl",
43
+ "language" => "ruby/2.5.3",
44
+ "notifier" => { "name" => "airbrake-ruby", "version" => "2.12.0" },
45
+ "component" => "MyComponent",
46
+ "action" => "MyAction"
47
+ },
48
+ "environment" => {
49
+ "program_name" => "bin/rails"
50
+ },
51
+ "session" => {},
52
+ "params" => {
53
+ "foo" => "bar",
54
+ "locale" => "en"
55
+ },
56
+ "project_id" => "1"
57
+ }.with_indifferent_access
46
58
 
47
- private
59
+ notice = RedmineAirbrakeBackend::Notice.new(
60
+ errors: params[:errors].map { |e| RedmineAirbrakeBackend::Error.new(e) },
61
+ params: params[:params],
62
+ session: params[:session],
63
+ context: params[:context],
64
+ environment: params[:environment]
65
+ )
48
66
 
49
- def prepare_xml(xml_data)
50
- xml_data.split("\n").map { |l| l.strip }.join('')
67
+ assert_equal(1, notice.errors.length)
68
+ assert_equal('OpenURI::HTTPError', notice.errors.first.type)
69
+ assert_equal('404 Not Found', notice.errors.first.message)
70
+ assert_equal('a16abb78bf4b40460258c72cdc971ca0', notice.id)
51
71
  end
52
72
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmine_airbrake_backend
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Schwab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-03 00:00:00.000000000 Z
11
+ date: 2019-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -86,6 +86,7 @@ files:
86
86
  - app/controllers/airbrake_project_settings_controller.rb
87
87
  - app/controllers/airbrake_report_controller.rb
88
88
  - app/controllers/concerns/airbrake_attachments.rb
89
+ - app/controllers/concerns/airbrake_issue_finding.rb
89
90
  - app/controllers/concerns/airbrake_issue_handling.rb
90
91
  - app/controllers/concerns/airbrake_rendering.rb
91
92
  - app/helpers/airbrake_helper.rb
@@ -135,8 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
136
  - !ruby/object:Gem::Version
136
137
  version: '0'
137
138
  requirements: []
138
- rubyforge_project:
139
- rubygems_version: 2.7.7
139
+ rubygems_version: 3.0.2
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: This plugin provides the necessary API to use Redmine as a Airbrake backend