shiplog 0.4.0 → 0.4.1
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/app/controllers/shiplog/changelogs_controller.rb +18 -6
- data/app/helpers/shiplog/newsletter_helper.rb +1 -6
- data/app/helpers/shiplog/permalink_helper.rb +7 -2
- data/app/helpers/shiplog/switcher_helper.rb +11 -6
- data/app/models/shiplog/sync/issue_importer.rb +1 -13
- data/app/models/shiplog/sync/node_attributes.rb +16 -0
- data/app/models/shiplog/sync/pull_request_importer.rb +1 -13
- data/lib/shiplog/configuration.rb +33 -29
- data/lib/shiplog/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6f136ae6482c03c3ef286c7e02828504c263b35d85dc4ac481d4e8d20cb627ee
|
|
4
|
+
data.tar.gz: 07e1028d26d35204930ba35cdfdd1ea482b571240f5af70aa5bdcfb0c06133ed
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '0957858697b4a81b7ba2cb8ab50cc26989c86785b223f3568bb6d303c7e7b4f08ae255929983dff097f919eb6cc686b67f5dd69ab05235f6a4956d1b38499d15'
|
|
7
|
+
data.tar.gz: f562886d8307ac110e96e0c71fa276c59254bf0f40bf71313e4e9f7792e2182f988e140f4a84e67f4f91518c7ce429c421358a80124cf39c58a416c661800221
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.1 (2026-11-08)
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Internal refactors with no change in behaviour: the issue and pull request importers share their find-or-build-and-save step, `ChangelogsController#show` extracts its scope and ETag parts, the configuration validates callable setters and extra pages through shared helpers, and the once-per-page stylesheet link and the permalink's entry-and-locale callables each live in one place.
|
|
8
|
+
|
|
3
9
|
## 0.4.0 (2026-10-27)
|
|
4
10
|
|
|
5
11
|
### Added
|
|
@@ -8,10 +8,8 @@ module Shiplog
|
|
|
8
8
|
|
|
9
9
|
def show
|
|
10
10
|
@page = page_number
|
|
11
|
-
scope = Entry.published_changelog.newest_first
|
|
12
11
|
@query = search_query
|
|
13
|
-
scope =
|
|
14
|
-
scope = scope.where(area_id: @area.id) if @area
|
|
12
|
+
scope = filtered_scope
|
|
15
13
|
@areas = filter_areas
|
|
16
14
|
records = scope.includes(:area).with_images_loaded.offset((@page - 1) * PER_PAGE).limit(PER_PAGE + 1).to_a
|
|
17
15
|
return head(:not_found) if @page > 1 && records.empty?
|
|
@@ -23,14 +21,28 @@ module Shiplog
|
|
|
23
21
|
shown = @months.values.flatten
|
|
24
22
|
@announcements = announcements_for(@months.keys)
|
|
25
23
|
preload_translations(shown)
|
|
26
|
-
fresh_when etag:
|
|
24
|
+
fresh_when etag: changelog_etag_parts(shown)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
# The published entries, narrowed to the search query and the area filter when there are any.
|
|
30
|
+
def filtered_scope
|
|
31
|
+
scope = Entry.published_changelog.newest_first
|
|
32
|
+
scope = scope.search(@query, locale: I18n.locale) if @query
|
|
33
|
+
scope = scope.where(area_id: @area.id) if @area
|
|
34
|
+
scope
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# What the page shows beyond the data every public page depends on: the filters, the page, the entries shown
|
|
38
|
+
# (with their images and translations) and the announcements of their months.
|
|
39
|
+
def changelog_etag_parts(shown)
|
|
40
|
+
[ *shiplog_etag_parts, *shiplog_area_etag_parts, @areas.map(&:id), @query, @page, @older,
|
|
27
41
|
shown.map { |entry| [ entry.id, entry.updated_at, entry.area_id ] },
|
|
28
42
|
shiplog_image_etag_parts(shown), shiplog_translation_etag_parts(shown),
|
|
29
43
|
@announcements.values.map { |announcement| [ announcement.id, announcement.slug, announcement.updated_at ] } ]
|
|
30
44
|
end
|
|
31
45
|
|
|
32
|
-
private
|
|
33
|
-
|
|
34
46
|
# The approved announcements of the months shown, by the month's first day (none while announcements are off).
|
|
35
47
|
def announcements_for(months)
|
|
36
48
|
return {} unless Shiplog.announcements? && months.any?
|
|
@@ -11,12 +11,7 @@ module Shiplog
|
|
|
11
11
|
def shiplog_newsletter_form(source: nil)
|
|
12
12
|
return "".html_safe unless Shiplog.newsletter?
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
@_shiplog_stylesheet_emitted = true
|
|
16
|
-
tag.link(rel: "stylesheet", nonce: content_security_policy_nonce,
|
|
17
|
-
href: shiplog_routes.frontend_path(version: Shiplog::VERSION, name: "shiplog.css"))
|
|
18
|
-
end
|
|
19
|
-
safe_join([ stylesheet, render("shiplog/newsletter/form", source:) ])
|
|
14
|
+
safe_join([ shiplog_stylesheet_link_once, render("shiplog/newsletter/form", source:) ])
|
|
20
15
|
end
|
|
21
16
|
|
|
22
17
|
# The form's action, in the engine's pages and the host's alike.
|
|
@@ -46,7 +46,7 @@ module Shiplog
|
|
|
46
46
|
callable = Shiplog.config.announcement_url
|
|
47
47
|
return unless Shiplog.config.announcements == :external && callable
|
|
48
48
|
|
|
49
|
-
value = callable
|
|
49
|
+
value = shiplog_call_with_locale(callable, announcement)
|
|
50
50
|
value if Shiplog::Configuration.safe_url?(value)
|
|
51
51
|
rescue StandardError => error
|
|
52
52
|
Rails.logger.error("[shiplog] config.announcement_url failed for entry #{announcement.id}: #{error.class}: #{error.message}")
|
|
@@ -90,7 +90,7 @@ module Shiplog
|
|
|
90
90
|
callable = Shiplog.config.og_image
|
|
91
91
|
return unless callable
|
|
92
92
|
|
|
93
|
-
value = callable
|
|
93
|
+
value = shiplog_call_with_locale(callable, entry)
|
|
94
94
|
url = shiplog_absolute_http_url(value)
|
|
95
95
|
Rails.logger.warn("[shiplog] config.og_image ignored for entry #{entry.id}: expected an http(s) URL or a path, got #{value.inspect}") unless url
|
|
96
96
|
url
|
|
@@ -99,6 +99,11 @@ module Shiplog
|
|
|
99
99
|
nil
|
|
100
100
|
end
|
|
101
101
|
|
|
102
|
+
# A config callable called with an entry and the locale. A Proc runs in the view, so it can use route helpers.
|
|
103
|
+
def shiplog_call_with_locale(callable, entry)
|
|
104
|
+
callable.is_a?(Proc) ? instance_exec(entry, I18n.locale, &callable) : callable.call(entry, I18n.locale)
|
|
105
|
+
end
|
|
106
|
+
|
|
102
107
|
# An http(s) URL as is, a path ("/cards/a.png", not "//host") made absolute with config.canonical_url or the
|
|
103
108
|
# request's origin; nil for anything else (javascript:, data:, blank, spaces, non-strings).
|
|
104
109
|
def shiplog_absolute_http_url(value)
|
|
@@ -35,12 +35,7 @@ module Shiplog
|
|
|
35
35
|
# The switcher for host pages: the bundled stylesheet (once per page, and not when the engine page already
|
|
36
36
|
# linked it; unless config.stylesheet is false) and the nav.
|
|
37
37
|
def shiplog_switcher
|
|
38
|
-
|
|
39
|
-
@_shiplog_stylesheet_emitted = true
|
|
40
|
-
tag.link(rel: "stylesheet", nonce: content_security_policy_nonce,
|
|
41
|
-
href: shiplog_routes.frontend_path(version: Shiplog::VERSION, name: "shiplog.css"))
|
|
42
|
-
end
|
|
43
|
-
safe_join([ stylesheet, render("shiplog/switcher") ])
|
|
38
|
+
safe_join([ shiplog_stylesheet_link_once, render("shiplog/switcher") ])
|
|
44
39
|
end
|
|
45
40
|
|
|
46
41
|
# The nav's aria-label: a plain String (never html_safe markup, never a translation-missing span).
|
|
@@ -73,6 +68,16 @@ module Shiplog
|
|
|
73
68
|
|
|
74
69
|
private
|
|
75
70
|
|
|
71
|
+
# The bundled stylesheet's link the first time a page asks for it (nil after that, or when config.stylesheet
|
|
72
|
+
# is false).
|
|
73
|
+
def shiplog_stylesheet_link_once
|
|
74
|
+
return unless Shiplog.config.stylesheet && !@_shiplog_stylesheet_emitted
|
|
75
|
+
|
|
76
|
+
@_shiplog_stylesheet_emitted = true
|
|
77
|
+
tag.link(rel: "stylesheet", nonce: content_security_policy_nonce,
|
|
78
|
+
href: shiplog_routes.frontend_path(version: Shiplog::VERSION, name: "shiplog.css"))
|
|
79
|
+
end
|
|
80
|
+
|
|
76
81
|
# Where the engine's route helpers live: the view itself inside the engine's own pages, otherwise (host pages)
|
|
77
82
|
# the proxy the host's mount defined, whatever its name.
|
|
78
83
|
def shiplog_routes
|
|
@@ -5,19 +5,7 @@ module Shiplog
|
|
|
5
5
|
|
|
6
6
|
def initialize(repository) = @repository = repository
|
|
7
7
|
|
|
8
|
-
def import(node)
|
|
9
|
-
with_race_retry do
|
|
10
|
-
issue = Issue.find_by(node_id: node["id"])
|
|
11
|
-
issue&.lock!
|
|
12
|
-
issue ||= Issue.new(node_id: node["id"])
|
|
13
|
-
next issue if stale?(issue, node)
|
|
14
|
-
|
|
15
|
-
issue.assign_attributes(attributes_for(node))
|
|
16
|
-
issue.save!
|
|
17
|
-
replace_links(issue, node)
|
|
18
|
-
issue
|
|
19
|
-
end
|
|
20
|
-
end
|
|
8
|
+
def import(node) = import_record(Issue, node)
|
|
21
9
|
|
|
22
10
|
private
|
|
23
11
|
|
|
@@ -17,6 +17,22 @@ module Shiplog
|
|
|
17
17
|
node.dig("author", "__typename") == "Bot" && login ? "#{login}[bot]" : login
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
+
# Finds or builds the record of a GraphQL node and saves it from attributes_for(node), then replace_links, in a
|
|
21
|
+
# race-safe transaction. A record already updated later than the node (a stale payload) is returned untouched.
|
|
22
|
+
def import_record(model, node)
|
|
23
|
+
with_race_retry do
|
|
24
|
+
record = model.find_by(node_id: node["id"])
|
|
25
|
+
record&.lock!
|
|
26
|
+
record ||= model.new(node_id: node["id"])
|
|
27
|
+
next record if stale?(record, node)
|
|
28
|
+
|
|
29
|
+
record.assign_attributes(attributes_for(node))
|
|
30
|
+
record.save!
|
|
31
|
+
replace_links(record, node)
|
|
32
|
+
record
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
20
36
|
def stale?(record, node)
|
|
21
37
|
record.persisted? && record.github_updated_at && record.github_updated_at > Time.iso8601(node["updatedAt"])
|
|
22
38
|
end
|
|
@@ -7,19 +7,7 @@ module Shiplog
|
|
|
7
7
|
|
|
8
8
|
def initialize(repository) = @repository = repository
|
|
9
9
|
|
|
10
|
-
def import(node)
|
|
11
|
-
with_race_retry do
|
|
12
|
-
pull_request = PullRequest.find_by(node_id: node["id"])
|
|
13
|
-
pull_request&.lock!
|
|
14
|
-
pull_request ||= PullRequest.new(node_id: node["id"])
|
|
15
|
-
next pull_request if stale?(pull_request, node)
|
|
16
|
-
|
|
17
|
-
pull_request.assign_attributes(attributes_for(node))
|
|
18
|
-
pull_request.save!
|
|
19
|
-
replace_links(pull_request, node)
|
|
20
|
-
pull_request
|
|
21
|
-
end
|
|
22
|
-
end
|
|
10
|
+
def import(node) = import_record(PullRequest, node)
|
|
23
11
|
|
|
24
12
|
private
|
|
25
13
|
|
|
@@ -127,21 +127,7 @@ module Shiplog
|
|
|
127
127
|
# evaluated in the view (instance_exec), e.g. `path: -> { main_app.news_path }`.
|
|
128
128
|
def extra_pages=(value)
|
|
129
129
|
raise ArgumentError, "extra_pages must be an Array of { label:, path: } Hashes, got #{value.inspect}" unless value.nil? || value.is_a?(Array)
|
|
130
|
-
pages = (value || []).map
|
|
131
|
-
raise ArgumentError, "Each extra page must be a Hash with :label and :path, got #{page.inspect}" unless page.is_a?(Hash)
|
|
132
|
-
page = page.to_h.transform_keys { |key| key.to_s.to_sym }
|
|
133
|
-
unless page.keys.sort == EXTRA_PAGE_KEYS
|
|
134
|
-
raise ArgumentError, "An extra page needs exactly the keys :label and :path, got #{page.keys.inspect}"
|
|
135
|
-
end
|
|
136
|
-
page.each do |key, item|
|
|
137
|
-
valid = item.respond_to?(:call) || (item.is_a?(String) && item.present?)
|
|
138
|
-
raise ArgumentError, "Extra page #{key} must be a non-empty String or a callable, got #{item.inspect}" unless valid
|
|
139
|
-
if key == :path && item.is_a?(String) && !self.class.safe_url?(item)
|
|
140
|
-
raise ArgumentError, "Extra page path must be relative (/...), http(s):// or mailto:, got #{item.inspect}"
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
{ label: page[:label], path: page[:path] }.freeze
|
|
144
|
-
end
|
|
130
|
+
pages = (value || []).map { |page| normalize_extra_page(page) }
|
|
145
131
|
@extra_pages = pages.freeze
|
|
146
132
|
end
|
|
147
133
|
|
|
@@ -205,8 +191,7 @@ module Shiplog
|
|
|
205
191
|
end
|
|
206
192
|
|
|
207
193
|
def og_image=(value)
|
|
208
|
-
|
|
209
|
-
@og_image = value
|
|
194
|
+
@og_image = optional_callable!(:og_image, value, "like ->(entry, locale) { url }")
|
|
210
195
|
end
|
|
211
196
|
|
|
212
197
|
def announcements=(value)
|
|
@@ -218,18 +203,15 @@ module Shiplog
|
|
|
218
203
|
end
|
|
219
204
|
|
|
220
205
|
def announcement_url=(value)
|
|
221
|
-
|
|
222
|
-
@announcement_url = value
|
|
206
|
+
@announcement_url = optional_callable!(:announcement_url, value, "like ->(announcement, locale) { url }")
|
|
223
207
|
end
|
|
224
208
|
|
|
225
209
|
def on_announcement_approved=(value)
|
|
226
|
-
|
|
227
|
-
@on_announcement_approved = value
|
|
210
|
+
@on_announcement_approved = optional_callable!(:on_announcement_approved, value, "like ->(announcement) { ... }")
|
|
228
211
|
end
|
|
229
212
|
|
|
230
213
|
def on_changelog_seen=(value)
|
|
231
|
-
|
|
232
|
-
@on_changelog_seen = value
|
|
214
|
+
@on_changelog_seen = optional_callable!(:on_changelog_seen, value)
|
|
233
215
|
end
|
|
234
216
|
|
|
235
217
|
def newsletter=(value)
|
|
@@ -238,18 +220,15 @@ module Shiplog
|
|
|
238
220
|
end
|
|
239
221
|
|
|
240
222
|
def newsletter_recipients=(value)
|
|
241
|
-
|
|
242
|
-
@newsletter_recipients = value
|
|
223
|
+
@newsletter_recipients = optional_callable!(:newsletter_recipients, value, "like -> { User.where(newsletter: true) }")
|
|
243
224
|
end
|
|
244
225
|
|
|
245
226
|
def newsletter_unsubscribe_url=(value)
|
|
246
|
-
|
|
247
|
-
@newsletter_unsubscribe_url = value
|
|
227
|
+
@newsletter_unsubscribe_url = optional_callable!(:newsletter_unsubscribe_url, value, "like ->(recipient) { url }")
|
|
248
228
|
end
|
|
249
229
|
|
|
250
230
|
def on_newsletter_unsubscribe=(value)
|
|
251
|
-
|
|
252
|
-
@on_newsletter_unsubscribe = value
|
|
231
|
+
@on_newsletter_unsubscribe = optional_callable!(:on_newsletter_unsubscribe, value, "like ->(email) { ... }")
|
|
253
232
|
end
|
|
254
233
|
|
|
255
234
|
def newsletter_from=(value)
|
|
@@ -406,6 +385,13 @@ module Shiplog
|
|
|
406
385
|
|
|
407
386
|
private
|
|
408
387
|
|
|
388
|
+
# Nil or anything that responds to #call; anything else raises.
|
|
389
|
+
def optional_callable!(setting, value, hint = nil)
|
|
390
|
+
return value if value.nil? || value.respond_to?(:call)
|
|
391
|
+
|
|
392
|
+
raise ArgumentError, "#{setting} must be nil or a callable#{" #{hint}" if hint}, got #{value.inspect}"
|
|
393
|
+
end
|
|
394
|
+
|
|
409
395
|
# Nil (also for a blank String) or a stripped non-empty String; anything else raises.
|
|
410
396
|
def optional_string!(setting, value, hint)
|
|
411
397
|
return if value.nil? || (value.is_a?(String) && value.strip.empty?)
|
|
@@ -414,6 +400,24 @@ module Shiplog
|
|
|
414
400
|
value.strip
|
|
415
401
|
end
|
|
416
402
|
|
|
403
|
+
# One extra page as a frozen { label:, path: } Hash, or an ArgumentError when it is not a Hash with exactly those
|
|
404
|
+
# keys, a label and path that are non-empty Strings or callables, and (for a String) a safe path.
|
|
405
|
+
def normalize_extra_page(page)
|
|
406
|
+
raise ArgumentError, "Each extra page must be a Hash with :label and :path, got #{page.inspect}" unless page.is_a?(Hash)
|
|
407
|
+
page = page.to_h.transform_keys { |key| key.to_s.to_sym }
|
|
408
|
+
unless page.keys.sort == EXTRA_PAGE_KEYS
|
|
409
|
+
raise ArgumentError, "An extra page needs exactly the keys :label and :path, got #{page.keys.inspect}"
|
|
410
|
+
end
|
|
411
|
+
page.each do |key, item|
|
|
412
|
+
valid = item.respond_to?(:call) || (item.is_a?(String) && item.present?)
|
|
413
|
+
raise ArgumentError, "Extra page #{key} must be a non-empty String or a callable, got #{item.inspect}" unless valid
|
|
414
|
+
if key == :path && item.is_a?(String) && !self.class.safe_url?(item)
|
|
415
|
+
raise ArgumentError, "Extra page path must be relative (/...), http(s):// or mailto:, got #{item.inspect}"
|
|
416
|
+
end
|
|
417
|
+
end
|
|
418
|
+
{ label: page[:label], path: page[:path] }.freeze
|
|
419
|
+
end
|
|
420
|
+
|
|
417
421
|
def normalize_canonical_url(value)
|
|
418
422
|
return if value.nil? || (value.is_a?(String) && value.strip.empty?)
|
|
419
423
|
raise ArgumentError, "canonical_url must be a String like \"https://example.com\", got #{value.inspect}" unless value.is_a?(String)
|
data/lib/shiplog/version.rb
CHANGED