Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for custom_backtrace_url's. #1524

Merged
merged 4 commits into from Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Expand Up @@ -177,7 +177,7 @@ Metrics/BlockLength:
# Offense count: 5
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 168
Max: 169

# Offense count: 6
Metrics/CyclomaticComplexity:
Expand Down
9 changes: 9 additions & 0 deletions app/decorators/app_decorator.rb
Expand Up @@ -24,4 +24,13 @@ def notify_user_display
def notify_err_display
object.notify_on_errs ? '' : 'display: none;'
end

def custom_backtrace_url_template?
object.custom_backtrace_url_template.present?
end

def custom_backtrace_url(file, line)
format(custom_backtrace_url_template, branch: object.repo_branch, file: file, line: line,
ebranch: CGI.escape(object.repo_branch), efile: CGI.escape(file))
end
end
8 changes: 7 additions & 1 deletion app/decorators/backtrace_line_decorator.rb
Expand Up @@ -64,7 +64,7 @@ def link_to_in_app_source_file(app, text)
end

def link_to_repo_source_file(app, text)
link_to_github(app, text) || link_to_bitbucket(app, text)
link_to_custom_backtrace_url(app, text) || link_to_github(app, text) || link_to_bitbucket(app, text)
end

def link_to_hosted_javascript(app, text)
Expand All @@ -84,6 +84,12 @@ def link_to_bitbucket(app, text = nil)
h.link_to(text || file_name, href, target: '_blank')
end

def link_to_custom_backtrace_url(app, text = nil)
return unless app.custom_backtrace_url_template?
href = app.custom_backtrace_url(decorated_path + file_name, number)
h.link_to(text || file_name, href, target: '_blank')
end

def link_to_issue_tracker_file(app, text = nil)
return unless app.issue_tracker && app.issue_tracker.respond_to?(:url_to_file)
href = app.issue_tracker.url_to_file(file_relative, number)
Expand Down
1 change: 1 addition & 0 deletions app/models/app.rb
Expand Up @@ -7,6 +7,7 @@ class App
field :api_key
field :github_repo
field :bitbucket_repo
field :custom_backtrace_url_template
field :asset_host
field :repository_branch
field :current_app_version
Expand Down
3 changes: 3 additions & 0 deletions app/views/apps/_fields.html.haml
Expand Up @@ -18,6 +18,9 @@
%div
= f.label :bitbucket_repo, t('.bitbucket_repo')
= f.text_field :bitbucket_repo, :placeholder => "errbit/errbit from https://bitbucket.org/errbit/errbit"
%div
= f.label :custom_backtrace_url_template, t('.custom_backtrace_url_template')
= f.text_field :custom_backtrace_url_template, :placeholder => "https://gitea.example.com/repos/name/src/branch/%{branch}/%{file}#L%{line}"
%div
= f.label :asset_host, t('.asset_host')
%em= t('.asset_host_help')
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Expand Up @@ -181,6 +181,7 @@ en:
repository_branch: Repo Branch
github_repo: GitHub Repo
bitbucket_repo: BitBucket Repo
custom_backtrace_url_template: Custom Backtrace URL Template
asset_host: Asset Host
asset_host_help: Used to generate links for JavaScript errors
asset_host_placeholder: "e.g. https://assets.example.com"
Expand Down
18 changes: 18 additions & 0 deletions docs/apps.md
Expand Up @@ -23,3 +23,21 @@ to the problems page and exclude the noisy apps from view like this:
/problems?filter=-app:noisy_app%20-app:another_noisy_app

There is no UI for this feature, just the query param.

## Linking backtraces to custom repositories

Errbit builds backtraces with clickable links to Github and Bitbucket repositories.
The entry 'custom backtrace URL template' can be used to support clickable backtraces with other repositories.

The following fields are available for this template:

- %{branch}: The repo branch name
- %{file}: The relative file/path name of the backtrace file
- %{line}: The line number the backtrace occurred
- %{ebranch}: The URI escaped version of the branch name
- %{efile}: The URI escaped version of the file name

A few examples:

- Gitea: `https://errbit.example.com/repo/name/src/branch/%{branch}/%{file}#L%{line}`
- Gitlab: `https://errbit.example.com/repo/name/-/blob/%{branch}/%{file}#L%{line}`
16 changes: 16 additions & 0 deletions spec/decorators/app_decorator_spec.rb
Expand Up @@ -24,4 +24,20 @@
expect(AppDecorator.new(double(notify_on_errs: true)).notify_err_display).to eql ''
end
end

context '#custom_backtrace_url' do
it 'should correctly replace the unescaped fields' do
dbl = double(repo_branch: 'feature/branch',
custom_backtrace_url_template: 'https://example.com/repo/name/src/branch/%{branch}/%{file}#L%{line}')
expect(AppDecorator.new(dbl).custom_backtrace_url("test/file.rb", 42)).to \
eq 'https://example.com/repo/name/src/branch/feature/branch/test/file.rb#L42'
end

it 'should correctly replace the escaped fields' do
dbl = double(repo_branch: 'feature/branch',
custom_backtrace_url_template: 'https://example.com/repo/name/src/branch/%{ebranch}/%{efile}#L%{line}')
expect(AppDecorator.new(dbl).custom_backtrace_url("test/file.rb", 42)).to \
eq 'https://example.com/repo/name/src/branch/feature%2Fbranch/test%2Ffile.rb#L42'
end
end
end