diff --git a/app/models/communication/website/git_file.rb b/app/models/communication/website/git_file.rb index 99993d0e5b72ce8fcc5c8fe2258f3f41b6227288..0f414e31fab00a776f9593ba2cde9deb34f369da 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 5d505ed0033e01e1d1e373ba84f8c671a5b764ca..981a0b1022ac4e0762adb29d6bb1016316f45e32 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 41b23c809486c23048f2d0d3129ec28c723c6072..913b19fc3dcbe87aec82da3d9417135cf69bdc62 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