diff --git a/app/controllers/api/v1/webhooks_controller.rb b/app/controllers/api/v1/webhooks_controller.rb index 1730034e..36e6a6d1 100644 --- a/app/controllers/api/v1/webhooks_controller.rb +++ b/app/controllers/api/v1/webhooks_controller.rb @@ -68,7 +68,7 @@ module Api # respuesta de error a plataformas def platforms_answer(exception) - ExceptionNotifier.notify_exception(exception, env: request.env, data: { headers: request.headers.to_h }) + ExceptionNotifier.notify_exception(exception, data: { headers: request.headers.to_h } head :forbidden end diff --git a/app/jobs/git_pull_job.rb b/app/jobs/git_pull_job.rb index 1dab07bf..55a6e4a1 100644 --- a/app/jobs/git_pull_job.rb +++ b/app/jobs/git_pull_job.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true -# Permite traer los cambios desde webhooks - +# Permite traer los cambios desde el repositorio remoto class GitPullJob < ApplicationJob # @param :site [Site] # @param :usuarie [Usuarie] @@ -9,9 +8,20 @@ class GitPullJob < ApplicationJob # @return [nil] def perform(site, usuarie, message) return unless site.repository.origin - return unless site.repository.fetch.positive? - site.repository.merge(usuarie, message) + site.repository.fetch + + return if site.repository.up_to_date? + + if site.repository.fast_forward? + site.repository.fast_forward! + else + site.repository.merge(usuarie, message) + end + + git_lfs_checkout site.reindex_changes! + + nil end end diff --git a/app/models/site/repository.rb b/app/models/site/repository.rb index acbf6553..e77aded9 100644 --- a/app/models/site/repository.rb +++ b/app/models/site/repository.rb @@ -75,13 +75,18 @@ class Site # Forzamos el checkout para mover el HEAD al último commit y # escribir los cambios rugged.checkout 'HEAD', strategy: :force - - git_sh("git", "lfs", "fetch", "origin", default_branch) - # reemplaza los pointers por los archivos correspondientes - git_sh("git", "lfs", "checkout") + commit end + # Trae todos los archivos desde LFS + # + # @return [Boolean] + def git_lfs_checkout + git_sh('git', 'lfs', 'fetch', 'origin', default_branch) + git_sh('git', 'lfs', 'checkout') + end + # El último commit # # @return [Rugged::Commit] @@ -111,10 +116,30 @@ class Site walker.each.to_a end - # Hay commits sin aplicar? - def needs_pull? - fetch - !commits.empty? + # Detecta si hay que hacer un pull o no + # + # @return [Boolean] + def up_to_date? + rugged.merge_analysis(remote_head_commit).include?(:up_to_date) + end + + # Detecta si es posible adelantar la historia local a la remota o + # necesitamos un merge + # + # @return [Boolean] + def fast_forward? + rugged.merge_analysis(remote_head_commit).include?(:fastforward) + end + + # Mueve la historia local a la remota + # + # @see {https://stackoverflow.com/a/27077322} + # @return [nil] + def fast_forward! + rugged.checkout_tree(remote_head_commit) + rugged.references.update(rugged.head.resolve, remote_head_commit.oid) + + nil end # Guarda los cambios en git diff --git a/config/initializers/core_extensions.rb b/config/initializers/core_extensions.rb index 44e38c26..7d1eab9e 100644 --- a/config/initializers/core_extensions.rb +++ b/config/initializers/core_extensions.rb @@ -125,8 +125,8 @@ module Jekyll unless spec I18n.with_locale(locale) do - raise ArgumentError, I18n.t('activerecord.errors.models.site.attributes.design_id.missing_gem', theme: name) - rescue ArgumentError => e + raise Jekyll::Errors::InvalidThemeName, I18n.t('activerecord.errors.models.site.attributes.design_id.missing_gem', theme: name) + rescue Jekyll::Errors::InvalidThemeName => e ExceptionNotifier.notify_exception(e, data: { theme: name, site: File.basename(site.source) }) raise end diff --git a/db/seeds/designs.yml b/db/seeds/designs.yml index 56655322..d1ae458e 100644 --- a/db/seeds/designs.yml +++ b/db/seeds/designs.yml @@ -18,7 +18,7 @@ - name_en: 'Minima' name_es: 'Mínima' gem: 'sutty-minima' - url: 'https://0xacab.org/sutty/jekyll/minima' + url: 'https://minima.sutty.nl/' description_en: "Sutty Minima is based on [Minima](https://jekyll.github.io/minima/), a blog-focused theme for Jekyll." description_es: 'Sutty Mínima es una plantilla para blogs basada en [Mínima](https://jekyll.github.io/minima/).' license: 'https://0xacab.org/sutty/jekyll/minima/-/blob/master/LICENSE.txt'