discourse_theme 0.7.5 → 0.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa9710726909f2b5a1381132fb5e68748965bf8af6cf50893c013126e1c6db0d
4
- data.tar.gz: 6446feb3d912101d7193a07776d4aa5dc476fd00ef649e7b4c94e10e1ac21b56
3
+ metadata.gz: 0e35e35e07bf23d22d711e479ed3568c98e72605c66c4ca4001483210b34c582
4
+ data.tar.gz: 62558986574bbec90b1ac204b0d3209607b61c446e4283f1d4f06433e8526b91
5
5
  SHA512:
6
- metadata.gz: 72cead3a6060f62bc7e3fd225b82a98ee59e0852559506bcd2d5bd0f83196e4372ca1331c14654d51edc9ff20dad665a7c29777391db85789b4d6367b61a64ea
7
- data.tar.gz: 65b6d6b3d547867b706be85beab21f7d2a47daa521e1b9a5dbd71420a80126a32740f8f3286d5c6ab5c52ee85b92ea9e71a7395def9f2ed8ec4d6bc6aa7f0959
6
+ metadata.gz: 89e48b2369ccb4a573cbecdd4b8ab8eb2de7f1eca593e7e3546e5361870d337e03e302797ba4cc348bd7e0fdda5e5841bfd3c523aa1333bd1dda31e6e3ade558
7
+ data.tar.gz: 8d03a0c13e592886dbe17874b46c385e5c83d0cfcbf96c2ecbf7a1f694f5290092fb4ea27d4de92bb20f75eef9de4c0176b2684647c9e1cbd7e8f73c81242e5b
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.7.6] - 2023-09-16
9
+
10
+ ### Fixed
11
+
12
+ - Remove trailing slash when storing URL (#25)
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  module DiscourseTheme
3
3
  class Client
4
- THEME_CREATOR_REGEX = /^https:\/\/(theme-creator\.discourse\.org|discourse\.theme-creator\.io)$/i
4
+ THEME_CREATOR_REGEX =
5
+ %r{^https://(theme-creator\.discourse\.org|discourse\.theme-creator\.io)$}i
5
6
 
6
7
  attr_reader :url
7
8
 
@@ -23,17 +24,17 @@ module DiscourseTheme
23
24
 
24
25
  # From https://github.com/discourse/discourse/blob/main/lib/version.rb
25
26
  def self.has_needed_version?(current, needed)
26
- current_split = current.split('.')
27
- needed_split = needed.split('.')
27
+ current_split = current.split(".")
28
+ needed_split = needed.split(".")
28
29
 
29
30
  (0..[current_split.size, needed_split.size].max).each do |idx|
30
- current_str = current_split[idx] || ''
31
+ current_str = current_split[idx] || ""
31
32
 
32
- c0 = (needed_split[idx] || '').sub('beta', '').to_i
33
- c1 = (current_str || '').sub('beta', '').to_i
33
+ c0 = (needed_split[idx] || "").sub("beta", "").to_i
34
+ c1 = (current_str || "").sub("beta", "").to_i
34
35
 
35
36
  # beta is less than stable
36
- return false if current_str.include?('beta') && (c0 == 0) && (c1 > 0)
37
+ return false if current_str.include?("beta") && (c0 == 0) && (c1 > 0)
37
38
 
38
39
  return true if c1 > c0
39
40
  return false if c0 > c1
@@ -43,12 +44,7 @@ module DiscourseTheme
43
44
  end
44
45
 
45
46
  def get_themes_list
46
- endpoint = root +
47
- if @is_theme_creator
48
- "/user_themes.json"
49
- else
50
- "/admin/customize/themes.json"
51
- end
47
+ endpoint = root + (@is_theme_creator ? "/user_themes.json" : "/admin/customize/themes.json")
52
48
 
53
49
  response = request(Net::HTTP::Get.new(endpoint), never_404: true)
54
50
  json = JSON.parse(response.body)
@@ -56,12 +52,9 @@ module DiscourseTheme
56
52
  end
57
53
 
58
54
  def get_raw_theme_export(id)
59
- endpoint = root +
60
- if @is_theme_creator
61
- "/user_themes/#{id}/export"
62
- else
63
- "/admin/customize/themes/#{id}/export"
64
- end
55
+ endpoint =
56
+ root +
57
+ (@is_theme_creator ? "/user_themes/#{id}/export" : "/admin/customize/themes/#{id}/export")
65
58
 
66
59
  response = request(Net::HTTP::Get.new endpoint)
67
60
  raise "Error downloading theme: #{response.code}" unless response.code.to_i == 200
@@ -70,32 +63,24 @@ module DiscourseTheme
70
63
  end
71
64
 
72
65
  def update_theme(id, args)
73
- endpoint = root +
74
- if @is_theme_creator
75
- "/user_themes/#{id}"
76
- else
77
- "/admin/themes/#{id}"
78
- end
66
+ endpoint = root + (@is_theme_creator ? "/user_themes/#{id}" : "/admin/themes/#{id}")
79
67
 
80
- put = Net::HTTP::Put.new(endpoint, 'Content-Type' => 'application/json')
68
+ put = Net::HTTP::Put.new(endpoint, "Content-Type" => "application/json")
81
69
  put.body = args.to_json
82
70
  request(put)
83
71
  end
84
72
 
85
73
  def upload_full_theme(tgz, theme_id:, components:)
86
- endpoint = root +
87
- if @is_theme_creator
88
- "/user_themes/import.json"
89
- else
90
- "/admin/themes/import.json"
91
- end
92
-
93
- post = Net::HTTP::Post::Multipart.new(
94
- endpoint,
95
- "theme_id" => theme_id,
96
- "components" => components,
97
- "bundle" => UploadIO.new(tgz, "application/tar+gzip", "bundle.tar.gz")
98
- )
74
+ endpoint =
75
+ root + (@is_theme_creator ? "/user_themes/import.json" : "/admin/themes/import.json")
76
+
77
+ post =
78
+ Net::HTTP::Post::Multipart.new(
79
+ endpoint,
80
+ "theme_id" => theme_id,
81
+ "components" => components,
82
+ "bundle" => UploadIO.new(tgz, "application/tar+gzip", "bundle.tar.gz"),
83
+ )
99
84
  request(post)
100
85
  end
101
86
 
@@ -132,14 +117,21 @@ module DiscourseTheme
132
117
  http = Net::HTTP.new(uri.host, uri.port)
133
118
  http.use_ssl = URI::HTTPS === uri
134
119
  add_headers(request)
135
- http.request(request).tap do |response|
136
- if response.code == '404' && never_404
137
- raise DiscourseTheme::ThemeError.new "Error: Incorrect site URL, or API key does not have the correct privileges"
138
- elsif !['200', '201'].include?(response.code)
139
- errors = JSON.parse(response.body)["errors"].join(', ') rescue nil
140
- raise DiscourseTheme::ThemeError.new "Error #{response.code} for #{request.path.split("?")[0]}#{(": " + errors) if errors}"
120
+ http
121
+ .request(request)
122
+ .tap do |response|
123
+ if response.code == "404" && never_404
124
+ raise DiscourseTheme::ThemeError.new "Error: Incorrect site URL, or API key does not have the correct privileges"
125
+ elsif !%w[200 201].include?(response.code)
126
+ errors =
127
+ begin
128
+ JSON.parse(response.body)["errors"].join(", ")
129
+ rescue StandardError
130
+ nil
131
+ end
132
+ raise DiscourseTheme::ThemeError.new "Error #{response.code} for #{request.path.split("?")[0]}#{(": " + errors) if errors}"
133
+ end
141
134
  end
142
- end
143
135
  rescue Errno::ECONNREFUSED
144
136
  raise DiscourseTheme::ThemeError.new "Connection refused for #{request.path}"
145
137
  end
@@ -153,19 +145,17 @@ module DiscourseTheme
153
145
  end
154
146
 
155
147
  def guess_url(settings)
156
- url = ENV['DISCOURSE_URL']
157
- if url
158
- UI.progress "Using #{url} from DISCOURSE_URL"
159
- end
148
+ url = normalize_url(ENV["DISCOURSE_URL"])
149
+ UI.progress "Using #{url} from DISCOURSE_URL" if url
160
150
 
161
151
  if !url && settings.url
162
- url = settings.url
152
+ url = normalize_url(settings.url)
163
153
  UI.progress "Using #{url} from #{DiscourseTheme::Cli.settings_file}"
164
154
  end
165
155
 
166
156
  if !url || @reset
167
- url = UI.ask("What is the root URL of your Discourse site?", default: url).strip
168
- url = "http://#{url}" unless url =~ /^https?:\/\//
157
+ url = normalize_url(UI.ask("What is the root URL of your Discourse site?", default: url))
158
+ url = "http://#{url}" unless url =~ %r{^https?://}
169
159
 
170
160
  # maybe this is an HTTPS redirect
171
161
  uri = URI.parse(url)
@@ -184,11 +174,13 @@ module DiscourseTheme
184
174
  url
185
175
  end
186
176
 
177
+ def normalize_url(url)
178
+ url&.strip&.chomp("/")
179
+ end
180
+
187
181
  def guess_api_key(settings)
188
- api_key = ENV['DISCOURSE_API_KEY']
189
- if api_key
190
- UI.progress "Using api key from DISCOURSE_API_KEY"
191
- end
182
+ api_key = ENV["DISCOURSE_API_KEY"]
183
+ UI.progress "Using api key from DISCOURSE_API_KEY" if api_key
192
184
 
193
185
  if !api_key && settings.api_key
194
186
  api_key = settings.api_key
@@ -213,8 +205,7 @@ module DiscourseTheme
213
205
  path = "/" if path.empty?
214
206
  req = Net::HTTP::Get.new("/")
215
207
  response = Net::HTTP.start(url.host, url.port) { |http| http.request(req) }
216
- Net::HTTPRedirection === response && response['location'] =~ /^https/i
208
+ Net::HTTPRedirection === response && response["location"] =~ /^https/i
217
209
  end
218
-
219
210
  end
220
211
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module DiscourseTheme
3
- VERSION = "0.7.5"
3
+ VERSION = "0.7.6"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discourse_theme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.7.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-03 00:00:00.000000000 Z
11
+ date: 2023-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitar
@@ -217,6 +217,7 @@ files:
217
217
  - ".github/workflows/ci.yml"
218
218
  - ".gitignore"
219
219
  - ".rubocop.yml"
220
+ - CHANGELOG.md
220
221
  - CODE_OF_CONDUCT.md
221
222
  - Gemfile
222
223
  - Guardfile