mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 03:31:41 +00:00
feat: Job para hacer push #12919
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
504f30997e
commit
42b6744f81
2 changed files with 32 additions and 11 deletions
12
app/jobs/git_push_job.rb
Normal file
12
app/jobs/git_push_job.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue