Class: ErrbitRedminePlugin::IssueTracker
- Inherits:
-
ErrbitPlugin::IssueTracker
- Object
- ErrbitPlugin::IssueTracker
- ErrbitRedminePlugin::IssueTracker
- 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
- #comments_allowed? ⇒ Boolean
-
#configured? ⇒ Boolean
configured properly if all the fields are filled in.
- #create_issue(title, body, user: {}) ⇒ Object
- #errors ⇒ Object
- #issue_link(issue) ⇒ Object
- #required_fields ⇒ Object
- #url ⇒ Object
Class Method Details
.fields ⇒ Object
48 49 50 |
# File 'lib/errbit_redmine_plugin/issue_tracker.rb', line 48 def self.fields FIELDS end |
.icons ⇒ Object
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 |
.label ⇒ Object
40 41 42 |
# File 'lib/errbit_redmine_plugin/issue_tracker.rb', line 40 def self.label LABEL end |
.note ⇒ Object
44 45 46 |
# File 'lib/errbit_redmine_plugin/issue_tracker.rb', line 44 def self.note NOTE end |
Instance Method Details
#comments_allowed? ⇒ 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
81 82 83 84 |
# File 'lib/errbit_redmine_plugin/issue_tracker.rb', line 81 def configured? = .reject { |k,v| v.empty? }.keys.map(&:intern) (required_fields - ).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 = ['api_token'] acc = ['account'] user = ['username'] passwd = ['password'] project_id = ['project_id'] tracker_id = ['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 |
#errors ⇒ Object
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 |
#issue_link(issue) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/errbit_redmine_plugin/issue_tracker.rb', line 123 def issue_link(issue) project_id = ['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_fields ⇒ Object
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 |
#url ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/errbit_redmine_plugin/issue_tracker.rb', line 66 def url account = ['account'] project_id = ['project_id'] acc_url = account.start_with?('http') ? account : "http://#{account}" acc_url = acc_url.gsub(/\/$/, '') URI.parse("#{acc_url}/projects/#{project_id}").to_s rescue URI::InvalidURIError end |