From 908a0a90a82d1a9e6a198122e5a9946643336e70 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 20 May 2021 19:58:08 -0300 Subject: [PATCH] poder traer actualizaciones desde repositorios remotos sin credenciales ssh no era posible traer los cambios desde repositorios remotos y permitir actualizar desde el panel. --- app/models/site/repository.rb | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/app/models/site/repository.rb b/app/models/site/repository.rb index d9695227..43dae271 100644 --- a/app/models/site/repository.rb +++ b/app/models/site/repository.rb @@ -44,8 +44,8 @@ class Site # # @return [Integer] def fetch - if origin.check_connection :fetch - rugged.fetch(origin)[:received_objects] + if origin.check_connection(:fetch, credentials: credentials) + rugged.fetch(origin, credentials: credentials)[:received_objects] else 0 end @@ -149,6 +149,26 @@ class Site private + # Si Sutty tiene una llave privada de tipo ED25519, devuelve las + # credenciales necesarias para trabajar con repositorios remotos. + # + # @return [Nil, Rugged::Credentials::SshKey] + def credentials + return unless File.exist? private_key + + @credentials ||= Rugged::Credentials::SshKey.new username: 'git', publickey: public_key, privatekey: private_key + end + + # @return [String] + def public_key + @public_key ||= Rails.root.join('.ssh', 'id_ed25519.pub') + end + + # @return [String] + def private_key + @private_key ||= Rails.root.join('.ssh', 'id_ed25519') + end + def relativize(file) Pathname.new(file).relative_path_from(Pathname.new(path)).to_s end