diff --git a/app/services/git/providers/abstract.rb b/app/services/git/providers/abstract.rb index e3bdd555ac..294b336cf5 100644 --- a/app/services/git/providers/abstract.rb +++ b/app/services/git/providers/abstract.rb @@ -29,8 +29,8 @@ def destroy_file(path) raise NoMethodError, "You must implement the `destroy_file` method in #{self.class.name}" end - def update_theme - raise NoMethodError, "You must implement the `update_theme` method in #{self.class.name}" + def update_theme! + raise NoMethodError, "You must implement the `update_theme!` method in #{self.class.name}" end def push(commit_message) @@ -58,4 +58,21 @@ def files_in_the_repository def batch @batch ||= [] end + + def current_theme_sha + @current_theme_sha ||= Osuny::ThemeInfo.get_current_sha + end + + def previous_theme_sha + @previous_theme_sha ||= git_sha(ENV["GITHUB_WEBSITE_THEME_PATH"]) + end + + def should_update_theme? + previous_theme_sha != current_theme_sha + end + + def theme_update_commit_message + theme_name = ENV["GITHUB_WEBSITE_THEME_REPOSITORY"].to_s.split("/").last + "Updated #{theme_name} version" + end end diff --git a/app/services/git/providers/github.rb b/app/services/git/providers/github.rb index 3c0346617f..edf5572297 100644 --- a/app/services/git/providers/github.rb +++ b/app/services/git/providers/github.rb @@ -3,7 +3,6 @@ class Git::Providers::Github < Git::Providers::Abstract COMMIT_BATCH_SIZE = 30 include WithSecrets - include WithTheme def url "#{BASE_URL}/#{repository}" @@ -56,6 +55,17 @@ def destroy_file(path) } end + def update_theme! + return unless should_update_theme? + batch << { + path: ENV["GITHUB_WEBSITE_THEME_PATH"], + mode: '160000', + type: 'commit', + sha: current_theme_sha + } + push(theme_update_commit_message) + end + def init_from_template(name) client.create_repository_from_template( ENV['GITHUB_WEBSITE_TEMPLATE_REPOSITORY'], diff --git a/app/services/git/providers/github/with_theme.rb b/app/services/git/providers/github/with_theme.rb deleted file mode 100644 index db55f279da..0000000000 --- a/app/services/git/providers/github/with_theme.rb +++ /dev/null @@ -1,22 +0,0 @@ -module Git::Providers::Github::WithTheme - extend ActiveSupport::Concern - - def update_theme - batch << { - path: ENV["GITHUB_WEBSITE_THEME_PATH"], - mode: '160000', - type: 'commit', - sha: current_theme_sha - } if previous_theme_sha != current_theme_sha - end - - protected - - def current_theme_sha - @current_theme_sha ||= Osuny::ThemeInfo.get_current_sha - end - - def previous_theme_sha - @previous_theme_sha ||= git_sha(ENV["GITHUB_WEBSITE_THEME_PATH"]) - end -end \ No newline at end of file diff --git a/app/services/git/providers/gitlab.rb b/app/services/git/providers/gitlab.rb index 7cf2c5c0c9..67144b8f15 100644 --- a/app/services/git/providers/gitlab.rb +++ b/app/services/git/providers/gitlab.rb @@ -40,8 +40,15 @@ def destroy_file(path) } end - def update_theme - raise NoMethodError, "You must implement the `update_theme` method in #{self.class.name}" + def update_theme! + return unless should_update_theme? + client.edit_submodule repository, + ENV["GITHUB_WEBSITE_THEME_PATH"], + { + branch: branch, + commit_sha: current_theme_sha, + commit_message: theme_update_commit_message + } end def init_from_template(name) diff --git a/app/services/git/repository.rb b/app/services/git/repository.rb index c458892e8f..29073b4186 100644 --- a/app/services/git/repository.rb +++ b/app/services/git/repository.rb @@ -24,9 +24,7 @@ def sync! end def update_theme_version! - provider.update_theme - theme_name = ENV["GITHUB_WEBSITE_THEME_REPOSITORY"].to_s.split("/").last - provider.push("Updated #{theme_name} version") + provider.update_theme! end # Based on content, with the provider's algorithm (sha1 or sha256)