updated UI

This commit is contained in:
Chris
2025-12-11 12:21:23 -08:00
parent 02f6a380d3
commit 44b9bb6161
4 changed files with 76 additions and 25 deletions

View File

@@ -1,17 +1,6 @@
<%= form_with model: provider do |form| %>
<%= render "shared/error_messages", resource: form.object %>
<%= form.hidden_field :provider, value: params[:provider_type] %>
<% if params[:provider_type] == Provider::GITHUB_PROVIDER || params[:provider_type] == Provider::GITLAB_PROVIDER %>
<div class="form-control mt-1 w-full max-w-sm">
<label class="label">
<span class="label-text">Host URL <span class="text-gray-400">(optional, for Enterprise)</span></span>
</label>
<%= form.text_field :registry_url, class: "input input-bordered", placeholder: params[:provider_type] == Provider::GITHUB_PROVIDER ? "https://github.example.com" : "https://gitlab.example.com" %>
<label class="label">
<span class="label-text-alt text-gray-400">Leave blank for <%= params[:provider_type] == Provider::GITHUB_PROVIDER ? "github.com" : "gitlab.com" %></span>
</label>
</div>
<% end %>
<%= form.hidden_field :provider, value: params[:provider_type] || form.object.provider %>
<% if params[:provider_type] == Provider::CUSTOM_REGISTRY_PROVIDER || form.object.provider == Provider::CUSTOM_REGISTRY_PROVIDER %>
<div data-controller="registry-selector">
<div class="form-control mt-1 w-full max-w-sm">
@@ -69,6 +58,27 @@
<%= form.text_field :access_token, class: "input input-bordered", required: true %>
</div>
<% provider_type = params[:provider_type] || form.object.provider %>
<% if provider_type == Provider::GITHUB_PROVIDER || provider_type == Provider::GITLAB_PROVIDER %>
<% provider_name = provider_type == Provider::GITHUB_PROVIDER ? "GitHub" : "GitLab" %>
<div data-controller="expandable-optional-input">
<div>
<a data-action="expandable-optional-input#show" class="btn btn-ghost btn-sm mt-2">
+ Add custom hostname
</a>
</div>
<div data-expandable-optional-input-target="container" class="form-control mt-1 w-full max-w-sm">
<label class="label">
<span class="label-text">Host URL</span>
</label>
<%= form.text_field :registry_url, class: "input input-bordered", placeholder: provider_type == Provider::GITHUB_PROVIDER ? "https://github.example.com" : "https://gitlab.example.com" %>
<label class="label">
<span class="label-text-alt text-gray-400">Enter your <%= provider_name %> Enterprise server URL</span>
</label>
</div>
</div>
<% end %>
<div class="form-footer">
<%= form.submit "Save", class: "btn btn-primary" %>
<%= link_to "Cancel", providers_path, class: "btn btn-outline" %>

View File

@@ -16,13 +16,13 @@
<% project_credential_providers = ProjectCredentialProvider.where(provider:).all %>
<tr>
<td>
<%= provider.provider %>
<br />
<% if provider.container_registry? %>
<span class="text-gray-500">
<%= provider.registry_url %>
</span>
<% end %>
<%= provider.provider.titleize %>
<% if provider.registry_url.present? %>
<br />
<span class="text-gray-500 text-sm">
<%= provider.registry_url %>
</span>
<% end %>
</td>
<td>
<%= render "providers/show", provider: %>

View File

@@ -22,9 +22,6 @@
<% end %>
permissions.
</div>
<div class="mt-2 text-sm text-gray-500">
For GitHub Enterprise, enter your server's host URL below.
</div>
<% elsif params[:provider_type] == Provider::GITLAB_PROVIDER %>
<%= link_to "Find your Gitlab token →", "https://gitlab.com/-/user_settings/personal_access_tokens", target: "_blank", class: "text-sm text-gray-500 " %>
<div class="mt-2">
@@ -34,9 +31,6 @@
<% end %>
permissions.
</div>
<div class="mt-2 text-sm text-gray-500">
For GitLab Enterprise/Self-Managed, enter your server's host URL below.
</div>
<% end %>
</div>
</div>

View File

@@ -0,0 +1,47 @@
require 'rails_helper'
RSpec.describe Provider, type: :model do
describe '#enterprise?' do
it 'returns true for github with registry_url' do
provider = build(:provider, :github, registry_url: 'https://github.example.com')
expect(provider.enterprise?).to be true
end
it 'returns true for gitlab with registry_url' do
provider = build(:provider, :gitlab, registry_url: 'https://gitlab.example.com')
expect(provider.enterprise?).to be true
end
it 'returns false for github without registry_url' do
provider = build(:provider, :github, registry_url: nil)
expect(provider.enterprise?).to be false
end
it 'returns false for gitlab without registry_url' do
provider = build(:provider, :gitlab, registry_url: nil)
expect(provider.enterprise?).to be false
end
it 'returns false for container_registry even with registry_url' do
provider = build(:provider, :container_registry)
expect(provider.enterprise?).to be false
end
end
describe '#api_base_url' do
it 'returns registry_url without trailing slash when present' do
provider = build(:provider, :github, registry_url: 'https://github.example.com/')
expect(provider.api_base_url).to eq('https://github.example.com')
end
it 'returns github api base when github without registry_url' do
provider = build(:provider, :github, registry_url: nil)
expect(provider.api_base_url).to eq('https://api.github.com')
end
it 'returns gitlab api base when gitlab without registry_url' do
provider = build(:provider, :gitlab, registry_url: nil)
expect(provider.api_base_url).to eq('https://gitlab.com')
end
end
end