Skip to content

Commit e76facd

Browse files
[ELITERT-1221] Fix crashes with GitHub hosted repos
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.
1 parent fbcb6f8 commit e76facd

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Please mark backwards incompatible changes with an exclamation mark at the start
88

99
## [Unreleased]
1010

11+
### Fixed
12+
- Dragnet no longer crashes when generating an HTML report for a repository
13+
hosted on Github.
14+
1115
## [5.3.0] - 2024-12-03
1216

1317
### Added

lib/dragnet/repository.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'forwardable'
4+
require 'git/url'
45

56
require_relative 'base_repository'
67

@@ -36,7 +37,7 @@ def head
3637
#
3738
# @return [String] The URI path of the repository
3839
def remote_uri_path
39-
URI.parse(git.remotes.first.url).path
40+
Git::URL.parse(git.remotes.first.url).path
4041
end
4142

4243
# @return [FalseClass] It always returns false

spec/dragnet/repository_spec.rb

+47-3
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,12 @@
8484
describe '#remote_uri_path' do
8585
subject(:method_call) { repository.remote_uri_path }
8686

87+
let(:remote_url) { 'ssh://[email protected]:29418/projects/central/bsw' }
88+
8789
let(:remote) do
8890
instance_double(
8991
Git::Remote,
90-
url: 'ssh://[email protected]:29418/projects/central/bsw'
92+
url: remote_url
9193
)
9294
end
9395

@@ -109,8 +111,50 @@
109111
method_call
110112
end
111113

112-
it "returns only the path of the remote's URL" do
113-
expect(method_call).to eq('/projects/central/bsw')
114+
context 'when the URL is a standard SSH url' do
115+
it "returns only the path of the remote's URL" do
116+
expect(method_call).to eq('/projects/central/bsw')
117+
end
118+
end
119+
120+
context 'when the URL is a Git URL' do
121+
let(:remote_url) { 'git://[email protected]/esrlabs/dox.git' }
122+
123+
it "returns only the path of the remote's URL" do
124+
expect(method_call).to eq('/esrlabs/dox.git')
125+
end
126+
end
127+
128+
context 'when the URL is a GitHub URL' do
129+
let(:remote_url) { '[email protected]:esrlabs/dox.git' }
130+
131+
it "returns only the path of the remote's URL" do
132+
expect(method_call).to eq('/esrlabs/dox.git')
133+
end
134+
end
135+
136+
context 'when the URL is an HTTPS URL' do
137+
let(:remote_url) { 'https://github.com/esrlabs/dox.git' }
138+
139+
it "returns only the path of the remote's URL" do
140+
expect(method_call).to eq('/esrlabs/dox.git')
141+
end
142+
end
143+
144+
context 'when the URL is a file URL' do
145+
let(:remote_url) { '~/Projects/esrlabs/dox' }
146+
147+
it "returns only the path of the remote's URL" do
148+
expect(method_call).to eq('~/Projects/esrlabs/dox')
149+
end
150+
end
151+
152+
context 'when the URL is a JOSH URL' do
153+
let(:remote_url) { 'https://[email protected]/bsw.git:/libs.git' }
154+
155+
it "returns only the path of the remote's URL" do
156+
expect(method_call).to eq('/bsw.git:/libs.git')
157+
end
114158
end
115159
end
116160

0 commit comments

Comments
 (0)