mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 09:31:41 +00:00
Merge branch 'rails' of 0xacab.org:sutty/sutty into issue-13619
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:
commit
ad4965226c
5 changed files with 34 additions and 31 deletions
|
@ -37,7 +37,7 @@ class Site
|
||||||
|
|
||||||
author = GitAuthor.new email: "sutty@#{Site.domain}", name: 'Sutty'
|
author = GitAuthor.new email: "sutty@#{Site.domain}", name: 'Sutty'
|
||||||
|
|
||||||
repository.commit(file: modified,
|
repository.commit(add: modified,
|
||||||
message: I18n.t('sites.find_and_replace'),
|
message: I18n.t('sites.find_and_replace'),
|
||||||
usuarie: author)
|
usuarie: author)
|
||||||
end
|
end
|
||||||
|
|
|
@ -114,14 +114,21 @@ class Site
|
||||||
end
|
end
|
||||||
|
|
||||||
# Guarda los cambios en git
|
# Guarda los cambios en git
|
||||||
def commit(file:, usuarie:, message:, remove: false)
|
#
|
||||||
file = [file] unless file.respond_to? :each
|
# @param :add [Array] Archivos a agregar
|
||||||
|
# @param :rm [Array] Archivos a eliminar
|
||||||
|
# @param :usuarie [Usuarie] Quién hace el commit
|
||||||
|
# @param :message [String] Mensaje
|
||||||
|
def commit(add: [], rm: [], usuarie:, message:)
|
||||||
# Cargar el árbol actual
|
# Cargar el árbol actual
|
||||||
rugged.index.read_tree rugged.head.target.tree
|
rugged.index.read_tree rugged.head.target.tree
|
||||||
|
|
||||||
file.each do |f|
|
add.each do |file|
|
||||||
remove ? rm(f) : add(f)
|
rugged.index.add(relativize(file))
|
||||||
|
end
|
||||||
|
|
||||||
|
rm.each do |file|
|
||||||
|
rugged.index.remove(relativize(file))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Escribir los cambios para que el repositorio se vea tal cual
|
# Escribir los cambios para que el repositorio se vea tal cual
|
||||||
|
@ -142,14 +149,6 @@ class Site
|
||||||
{ name: 'Sutty', email: "sutty@#{Site.domain}", time: Time.now }
|
{ name: 'Sutty', email: "sutty@#{Site.domain}", time: Time.now }
|
||||||
end
|
end
|
||||||
|
|
||||||
def add(file)
|
|
||||||
rugged.index.add(relativize(file))
|
|
||||||
end
|
|
||||||
|
|
||||||
def rm(file)
|
|
||||||
rugged.index.remove(relativize(file))
|
|
||||||
end
|
|
||||||
|
|
||||||
# Garbage collection
|
# Garbage collection
|
||||||
#
|
#
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
|
@ -158,10 +157,8 @@ class Site
|
||||||
cmd = 'git gc'
|
cmd = 'git gc'
|
||||||
|
|
||||||
r = nil
|
r = nil
|
||||||
Dir.chdir(path) do
|
Open3.popen2e(env, cmd, unsetenv_others: true, chdir: path) do |_, _, t|
|
||||||
Open3.popen2e(env, cmd, unsetenv_others: true) do |_, _, t|
|
r = t.value
|
||||||
r = t.value
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
r&.success?
|
r&.success?
|
||||||
|
|
|
@ -22,7 +22,7 @@ class LfsObjectService
|
||||||
Site::Writer.new(site: site, file: path, content: pointer).save
|
Site::Writer.new(site: site, file: path, content: pointer).save
|
||||||
|
|
||||||
# Commitear el pointer
|
# Commitear el pointer
|
||||||
site.repository.commit(file: path, usuarie: author, message: File.basename(path))
|
site.repository.commit(add: [path], usuarie: author, message: File.basename(path))
|
||||||
|
|
||||||
# Eliminar el pointer
|
# Eliminar el pointer
|
||||||
FileUtils.rm(path)
|
FileUtils.rm(path)
|
||||||
|
|
|
@ -16,7 +16,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
||||||
post.slug.value = p[:slug] if p[:slug].present?
|
post.slug.value = p[:slug] if p[:slug].present?
|
||||||
end
|
end
|
||||||
|
|
||||||
commit(action: :created, file: update_related_posts) if post.update(post_params)
|
commit(action: :created, add: update_related_posts) if post.update(post_params)
|
||||||
|
|
||||||
update_site_license!
|
update_site_license!
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
||||||
# Los artículos anónimos siempre son borradores
|
# Los artículos anónimos siempre son borradores
|
||||||
params[:draft] = true
|
params[:draft] = true
|
||||||
|
|
||||||
commit(action: :created) if post.update(anon_post_params)
|
commit(action: :created, add: [post.path.absolute]) if post.update(anon_post_params)
|
||||||
post
|
post
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -42,11 +42,17 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
||||||
post.usuaries << usuarie
|
post.usuaries << usuarie
|
||||||
params[:post][:draft] = true if site.invitade? usuarie
|
params[:post][:draft] = true if site.invitade? usuarie
|
||||||
|
|
||||||
# Es importante que el artículo se guarde primero y luego los
|
# Eliminar ("mover") el archivo si cambió de ubicación.
|
||||||
# relacionados.
|
if post.update(post_params)
|
||||||
commit(action: :updated, file: update_related_posts) if post.update(post_params)
|
rm = []
|
||||||
|
rm << post.path.value_was if post.path.changed?
|
||||||
|
|
||||||
update_site_license!
|
# Es importante que el artículo se guarde primero y luego los
|
||||||
|
# relacionados.
|
||||||
|
commit(action: :updated, add: update_related_posts, rm: rm)
|
||||||
|
|
||||||
|
update_site_license!
|
||||||
|
end
|
||||||
|
|
||||||
# Devolver el post aunque no se haya salvado para poder rescatar los
|
# Devolver el post aunque no se haya salvado para poder rescatar los
|
||||||
# errores
|
# errores
|
||||||
|
@ -56,7 +62,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
||||||
def destroy
|
def destroy
|
||||||
post.destroy!
|
post.destroy!
|
||||||
|
|
||||||
commit(action: :destroyed) if post.destroyed?
|
commit(action: :destroyed, rm: [post.path.absolute]) if post.destroyed?
|
||||||
|
|
||||||
post
|
post
|
||||||
end
|
end
|
||||||
|
@ -85,15 +91,15 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
||||||
|
|
||||||
# TODO: Implementar transacciones!
|
# TODO: Implementar transacciones!
|
||||||
posts.save_all(validate: false) &&
|
posts.save_all(validate: false) &&
|
||||||
commit(action: :reorder, file: files)
|
commit(action: :reorder, add: files)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def commit(action:, file: nil)
|
def commit(action:, add: [], rm: [])
|
||||||
site.repository.commit(file: file || post.path.absolute,
|
site.repository.commit(add: add,
|
||||||
|
rm: rm,
|
||||||
usuarie: usuarie,
|
usuarie: usuarie,
|
||||||
remove: action == :destroyed,
|
|
||||||
message: I18n.t("post_service.#{action}",
|
message: I18n.t("post_service.#{action}",
|
||||||
title: post&.title&.value))
|
title: post&.title&.value))
|
||||||
end
|
end
|
||||||
|
|
|
@ -94,7 +94,7 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
|
||||||
def commit_config(action:)
|
def commit_config(action:)
|
||||||
site.repository
|
site.repository
|
||||||
.commit(usuarie: usuarie,
|
.commit(usuarie: usuarie,
|
||||||
file: site.config.path,
|
add: [site.config.path],
|
||||||
message: I18n.t("site_service.#{action}",
|
message: I18n.t("site_service.#{action}",
|
||||||
name: site.name))
|
name: site.name))
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue