Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions app/services/git/providers/abstract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
12 changes: 11 additions & 1 deletion app/services/git/providers/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ class Git::Providers::Github < Git::Providers::Abstract
COMMIT_BATCH_SIZE = 30

include WithSecrets
include WithTheme

def url
"#{BASE_URL}/#{repository}"
Expand Down Expand Up @@ -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'],
Expand Down
22 changes: 0 additions & 22 deletions app/services/git/providers/github/with_theme.rb

This file was deleted.

11 changes: 9 additions & 2 deletions app/services/git/providers/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions app/services/git/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading