Skip to content

Commit

Permalink
Include id of existing repository in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
digitaltom committed Dec 21, 2023
1 parent 803d2b2 commit 1826d3e
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/rmt/cli/repos_custom.rb
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ def add(url, name)

error = nil
if Repository.find_by(external_url: url)
error = _('A repository by the URL %{url} already exists.') % { url: url }
error = _('A repository by the URL %{url} already exists (ID %{id}).') % { url: url, id: Repository.find_by(external_url: url).friendly_id }
elsif Repository.find_by(friendly_id: options.id.to_s)
# When given an ID by a user, don't append to it to make a unique ID.
error = _('A repository by the ID %{id} already exists.') % { id: friendly_id }
13 changes: 7 additions & 6 deletions spec/lib/rmt/cli/repos_custom_spec.rb
Original file line number Diff line number Diff line change
@@ -104,10 +104,10 @@

it 'does not update previous repository if non-custom' do
expect(described_class).to receive(:exit)
existing_repo = create :repository, external_url: external_url, name: 'foobar'
expect do
create :repository, external_url: external_url, name: 'foobar'
described_class.start(argv)
end.to output("\e[31mA repository by the URL #{external_url} already exists.\e[0m\nCouldn't add custom repository.\n")
end.to output("\e[31mA repository by the URL #{external_url} already exists (ID #{existing_repo.friendly_id}).\e[0m\nCouldn't add custom repository.\n")
.to_stderr
.and output('').to_stdout
expect(Repository.find_by(external_url: external_url).name).to eq('foobar')
@@ -119,20 +119,21 @@
expect do
described_class.start(%w[add http://example.com/repo/ foo])
end.to output("Successfully added custom repository.\n").to_stdout.and output('').to_stderr

existing_repo = Repository.find_by(external_url: 'http://example.com/repo/')
expect do
described_class.start(%w[add http://example.com/repo foo])
end.to output("\e[31mA repository by the URL http://example.com/repo/ already exists.\e[0m\nCouldn't add custom repository.\n")
end.to output("\e[31mA repository by the URL http://example.com/repo/ already exists (ID #{existing_repo.friendly_id})." \
"\e[0m\nCouldn't add custom repository.\n")
.to_stderr
.and output('').to_stdout
end

it 'does not update previous repository if custom' do
expect(described_class).to receive(:exit)
existing_repo = create :repository, :custom, external_url: external_url, name: 'foobar'
expect do
create :repository, :custom, external_url: external_url, name: 'foobar'
described_class.start(argv)
end.to output("\e[31mA repository by the URL #{external_url} already exists.\e[0m\nCouldn't add custom repository.\n")
end.to output("\e[31mA repository by the URL #{external_url} already exists (ID #{existing_repo.friendly_id}).\e[0m\nCouldn't add custom repository.\n")
.to_stderr
.and output('').to_stdout
expect(Repository.find_by(external_url: external_url).name).to eq('foobar')

0 comments on commit 1826d3e

Please sign in to comment.