gitlab_exception_notification 1.1.0 → 1.2.0

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: 05e350f92a0ff8559200fa1bd5340a686c3febf9
4
- data.tar.gz: a2801371fe60a17f629e28c5a2281543eefed19b
3
+ metadata.gz: e50cdaeeea3ed9e989d8d904e3b9b4a1ab7b8a66
4
+ data.tar.gz: a76c1afbc2e1d32ae9dfe308c0103c39750ec1db
5
5
  SHA512:
6
- metadata.gz: 9ec68a6254205a729627d3f779e3b2b89dd595f361ab289dc08120df6d206d69c5185c0b3b7c173ec0e5f6699c5ca5299c51e22e9eedb334cd9faf4f21d0f549
7
- data.tar.gz: 21562ad1b2070b0ca0467c14c0584d433514d1ba1c4738ba605b38fd780bab8df9159271025f1bf6c8527d4c2fe49399d10bb340a4d9e23f2b6b1c883b615705
6
+ metadata.gz: 9eaece63cd52733ed35a9693c89b3dbecde2e30deba07d6dc6001c5a850ded29b98787d79b575f943e30edb2e2e297834ff387df6ac4585697562f5669e3ac3c
7
+ data.tar.gz: 7e4efa688a4450cc7bcbdc59298a17bbd9d978016bd1c0fac143619a9db064d43529df5ddab92e496b1708f12a8dabd7aa6d43a1052390d3a02ed8e6ab0e543c
@@ -1,11 +1,10 @@
1
- module GitlabExceptionNotification
1
+ require "gitlab"
2
+ require "digest"
2
3
 
3
- require "gitlab"
4
- require 'digest'
4
+ module GitlabExceptionNotification
5
5
 
6
6
  REJECT_HEADERS = /HTTP_COOKIE|(rack.*)|(action_dispatch.*)/
7
- SLINE = "
8
- "
7
+ SLINE = "\n"
9
8
  STAB = SLINE + " "
10
9
 
11
10
  PER_PAGE = 40
@@ -3,6 +3,7 @@
3
3
  module ExceptionNotifier
4
4
  class GitlabNotifier
5
5
  def initialize(options)
6
+ puts "On init, options => #{options.inspect}"
6
7
  @options = options
7
8
  end
8
9
 
@@ -17,8 +18,9 @@ module ExceptionNotifier
17
18
  end
18
19
 
19
20
  def call(exception, options={})
21
+ puts "On call, exception => #{exception.inspect}, options => #{options.inspect}"
20
22
  env = options[:env] || {}
21
23
  exception_notification(env, exception, @options.merge(options))
22
24
  end
23
25
  end
24
- end
26
+ end
@@ -1,7 +1,7 @@
1
1
  module GitlabExceptionNotification
2
2
 
3
3
  class Issue
4
-
4
+
5
5
  def initialize(env, exception, options={})
6
6
  @env = env
7
7
  @exception = exception
@@ -10,13 +10,14 @@ module GitlabExceptionNotification
10
10
  @request = ActionDispatch::Request.new(env)
11
11
  @data = (env['exception_notifier.exception_data'] || {}).merge(options[:data] || {})
12
12
  @digest = digest
13
- @client = Gitlab.client(endpoint: 'http://gitlab.42.fr/api/v3', private_token: options[:private_token])
13
+ @client = Gitlab.client(endpoint: options[:gitlab_url], private_token: options[:private_token])
14
14
  @project_id = @client.project_search(options[:project_name]).first.id
15
15
  @issues = self.all
16
16
  end
17
17
 
18
18
  def create
19
- @client.create_issue(@project_id, title, {description: description})
19
+ puts "create_issue with labels: #{[Rails.env, 'bug'].join(',').inspect}"
20
+ @client.create_issue(@project_id, title, {description: description, labels: [Rails.env, 'bug'].join(',')})
20
21
  end
21
22
 
22
23
  def update(id)
@@ -24,7 +25,7 @@ module GitlabExceptionNotification
24
25
  last = issue.updated_at.to_date
25
26
  if last < 1.hour.ago
26
27
  begin
27
- @client.edit_issue(@project_id, id, {state_event: "reopen"})
28
+ @client.edit_issue(@project_id, id, {state_event: "reopen", labels: [Rails.env, 'bug'].join(',')})
28
29
  iss = @client.edit_issue(@project_id, id, {title: increment_title(issue)})
29
30
  rescue Exception => e
30
31
  p "An error occured: #{e.inspect}"
@@ -41,7 +42,7 @@ module GitlabExceptionNotification
41
42
 
42
43
  def is_same_exception? issue
43
44
  return false if issue.nil? or issue.description.nil?
