Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Fixed hostname copied to clipboard on tags
Browse files Browse the repository at this point in the history
The internal hostname was being referring as the hostname to be copied
to the clipboard when the user clicked on the labeled tags. This patch
fixes that by checking if external hostname is set or not. If set,
external hostname will be used instead of internal hostname.

This change affects the API directly because the repository entity is
now using the #reacheable_hostname method that tried to prioritize the
external hostname if set.

Signed-off-by: Vítor Avelino <[email protected]>
  • Loading branch information
Vítor Avelino committed Apr 19, 2018
1 parent 85a4fce commit 83b4b3a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/models/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ def reachable?
e.message
end

# Returns the hostname value that should be priotized and used by the user.
# In other words, whenever external hostname is present, that would be returned.
# Otherwise the internal hostname is returned.1
def reachable_hostname
external_hostname.presence || hostname
end

protected

# Fetch the tag being pushed through the given target object.
Expand Down
5 changes: 3 additions & 2 deletions lib/api/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ class Repositories < Grape::Entity
end
expose :registry_hostname, documentation: {
type: Integer,
desc: "The repository's registry hostname"
desc: "The repository's registry hostname. Prioritizes external hostname value" \
"if present, otherwise internal hostname is shown"
}, if: { type: :internal } do |repository|
repository.registry.hostname
repository.registry.reachable_hostname
end
expose :stars, documentation: {
type: Integer,
Expand Down
13 changes: 13 additions & 0 deletions spec/models/registry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ def create_empty_namespace
end
end

describe "#reachable_hostname" do
let!(:registry) { create(:registry, use_ssl: true) }
let!(:registry_external) { create(:registry, external_hostname: "external", use_ssl: true) }

it "returns internal hostname when external not present" do
expect(registry.reachable_hostname).to eq registry.hostname
end

it "returns external hostname whenever is present" do
expect(registry_external.reachable_hostname).to eq registry_external.external_hostname
end
end

describe "#reachable" do
after :each do
allow_any_instance_of(::Portus::RegistryClient).to receive(:perform_request).and_call_original
Expand Down

0 comments on commit 83b4b3a

Please sign in to comment.