Class: ErrbitUnfuddlePlugin::IssueTracker

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

Constant Summary collapse

LABEL =
'unfuddle'
NOTE =
''
FIELDS =
[
  [:account, {
    :placeholder => "account-name (from account-name.unfuddle.com)"
  }],
  [:username, {
    :placeholder => "Your username"
  }],

  [:password, {
    :placeholder => "Your password"
  }],
  [:project_id, {
    :label       => "Ticket Project ID",
    :placeholder => "Project where tickets will be created"
  }],
  [:milestone_id, {
    :optional    => true,
    :label       => "Ticket Milestone ID",
    :placeholder => "Milestone where tickets will be created"
  }]
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.body_templateObject



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

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

.fieldsObject



37
38
39
# File 'lib/errbit_unfuddle_plugin/issue_tracker.rb', line 37

def self.fields
  FIELDS
end

.labelObject



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

def self.label
  LABEL
end

.noteObject



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

def self.note
  NOTE
end

Instance Method Details

#comments_allowed?Boolean

Returns:

  • (Boolean)


61
# File 'lib/errbit_unfuddle_plugin/issue_tracker.rb', line 61

def comments_allowed?; false; end

#configured?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/errbit_unfuddle_plugin/issue_tracker.rb', line 57

def configured?
  errors.empty?
end

#create_issue(problem, reported_by = nil) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/errbit_unfuddle_plugin/issue_tracker.rb', line 71

def create_issue(problem, reported_by = nil)
  ErrbitUnfuddlePlugin.config(params['account'], params['username'], params['password'])
  begin
    issue_options = {
      :project_id => params['project_id'],
      :summary => "[#{ problem.environment }][#{ problem.where }] #{problem.message.to_s.truncate(100)}",
      :priority => '5',
      :status => "new",
      :description => self.class.body_template.result(binding),
      'description-format' => 'textile'
    }

    if params['milestone_id'].present?
      issue_options[:milestone_id] = params['milestone_id']
    end

    issue = ErrbitUnfuddlePlugin::Ticket.create(issue_options)
    problem.update_attributes(
      :issue_link => File.join("#{url}/tickets/#{issue.id}"),
      :issue_type => self.class.label
    )
  rescue ActiveResource::UnauthorizedAccess
    raise ActiveResource::UnauthorizedAccess,
      "Could not authenticate with Unfuddle. Please check your username and password."
  end
end

#errorsObject



63
64
65
66
67
68
69
# File 'lib/errbit_unfuddle_plugin/issue_tracker.rb', line 63

def errors
  errors = []
  if self.class.fields.detect {|f| !f[1][:optional] && params[f[0].to_s].blank? }
    errors << [:base, 'You must specify your Account, Username, Password and Project ID']
  end
  errors
end

#urlObject



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

def url
  sprintf(
    "https://%s.unfuddle.com/projects/%s",
    params['account'],
    params['project_id']
  )
end