diff --git a/app/models/communication/website/with_git_repository.rb b/app/models/communication/website/with_git_repository.rb index 36b9649903435f0530dcee93025d5891d4d80f0c..e78f7db898bc0b3424258651ab17ef2208915282 100644 --- a/app/models/communication/website/with_git_repository.rb +++ b/app/models/communication/website/with_git_repository.rb @@ -49,6 +49,11 @@ module Communication::Website::WithGitRepository (saved_change_to_about_id? && about_id_before_last_save.present?) || language_was_removed end + def update_theme_version + git_repository.update_theme_version! + end + handle_asynchronously :update_theme_version, queue: :default + protected def add_direct_source_to_sync(direct_source) diff --git a/app/services/git/providers/abstract.rb b/app/services/git/providers/abstract.rb index cd53c2d0d9b31ad20a09dc7f1de4241f7be85f31..ceb8a34233d77c6fbd425b6bf253b2435ab0ad13 100644 --- a/app/services/git/providers/abstract.rb +++ b/app/services/git/providers/abstract.rb @@ -28,6 +28,10 @@ class Git::Providers::Abstract raise NotImplementedError end + def update_theme + raise NotImplementedError + end + def push(commit_message) raise NotImplementedError end diff --git a/app/services/git/providers/github.rb b/app/services/git/providers/github.rb index 407dc39a7633ba4a7cfc52d06b43238cfbb550ca..6dc2f4f809fbf54051205a74ef88513cf35b5849 100644 --- a/app/services/git/providers/github.rb +++ b/app/services/git/providers/github.rb @@ -1,5 +1,8 @@ class Git::Providers::Github < Git::Providers::Abstract BASE_URL = "https://github.com".freeze + THEME_REPOSITORY = "noesya/osuny-hugo-theme-aaa".freeze + THEME_BRANCH = "main".freeze + THEME_PATH = "themes/osuny-hugo-theme-aaa".freeze def url "#{BASE_URL}/#{repository}" @@ -44,6 +47,16 @@ class Git::Providers::Github < Git::Providers::Abstract } end + def update_theme + previous_theme_sha = git_sha(THEME_PATH) + batch << { + path: THEME_PATH, + mode: '160000', + type: 'commit', + sha: current_theme_sha + } if previous_theme_sha != current_theme_sha + end + def push(commit_message) return if !valid? || batch.empty? new_tree = client.create_tree repository, batch, base_tree: tree[:sha] @@ -91,6 +104,10 @@ class Git::Providers::Github < Git::Providers::Abstract @branch_sha ||= client.branch(repository, default_branch)[:commit][:sha] end + def current_theme_sha + @current_theme_sha ||= client.branch(THEME_REPOSITORY, THEME_BRANCH)[:commit][:sha] + end + def tree_item_at_path(path) tree_items_by_path[path] if tree_items_by_path.has_key? path end diff --git a/app/services/git/repository.rb b/app/services/git/repository.rb index 5ccb56b744ea25bf75136cd12b5f2563bd72d82c..9ee604fc44820767a9ee2d179b0843e2ebafb4aa 100644 --- a/app/services/git/repository.rb +++ b/app/services/git/repository.rb @@ -26,6 +26,11 @@ class Git::Repository mark_as_synced if provider.push(commit_message) end + def update_theme_version! + provider.update_theme + provider.push("Updated osuny-hugo-theme-aaa version") + end + # Based on content, with the provider's algorithm (sha1 or sha256) def computed_sha(string) provider.computed_sha(string)