Commit 847f4d314203f8de3ea982526ea1cc6a9a43700d

Authored by Nathan Broadbent
1 parent f3f95fd7
Exists in master and in 1 other branch production

Added issue_type to problems, to record which issue tracker the link belongs to …

…(in case tracker is changed, or multiple trackers are registered)
app/models/issue_tracker.rb
@@ -29,5 +29,10 @@ class IssueTracker @@ -29,5 +29,10 @@ class IssueTracker
29 def type=(t); self._type=t; end 29 def type=(t); self._type=t; end
30 30
31 def url; nil; end 31 def url; nil; end
  32 +
  33 + Label = ''
  34 + def self.label
  35 + self::Label
  36 + end
32 end 37 end
33 38
app/models/issue_trackers/fogbugz_tracker.rb
@@ -34,7 +34,11 @@ class IssueTrackers::FogbugzTracker < IssueTracker @@ -34,7 +34,11 @@ class IssueTrackers::FogbugzTracker < IssueTracker
34 issue['cols'] = ['ixBug'].join(',') 34 issue['cols'] = ['ixBug'].join(',')
35 35
36 fb_resp = fogbugz.command(:new, issue) 36 fb_resp = fogbugz.command(:new, issue)
37 - problem.update_attribute :issue_link, "https://#{account}.fogbugz.com/default.asp?#{fb_resp['case']['ixBug']}" 37 + problem.update_attributes(
  38 + :issue_link => "https://#{account}.fogbugz.com/default.asp?#{fb_resp['case']['ixBug']}",
  39 + :issue_type => Label
  40 + )
  41 +
38 end 42 end
39 43
40 def body_template 44 def body_template
app/models/issue_trackers/github_issues_tracker.rb
@@ -15,6 +15,10 @@ class IssueTrackers::GithubIssuesTracker < IssueTracker @@ -15,6 +15,10 @@ class IssueTrackers::GithubIssuesTracker < IssueTracker
15 15
16 attr_accessor :oauth_token 16 attr_accessor :oauth_token
17 17
  18 + def project_id
  19 + app.github_repo
  20 + end
  21 +
18 def check_params 22 def check_params
19 if Fields.detect {|f| self[f[0]].blank? } 23 if Fields.detect {|f| self[f[0]].blank? }
20 errors.add :base, 'You must specify your GitHub repository, username and password' 24 errors.add :base, 'You must specify your GitHub repository, username and password'
@@ -30,8 +34,12 @@ class IssueTrackers::GithubIssuesTracker < IssueTracker @@ -30,8 +34,12 @@ class IssueTrackers::GithubIssuesTracker < IssueTracker
30 end 34 end
31 35
32 begin 36 begin
33 - issue = client.create_issue(app.github_repo, issue_title(problem), body_template.result(binding).unpack('C*').pack('U*'), options = {})  
34 - problem.update_attribute :issue_link, issue.html_url 37 + issue = client.create_issue(project_id, issue_title(problem), body_template.result(binding).unpack('C*').pack('U*'), options = {})
  38 + problem.update_attributes(
  39 + :issue_link => issue.html_url,
  40 + :issue_type => Label
  41 + )
  42 +
