party_foul 1.4.0 → 1.5.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: 8f80dcba58cf47603afe74982f963afc9e5bc188
4
- data.tar.gz: b44e5e15e8288f829b85835e3c33ea5ca27a6f03
3
+ metadata.gz: aa0cf12a33de9ac49934ecfe1d6b738f50e2e927
4
+ data.tar.gz: 633450be535b01dabf7ab095c3ea72722759b930
5
5
  SHA512:
6
- metadata.gz: 28bd2e96700f5e2932b85671579830ad9ed28f9fd6c04ab62f16a528ed46ce044a8b485dd8c39c65bfa5c2ffb9140439f6ea7e1d08f95efae4a9ba05bc5e6b09
7
- data.tar.gz: 5f6527076d22d9c696d7a6c44e0e887bdf40493d9fe5b85fb8b4a62addf63aa097938362dd55f721d22e69837907070a83645155f4d4d9f422eea0d95296bc7a
6
+ metadata.gz: 4ab9b33bbe4914667ba0da42d38d67d6eace05c0c7fef1376c6d2a7f21caa2e3a9bf19665b968670cfd1c3851f461805726cddc25fe9d8025305b7f06ebd9ccf
7
+ data.tar.gz: 30959491d47671b49baa742e8a06c53cfc00c7d8cc7640d1d8c05b78ad591ef8f2570ab86d0aff730ae98106c5146f2f410732a713b03e3c4d05e2ca423fece1
data/README.md CHANGED
@@ -92,6 +92,10 @@ PartyFoul.configure do |config|
92
92
 
93
93
  # The branch for your deployed code
94
94
  # config.branch = 'master'
95
+
96
+ # Setting your title prefix can help with
97
+ # distinguising the issue between environments
98
+ # config.title_prefix = Rails.env
95
99
  end
