Commit 3484c2429e2cf32fb9193fb3051a0e76905f49c9
1 parent
d55b0776
Exists in
master
and in
1 other branch
Using /issues.xml for Redmine issue creation. Overriding RedmineClient::Base.site on every request.
Showing
3 changed files
with
11 additions
and
8 deletions
Show diff stats
app/controllers/errs_controller.rb
@@ -36,7 +36,8 @@ class ErrsController < ApplicationController | @@ -36,7 +36,8 @@ class ErrsController < ApplicationController | ||
36 | flash[:error] = "This up has no issue tracker setup." | 36 | flash[:error] = "This up has no issue tracker setup." |
37 | end | 37 | end |
38 | redirect_to app_err_path(@app, @err) | 38 | redirect_to app_err_path(@app, @err) |
39 | - rescue ActiveResource::ConnectionError | 39 | + rescue ActiveResource::ConnectionError => e |
40 | + Rails.logger.error e.to_s | ||
40 | flash[:error] = "There was an error during issue creation. Check your tracker settings or try again later." | 41 | flash[:error] = "There was an error during issue creation. Check your tracker settings or try again later." |
41 | redirect_to app_err_path(@app, @err) | 42 | redirect_to app_err_path(@app, @err) |
42 | end | 43 | end |
app/models/issue_tracker.rb
@@ -22,15 +22,16 @@ class IssueTracker | @@ -22,15 +22,16 @@ class IssueTracker | ||
22 | protected | 22 | protected |
23 | def create_redmine_issue err | 23 | def create_redmine_issue err |
24 | token = api_token | 24 | token = api_token |
25 | + acc = account | ||
25 | RedmineClient::Base.configure do | 26 | RedmineClient::Base.configure do |
26 | self.token = token | 27 | self.token = token |
28 | + self.site = acc | ||
27 | end | 29 | end |
28 | - RedmineClient::Issue.site = account + "/projects/:project_id" | ||
29 | issue = RedmineClient::Issue.new(:project_id => project_id) | 30 | issue = RedmineClient::Issue.new(:project_id => project_id) |
30 | issue.subject = issue_title err | 31 | issue.subject = issue_title err |
31 | issue.description = self.class.redmine_body_template.result(binding) | 32 | issue.description = self.class.redmine_body_template.result(binding) |
32 | issue.save! | 33 | issue.save! |
33 | - err.update_attribute :issue_link, "#{RedmineClient::Issue.site.to_s.sub(/#{RedmineClient::Issue.site.path}$/, '')}#{RedmineClient::Issue.element_path(issue.id, :project_id => project_id)}".sub(/\.xml$/, '') | 34 | + err.update_attribute :issue_link, "#{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}") |
34 | end | 35 | end |
35 | 36 | ||
36 | def create_lighthouseapp_issue err | 37 | def create_lighthouseapp_issue err |
spec/controllers/errs_controller_spec.rb
@@ -261,17 +261,18 @@ describe ErrsController do | @@ -261,17 +261,18 @@ describe ErrsController do | ||
261 | 261 | ||
262 | before(:each) do | 262 | before(:each) do |
263 | number = 5 | 263 | number = 5 |
264 | - @issue_link = "#{tracker.account}/projects/#{tracker.project_id}/issues/#{number}.xml" | ||
265 | - body = "<issue><id type=\"integer\">#{number}</id></issue>" | ||
266 | - stub_request(:post, "#{tracker.account}/projects/#{tracker.project_id}/issues.xml").to_return(:status => 201, :headers => {'Location' => @issue_link}, :body => body ) | 264 | + @issue_link = "#{tracker.account}/issues/#{number}.xml?project_id=#{tracker.project_id}" |
265 | + body = "<issue><subject>my subject</subject><id>#{number}</id></issue>" | ||
266 | + stub_request(:post, "#{tracker.account}/issues.xml").to_return(:status => 201, :headers => {'Location' => @issue_link}, :body => body ) | ||
267 | 267 | ||
268 | post :create_issue, :app_id => err.app.id, :id => err.id | 268 | post :create_issue, :app_id => err.app.id, :id => err.id |
269 | err.reload | 269 | err.reload |
270 | end | 270 | end |
271 | 271 | ||
272 | it "should make request to Redmine with err params" do | 272 | it "should make request to Redmine with err params" do |
273 | - requested = have_requested(:post, "#{tracker.account}/projects/#{tracker.project_id}/issues.xml") | 273 | + requested = have_requested(:post, "#{tracker.account}/issues.xml") |
274 | WebMock.should requested.with(:headers => {'X-Redmine-API-Key' => tracker.api_token}) | 274 | WebMock.should requested.with(:headers => {'X-Redmine-API-Key' => tracker.api_token}) |
275 | + WebMock.should requested.with(:body => /<project-id>#{tracker.project_id}<\/project-id>/) | ||
275 | WebMock.should requested.with(:body => /<subject>\[#{ err.environment }\]\[#{err.where}\] #{err.message.to_s.truncate(100)}<\/subject>/) | 276 | WebMock.should requested.with(:body => /<subject>\[#{ err.environment }\]\[#{err.where}\] #{err.message.to_s.truncate(100)}<\/subject>/) |
276 | WebMock.should requested.with(:body => /<description>.+<\/description>/m) | 277 | WebMock.should requested.with(:body => /<description>.+<\/description>/m) |
277 | end | 278 | end |
@@ -281,7 +282,7 @@ describe ErrsController do | @@ -281,7 +282,7 @@ describe ErrsController do | ||
281 | end | 282 | end |
282 | 283 | ||
283 | it "should create issue link for err" do | 284 | it "should create issue link for err" do |
284 | - err.issue_link.should == @issue_link.sub(/\.xml$/, '') | 285 | + err.issue_link.should == @issue_link.sub(/\.xml/, '') |
285 | end | 286 | end |
286 | end | 287 | end |
287 | end | 288 | end |