Class: Issue

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/issue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body


3
4
5
# File 'app/models/issue.rb', line 3

def body
  @body
end

#problemObject

Returns the value of attribute problem


3
4
5
# File 'app/models/issue.rb', line 3

def problem
  @problem
end

#userObject

Returns the value of attribute user


3
4
5
# File 'app/models/issue.rb', line 3

def user
  @user
end

Instance Method Details

#issue_trackerObject


5
6
7
# File 'app/models/issue.rb', line 5

def issue_tracker
  @issue_tracker ||= problem.app.issue_tracker
end

#render_body_argsObject


13
14
15
16
17
18
19
# File 'app/models/issue.rb', line 13

def render_body_args
  if tracker.respond_to?(:render_body_args)
    tracker.render_body_args
  else
    [ 'issue_trackers/issue', formats: [:md] ]
  end
end

#saveObject


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/issue.rb', line 29

def save
  errors.add :base, "The issue has no body" unless body
  errors.add :base, "This app has no issue tracker" unless issue_tracker
  return false if errors.present?

  tracker.errors.each { |k, err| errors.add k, err }
  return false if errors.present?

  url = issue_tracker.create_issue(title, body, user: user.as_document)
  problem.update_attributes(issue_link: url, issue_type: tracker.class.label)

  errors.empty?
rescue => ex
  errors.add :base, "There was an error during issue creation: #{ex.message}"
  false
end

#titleObject


21
22
23
24
25
26
27
# File 'app/models/issue.rb', line 21

def title
  if tracker.respond_to?(:title)
    tracker.title
  else
    "[#{ problem.environment }][#{ problem.where }] #{problem.message.to_s.truncate(100)}"
  end
end

#trackerObject


9
10
11
# File 'app/models/issue.rb', line 9

def tracker
  @tracker ||= issue_tracker && issue_tracker.tracker
end