Class: ErrbitRedminePlugin::IssueTracker

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

Constant Summary collapse

LABEL =
"redmine"
FIELDS =
[
  [:account, {
    :label       => "Redmine URL",
    :placeholder => "http://www.redmine.org/"
  }],
  [:api_token, {
    :placeholder => "API Token for your account"
  }],
  [:username, {
    :placeholder => "Your username"
  }],
  [:password, {
    :placeholder => "Your password"
  }],
  [:project_id, {
    :label       => "Ticket Project",
    :placeholder => "Redmine Project where tickets will be created"
  }],
  [:alt_project_id, {
    :optional    => true,
    :label       => "App Project",
    :placeholder => "Where app's files & revisions can be viewed. (Leave blank to use the above project by default)"
  }],
  [:tracker_id, {
    :optional    => true,
    :label       => "Issue Tracker Id",
    :placeholder => "The tracker where tickets will be created. (Leave blank to use default)"
  }]
]
NOTE =
"REST web service must be enabled in Redmine"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fieldsObject



48
49
50
# File 'lib/errbit_redmine_plugin/issue_tracker.rb', line 48

def self.fields
  FIELDS
end

.iconsObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/errbit_redmine_plugin/issue_tracker.rb', line 52

def self.icons
  @icons ||= {
    create: [
      'image/png', ErrbitRedminePlugin.read_static_file('redmine_create.png')
    ],
    goto: [
      'image/png', ErrbitRedminePlugin.read_static_file('redmine_goto.png'),
    ],
    inactive: [
      'image/png', ErrbitRedminePlugin.read_static_file('redmine_inactive.png'),
    ]
  }
end

.labelObject



40
41
42
# File 'lib/errbit_redmine_plugin/issue_tracker.rb', line 40

def self.label
  LABEL
end

.noteObject



44
45
46
# File 'lib/errbit_redmine_plugin/issue_tracker.rb', line 44

def self.note
  NOTE
end

Instance Method Details

#comments_allowed?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/errbit_redmine_plugin/issue_tracker.rb', line 76

def comments_allowed?
  false
end

#configured?Boolean

configured properly if all the fields are filled in

Returns:

  • (Boolean)


81
82
83
84
# File 'lib/errbit_redmine_plugin/issue_tracker.rb', line 81

def configured?
  non_empty_options = options.reject { |k,v| v.empty? }.keys.map(&:intern)
  (required_fields - non_empty_options).empty?
end

#create_issue(title, body, user: {}) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/errbit_redmine_plugin/issue_tracker.rb', line 98

def create_issue(title, body, user: {})
  token  = options['api_token']
  acc    = options['account']
  user   = options['username']
  passwd = options['password']
  project_id = options['project_id']
  tracker_id = options['tracker_id']

  RedmineClient::Base.configure do
    self.token = token
    self.user = user
    self.password = passwd
    self.site = acc
    self.format = :xml
  end

  issue = RedmineClient::Issue.new(:project_id => project_id)
  issue.subject = title
  issue.description = body
  issue.tracker_id = tracker_id if tracker_id.present?
  issue.save!

  issue_link(issue)
end

#errorsObject



90
91
92
93
94
95
96
# File 'lib/errbit_redmine_plugin/issue_tracker.rb', line 90

def errors
  errors = []
  unless configured?
    errors << [:base, 'You must specify your Redmine URL, API token, Username, Password and Project ID']
  end
  errors
end


123
124
125
126
127
128
129
130
# File 'lib/errbit_redmine_plugin/issue_tracker.rb', line 123

def issue_link(issue)
  project_id = options['project_id']

  RedmineClient::Issue.site.to_s
    .sub(/#{RedmineClient::Issue.site.path}$/, '') <<
  RedmineClient::Issue.element_path(issue.id, :project_id => project_id)
    .sub(/\.xml\?project_id=#{project_id}$/, "\?project_id=#{project_id}")
end

#required_fieldsObject



86
87
88
# File 'lib/errbit_redmine_plugin/issue_tracker.rb', line 86

def required_fields
  FIELDS.reject { |k,v| v[:optional] }.map { |f| f[0] }.map(&:intern)
end

#urlObject



66
67
68
69
70
71
72
73
74
# File 'lib/errbit_redmine_plugin/issue_tracker.rb', line 66

def url
   = options['account']
  project_id = options['project_id']

  acc_url = .start_with?('http') ?  : "http://#{}"
  acc_url = acc_url.gsub(/\/$/, '')
  URI.parse("#{acc_url}/projects/#{project_id}").to_s
rescue URI::InvalidURIError
end