From 44b9bb6161a786dc2ea32653f90a01b11fb5698a Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 11 Dec 2025 12:21:23 -0800 Subject: [PATCH] updated UI --- app/views/providers/_form.html.erb | 34 +++++++++++++-------- app/views/providers/_index.html.erb | 14 ++++----- app/views/providers/new.html.erb | 6 ---- spec/models/provider_spec.rb | 47 +++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 25 deletions(-) create mode 100644 spec/models/provider_spec.rb diff --git a/app/views/providers/_form.html.erb b/app/views/providers/_form.html.erb index c385666e..0c5afb7c 100644 --- a/app/views/providers/_form.html.erb +++ b/app/views/providers/_form.html.erb @@ -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 %> -
- - <%= form.text_field :registry_url, class: "input input-bordered", placeholder: params[:provider_type] == Provider::GITHUB_PROVIDER ? "https://github.example.com" : "https://gitlab.example.com" %> - -
- <% 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 %>
@@ -69,6 +58,27 @@ <%= form.text_field :access_token, class: "input input-bordered", required: true %>
+ <% 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" %> +
+
+ + + Add custom hostname + +
+
+ + <%= form.text_field :registry_url, class: "input input-bordered", placeholder: provider_type == Provider::GITHUB_PROVIDER ? "https://github.example.com" : "https://gitlab.example.com" %> + +
+
+ <% end %> + -
- For GitHub Enterprise, enter your server's host URL below. -
<% 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 " %>
@@ -34,9 +31,6 @@ <% end %> permissions.
-
- For GitLab Enterprise/Self-Managed, enter your server's host URL below. -
<% end %>
diff --git a/spec/models/provider_spec.rb b/spec/models/provider_spec.rb new file mode 100644 index 00000000..e422841b --- /dev/null +++ b/spec/models/provider_spec.rb @@ -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