44
- issue.description.split(SLINE).last.strip == @digest
45
+ issue.description.split(SLINE).last && issue.description.split(SLINE).last.strip == @digest
45
46
  end
46
47
 
47
48
  def exists?
@@ -54,10 +55,10 @@ module GitlabExceptionNotification
54
55
 
55
56
  def all
56
57
  page = 1
57
- i = @client.issues(@project_id, per_page: PER_PAGE, page: page, order_by: :updated_at)
58
+ i = @client.issues(@project_id, per_page: PER_PAGE, page: page, order_by: :updated_at, labels: [Rails.env, 'bug'].join(','))
58
59
  @issues = i
59
60
  while i.count == PER_PAGE
60
- i = @client.issues(@project_id, per_page: PER_PAGE, page: page, order_by: :updated_at)
61
+ i = @client.issues(@project_id, per_page: PER_PAGE, page: page, order_by: :updated_at, labels: [Rails.env, 'bug'].join(','))
61
62
  @issues += i
62
63
  page += 1
63
64
  end
@@ -72,8 +73,6 @@ module GitlabExceptionNotification
72
73
  # The issue title
73
74
  def title
74
75
  t = []
75
- t << "#{@kontroller.controller_name}##{@kontroller.action_name}" if @kontroller
76
- t << "(#{@exception.class})"
77
76
  t << (@exception.message.length > 120 ? @exception.message[0..120] + "..." : @exception.message)
78
77
  t.join(' ')
79
78
  end
@@ -98,9 +97,12 @@ module GitlabExceptionNotification
98
97
 
99
98
  # Get the concerned file
100
99
  file = @exception.backtrace.first
100
+ repo_file = file.gsub(/.*\/#{@options[:project_name]}\/([^:]*):(\d*)(:in.*)/, '\1#L\2')
101
+
102
+ d = ["> (#{@exception.class}) #{@exception.message} #{@kontroller ? 'in controller ' + @kontroller.controller_name + '#' + @kontroller.action_name : ''}"]
101
103
 
102
- d = ["#{@exception.message} #{@kontroller ? 'in controller ' + @kontroller.controller_name + '#' + @kontroller.action_name : ''}"]
103
- d << "File: #{file}"
104
+ d << "\n**Full path**: #{file}"
105
+ d << "\n**File**: [#{repo_file}](#{repo_file})"
104
106
  {
105
107
  'Summary': summary.map { |k, v| "- #{k}: #{v}"}.join(SLINE),
106
108
  'session id': @request.ssl? ? "[FILTERED]" : (@request.session['session_id'] || (@request.env["rack.session.options"] and @request.env["rack.session.options"][:id])).inspect,
@@ -109,8 +111,8 @@ module GitlabExceptionNotification
109
111
  'request headers': md_hash(@request.headers),
110
112
  'environment': md_hash(@env.reject{|k, v| (REJECT_HEADERS =~ k).nil? })
111
113
  }.reject{|k, v| v.nil? or v.blank?}.each do |k, v|
112
- d << "--------------------------------"
113
- d << "#### #{k.to_s.humanize}: "
114
+ d << "\n--------------------------------\n"
115
+ d << "#### #{k.to_s.humanize}:\n"
114
116
  d << v.to_s
115
117
  end
116
118
  d << @digest
@@ -132,11 +134,14 @@ module GitlabExceptionNotification
132
134
  def md_hash hash, pre = ""
133
135
  hash.map { |k, v| "#{pre}- **#{k}**: `#{v}`"}.join(SLINE)
134
136
  end
135
-
137
+
136
138
  def digest
139
+ puts "Creating digest with: "
140
+ puts "- #{@exception.to_s}"
141
+ puts "- #{@exception.backtrace.first.split(":in").first.to_s}"
137
142
  "EXC" + Digest::SHA256.hexdigest(@exception.to_s + @exception.backtrace.first.split(":in").first.to_s)
138
143
  end
139
144
 
140
145
 
141
146
  end
142
- end
147
+ end
@@ -1,3 +1,3 @@
1
1
  module GitlabExceptionNotification
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab_exception_notification
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andre Aubin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-05 00:00:00.000000000 Z
11
+ date: 2017-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -56,20 +56,20 @@ dependencies:
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: '3.5'
59
+ version: '3.7'
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 3.5.0
62
+ version: 3.7.0
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: '3.5'
69
+ version: '3.7'
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
- version: 3.5.0
72
+ version: 3.7.0
73
73
  description: Automatically create, open and updates Gitlab issues on rails exceptions.
74
74
  email:
75
75
  - andre.aubin@lambdaweb.fr
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  version: '0'
140
140
  requirements: []
141
141
  rubyforge_project:
142
- rubygems_version: 2.4.8
142
+ rubygems_version: 2.5.1
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: A Gitlab plugin for the exception_notification gem.