Class: ExceptionNotifier::YoutrackNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/exception_notifier/youtrack_notifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ YoutrackNotifier

Returns a new instance of YoutrackNotifier.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/exception_notifier/youtrack_notifier.rb', line 7

def initialize(options)
  @project = options[:project]

  @client = Youtrack::Client.new do |c|
    c.url = options[:url]
    c. = options[:user]
    c.password = options[:password]
  end

  @client.connect!
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



5
6
7
# File 'lib/exception_notifier/youtrack_notifier.rb', line 5

def client
  @client
end

#projectObject

Returns the value of attribute project.



5
6
7
# File 'lib/exception_notifier/youtrack_notifier.rb', line 5

def project
  @project
end

Instance Method Details

#call(exception, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/exception_notifier/youtrack_notifier.rb', line 19

def call(exception, options={})
  issue_resource = @client.issues

  backtrace = enrich_message_with_backtrace(exception)

  issue = {
    project: @project,
    summary: exception.message,
    description: backtrace,
    type: 'bug',
    priority: 'critical',
    state: 'open'
  }

  issue_resource.create(issue)
end

#clean_backtrace(exception) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/exception_notifier/youtrack_notifier.rb', line 41

def clean_backtrace(exception)
  if defined?(Rails) && Rails.respond_to?(:backtrace_cleaner)
    Rails.backtrace_cleaner.send(:filter, exception.backtrace)
  else
    exception.backtrace
  end
end

#enrich_message_with_backtrace(exception) ⇒ Object



36
37
38
39
# File 'lib/exception_notifier/youtrack_notifier.rb', line 36

def enrich_message_with_backtrace(exception)
  backtrace = clean_backtrace(exception).first(10).join("\n")
  ['*Backtrace:*', backtrace].join("\n")
end