Class: ErrbitLighthousePlugin::IssueTracker

Inherits:
ErrbitPlugin::IssueTracker
  • Object
show all
Defined in:
lib/errbit_lighthouse_plugin/issue_tracker.rb

Constant Summary collapse

LABEL =
"lighthouseapp"
FIELDS =
[
  [:account, {
    :label       => "Subdomain",
    :placeholder => "subdomain from http://{{subdomain}}.lighthouseapp.com"
  }],
  [:api_token, {
    :label       => "API Token",
    :placeholder => "123456789abcdef123456789abcdef"
  }],
  [:project_id, {
    :label       => "Project ID",
    :placeholder => "123456"
  }]
]
NOTE =
""

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.body_templateObject


92
93
94
95
96
97
98
# File 'lib/errbit_lighthouse_plugin/issue_tracker.rb', line 92

def self.body_template
  @body_template ||= ERB.new(File.read(
    File.join(
      ErrbitLighthousePlugin.root, 'views', 'lighthouseapp_body.txt.erb'
    )
  ))
end

.fieldsObject


33
34
35
# File 'lib/errbit_lighthouse_plugin/issue_tracker.rb', line 33

def self.fields
  FIELDS
end

.labelObject


25
26
27
# File 'lib/errbit_lighthouse_plugin/issue_tracker.rb', line 25

def self.label
  LABEL
end

.noteObject


29
30
31
# File 'lib/errbit_lighthouse_plugin/issue_tracker.rb', line 29

def self.note
  NOTE
end

Instance Method Details

#comments_allowed?Boolean

Returns:

  • (Boolean)

45
46
47
# File 'lib/errbit_lighthouse_plugin/issue_tracker.rb', line 45

def comments_allowed?
  false
end

#configured?Boolean

configured properly if all the fields are filled in

Returns:

  • (Boolean)

50
51
52
53
54
55
# File 'lib/errbit_lighthouse_plugin/issue_tracker.rb', line 50

def configured?
  non_empty_params = params.reject { |k,v| v.empty? }.keys.map(&:intern)
  required_fields  = FIELDS.map { |f| f[0].intern }

  (required_fields - non_empty_params).empty?
end

#create_issue(problem, reported_by = nil) ⇒ Object


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/errbit_lighthouse_plugin/issue_tracker.rb', line 65

def create_issue(problem, reported_by = nil)
  Lighthouse. = params['account']
  Lighthouse.token   = params['api_token']
  # updating lighthouse account
  Lighthouse::Ticket.site
  Lighthouse::Ticket.format = :xml
  ticket = Lighthouse::Ticket.new(:project_id => params['project_id'])
  ticket.title = "[#{ problem.environment }][#{ problem.where }] #{problem.message.to_s.truncate(100)}"

  ticket.body = self.class.body_template.result(binding)

  ticket.tags << "errbit"
  ticket.save!
  problem.update_attributes(
    :issue_link => ticket_link(ticket),
    :issue_type => self.class.label
  )
end

#errorsObject


57
58
59
60
61
62
63
# File 'lib/errbit_lighthouse_plugin/issue_tracker.rb', line 57

def errors
  errors = []
  if FIELDS.detect {|f| params[f[0]].blank? }
    errors << [:base, 'You must specify your Lighthouseapp Subdomain, API token and Project ID']
  end
  errors
end

84
85
86
87
88
89
90
# File 'lib/errbit_lighthouse_plugin/issue_tracker.rb', line 84

def ticket_link(ticket)
  Lighthouse::Ticket.site.to_s
    .sub(/#{Lighthouse::Ticket.site.path}$/, '') <<
  Lighthouse::Ticket.element_path(
    ticket.id, :project_id => params['project_id'])
    .sub(/\.xml$/, '')
end

#urlObject


37
38
39
40
41
42
43
# File 'lib/errbit_lighthouse_plugin/issue_tracker.rb', line 37

def url
  sprintf(
    "http://%s.lighthouseapp.com/projects/%s",
    params[:subdomain],
    params[:project_id]
  )
end