From 42b6744f81c8b3399893fba9cf561ef6f96b2b4b Mon Sep 17 00:00:00 2001 From: jazzari Date: Tue, 18 Jul 2023 15:47:26 -0300 Subject: [PATCH 1/4] feat: Job para hacer push #12919 --- app/jobs/git_push_job.rb | 12 ++++++++++++ app/models/site/repository.rb | 31 ++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 app/jobs/git_push_job.rb diff --git a/app/jobs/git_push_job.rb b/app/jobs/git_push_job.rb new file mode 100644 index 00000000..fb3ca662 --- /dev/null +++ b/app/jobs/git_push_job.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# Permite pushear los cambios cada vez que se +# hacen commits en un sitio +class GitPushJob < ApplicationJob + # @param :site [Site] + # @return [nil] + def perform(site) + #detectar que el repo local tiene repo remoto + site.repository.push if site.repository.origin + end +end \ No newline at end of file diff --git a/app/models/site/repository.rb b/app/models/site/repository.rb index 62e4c45e..10ab481d 100644 --- a/app/models/site/repository.rb +++ b/app/models/site/repository.rb @@ -29,7 +29,7 @@ class Site # Obtiene el origin # - # @return [Rugged::Remote] + # @return [Rugged::Remote, nil] def origin @origin ||= rugged.remotes.find do |remote| remote.name == 'origin' @@ -154,17 +154,15 @@ class Site # # @return [Boolean] def gc - env = { 'PATH' => '/usr/bin', 'LANG' => ENV['LANG'], 'HOME' => path } - cmd = 'git gc' + git_sh("git gc") + end - r = nil - Dir.chdir(path) do - Open3.popen2e(env, cmd, unsetenv_others: true) do |_, _, t| - r = t.value - end - end - - r&.success? + # Pushea cambios al repositorio remoto + # + # @return [Boolean, nil] + def push + origin.push(rugged.head.canonical_name, credentials: credentials) + git_sh("git lfs push") end private @@ -192,5 +190,16 @@ class Site def relativize(file) Pathname.new(file).relative_path_from(Pathname.new(path)).to_s end + + def git_sh(cmd) + env = { 'PATH' => '/usr/bin', 'LANG' => ENV['LANG'], 'HOME' => path } + + r = nil + Open3.popen2e(env, cmd, unsetenv_others: true, chdir: path) do |_, _, t| + r = t.value + end + + r&.success? + end end end From ca9fa31cf135d79e0204aad24d716a7f04c917c7 Mon Sep 17 00:00:00 2001 From: jazzari Date: Thu, 20 Jul 2023 15:31:38 -0300 Subject: [PATCH 2/4] fix: change git_sh method to accept array of params #12919 --- app/jobs/git_push_job.rb | 1 - app/models/site/repository.rb | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/jobs/git_push_job.rb b/app/jobs/git_push_job.rb index fb3ca662..3c62bee2 100644 --- a/app/jobs/git_push_job.rb +++ b/app/jobs/git_push_job.rb @@ -6,7 +6,6 @@ class GitPushJob < ApplicationJob # @param :site [Site] # @return [nil] def perform(site) - #detectar que el repo local tiene repo remoto site.repository.push if site.repository.origin end end \ No newline at end of file diff --git a/app/models/site/repository.rb b/app/models/site/repository.rb index 10ab481d..6306730e 100644 --- a/app/models/site/repository.rb +++ b/app/models/site/repository.rb @@ -154,7 +154,7 @@ class Site # # @return [Boolean] def gc - git_sh("git gc") + git_sh("git", "gc") end # Pushea cambios al repositorio remoto @@ -162,7 +162,7 @@ class Site # @return [Boolean, nil] def push origin.push(rugged.head.canonical_name, credentials: credentials) - git_sh("git lfs push") + git_sh("git", "lfs", "push", "origin", "#{default_branch}") end private @@ -191,11 +191,15 @@ class Site Pathname.new(file).relative_path_from(Pathname.new(path)).to_s end - def git_sh(cmd) + # Ejecuta un comando de git + # + # @param :args [Array] + # @return [Boolean] + def git_sh(*args) env = { 'PATH' => '/usr/bin', 'LANG' => ENV['LANG'], 'HOME' => path } r = nil - Open3.popen2e(env, cmd, unsetenv_others: true, chdir: path) do |_, _, t| + Open3.popen2e(env, args, unsetenv_others: true, chdir: path) do |_, _, t| r = t.value end From c2d64e11d7c0c6fb414e6970f6c933db19442561 Mon Sep 17 00:00:00 2001 From: jazzari Date: Thu, 20 Jul 2023 16:26:43 -0300 Subject: [PATCH 3/4] fix: missing splat in git_sh method #12919 --- app/models/site/repository.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/site/repository.rb b/app/models/site/repository.rb index 6306730e..a900fea2 100644 --- a/app/models/site/repository.rb +++ b/app/models/site/repository.rb @@ -162,7 +162,7 @@ class Site # @return [Boolean, nil] def push origin.push(rugged.head.canonical_name, credentials: credentials) - git_sh("git", "lfs", "push", "origin", "#{default_branch}") + git_sh("git", "lfs", "push", "origin", "default_branch") end private @@ -199,7 +199,7 @@ class Site env = { 'PATH' => '/usr/bin', 'LANG' => ENV['LANG'], 'HOME' => path } r = nil - Open3.popen2e(env, args, unsetenv_others: true, chdir: path) do |_, _, t| + Open3.popen2e(env, *args, unsetenv_others: true, chdir: path) do |_, _, t| r = t.value end From b7dc448daaec35c2e45045ab2272fe0f82ada948 Mon Sep 17 00:00:00 2001 From: jazzari Date: Fri, 21 Jul 2023 17:15:36 -0300 Subject: [PATCH 4/4] fix: fix git_sh method in site.repository.rb #12919 --- app/models/site/repository.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/site/repository.rb b/app/models/site/repository.rb index a900fea2..1ce10ed5 100644 --- a/app/models/site/repository.rb +++ b/app/models/site/repository.rb @@ -162,7 +162,7 @@ class Site # @return [Boolean, nil] def push origin.push(rugged.head.canonical_name, credentials: credentials) - git_sh("git", "lfs", "push", "origin", "default_branch") + git_sh("git", "lfs", "push", "origin", default_branch) end private