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
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
......
......@@ -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)
......
......@@ -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
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