mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-19 21:05:15 +00:00
allow repo mapping on projects without a repo url (#771)
This commit is contained in:
parent
7ebb1b2085
commit
6a6854f2db
5 changed files with 42 additions and 37 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 %>
|
||||
<div class="bg-dark border border-primary rounded-xl p-6 shadow-lg transition-all duration-300 flex flex-col gap-4 hover:border-primary/40 hover:-translate-y-1 hover:shadow-xl backdrop-blur-sm">
|
||||
|
|
@ -54,28 +52,26 @@
|
|||
<path fill="currentColor" d="M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83l3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75z" />
|
||||
</svg>
|
||||
</button>
|
||||
<% if project[:has_mapping] %>
|
||||
<% if show_archived %>
|
||||
<% unarchive_modal_id = "unarchive-project-modal-#{project[:project]&.parameterize || 'unknown'}" %>
|
||||
<button type="button"
|
||||
onclick="document.getElementById(<%= unarchive_modal_id.to_json %>).dispatchEvent(new CustomEvent('modal:open'))"
|
||||
class="p-2 rounded-lg bg-white/5 hover:bg-white/10 transition-colors duration-200 cursor-pointer"
|
||||
title="Restore project">
|
||||
<svg class="w-4 h-4 text-white/70" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="m20.55 5.22l-1.39-1.68A1.51 1.51 0 0 0 18 3H6c-.47 0-.88.21-1.15.55L3.46 5.22C3.17 5.57 3 6.01 3 6.5V19a2 2 0 0 0 2 2h14c1.1 0 2-.9 2-2V6.5c0-.49-.17-.93-.45-1.28m-8.2 4.63L17.5 15H14v2h-4v-2H6.5l5.15-5.15c.19-.19.51-.19.7 0M5.12 5l.82-1h12l.93 1z"/>
|
||||
</svg>
|
||||
</button>
|
||||
<% else %>
|
||||
<% archive_modal_id = "archive-project-modal-#{project[:project]&.parameterize || 'unknown'}" %>
|
||||
<button type="button"
|
||||
onclick="document.getElementById(<%= archive_modal_id.to_json %>).dispatchEvent(new CustomEvent('modal:open'))"
|
||||
class="p-2 rounded-lg bg-white/5 hover:bg-white/10 transition-colors duration-200 cursor-pointer"
|
||||
title="Archive project">
|
||||
<svg class="w-4 h-4 text-white/70" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="m20.54 5.23l-1.39-1.68C18.88 3.21 18.47 3 18 3H6c-.47 0-.88.21-1.16.55L3.46 5.23C3.17 5.57 3 6.02 3 6.5V19c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6.5c0-.48-.17-.93-.46-1.27m-8.89 11.92L6.5 12H10v-2h4v2h3.5l-5.15 5.15c-.19.19-.51.19-.7 0M5.12 5l.81-1h12l.94 1z"/>
|
||||
</svg>
|
||||
</button>
|
||||
<% end %>
|
||||
<% if show_archived %>
|
||||
<% unarchive_modal_id = "unarchive-project-modal-#{project[:project]&.parameterize || 'unknown'}" %>
|
||||
<button type="button"
|
||||
onclick="document.getElementById(<%= unarchive_modal_id.to_json %>).dispatchEvent(new CustomEvent('modal:open'))"
|
||||
class="p-2 rounded-lg bg-white/5 hover:bg-white/10 transition-colors duration-200 cursor-pointer"
|
||||
title="Restore project">
|
||||
<svg class="w-4 h-4 text-white/70" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="m20.55 5.22l-1.39-1.68A1.51 1.51 0 0 0 18 3H6c-.47 0-.88.21-1.15.55L3.46 5.22C3.17 5.57 3 6.01 3 6.5V19a2 2 0 0 0 2 2h14c1.1 0 2-.9 2-2V6.5c0-.49-.17-.93-.45-1.28m-8.2 4.63L17.5 15H14v2h-4v-2H6.5l5.15-5.15c.19-.19.51-.19.7 0M5.12 5l.82-1h12l.93 1z"/>
|
||||
</svg>
|
||||
</button>
|
||||
<% else %>
|
||||
<% archive_modal_id = "archive-project-modal-#{project[:project]&.parameterize || 'unknown'}" %>
|
||||
<button type="button"
|
||||
onclick="document.getElementById(<%= archive_modal_id.to_json %>).dispatchEvent(new CustomEvent('modal:open'))"
|
||||
class="p-2 rounded-lg bg-white/5 hover:bg-white/10 transition-colors duration-200 cursor-pointer"
|
||||
title="Archive project">
|
||||
<svg class="w-4 h-4 text-white/70" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="m20.54 5.23l-1.39-1.68C18.88 3.21 18.47 3 18 3H6c-.47 0-.88.21-1.16.55L3.46 5.23C3.17 5.57 3 6.02 3 6.5V19c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6.5c0-.48-.17-.93-.46-1.27m-8.89 11.92L6.5 12H10v-2h4v2h3.5l-5.15 5.15c-.19.19-.51.19-.7 0M5.12 5l.81-1h12l.94 1z"/>
|
||||
</svg>
|
||||
</button>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
class AllowNullRepoUrlOnProjectRepoMappings < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
change_column_null :project_repo_mappings, :repo_url, true
|
||||
end
|
||||
end
|
||||
4
db/schema.rb
generated
4
db/schema.rb
generated
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue