From bf166e7cfb23634d72ac0857ca7b661a38587f19 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 9 Sep 2011 17:44:52 +0800 Subject: [PATCH] Allow the user to provide a redmine url for linking to codebase. The same as the github url, but points to a redmine repo. The format of the link is something like: --- app/helpers/errs_helper.rb | 10 +++++++++- app/helpers/notices_helper.rb | 15 ++++++++++++++- app/models/app.rb | 5 +++++ app/views/apps/_fields.html.haml | 10 +++++++--- app/views/notices/_backtrace.html.haml | 6 +----- 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/app/helpers/errs_helper.rb b/app/helpers/errs_helper.rb index 93049ee..0905998 100644 --- a/app/helpers/errs_helper.rb +++ b/app/helpers/errs_helper.rb @@ -15,4 +15,12 @@ module ErrsHelper link_to(text || file_name, "#{app.github_url_to_file(file_path)}#L#{line_number}", :target => '_blank') end -end \ No newline at end of file + def link_to_redmine app, line, text=nil + file_name = line['file'].split('/').last + file_path = line['file'].gsub('[PROJECT_ROOT]', '') + line_number = line['number'] + lnk = "%s%s#L%s" % [ app.redmine_url, file_path, line_number] + link_to(text || file_name, lnk, :target => '_blank') + end + +end diff --git a/app/helpers/notices_helper.rb b/app/helpers/notices_helper.rb index bd4974b..bb34062 100644 --- a/app/helpers/notices_helper.rb +++ b/app/helpers/notices_helper.rb @@ -3,4 +3,17 @@ module NoticesHelper def notice_atom_summary notice render :partial => "notices/atom_entry.html.haml", :locals => {:notice => notice} end -end \ No newline at end of file + + def render_line_number(app, line) + unless Notice.in_app_backtrace_line?(line) + line['number'] + else + case true + when app.github_url? then link_to_github(app, line, line['number']) + when app.redmine_url? then link_to_redmine(app, line, line['number']) + else + line['number'] + end + end + end +end diff --git a/app/models/app.rb b/app/models/app.rb index 230bfbe..8e2742d 100644 --- a/app/models/app.rb +++ b/app/models/app.rb @@ -5,6 +5,7 @@ class App field :name, :type => String field :api_key field :github_url + field :redmine_url field :resolve_errs_on_deploy, :type => Boolean, :default => false field :notify_all_users, :type => Boolean, :default => false field :notify_on_errs, :type => Boolean, :default => true @@ -66,6 +67,10 @@ class App self.github_url.present? end + def redmine_url? + self.redmine_url.present? + end + def github_url_to_file(file) "#{self.github_url}/blob/master#{file}" end diff --git a/app/views/apps/_fields.html.haml b/app/views/apps/_fields.html.haml index b14a65d..04e0b33 100644 --- a/app/views/apps/_fields.html.haml +++ b/app/views/apps/_fields.html.haml @@ -4,9 +4,13 @@ = f.label :name = f.text_field :name -%div - = f.label :github_url - = f.text_field :github_url +%fieldset + %legend Links to Codebase + %div + = f.label :github_url + = f.text_field :github_url + = f.label :redmine_url + = f.text_field :redmine_url %fieldset %legend Notifications diff --git a/app/views/notices/_backtrace.html.haml b/app/views/notices/_backtrace.html.haml index 7f5438f..354ca53 100644 --- a/app/views/notices/_backtrace.html.haml +++ b/app/views/notices/_backtrace.html.haml @@ -4,11 +4,7 @@ %th %ul.line-numbers - lines.each do |line| - %li - - if line['number'].present? - = (@app.github_url? && Notice.in_app_backtrace_line?(line)) ? link_to_github(@app, line, line['number']) : line['number'] - - else -   + %li= line_number_with_link(@app, line) %td %ul.lines - lines.each do |line| -- libgit2 0.21.2