From 84f82cbb0fccde12f51cc69678ccdafe151b96b3 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 22 Sep 2023 12:21:55 -0300 Subject: [PATCH] fix: obtener el usuario del repositorio --- Gemfile | 1 + Gemfile.lock | 4 ++++ app/models/site/repository.rb | 16 +++++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index dd880219..6edeac5a 100644 --- a/Gemfile +++ b/Gemfile @@ -70,6 +70,7 @@ gem 'redis-rails' gem 'rollups', git: 'https://github.com/fauno/rollup.git', branch: 'update' gem 'rubyzip' gem 'rugged' +gem 'git_clone_url' gem 'concurrent-ruby-ext' gem 'que' gem 'symbol-fstring', require: 'fstring/all' diff --git a/Gemfile.lock b/Gemfile.lock index f71053d7..9549a51d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -217,6 +217,8 @@ GEM activerecord (>= 4.0.0) get_process_mem (0.2.7) ffi (~> 1.0) + git_clone_url (2.0.0) + uri-ssh_git (>= 2.0) globalid (1.1.0) activesupport (>= 5.0) groupdate (6.2.1) @@ -553,6 +555,7 @@ GEM unf_ext unf_ext (0.0.8.2-x86_64-linux-musl) unicode-display_width (1.8.0) + uri-ssh_git (2.0.0) validates_hostname (1.0.13) activerecord (>= 3.0) activesupport (>= 3.0) @@ -606,6 +609,7 @@ DEPENDENCIES fast_jsonparser (~> 0.5.0) flamegraph friendly_id + git_clone_url hairtrigger haml-lint hamlit-rails diff --git a/app/models/site/repository.rb b/app/models/site/repository.rb index 74d874c1..d776efa4 100644 --- a/app/models/site/repository.rb +++ b/app/models/site/repository.rb @@ -173,7 +173,21 @@ class Site def credentials return unless File.exist? private_key - @credentials ||= Rugged::Credentials::SshKey.new username: 'git', publickey: public_key, privatekey: private_key + @credentials ||= + begin + username = parse_url(origin.url)&.user || 'git' + + Rugged::Credentials::SshKey.new username: username, publickey: public_key, privatekey: private_key + end + end + + # @param :url [String] + # @return [URI, nil] + def parse_url(url) + GitCloneUrl.parse(url) + rescue URI::Error => e + ExceptionNotifier.notify_exception(e, data: { site: site.name, url: url }) + nil end # @return [String]