Class: ErrbitTracPlugin::IssueTracker

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

Constant Summary collapse

LABEL =
'trac'
FIELDS =
[
  [:base_url, {
    :label => 'Trac Project URL (without /xmlrpc)',
    :placeholder => 'http://www.example.com/trac/project'
  }],
  [:username, {
    :label => 'Trac User',
    :placeholder => 'johndoe'
  }],
  [:password, {
    :label => 'Trac Password',
    :placeholder => 'p@assW0rd'
  }],
  [:issue_kind, {
    :label => 'Type of issue to create',
    :placeholder => 'defect'
  }],
]
NOTE =
'This issue tracker integrates with ' \
'<a href="http://trac.edgewall.org/">trac</a> through the ' \
'<a href="http://trac-hacks.org/wiki/XmlRpcPlugin">XmlRpcPlugin</a>. ' \
'Fill in the form below with a URL to your trac project, and account ' \
'credentials for a user with the XML_RPC permision.'

Instance Method Summary collapse

Instance Method Details

#body_templateObject



97
98
99
100
# File 'lib/errbit_trac_plugin/issue_tracker.rb', line 97

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

#check_paramsObject



53
54
55
56
57
# File 'lib/errbit_trac_plugin/issue_tracker.rb', line 53

def check_params
  if fields.detect { |f| self[f[0]].blank? && !f[1][:optional] }
    errors.add :base, 'You must specify all values!'
  end
end

#comments_allowed?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/errbit_trac_plugin/issue_tracker.rb', line 59

def comments_allowed?
  false
end

#configured?Boolean

Returns:

  • (Boolean)


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

def configured?
  true
end

#create_issue(problem, reported_by = nil) ⇒ Object

Parameters:

  • problem

    Problem



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

def create_issue(problem, reported_by = nil)
  if reported_by
    reporter = reported_by.name
  else
    reporter = "errbit"
  end

  client = Trac.new(params['base_url'], params['username'], params['password'])

  ticket_id = client.tickets.create(issue_title(problem),
                                    body_template.result(binding), {
    :type => params['issue_kind'],
    :reporter => reporter,
    :keywords => "errbit",
  })

  problem.update_attributes(
    :issue_link => link_for_issue(ticket_id),
    :issue_type => label
  )
end

#fieldsObject



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

def fields
  FIELDS
end

#labelObject



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

def label
  LABEL
end


86
87
88
89
90
91
92
93
94
95
# File 'lib/errbit_trac_plugin/issue_tracker.rb', line 86

def link_for_issue(ticket_id)
  # if it ends in /, remove the /
  if matches = /(.*)\/$/.match(params['base_url'])
    url = matches[1]
  else
    url = params['base_url']
  end

  "%s/ticket/%s" % [url, ticket_id]
end

#noteObject



49
50
51
# File 'lib/errbit_trac_plugin/issue_tracker.rb', line 49

def note
  NOTE
end

#urlObject



41
42
43
# File 'lib/errbit_trac_plugin/issue_tracker.rb', line 41

def url
  params["base_url"]
end