35 rescue Octokit::Unauthorized 43 rescue Octokit::Unauthorized
36 raise IssueTrackers::AuthenticationError, "Could not authenticate with GitHub. Please check your username and password." 44 raise IssueTrackers::AuthenticationError, "Could not authenticate with GitHub. Please check your username and password."
37 end 45 end
@@ -42,6 +50,6 @@ class IssueTrackers::GithubIssuesTracker < IssueTracker @@ -42,6 +50,6 @@ class IssueTrackers::GithubIssuesTracker < IssueTracker
42 end 50 end
43 51
44 def url 52 def url
45 - "https://github.com/#{app.github_repo}/issues" 53 + "https://github.com/#{project_id}/issues"
46 end 54 end
47 end 55 end
app/models/issue_trackers/lighthouse_tracker.rb
@@ -31,7 +31,11 @@ class IssueTrackers::LighthouseTracker < IssueTracker @@ -31,7 +31,11 @@ class IssueTrackers::LighthouseTracker < IssueTracker
31 31
32 ticket.tags << "errbit" 32 ticket.tags << "errbit"
33 ticket.save! 33 ticket.save!
34 - problem.update_attribute :issue_link, "#{Lighthouse::Ticket.site.to_s.sub(/#{Lighthouse::Ticket.site.path}$/, '')}#{Lighthouse::Ticket.element_path(ticket.id, :project_id => project_id)}".sub(/\.xml$/, '') 34 + problem.update_attributes(
  35 + :issue_link => "#{Lighthouse::Ticket.site.to_s.sub(/#{Lighthouse::Ticket.site.path}$/, '')}#{Lighthouse::Ticket.element_path(ticket.id, :project_id => project_id)}".sub(/\.xml$/, ''),
  36 + :issue_type => Label
  37 + )
  38 +
35 end 39 end
36 40
37 def body_template 41 def body_template
app/models/issue_trackers/mingle_tracker.rb
@@ -43,7 +43,10 @@ class IssueTrackers::MingleTracker &lt; IssueTracker @@ -43,7 +43,10 @@ class IssueTrackers::MingleTracker &lt; IssueTracker
43 end 43 end
44 44
45 card.save! 45 card.save!
46 - problem.update_attribute :issue_link, URI.parse("#{account}/projects/#{project_id}/cards/#{card.id}").to_s 46 + problem.update_attributes(
  47 + :issue_link => URI.parse("#{account}/projects/#{project_id}/cards/#{card.id}").to_s,
  48 + :issue_type => Label
  49 + )
47 end 50 end
48 51
49 def body_template 52 def body_template
app/models/issue_trackers/pivotal_labs_tracker.rb
@@ -18,7 +18,10 @@ class IssueTrackers::PivotalLabsTracker &lt; IssueTracker @@ -18,7 +18,10 @@ class IssueTrackers::PivotalLabsTracker &lt; IssueTracker
18 PivotalTracker::Client.use_ssl = true 18 PivotalTracker::Client.use_ssl = true
19 project = PivotalTracker::Project.find project_id.to_i 19 project = PivotalTracker::Project.find project_id.to_i
20 story = project.stories.create :name => issue_title(problem), :story_type => 'bug', :description => body_template.result(binding) 20 story = project.stories.create :name => issue_title(problem), :story_type => 'bug', :description => body_template.result(binding)
21 - problem.update_attribute :issue_link, "https://www.pivotaltracker.com/story/show/#{story.id}" 21 + problem.update_attributes(
  22 + :issue_link => "https://www.pivotaltracker.com/story/show/#{story.id}",
  23 + :issue_type => Label
  24 + )
22 end 25 end
23 26
24 def body_template 27 def body_template
app/models/issue_trackers/redmine_tracker.rb
@@ -37,7 +37,10 @@ class IssueTrackers::RedmineTracker &lt; IssueTracker @@ -37,7 +37,10 @@ class IssueTrackers::RedmineTracker &lt; IssueTracker
37 issue.subject = issue_title problem 37 issue.subject = issue_title problem
38 issue.description = body_template.result(binding) 38 issue.description = body_template.result(binding)
39 issue.save! 39 issue.save!
40 - problem.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}") 40 + problem.update_attributes(
  41 + :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}"),
  42 + :issue_type => Label
  43 + )
41 end 44 end
42 45
43 def url_to_file(file_path, line_number = nil) 46 def url_to_file(file_path, line_number = nil)
app/models/problem.rb
@@ -10,6 +10,7 @@ class Problem @@ -10,6 +10,7 @@ class Problem
10 field :last_deploy_at, :type => Time 10 field :last_deploy_at, :type => Time
11 field :resolved, :type => Boolean, :default => false 11 field :resolved, :type => Boolean, :default => false
12 field :issue_link, :type => String 12 field :issue_link, :type => String
  13 + field :issue_type, :type => String
