diff --git a/app/models/issue_tracker.rb b/app/models/issue_tracker.rb index 70bbb18..f61c6b7 100644 --- a/app/models/issue_tracker.rb +++ b/app/models/issue_tracker.rb @@ -29,5 +29,10 @@ class IssueTracker def type=(t); self._type=t; end def url; nil; end + + Label = '' + def self.label + self::Label + end end diff --git a/app/models/issue_trackers/fogbugz_tracker.rb b/app/models/issue_trackers/fogbugz_tracker.rb index a55e190..f315f23 100644 --- a/app/models/issue_trackers/fogbugz_tracker.rb +++ b/app/models/issue_trackers/fogbugz_tracker.rb @@ -34,7 +34,11 @@ class IssueTrackers::FogbugzTracker < IssueTracker issue['cols'] = ['ixBug'].join(',') fb_resp = fogbugz.command(:new, issue) - problem.update_attribute :issue_link, "https://#{account}.fogbugz.com/default.asp?#{fb_resp['case']['ixBug']}" + problem.update_attributes( + :issue_link => "https://#{account}.fogbugz.com/default.asp?#{fb_resp['case']['ixBug']}", + :issue_type => Label + ) + end def body_template diff --git a/app/models/issue_trackers/github_issues_tracker.rb b/app/models/issue_trackers/github_issues_tracker.rb index 4dedcc5..6dab8c0 100644 --- a/app/models/issue_trackers/github_issues_tracker.rb +++ b/app/models/issue_trackers/github_issues_tracker.rb @@ -15,6 +15,10 @@ class IssueTrackers::GithubIssuesTracker < IssueTracker attr_accessor :oauth_token + def project_id + app.github_repo + end + def check_params if Fields.detect {|f| self[f[0]].blank? } errors.add :base, 'You must specify your GitHub repository, username and password' @@ -30,8 +34,12 @@ class IssueTrackers::GithubIssuesTracker < IssueTracker end begin - issue = client.create_issue(app.github_repo, issue_title(problem), body_template.result(binding).unpack('C*').pack('U*'), options = {}) - problem.update_attribute :issue_link, issue.html_url + issue = client.create_issue(project_id, issue_title(problem), body_template.result(binding).unpack('C*').pack('U*'), options = {}) + problem.update_attributes( + :issue_link => issue.html_url, + :issue_type => Label + ) + rescue Octokit::Unauthorized raise IssueTrackers::AuthenticationError, "Could not authenticate with GitHub. Please check your username and password." end @@ -42,6 +50,6 @@ class IssueTrackers::GithubIssuesTracker < IssueTracker end def url - "https://github.com/#{app.github_repo}/issues" + "https://github.com/#{project_id}/issues" end end diff --git a/app/models/issue_trackers/lighthouse_tracker.rb b/app/models/issue_trackers/lighthouse_tracker.rb index 75c4d7b..39bad82 100644 --- a/app/models/issue_trackers/lighthouse_tracker.rb +++ b/app/models/issue_trackers/lighthouse_tracker.rb @@ -31,7 +31,11 @@ class IssueTrackers::LighthouseTracker < IssueTracker ticket.tags << "errbit" ticket.save! - 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$/, '') + problem.update_attributes( + :issue_link => "#{Lighthouse::Ticket.site.to_s.sub(/#{Lighthouse::Ticket.site.path}$/, '')}#{Lighthouse::Ticket.element_path(ticket.id, :project_id => project_id)}".sub(/\.xml$/, ''), + :issue_type => Label + ) + end def body_template diff --git a/app/models/issue_trackers/mingle_tracker.rb b/app/models/issue_trackers/mingle_tracker.rb index 597948c..2105148 100644 --- a/app/models/issue_trackers/mingle_tracker.rb +++ b/app/models/issue_trackers/mingle_tracker.rb @@ -43,7 +43,10 @@ class IssueTrackers::MingleTracker < IssueTracker end card.save! - problem.update_attribute :issue_link, URI.parse("#{account}/projects/#{project_id}/cards/#{card.id}").to_s + problem.update_attributes( + :issue_link => URI.parse("#{account}/projects/#{project_id}/cards/#{card.id}").to_s, + :issue_type => Label + ) end def body_template diff --git a/app/models/issue_trackers/pivotal_labs_tracker.rb b/app/models/issue_trackers/pivotal_labs_tracker.rb index 964086e..6ecddac 100644 --- a/app/models/issue_trackers/pivotal_labs_tracker.rb +++ b/app/models/issue_trackers/pivotal_labs_tracker.rb @@ -18,7 +18,10 @@ class IssueTrackers::PivotalLabsTracker < IssueTracker PivotalTracker::Client.use_ssl = true project = PivotalTracker::Project.find project_id.to_i story = project.stories.create :name => issue_title(problem), :story_type => 'bug', :description => body_template.result(binding) - problem.update_attribute :issue_link, "https://www.pivotaltracker.com/story/show/#{story.id}" + problem.update_attributes( + :issue_link => "https://www.pivotaltracker.com/story/show/#{story.id}", + :issue_type => Label + ) end def body_template diff --git a/app/models/issue_trackers/redmine_tracker.rb b/app/models/issue_trackers/redmine_tracker.rb index 7780967..6895013 100644 --- a/app/models/issue_trackers/redmine_tracker.rb +++ b/app/models/issue_trackers/redmine_tracker.rb @@ -37,7 +37,10 @@ class IssueTrackers::RedmineTracker < IssueTracker issue.subject = issue_title problem issue.description = body_template.result(binding) issue.save! - 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}") + problem.update_attributes( + :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}"), + :issue_type => Label + ) end def url_to_file(file_path, line_number = nil) diff --git a/app/models/problem.rb b/app/models/problem.rb index 4ca333f..f18e37e 100644 --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -10,6 +10,7 @@ class Problem field :last_deploy_at, :type => Time field :resolved, :type => Boolean, :default => false field :issue_link, :type => String + field :issue_type, :type => String # Cached fields field :app_name, :type => String @@ -145,6 +146,12 @@ class Problem ) end + def issue_type + # Return issue_type if configured, but fall back to detecting app's issue tracker + attributes['issue_type'] ||= + (app.issue_tracker_configured? && app.issue_tracker.class::Label) || nil + end + private def attribute_count_increase(name, value) counter, index = send(name), attribute_index(value) diff --git a/app/views/errs/_issue_tracker_links.html.haml b/app/views/errs/_issue_tracker_links.html.haml index 7c6e6f2..d192f7e 100644 --- a/app/views/errs/_issue_tracker_links.html.haml +++ b/app/views/errs/_issue_tracker_links.html.haml @@ -1,9 +1,9 @@ - if @app.issue_tracker_configured? || current_user.github_account? - if @problem.issue_link.present? - %span= link_to 'go to issue', @problem.issue_link, :class => "#{@app.issue_tracker.class::Label}_goto goto-issue" + %span= link_to 'go to issue', @problem.issue_link, :class => "#{@problem.issue_type}_goto goto-issue" = link_to 'unlink issue', unlink_issue_app_err_path(@app, @problem), :method => :delete, :confirm => "Unlink err issues?", :class => "unlink-issue" - elsif @problem.issue_link == "pending" - %span.disabled= link_to 'creating...', '#', :class => "#{@app.issue_tracker.class::Label}_inactive create-issue" + %span.disabled= link_to 'creating...', '#', :class => "#{@problem.issue_type}_inactive create-issue" = link_to 'retry', create_issue_app_err_path(@app, @problem), :method => :post - else - if current_user.github_account? && @app.github_repo? diff --git a/app/views/errs/_table.html.haml b/app/views/errs/_table.html.haml index 7fc5fa3..b026232 100644 --- a/app/views/errs/_table.html.haml +++ b/app/views/errs/_table.html.haml @@ -39,7 +39,7 @@ - if any_issue_links %td.issue_link - if problem.app.issue_tracker_configured? && problem.issue_link.present? && problem.issue_link != 'pending' - = link_to image_tag("#{problem.app.issue_tracker.class::Label}_goto.png"), problem.issue_link, :target => "_blank" + = link_to image_tag("#{problem.issue_type}_goto.png"), problem.issue_link, :target => "_blank" %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? - if errs.none? %tr diff --git a/db/migrate/20120605091105_set_issue_type_on_problems.rb b/db/migrate/20120605091105_set_issue_type_on_problems.rb new file mode 100644 index 0000000..4bd3f37 --- /dev/null +++ b/db/migrate/20120605091105_set_issue_type_on_problems.rb @@ -0,0 +1,12 @@ +class SetIssueTypeOnProblems < Mongoid::Migration + def self.up + Problem.all.each do |p| + if p.issue_link.present? && p.app.issue_tracker_configured? + p.update_attribute :issue_type, p.app.issue_tracker.class::Label + end + end + end + + def self.down + end +end -- libgit2 0.21.2