From 6a6854f2db37d316e4f48daae229b8261306b8ec Mon Sep 17 00:00:00 2001 From: Echo Date: Tue, 6 Jan 2026 09:45:27 -0500 Subject: [PATCH] allow repo mapping on projects without a repo url (#771) --- .../my/project_repo_mappings_controller.rb | 2 +- app/models/project_repo_mapping.rb | 16 +++--- .../static_pages/_project_durations.html.erb | 52 +++++++++---------- ..._null_repo_url_on_project_repo_mappings.rb | 5 ++ db/schema.rb | 4 +- 5 files changed, 42 insertions(+), 37 deletions(-) create mode 100644 db/migrate/20260106143925_allow_null_repo_url_on_project_repo_mappings.rb diff --git a/app/controllers/my/project_repo_mappings_controller.rb b/app/controllers/my/project_repo_mappings_controller.rb index 1e7f5f9..4eab69f 100644 --- a/app/controllers/my/project_repo_mappings_controller.rb +++ b/app/controllers/my/project_repo_mappings_controller.rb @@ -59,7 +59,7 @@ class My::ProjectRepoMappingsController < ApplicationController def set_project_repo_mapping decoded_project_name = CGI.unescape(params[:project_name]) - @project_repo_mapping = current_user.project_repo_mappings.find_by!( + @project_repo_mapping = current_user.project_repo_mappings.find_or_create_by!( project_name: decoded_project_name ) end diff --git a/app/models/project_repo_mapping.rb b/app/models/project_repo_mapping.rb index b5f1ad1..3990bac 100644 --- a/app/models/project_repo_mapping.rb +++ b/app/models/project_repo_mapping.rb @@ -5,16 +5,20 @@ class ProjectRepoMapping < ApplicationRecord has_paper_trail validates :project_name, presence: true - validates :repo_url, presence: true validates :project_name, uniqueness: { scope: :user_id } + validates :repo_url, presence: true, if: :repo_url_required? validates :repo_url, format: { with: %r{\A(https?://[^/]+/[^/]+/[^/]+)\z}, message: "must be a valid repository URL" - } + }, if: :repo_url_required? - validate :repo_host_supported - validate :repo_url_exists + validate :repo_host_supported, if: :repo_url_required? + validate :repo_url_exists, if: :repo_url_required? + + def repo_url_required? + repo_url.present? + end IGNORED_PROJECTS = [ nil, @@ -26,8 +30,8 @@ class ProjectRepoMapping < ApplicationRecord scope :archived, -> { where.not(archived_at: nil) } scope :all_statuses, -> { unscoped.where(nil) } - after_create :create_repository_and_sync - after_update :sync_repository_if_url_changed + after_create :create_repository_and_sync, if: :repo_url_required? + after_update :sync_repository_if_url_changed, if: :repo_url_required? def archive! update!(archived_at: Time.current) diff --git a/app/views/static_pages/_project_durations.html.erb b/app/views/static_pages/_project_durations.html.erb index b3a9505..e7dd8e5 100644 --- a/app/views/static_pages/_project_durations.html.erb +++ b/app/views/static_pages/_project_durations.html.erb @@ -6,12 +6,10 @@ <% project_durations.each do |project| %> <% if current_user.github_uid.present? && project[:project].present? %> <%= render "my/project_repo_mappings/edit_modal", project: project %> - <% if project[:has_mapping] %> - <% if show_archived %> - <%= render "my/project_repo_mappings/unarchive_modal", project: project %> - <% else %> - <%= render "my/project_repo_mappings/archive_modal", project: project %> - <% end %> + <% if show_archived %> + <%= render "my/project_repo_mappings/unarchive_modal", project: project %> + <% else %> + <%= render "my/project_repo_mappings/archive_modal", project: project %> <% end %> <% end %>
@@ -54,28 +52,26 @@ - <% if project[:has_mapping] %> - <% if show_archived %> - <% unarchive_modal_id = "unarchive-project-modal-#{project[:project]&.parameterize || 'unknown'}" %> - - <% else %> - <% archive_modal_id = "archive-project-modal-#{project[:project]&.parameterize || 'unknown'}" %> - - <% end %> + <% if show_archived %> + <% unarchive_modal_id = "unarchive-project-modal-#{project[:project]&.parameterize || 'unknown'}" %> + + <% else %> + <% archive_modal_id = "archive-project-modal-#{project[:project]&.parameterize || 'unknown'}" %> + <% end %> <% end %>
diff --git a/db/migrate/20260106143925_allow_null_repo_url_on_project_repo_mappings.rb b/db/migrate/20260106143925_allow_null_repo_url_on_project_repo_mappings.rb new file mode 100644 index 0000000..83f3653 --- /dev/null +++ b/db/migrate/20260106143925_allow_null_repo_url_on_project_repo_mappings.rb @@ -0,0 +1,5 @@ +class AllowNullRepoUrlOnProjectRepoMappings < ActiveRecord::Migration[8.1] + def change + change_column_null :project_repo_mappings, :repo_url, true + end +end diff --git a/db/schema.rb b/db/schema.rb index ecd941e..916c559 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.1].define(version: 2026_01_05_230132) do +ActiveRecord::Schema[8.1].define(version: 2026_01_06_143925) do create_schema "pganalyze" # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" @@ -387,7 +387,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_01_05_230132) do t.datetime "archived_at" t.datetime "created_at", null: false t.string "project_name", null: false - t.string "repo_url", null: false + t.string "repo_url" t.bigint "repository_id" t.datetime "updated_at", null: false t.bigint "user_id", null: false