Class: MantisBugReporter::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(username, password, wsdl, project_id, project_name) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/mantis_bug_reporter.rb', line 6

def initialize(username, password, wsdl, project_id, project_name)
  Savon.configure do |config|
    config.log = false
  end

  @username = username
  @password = password
  @wsdl     = wsdl
  @project_id = project_id
  @project_name = project_name
end

Instance Method Details

#file_bug(exception, env) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/mantis_bug_reporter.rb', line 105

def file_bug(exception, env)
  summary = env["action_dispatch.request.path_parameters"][:controller] + "_controller - " + exception.to_s
  category = "2. Development (Implementation) - Bug"
  description = "The controller " + env["action_dispatch.request.path_parameters"][:controller] + " experienced an exception of " + exception.to_s
  additional_information = exception.backtrace.to_s.delete("[" "]").gsub(",","<br />")
  
  issue_id = self.mc_issue_get_id_from_summary(removeUniqueIdentifier(summary))
  if issue_id.to_i == 0
    self.mc_issue_add(summary, additional_information, category, description)
  else
    issue = self.mc_issue_get(issue_id.to_i)
    begin
      self.mc_issue_update(increment_mantis_reports_field(issue))
    rescue Savon::Error => error
      logger.debug error.to_s
      puts error.to_s
    end
  end
end

#mc_issue_add(summary, additional_information, category, description) ⇒ Object

Creates an issue in Mantis



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mantis_bug_reporter.rb', line 48

def mc_issue_add(summary, additional_information, category, description)
  client = Savon.client(@wsdl)
  response = client.request(:mc_issue_add) do
    soap.body = {
      :username => username,
      :password => password,
      :issue => {
        :summary => removeUniqueIdentifier(summary),
        :project =>  { :id => @project_id, :name => project_name }, # For some reason Mantis wants the id and the name
        :category => category,
        :description => description + "<br /> <br />" + additional_information
      }
    }
  end
end

#mc_issue_exists?(issue_id) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mantis_bug_reporter.rb', line 18

def mc_issue_exists?(issue_id)
  client = Savon.client(@wsdl)
  response = client.request(:mc_issue_exists) do
    soap.body = {
      username: username,
      password: password,
      issue_id: issue_id
    }
  end
  if response.success?
    return response.body[:mc_issue_exists_response][:return]
  end
end

#mc_issue_get(issue_id) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/mantis_bug_reporter.rb', line 64

def mc_issue_get(issue_id)
  client = Savon.client(@wsdl)
  response = client.request(:mc_issue_get) do
    soap.body = {
      :username => username,
      :password => password,
      :issue_id => issue_id
    }
  end
  if response.success?
    return response.body[:mc_issue_get_response][:return]
  end
end

#mc_issue_get_id_from_summary(summary) ⇒ Object

Checks if an issue already exists in Mantis by the summary



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/mantis_bug_reporter.rb', line 91

def mc_issue_get_id_from_summary(summary)
  client = Savon.client(@wsdl)
  response = client.request(:mc_issue_get_id_from_summary) do
    soap.body = {
      :username => username,
      :password => password,
      :summary => { text: removeUniqueIdentifier(summary[0..127]) } #Summary character max is 128
    }
  end
  if response.success?
    return response.body[:mc_issue_get_id_from_summary_response][:return]
  end
end

#mc_issue_note_add(issue_id, note) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mantis_bug_reporter.rb', line 32

def mc_issue_note_add(issue_id, note)
  client = Savon.client(@wsdl)
  response = client.request(:mc_issue_note_add) do
    soap.body = {
      :username => username,
      :password => password,
      :issue_id => issue_id,
      :note => { text: note }
    }
  end
  if response.success?
    return note_id = response.body[:mc_issue_note_add_response][:return]
  end
end

#mc_issue_update(issue) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/mantis_bug_reporter.rb', line 78

def mc_issue_update(issue)
  client = Savon.client(@wsdl)
  response = client.request(:mc_issue_update) do
    soap.body = {
      :username => username,
      :password => password,
      :issue_id => issue[:id],
      :issue => issue
    }
  end
end