airbrake-ruby 2.10.0 → 2.11.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
  SHA1:
3
- metadata.gz: 706d644022c1c9c99dc3e01584d0e405411d2159
4
- data.tar.gz: 56b17f05ad9e78e0579e20a58dfbeef86e35ec54
3
+ metadata.gz: 0a6cbbc0e744591a711d5452e6bae85c3c261607
4
+ data.tar.gz: 5b35acf12d2e1f8d6fb59ce953cf93c1611953b9
5
5
  SHA512:
6
- metadata.gz: 8ee8b4959b41efcc3687f16a5d6ec145644bb8b28b5e3b9fd18dbb9eb729a712708cf082b0afdd0f1ccf12b150974dda5563a535b1a3229e1d8e0ecbd7df7f8b
7
- data.tar.gz: dbfbf97c9f39401e42d2cd00438616432e1acf9d87a07742c0aa7b405691debd2289b955779fa76dd5dd86f5656043538e25791af06c040100f07672d5399ad8
6
+ metadata.gz: 85e6610457fb10e5b7247a6fdf20e694abff4b5ab94d27484078c04b8fc0f4fdf350b8da76412e55f0348a80bdca6169cc9a97c3f5e32bbf529916e02252c7e8
7
+ data.tar.gz: 80a7f9beddf36c304a264edbfe2044732654f9026f6a7a82feffdba95d6859c1746cb631bd09f7400a630008794daf61f53f84ac3d9d62ea0db5b48237798a18
@@ -26,6 +26,7 @@ require 'airbrake-ruby/filters/thread_filter'
26
26
  require 'airbrake-ruby/filters/context_filter'
27
27
  require 'airbrake-ruby/filters/exception_attributes_filter'
28
28
  require 'airbrake-ruby/filters/dependency_filter'
29
+ require 'airbrake-ruby/filters/git_revision_filter'
29
30
  require 'airbrake-ruby/filter_chain'
30
31
  require 'airbrake-ruby/notifier'
31
32
  require 'airbrake-ruby/code_hunk'