13 14
14 # Cached fields 15 # Cached fields
15 field :app_name, :type => String 16 field :app_name, :type => String
@@ -145,6 +146,12 @@ class Problem @@ -145,6 +146,12 @@ class Problem
145 ) 146 )
146 end 147 end
147 148
  149 + def issue_type
  150 + # Return issue_type if configured, but fall back to detecting app's issue tracker
  151 + attributes['issue_type'] ||=
  152 + (app.issue_tracker_configured? && app.issue_tracker.class::Label) || nil
  153 + end
  154 +
148 private 155 private
149 def attribute_count_increase(name, value) 156 def attribute_count_increase(name, value)
150 counter, index = send(name), attribute_index(value) 157 counter, index = send(name), attribute_index(value)
app/views/errs/_issue_tracker_links.html.haml
1 - if @app.issue_tracker_configured? || current_user.github_account? 1 - if @app.issue_tracker_configured? || current_user.github_account?
2 - if @problem.issue_link.present? 2 - if @problem.issue_link.present?
3 - %span= link_to 'go to issue', @problem.issue_link, :class => "#{@app.issue_tracker.class::Label}_goto goto-issue" 3 + %span= link_to 'go to issue', @problem.issue_link, :class => "#{@problem.issue_type}_goto goto-issue"
4 = link_to 'unlink issue', unlink_issue_app_err_path(@app, @problem), :method => :delete, :confirm => "Unlink err issues?", :class => "unlink-issue" 4 = link_to 'unlink issue', unlink_issue_app_err_path(@app, @problem), :method => :delete, :confirm => "Unlink err issues?", :class => "unlink-issue"
5 - elsif @problem.issue_link == "pending" 5 - elsif @problem.issue_link == "pending"
6 - %span.disabled= link_to 'creating...', '#', :class => "#{@app.issue_tracker.class::Label}_inactive create-issue" 6 + %span.disabled= link_to 'creating...', '#', :class => "#{@problem.issue_type}_inactive create-issue"
7 = link_to 'retry', create_issue_app_err_path(@app, @problem), :method => :post 7 = link_to 'retry', create_issue_app_err_path(@app, @problem), :method => :post
8 - else 8 - else
9 - if current_user.github_account? && @app.github_repo? 9 - if current_user.github_account? && @app.github_repo?
app/views/errs/_table.html.haml
@@ -39,7 +39,7 @@ @@ -39,7 +39,7 @@
39 - if any_issue_links 39 - if any_issue_links
40 %td.issue_link 40 %td.issue_link
41 - if problem.app.issue_tracker_configured? && problem.issue_link.present? && problem.issue_link != 'pending' 41 - if problem.app.issue_tracker_configured? && problem.issue_link.present? && problem.issue_link != 'pending'
42 - = link_to image_tag("#{problem.app.issue_tracker.class::Label}_goto.png"), problem.issue_link, :target => "_blank" 42 + = link_to image_tag("#{problem.issue_type}_goto.png"), problem.issue_link, :target => "_blank"
43 %td.resolve= link_to image_tag("thumbs-up.png"), resolve_app_err_path(problem.app, problem), :title => "Resolve", :method => :put, :confirm => err_confirm, :class => 'resolve' if problem.unresolved? 43 %td.resolve= link_to image_tag("thumbs-up.png"), resolve_app_err_path(problem.app, problem), :title => "Resolve", :method => :put, :confirm => err_confirm, :class => 'resolve' if problem.unresolved?
44 - if errs.none? 44 - if errs.none?
45 %tr 45 %tr
db/migrate/20120605091105_set_issue_type_on_problems.rb 0 → 100644
@@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
  1 +class SetIssueTypeOnProblems < Mongoid::Migration
  2 + def self.up
  3 + Problem.all.each do |p|
  4 + if p.issue_link.present? && p.app.issue_tracker_configured?
  5 + p.update_attribute :issue_type, p.app.issue_tracker.class::Label
  6 + end
  7 + end
  8 + end
  9 +
  10 + def self.down
  11 + end
  12 +end