Skip to content
Snippets Groups Projects
Commit 9958558b authored by Arnaud Levy's avatar Arnaud Levy
Browse files

fix

parent df3de0d4
No related branches found
No related tags found
No related merge requests found
...@@ -59,13 +59,13 @@ class Communication::Website::GitFile < ApplicationRecord ...@@ -59,13 +59,13 @@ class Communication::Website::GitFile < ApplicationRecord
end end
def path def path
about.send "git_path_#{identifier}" @path ||= about.send "git_path_#{identifier}"
end end
def sha def sha
# Git SHA-1 is calculated from the String "blob <length>\x00<contents>" # 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 # 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 end
def to_s def to_s
......
...@@ -8,7 +8,6 @@ module WithGit ...@@ -8,7 +8,6 @@ module WithGit
dependent: :destroy dependent: :destroy
end end
# Needs override
def git_path_static def git_path_static
raise NotImplementedError raise NotImplementedError
end end
...@@ -34,39 +33,38 @@ module WithGit ...@@ -34,39 +33,38 @@ module WithGit
def destroy_and_sync def destroy_and_sync
destroy_from_git destroy_from_git
destroy destroy
true
end end
def destroy_from_git def sync_with_git
websites_with_fallback.each do |website| websites_for_self.each do |website|
identifiers(website: website).each do |identifier| identifiers(website: website).each do |identifier|
Communication::Website::GitFile.sync website, self, identifier, destroy: true Communication::Website::GitFile.sync website, self, identifier
dependencies = send "git_destroy_dependencies_#{identifier}" dependencies = send "git_dependencies_#{identifier}"
dependencies.each do |object| dependencies.each do |object|
Communication::Website::GitFile.sync website, object, identifier, destroy: true Communication::Website::GitFile.sync website, object, identifier
end end
end end
website.git_repository.sync! website.git_repository.sync!
end end
end end
handle_asynchronously :sync_with_git
def sync_with_git def destroy_from_git
websites_with_fallback.each do |website| websites_for_self.each do |website|
identifiers(website: website).each do |identifier| identifiers(website: website).each do |identifier|
Communication::Website::GitFile.sync website, self, identifier Communication::Website::GitFile.sync website, self, identifier, destroy: true
dependencies = send "git_dependencies_#{identifier}" dependencies = send "git_destroy_dependencies_#{identifier}"
dependencies.each do |object| dependencies.each do |object|
Communication::Website::GitFile.sync website, object, identifier Communication::Website::GitFile.sync website, object, identifier, destroy: true
end end
end end
website.git_repository.sync! website.git_repository.sync!
end end
end end
handle_asynchronously :sync_with_git
protected protected
def websites_with_fallback def websites_for_self
if is_a? Communication::Website if is_a? Communication::Website
[self] [self]
elsif respond_to?(:websites) elsif respond_to?(:websites)
......
...@@ -25,7 +25,7 @@ class Git::Repository ...@@ -25,7 +25,7 @@ class Git::Repository
protected protected
# TODO add gitlab # Enhancement add gitlab
def provider def provider
@provider ||= Git::Providers::Github.new(website&.access_token, website&.repository) @provider ||= Git::Providers::Github.new(website&.access_token, website&.repository)
end end
...@@ -48,7 +48,7 @@ class Git::Repository ...@@ -48,7 +48,7 @@ class Git::Repository
def mark_as_synced def mark_as_synced
git_files.each do |git_file| 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 end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment