FEATURE: add branch option to remote theme import

* FEATURE: add branch option to remote theme import

* FIX: Add missing variable in params

* FIX: Add missing param for import_theme method

* SPEC: Add test methods for branch support in git import

* FIX: Add missing space to scss style

* Do not assume default branch as master

* Change branch field placeholder

* FIX: add missing div start tag
This commit is contained in:
Erin Kosewic
2018-10-08 23:01:08 -07:00
committed by Sam
parent acba7d2a5d
commit 51aba32651
9 changed files with 99 additions and 18 deletions

View File

@@ -5,13 +5,14 @@ class ThemeStore::GitImporter
class ImportFailed < StandardError; end
attr_reader :url
def initialize(url, private_key: nil)
def initialize(url, private_key: nil, branch: nil)
@url = url
if @url.start_with?("https://github.com") && !@url.end_with?(".git")
@url += ".git"
end
@temp_folder = "#{Pathname.new(Dir.tmpdir).realpath}/discourse_theme_#{SecureRandom.hex}"
@private_key = private_key
@branch = branch
end
def import!
@@ -67,7 +68,11 @@ class ThemeStore::GitImporter
def import_public!
begin
Discourse::Utils.execute_command("git", "clone", @url, @temp_folder)
if @branch.present?
Discourse::Utils.execute_command("git", "clone", "--single-branch", "-b", @branch, @url, @temp_folder)
else
Discourse::Utils.execute_command("git", "clone", @url, @temp_folder)
end
rescue => err
raise ImportFailed.new(err.message)
end
@@ -83,9 +88,12 @@ class ThemeStore::GitImporter
end
begin
Discourse::Utils.execute_command({
'GIT_SSH_COMMAND' => "ssh -i #{ssh_folder}/id_rsa -o StrictHostKeyChecking=no"
}, "git", "clone", @url, @temp_folder)
git_ssh_command = { 'GIT_SSH_COMMAND' => "ssh -i #{ssh_folder}/id_rsa -o StrictHostKeyChecking=no" }
if @branch.present?
Discourse::Utils.execute_command(git_ssh_command, "git", "clone", "--single-branch", "-b", @branch, @url, @temp_folder)
else
Discourse::Utils.execute_command(git_ssh_command, "git", "clone", @url, @temp_folder)
end
rescue => err
raise ImportFailed.new(err.message)
end