96
100
  ```
97
101
 
@@ -14,7 +14,7 @@ module PartyFoul
14
14
  @web_url = ask_with_default 'Web URL:', 'https://github.com'
15
15
 
16
16
  begin
17
- octokit = Octokit.new :login => login, :password => password, :api_endpoint => @api_endpoint
17
+ octokit = Octokit::Client.new :login => login, :password => password, :api_endpoint => @api_endpoint
18
18
  @oauth_token = octokit.create_authorization(scopes: ['repo'], note: "PartyFoul #{@owner}/#{@repo}", note_url: "#{@web_url}/#{@owner}/#{@repo}").token
19
19
  template 'party_foul.rb', 'config/initializers/party_foul.rb'
20
20
  rescue Octokit::Unauthorized
@@ -32,4 +32,8 @@ PartyFoul.configure do |config|
32
32
 
33
33
  # Limit the number of comments per issue
34
34
  # config.comment_limit = 10
35
+
36
+ # Setting your title prefix can help with
37
+ # distinguising the issue between environments
38
+ # config.title_prefix = Rails.env
35
39
  end
@@ -2,7 +2,7 @@ require 'octokit'
2
2
 
3
3
  module PartyFoul
4
4
  class << self
5
- attr_accessor :github, :oauth_token, :api_endpoint, :owner, :repo, :blacklisted_exceptions, :processor, :web_url, :branch, :whitelisted_rack_variables, :additional_labels, :comment_limit
5
+ attr_accessor :github, :oauth_token, :api_endpoint, :owner, :repo, :blacklisted_exceptions, :processor, :web_url, :branch, :whitelisted_rack_variables, :additional_labels, :comment_limit, :title_prefix
6
6
  end
7
7
 
8
8
  # The git branch that is used for linking in the stack trace
@@ -16,7 +16,11 @@ class PartyFoul::IssueRenderers::Base
16
16
  #
17
17
  # @return [String]
18
18
  def title
19
- raw_title.gsub(/0x(\w+)/, "0xXXXXXX")
19
+ if PartyFoul.title_prefix
20
+ "[#{PartyFoul.title_prefix}] #{masked_title}"
21
+ else
22
+ masked_title
23
+ end
20
24
  end
21
25
 
22
26
  # Renders the issue body
@@ -53,7 +57,9 @@ BODY
53
57
  # @return [String]
54
58
  def stack_trace
55
59
  exception.backtrace.map do |line|
56
- if (matches = extract_file_name_and_line_number(line))
60
+ if from_bundler?(line)
61
+ format_line(line)
62
+ elsif (matches = extract_file_name_and_line_number(line))
57
63
  "<a href='#{PartyFoul.repo_url}/blob/#{sha}/#{matches[2]}#L#{matches[3]}'>#{format_line(line)}</a>"
58
64
  else
59
65
  format_line(line)
@@ -152,20 +158,29 @@ BODY
152
158
  Bundler.bundle_path.to_s if defined?(Bundler)
153
159
  end
154
160
 
155
- def extract_file_name_and_line_number(backtrace_line)
156
- backtrace_line.match(/#{app_root}\/((.+?):(\d+))/)
161
+ def from_bundler?(line)
162
+ if bundle_root
163
+ line.match(bundle_root)
164
+ end
165
+ end
166
+
167
+ def extract_file_name_and_line_number(line)
168
+ line.match(/#{app_root}\/((.+?):(\d+))/)
157
169
  end
158
170
 
159
171
  def raw_title
160
172
  raise NotImplementedError
161
173
  end
162
174
 
175
+ def masked_title
176
+ raw_title.gsub(/0x(\w+)/, "0xXXXXXX")
177
+ end
178
+
163
179
  def format_line(line)
164
- if bundle_root
165
- line.sub(app_root, '[app]...').sub(bundle_root, '[bundle]...')
180
+ if from_bundler?(line)
181
+ line.sub(bundle_root, '[bundle]...')
166
182
  else
167
183
  line.sub(app_root, '[app]...')
168
184
  end
169
185
  end
170
-
171
186
  end
@@ -15,6 +15,14 @@ class PartyFoul::IssueRenderers::Rails < PartyFoul::IssueRenderers::Rack
15
15
  parameter_filter.filter(env['rack.session'] || { } )
16
16
  end
17
17
 
18
+ # The timestamp when the exception occurred. Will use Time.current when available to record
19
+ # the time with the proper timezone
20
+ #
21
+ # @return [String]
22
+ def occurred_at
23
+ @occurred_at ||= Time.current.strftime('%B %d, %Y %H:%M:%S %z')
24
+ end
25
+
18
26
  private
19
27
 
20
28
  def app_root
@@ -1,3 +1,3 @@
1
1
  module PartyFoul
2
- VERSION = '1.4.0'
2
+ VERSION = '1.5.0'
3
3
  end
@@ -9,9 +9,9 @@ class PartyFoul::GeneratorTest < Rails::Generators::TestCase
9
9
  test 'it copies the initializer' do
10
10
  owner = 'test_owner'
11
11
  repo = 'test_repo'
12
- octokit = mock('Octokit')
12
+ octokit = mock('Octokit::Client')
13
13
  octokit.expects(:create_authorization).with(scopes: ['repo'], note: 'PartyFoul test_owner/test_repo', note_url: 'http://example.com/test_owner/test_repo').returns(sawyer_resource({token: 'test_token'}))
14
- Octokit.stubs(:new).with(:login => 'test_login', :password => 'test_password', :api_endpoint => 'http://api.example.com').returns(octokit)
14
+ Octokit::Client.stubs(:new).with(:login => 'test_login', :password => 'test_password', :api_endpoint => 'http://api.example.com').returns(octokit)
15
15
  $stdin.stubs(:gets).returns('test_login').then.returns('test_password').then.returns(owner).then.returns(repo).then.returns('http://api.example.com').then.returns('http://example.com').then.returns('')
16
16
  run_generator
17
17
 
@@ -117,21 +117,48 @@ Fingerprint: `abcdefg1234567890`
117
117
  rendered_issue.stubs(:raw_title).returns('Error for #<#<ClassName:0x007fbddbdcd340>:0x007fbddf6be0a0>')
118
118
  rendered_issue.title.must_equal 'Error for #<#<ClassName:0xXXXXXX>:0xXXXXXX>'
119
119
  end
120
- end
121
120
 
122
- describe '#stack_trace' do
123
- it 'returns the stack trace' do
124
- exception = mock do
125
- stubs backtrace: ['/path/to/gems/gem-name/lib/some/file.rb:123 in `method`']
121
+ context 'when a custom title prefix is configured' do
122
+ before do
123
+ PartyFoul.configure do |config|
124
+ config.title_prefix = 'PRODUCTION'
125
+ end
126
+ end
127
+
128
+ it 'adds a custom prefix' do
129
+ rendered_issue = PartyFoul::IssueRenderers::Base.new(nil, nil)
130
+ rendered_issue.stubs(:raw_title).returns('Error')
131
+ rendered_issue.title.must_equal '[PRODUCTION] Error'
132
+ end
133
+
134
+ it 'generated unique fingerprints' do
135
+ rendered_issue = PartyFoul::IssueRenderers::Base.new(nil, nil)
136
+ rendered_issue.stubs(:raw_title).returns('Error')
137
+ fingerprint = rendered_issue.fingerprint
138
+
139
+ PartyFoul.configure do |config|
140
+ config.title_prefix = 'STAGING'
141
+ end
142
+
143
+ fingerprint.wont_equal rendered_issue.fingerprint
126
144
  end
127
- rendered_issue = PartyFoul::IssueRenderers::Base.new(exception, nil)
128
- rendered_issue.stack_trace.must_equal exception.backtrace.first
129
145
  end
146
+ end
147
+
148
+ describe '#stack_trace' do
149
+ # it 'returns the stack trace' do
150
+ # exception = mock do
151
+ # stubs backtrace: ['/path/to/gems/gem-name/lib/some/file.rb:123 in `method`']
152
+ # end
153
+ # rendered_issue = PartyFoul::IssueRenderers::Base.new(exception, nil)
154
+ # rendered_issue.stack_trace.must_equal exception.backtrace.first
155
+ # end
130
156
 
131
157
  it 'formats the stack trace with shortened bundle paths' do
132
158
  exception = mock do
133
159
  stubs backtrace: ["#{Bundler.bundle_path}/some_gem/lib/some/file.rb:123 in `method`"]
134
160
  end
161
+
135
162
  rendered_issue = PartyFoul::IssueRenderers::Base.new(exception, nil)
136
163
  rendered_issue.stack_trace.must_equal '[bundle].../some_gem/lib/some/file.rb:123 in `method`'
137
164
  end
@@ -142,9 +169,19 @@ Fingerprint: `abcdefg1234567890`
142
169
  end
143
170
  rendered_issue = PartyFoul::IssueRenderers::Base.new(exception, nil)
144
171
  rendered_issue.stubs app_root: '/path/to/app'
145
- rendered_issue.stack_trace.must_match "<a href='https://github.com/"
146
- rendered_issue.stack_trace.must_match ">[app].../lib/some/file.rb:123 in `method`</a>"
172
+ rendered_issue.stack_trace.must_match "<a href='https://github.com///blob//lib/some/file.rb#L123'>[app].../lib/some/file.rb:123 in `method`</a>"
147
173
  end
148
- end
149
174
 
175
+ it 'does not link to bundled resources on Heroku' do
176
+ Bundler.stub(:bundle_path, '/app/vendor/bundle/ruby/2.0.0') do
177
+ exception = mock do
178
+ stubs backtrace: ["#{Bundler.bundle_path}/some_gem/lib/some/file.rb:123 in `method`"]
179
+ end
180
+
181
+ rendered_issue = PartyFoul::IssueRenderers::Base.new(exception, nil)
182
+ rendered_issue.stubs app_root: '/app'
183
+ rendered_issue.stack_trace.must_equal '[bundle].../some_gem/lib/some/file.rb:123 in `method`'
184
+ end
185
+ end
186
+ end
150
187
  end
@@ -12,6 +12,17 @@ describe 'Rails Issue Renderer' do
12
12
  end
13
13
  end
14
14
 
15
+ describe '#occurred_at' do
16
+ it 'uses current when possible' do
17
+ Time.stubs(:now).returns(Time.new(1970, 1, 1, 0, 0, 1, '-08:00'))
18
+ Time.stubs(:current).returns(Time.new(1970, 1, 1, 0, 0, 1, '-05:00'))
19
+ current_as_string = Time.current.strftime('%B %d, %Y %H:%M:%S %z')
20
+ rendered_issue = PartyFoul::IssueRenderers::Rails.new(nil, nil)
21
+ expected = rendered_issue.occurred_at
22
+ rendered_issue.occurred_at.must_equal current_as_string
23
+ end
24
+ end
25
+
15
26
  describe '#session' do
16
27
  let(:params) { {'action_dispatch.parameter_filter' => ['password'], 'rack.session' => { 'status' => 'ok', 'password' => 'test' }, 'QUERY_STRING' => { 'status' => 'fail' } } }
17
28
 
@@ -32,4 +32,8 @@ PartyFoul.configure do |config|
32
32
 
33
33
  # Limit the number of comments per issue
34
34
  # config.comment_limit = 10
35
+
36
+ # Setting your title prefix can help with
37
+ # distinguising the issue between environments
38
+ # config.title_prefix = Rails.env
35
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: party_foul
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cardarella
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-05 00:00:00.000000000 Z
12
+ date: 2013-11-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: octokit
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ~>
19
19
  - !ruby/object:Gem::Version
20
- version: 2.3.1
20
+ version: 2.5.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
- version: 2.3.1
27
+ version: 2.5.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: actionpack
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -196,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
196
  version: '0'
197
197
  requirements: []
198
198
  rubyforge_project:
199
- rubygems_version: 2.1.5
199
+ rubygems_version: 2.0.3
200
200
  signing_key:
201
201
  specification_version: 4
202
202
  summary: Auto-submit Rails exceptions as new issues on GitHub