Skip to content

Commit

Permalink
[ELITERT-1221] Fix crashes with GitHub hosted repos
Browse files Browse the repository at this point in the history
Fixes an issue that caused Dragnet to crash when generating an HTML
report for the results of an execution over a repository hosted on
Github.

The reason for the crash was that Ruby's URI parser is incapable of
parsing a GitHub URL, so it was replaced by Git's URL.parse method,
which is capable of doing it.
  • Loading branch information
Sergio Bobillier committed Dec 11, 2024
1 parent fbcb6f8 commit 1601505
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Please mark backwards incompatible changes with an exclamation mark at the start

## [Unreleased]

### Fixed
- Dragnet no longer crashes when generating an HTML report for a repository
hosted on Github.

## [5.3.0] - 2024-12-03

### Added
Expand Down
3 changes: 2 additions & 1 deletion lib/dragnet/repository.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'forwardable'
require 'git/url'

require_relative 'base_repository'

Expand Down Expand Up @@ -36,7 +37,7 @@ def head
#
# @return [String] The URI path of the repository
def remote_uri_path
URI.parse(git.remotes.first.url).path
Git::URL.parse(git.remotes.first.url).path
end

# @return [FalseClass] It always returns false
Expand Down
50 changes: 47 additions & 3 deletions spec/dragnet/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@
describe '#remote_uri_path' do
subject(:method_call) { repository.remote_uri_path }

let(:remote_url) { 'ssh://focal.fossa@gerrit.local:29418/projects/central/bsw' }

let(:remote) do
instance_double(
Git::Remote,
url: 'ssh://focal.fossa@gerrit.int.esrlabs.com:29418/projects/central/bsw'
url: remote_url
)
end

Expand All @@ -109,8 +111,50 @@
method_call
end

it "returns only the path of the remote's URL" do
expect(method_call).to eq('/projects/central/bsw')
context 'when the URL is a standard SSH url' do
it "returns only the path of the remote's URL" do
expect(method_call).to eq('/projects/central/bsw')
end
end

context 'when the URL is a Git URL' do
let(:remote_url) { 'git://git@git.local/esrlabs/dox.git' }

it "returns only the path of the remote's URL" do
expect(method_call).to eq('/esrlabs/dox.git')
end
end

context 'when the URL is a GitHub URL' do
let(:remote_url) { 'git@github.com:esrlabs/dox.git' }

it "returns only the path of the remote's URL" do
expect(method_call).to eq('/esrlabs/dox.git')
end
end

context 'when the URL is an HTTPS URL' do
let(:remote_url) { 'https://github.com/esrlabs/dox.git' }

it "returns only the path of the remote's URL" do
expect(method_call).to eq('/esrlabs/dox.git')
end
end

context 'when the URL is a file URL' do
let(:remote_url) { '~/Projects/esrlabs/dox' }

it "returns only the path of the remote's URL" do
expect(method_call).to eq('~/Projects/esrlabs/dox')
end
end

context 'when the URL is a JOSH URL' do
let(:remote_url) { 'https://focal.fossa@josh.local/bsw.git:/libs.git' }

it "returns only the path of the remote's URL" do
expect(method_call).to eq('/bsw.git:/libs.git')
end
end
end

Expand Down

0 comments on commit 1601505

Please sign in to comment.