exception_notification-lark-notifier 1.0.0 → 1.0.1

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: 4e0a0ee12c91e89f27b20f8af7803b09cc1cad5c4c81de4f4740add60409af83
4
- data.tar.gz: 5c9d14db23ec2f71276cd1cfbfe026fdc620f465dee858b32a5f2876903ee3c8
3
+ metadata.gz: e5f0ab0e3d65f71e4078769b0261b913088a32b48c400e731f6bc88b97db15b9
4
+ data.tar.gz: e54d66cb04d799fa8f6df66e13b3b5ea2befa83b9f22c75daeff8e6bd5b3aa4b
5
5
  SHA512:
6
- metadata.gz: 2045bebbcc8ef6f9428b28c80203660d37109fc96267b9123a2e0e00872b91b4914ca12695bf2e153d0d86e2df1715ce7129fb62d7be95e098da2fc432425350
7
- data.tar.gz: b3bc14d8e61f6caa17d373becb1baeca121ba0b0892c6a28fa7db5664c601f4431b30731ad6356cd190ca78bdf4e49ca4a61282c1364e3458d5b4a5a3eebfee2
6
+ metadata.gz: aca1f9d76f52fcdbc8cb5b994862a6b1af7867bc5db0b77ab89fa5f664387ecb9ee095e7795d3a18d2eb4f152b08d9b8c27559c0f1ca4db8fbdbe2b5286db57b
7
+ data.tar.gz: 7ddb0447939c148d101d174a6c9c2dfc4922e2c8ea71d0be8d7218f425953eab4e9e3faf3bd69187bbb35856e9e5359c66b8e214c93efd98dcfc06a221b4273f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- exception_notification-lark-notifier (0.0.1)
4
+ exception_notification-lark-notifier (1.0.1)
5
5
  exception_notification (~> 4.0)
6
6
  http (~> 5.0)
7
7
 
data/README.md CHANGED
@@ -55,6 +55,18 @@ The Incoming WebHook URL on Lark.
55
55
 
56
56
  The secret key for *Signature validation*.
57
57
 
58
+ #### app_name
59
+
60
+ *String, optional*
61
+
62
+ Your application name, shown in the notification.
63
+
64
+ #### env_name
65
+
66
+ *String, optional*
67
+
68
+ Your env name, shown in the notification.
69
+
58
70
  #### http
59
71
 
60
72
  *Hash, optional*
@@ -1,3 +1,3 @@
1
1
  module ExceptionNotificationLarkNotifier
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -2,19 +2,44 @@ module ExceptionNotifier
2
2
  class LarkNotifier
3
3
  include ExceptionNotifier::BacktraceCleaner
4
4
 
5
+ class << self
6
+ def rails_app_name
7
+ return unless defined?(::Rails) && ::Rails.respond_to?(:application)
8
+ if ::Gem::Version.new(::Rails.version) >= ::Gem::Version.new("6.0")
9
+ ::Rails.application.class.module_parent_name
10
+ else
11
+ ::Rails.application.class.parent_name
12
+ end
13
+ end
14
+
15
+ def rails_env_name
16
+ return unless defined?(::Rails) && ::Rails.respond_to?(:env)
17
+ ::Rails.env
18
+ end
19
+ end
20
+
5
21
  def initialize(options)
6
- @default_appname = "#{rails_app_name} (env: #{rails_env_name})" if rails_app_name && rails_env_name
22
+ @default_app_name = self.class.rails_app_name
23
+ @default_env_name = self.class.rails_env_name
24
+ @default_options = options
25
+
7
26
  @notifier = ExceptionNotificationLarkNotifier::Client.new(
8
27
  options.slice(:webhook_url, :webhook_secret, :http)
9
28
  )
10
29
  end
11
30
 
12
- def call(exception, options = {})
13
- title = @default_appname ? "Exception Occurred in #{@default_appname}" : "Exception Occurred"
14
- clean_message = exception.message.tr("`", "'")
15
- backtrace = exception.backtrace ? clean_backtrace(exception) : ""
16
- info, data = information_from_options(exception.class, options)
17
- fields = fields(clean_message, backtrace, data)
31
+ def call(exception, call_options = {})
32
+ options = call_options.merge(@default_options)
33
+ app_name = options.delete(:app_name) || @default_app_name
34
+ env_name = options.delete(:env_name) || @default_env_name
35
+
36
+ title = "Exception Occurred"
37
+ title += " in #{app_name}" if app_name
38
+ title += " (env: #{env_name})" if env_name
39
+
40
+ backtrace = exception.backtrace ? clean_backtrace(exception) : []
41
+ summary, data = information_from_options(exception.class, options)
42
+ fields = fields(exception.message, backtrace, data)
18
43
 
19
44
  @notifier.post interactive: {
20
45
  header: {
@@ -22,7 +47,7 @@ module ExceptionNotifier
22
47
  },
23
48
  elements: [{
24
49
  tag: "div",
25
- text: {tag: "lark_md", content: info},
50
+ text: {tag: "lark_md", content: summary},
26
51
  fields: fields
27
52
  }]
28
53
  }
@@ -30,26 +55,26 @@ module ExceptionNotifier
30
55
 
31
56
  private
32
57
 
33
- def fields(clean_message, backtrace, data)
58
+ def fields(message, backtrace, data)
34
59
  fields = []
35
60
 
36
- unless clean_message.empty?
61
+ unless message.empty?
37
62
  fields << {is_short: false, text: {tag: "lark_md", content: "**Message:**"}}
38
- fields << {is_short: false, text: {tag: "plain_text", content: clean_message}}
39
- fields << {is_short: false, text: {tag: "lark_md", content: "\n"}}
63
+ fields << {is_short: false, text: {tag: "plain_text", content: message}}
64
+ fields << {is_short: false, text: {tag: "plain_text", content: "\n"}}
40
65
  end
41
66
 
42
67
  unless backtrace.empty?
43
68
  fields << {is_short: false, text: {tag: "lark_md", content: "**Backtrace:**"}}
44
69
  fields << {is_short: false, text: {tag: "plain_text", content: backtrace.first(10).join("\n")}}
45
- fields << {is_short: false, text: {tag: "lark_md", content: "\n"}}
70
+ fields << {is_short: false, text: {tag: "plain_text", content: "\n"}}
46
71
  end
47
72
 
48
73
  unless data.empty?
49
74
  data = data.map { |k, v| "#{k}: #{v}" }.join("\n")
50
75
  fields << {is_short: false, text: {tag: "lark_md", content: "**Data:**"}}
51
76
  fields << {is_short: false, text: {tag: "plain_text", content: data}}
52
- fields << {is_short: false, text: {tag: "lark_md", content: "\n"}}
77
+ fields << {is_short: false, text: {tag: "plain_text", content: "\n"}}
53
78
  end
54
79
 
55
80
  fields
@@ -79,19 +104,5 @@ module ExceptionNotifier
79
104
 
80
105
  [text, data]
81
106
  end
82
-
83
- def rails_app_name
84
- return unless defined?(::Rails) && ::Rails.respond_to?(:application)
85
- if ::Gem::Version.new(::Rails.version) >= ::Gem::Version.new("6.0")
86
- ::Rails.application.class.module_parent_name
87
- else
88
- ::Rails.application.class.parent_name
89
- end
90
- end
91
-
92
- def rails_env_name
93
- return unless defined?(::Rails) && ::Rails.respond_to?(:env)
94
- ::Rails.env
95
- end
96
107
  end
97
108
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exception_notification-lark-notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Doe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-29 00:00:00.000000000 Z
11
+ date: 2022-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: exception_notification