@@ -0,0 +1,58 @@
1
+ module Airbrake
2
+ module Filters
3
+ # Attaches current git revision to `context`.
4
+ # @api private
5
+ # @since v2.11.0
6
+ class GitRevisionFilter
7
+ # @return [Integer]
8
+ attr_reader :weight
9
+
10
+ # @return [String]
11
+ PREFIX = 'ref: '.freeze
12
+
13
+ # @param [String] root_directory
14
+ def initialize(root_directory)
15
+ @git_path = File.join(root_directory, '.git')
16
+ @weight = 116
17
+ end
18
+
19
+ # @macro call_filter
20
+ def call(notice)
21
+ return if notice[:context].key?(:revision)
22
+ return unless File.exist?(@git_path)
23
+
24
+ revision = find_revision
25
+ notice[:context][:revision] = revision if revision
26
+ end
27
+
28
+ private
29
+
30
+ def find_revision
31
+ head_path = File.join(@git_path, 'HEAD')
32
+ return unless File.exist?(head_path)
33
+
34
+ head = File.read(head_path)
35
+ return head unless head.start_with?(PREFIX)
36
+ head = head.chomp[PREFIX.size..-1]
37
+
38
+ ref_path = File.join(@git_path, head)
39
+ return File.read(ref_path).chomp if File.exist?(ref_path)
40
+
41
+ find_from_packed_refs(head)
42
+ end
43
+
44
+ def find_from_packed_refs(head)
45
+ packed_refs_path = File.join(@git_path, 'packed-refs')
46
+ return head unless File.exist?(packed_refs_path)
47
+
48
+ File.readlines(packed_refs_path).each do |line|
49
+ next if %w[# ^].include?(line[0])
50
+ next unless (parts = line.split(' ')).size == 2
51
+ return parts.first if parts.last == head
52
+ end
53
+
54
+ nil
55
+ end
56
+ end
57
+ end
58
+ end
@@ -143,6 +143,7 @@ module Airbrake
143
143
  clean_bt
144
144
  end
145
145
 
146
+ # rubocop:disable Metrics/AbcSize
146
147
  def add_default_filters
147
148
  if (whitelist_keys = @config.whitelist_keys).any?
148
149
  @filter_chain.add_filter(
@@ -165,6 +166,11 @@ module Airbrake
165
166
  @filter_chain.add_filter(
166
167
  Airbrake::Filters::RootDirectoryFilter.new(root_directory)
167
168
  )
169
+
170
+ @filter_chain.add_filter(
171
+ Airbrake::Filters::GitRevisionFilter.new(root_directory)
172
+ )
168
173
  end
174
+ # rubocop:enable Metrics/AbcSize
169
175
  end
170
176
  end
@@ -2,5 +2,5 @@
2
2
  # More information: http://semver.org/
3
3
  module Airbrake
4
4
  # @return [String] the library version
5
- AIRBRAKE_RUBY_VERSION = '2.10.0'.freeze
5
+ AIRBRAKE_RUBY_VERSION = '2.11.0'.freeze
6
6
  end
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Airbrake::Filters::GitRevisionFilter do
4
+ subject { described_class.new('root/dir') }
5
+
6
+ let(:notice) do
7
+ Airbrake::Notice.new(Airbrake::Config.new, AirbrakeTestError.new)
8
+ end
9
+
10
+ context "when context/revision is defined" do
11
+ it "doesn't attach anything to context/revision" do
12
+ notice[:context][:revision] = '1.2.3'
13
+ subject.call(notice)
14
+ expect(notice[:context][:revision]).to eq('1.2.3')
15
+ end
16
+ end
17
+
18
+ context "when .git directory doesn't exist" do
19
+ it "doesn't attach anything to context/revision" do
20
+ subject.call(notice)
21
+ expect(notice[:context][:revision]).to be_nil
22
+ end
23
+ end
24
+
25
+ context "when .git directory exists" do
26
+ before do
27
+ expect(File).to receive(:exist?).with('root/dir/.git').and_return(true)
28
+ end
29
+
30
+ context "and when HEAD doesn't exist" do
31
+ before do
32
+ expect(File).to receive(:exist?).with('root/dir/.git/HEAD').and_return(false)
33
+ end
34
+
35
+ it "doesn't attach anything to context/revision" do
36
+ subject.call(notice)
37
+ expect(notice[:context][:revision]).to be_nil
38
+ end
39
+ end
40
+
41
+ context "and when HEAD exists" do
42
+ before do
43
+ expect(File).to receive(:exist?).with('root/dir/.git/HEAD').and_return(true)
44
+ end
45
+
46
+ context "and also when HEAD doesn't start with 'ref: '" do
47
+ before do
48
+ expect(File).to(
49
+ receive(:read).with('root/dir/.git/HEAD').and_return('refs/foo')
50
+ )
51
+ end
52
+
53
+ it "attaches the content of HEAD to context/revision" do
54
+ subject.call(notice)
55
+ expect(notice[:context][:revision]).to eq('refs/foo')
56
+ end
57
+ end
58
+
59
+ context "and also when HEAD starts with 'ref: " do
60
+ before do
61
+ expect(File).to(
62
+ receive(:read).with('root/dir/.git/HEAD').and_return("ref: refs/foo\n")
63
+ )
64
+ end
65
+
66
+ context "when the ref exists" do
67
+ before do
68
+ expect(File).to(
69
+ receive(:exist?).with('root/dir/.git/refs/foo').and_return(true)
70
+ )
71
+ expect(File).to(
72
+ receive(:read).with('root/dir/.git/refs/foo').and_return("d34db33f\n")
73
+ )
74
+ end
75
+
76
+ it "attaches the revision from the ref to context/revision" do
77
+ subject.call(notice)
78
+ expect(notice[:context][:revision]).to eq('d34db33f')
79
+ end
80
+ end
81
+
82
+ context "when the ref doesn't exist" do
83
+ before do
84
+ expect(File).to(
85
+ receive(:exist?).with('root/dir/.git/refs/foo').and_return(false)
86
+ )
87
+ end
88
+
89
+ context "and when '.git/packed-refs' exists" do
90
+ before do
91
+ expect(File).to(
92
+ receive(:exist?).with('root/dir/.git/packed-refs').and_return(true)
93
+ )
94
+ expect(File).to(
95
+ receive(:readlines).with('root/dir/.git/packed-refs').and_return(
96
+ [
97
+ "# pack-refs with: peeled fully-peeled\n",
98
+ "ccb316eecff79c7528d1ad43e5fa165f7a44d52e refs/tags/v3.0.30\n",
99
+ "^d358900f73ee5bfd6ca3a592cf23ac6e82df83c1",
100
+ "d34db33f refs/foo\n"
101
+ ]
102
+ )
103
+ )
104
+ end
105
+
106
+ it "attaches the revision from 'packed-refs' to context/revision" do
107
+ subject.call(notice)
108
+ expect(notice[:context][:revision]).to eq('d34db33f')
109
+ end
110
+ end
111
+
112
+ context "and when '.git/packed-refs' doesn't exist" do
113
+ before do
114
+ expect(File).to(
115
+ receive(:exist?).with('root/dir/.git/packed-refs').and_return(false)
116
+ )
117
+ end
118
+
119
+ it "attaches the content of HEAD to context/revision" do
120
+ subject.call(notice)
121
+ expect(notice[:context][:revision]).to eq('refs/foo')
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airbrake-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.0
4
+ version: 2.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airbrake Technologies, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-03 00:00:00.000000000 Z
11
+ date: 2018-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -127,6 +127,7 @@ files:
127
127
  - lib/airbrake-ruby/filters/dependency_filter.rb
128
128
  - lib/airbrake-ruby/filters/exception_attributes_filter.rb
129
129
  - lib/airbrake-ruby/filters/gem_root_filter.rb
130
+ - lib/airbrake-ruby/filters/git_revision_filter.rb
130
131
  - lib/airbrake-ruby/filters/keys_blacklist.rb
131
132
  - lib/airbrake-ruby/filters/keys_filter.rb
132
133
  - lib/airbrake-ruby/filters/keys_whitelist.rb
@@ -153,6 +154,7 @@ files:
153
154
  - spec/filters/dependency_filter_spec.rb
154
155
  - spec/filters/exception_attributes_filter_spec.rb
155
156
  - spec/filters/gem_root_filter_spec.rb
157
+ - spec/filters/git_revision_filter_spec.rb
156
158
  - spec/filters/keys_blacklist_spec.rb
157
159
  - spec/filters/keys_whitelist_spec.rb
158
160
  - spec/filters/root_directory_filter_spec.rb
@@ -208,6 +210,7 @@ test_files:
208
210
  - spec/filters/thread_filter_spec.rb
209
211
  - spec/filters/dependency_filter_spec.rb
210
212
  - spec/filters/context_filter_spec.rb
213
+ - spec/filters/git_revision_filter_spec.rb
211
214
  - spec/filters/keys_blacklist_spec.rb
212
215
  - spec/filters/gem_root_filter_spec.rb
213
216
  - spec/spec_helper.rb