discourse_theme 0.7.4 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47b628418ce66dfc84cec377019bb57e6ab82a82d681acda24d5d69c4a20f64c
4
- data.tar.gz: 7bc2abbb64c101c59dc282f8cd24d340ca22a08ed805b4bd82d392f3a4358007
3
+ metadata.gz: 0e35e35e07bf23d22d711e479ed3568c98e72605c66c4ca4001483210b34c582
4
+ data.tar.gz: 62558986574bbec90b1ac204b0d3209607b61c446e4283f1d4f06433e8526b91
5
5
  SHA512:
6
- metadata.gz: 323c310d872c6c0efad7f2044404d3e53c754da50fbcba764cc52f32349f54c31a95ff7cb1dc756603dcd20215afb5801b5ab3c7654ec40962a67b725294983c
7
- data.tar.gz: 1be9095c46371db3ab45dcd090e49d3a8f09185d06da44b8f3421579255882acc1a2952d75a1f7078e3369fdf08e64f277a3a460018ec6aa0f86e4507c4bd8e7
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
 
@@ -112,7 +97,7 @@ module DiscourseTheme
112
97
  # confuse AWS albs
113
98
  parsed.user = nil
114
99
  parsed.password = nil
115
- parsed
100
+ parsed.to_s
116
101
  end
117
102
 
118
103
  def is_theme_creator
@@ -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.4"
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.4
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-01-25 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