From 9958558b1463037c1292ff93c91e3be8aca88add Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Thu, 6 Jan 2022 10:29:31 +0100 Subject: [PATCH] fix --- app/models/communication/website/git_file.rb | 4 +-- app/models/concerns/with_git.rb | 26 +++++++++----------- app/services/git/repository.rb | 4 +-- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/models/communication/website/git_file.rb b/app/models/communication/website/git_file.rb index 99993d0e5..0f414e31f 100644 --- a/app/models/communication/website/git_file.rb +++ b/app/models/communication/website/git_file.rb @@ -59,13 +59,13 @@ class Communication::Website::GitFile < ApplicationRecord end def path - about.send "git_path_#{identifier}" + @path ||= about.send "git_path_#{identifier}" end def sha # Git SHA-1 is calculated from the String "blob <length>\x00<contents>" # Source: https://alblue.bandlem.com/2011/08/git-tip-of-week-objects.html - OpenSSL::Digest::SHA1.hexdigest "blob #{to_s.bytesize}\x00#{to_s}" + @sha ||= OpenSSL::Digest::SHA1.hexdigest "blob #{to_s.bytesize}\x00#{to_s}" end def to_s diff --git a/app/models/concerns/with_git.rb b/app/models/concerns/with_git.rb index 5d505ed00..981a0b102 100644 --- a/app/models/concerns/with_git.rb +++ b/app/models/concerns/with_git.rb @@ -8,7 +8,6 @@ module WithGit dependent: :destroy end - # Needs override def git_path_static raise NotImplementedError end @@ -34,39 +33,38 @@ module WithGit def destroy_and_sync destroy_from_git destroy - true end - def destroy_from_git - websites_with_fallback.each do |website| + def sync_with_git + websites_for_self.each do |website| identifiers(website: website).each do |identifier| - Communication::Website::GitFile.sync website, self, identifier, destroy: true - dependencies = send "git_destroy_dependencies_#{identifier}" + Communication::Website::GitFile.sync website, self, identifier + dependencies = send "git_dependencies_#{identifier}" dependencies.each do |object| - Communication::Website::GitFile.sync website, object, identifier, destroy: true + Communication::Website::GitFile.sync website, object, identifier end end website.git_repository.sync! end end + handle_asynchronously :sync_with_git - def sync_with_git - websites_with_fallback.each do |website| + def destroy_from_git + websites_for_self.each do |website| identifiers(website: website).each do |identifier| - Communication::Website::GitFile.sync website, self, identifier - dependencies = send "git_dependencies_#{identifier}" + Communication::Website::GitFile.sync website, self, identifier, destroy: true + dependencies = send "git_destroy_dependencies_#{identifier}" dependencies.each do |object| - Communication::Website::GitFile.sync website, object, identifier + Communication::Website::GitFile.sync website, object, identifier, destroy: true end end website.git_repository.sync! end end - handle_asynchronously :sync_with_git protected - def websites_with_fallback + def websites_for_self if is_a? Communication::Website [self] elsif respond_to?(:websites) diff --git a/app/services/git/repository.rb b/app/services/git/repository.rb index 41b23c809..913b19fc3 100644 --- a/app/services/git/repository.rb +++ b/app/services/git/repository.rb @@ -25,7 +25,7 @@ class Git::Repository protected - # TODO add gitlab + # Enhancement add gitlab def provider @provider ||= Git::Providers::Github.new(website&.access_token, website&.repository) end @@ -48,7 +48,7 @@ class Git::Repository def mark_as_synced git_files.each do |git_file| - git_file.update_columns previous_path: git_file.path, previous_sha: git_file.sha + git_file.update previous_path: git_file.path, previous_sha: git_file.sha end end end -- GitLab