Skip to content
Snippets Groups Projects
Unverified Commit d0c3a39f authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

update theme version

parent 92c3459d
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -28,6 +28,10 @@ class Git::Providers::Abstract
raise NotImplementedError
end
def update_theme
raise NotImplementedError
end
def push(commit_message)
raise NotImplementedError
end
......
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
......
......@@ -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)
......
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