UX: Do not prepend `discourse` to theme filename if it's already there

UX: Do not prepend discourse to theme filename if it’s already there

diff --git a/lib/theme_store/tgz_exporter.rb b/lib/theme_store/tgz_exporter.rb
index 29083b7..deeaadb 100644
--- a/lib/theme_store/tgz_exporter.rb
+++ b/lib/theme_store/tgz_exporter.rb
@@ -5,7 +5,8 @@ class ThemeStore::TgzExporter
   def initialize(theme)
     @theme = theme
     @temp_folder = "#{Pathname.new(Dir.tmpdir).realpath}/discourse_theme_#{SecureRandom.hex}"
-    @export_name = "discourse-#{@theme.name.downcase.gsub(/[^0-9a-z.\-]/, '-')}-theme"
+    @export_name = "#{@theme.name.downcase.gsub(/[^0-9a-z.\-]/, '-')}-theme"
+    @export_name = "discourse-#{@export_name}" unless @export_name.starts_with?("discourse")
   end
 
   def package_filename
diff --git a/spec/components/theme_store/tgz_exporter_spec.rb b/spec/components/theme_store/tgz_exporter_spec.rb
index cde028d..12dd763 100644
--- a/spec/components/theme_store/tgz_exporter_spec.rb
+++ b/spec/components/theme_store/tgz_exporter_spec.rb
@@ -109,4 +109,12 @@ describe ThemeStore::TgzExporter do
     end.to raise_error(RuntimeError)
   end
 
+  it "doesn't prepend 'discourse' to filename if already there" do
+    theme.update!(name: "Discourse Header Icons")
+    exporter = ThemeStore::TgzExporter.new(theme)
+    filename = exporter.package_filename
+    exporter.cleanup!
+    expect(filename).to end_with "/discourse-header-icons-theme.tar.gz"
+  end
+
 end

GitHub sha: 99e0820c

2 Likes