metanorma-release 0.2.18 → 0.2.20

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: ec89b09e8c3ae49b1d216cb7a07322b94f5d4da7cce71ccd72e7257074c35419
4
- data.tar.gz: 9fb37a76873418ca0e7cda9c4db6fe5362fbc892ba4589b01040979e1e83de49
3
+ metadata.gz: 01147610e009c11c2192cd56b2aed8fc731c2c002a9d6e35f91c61045197fcfe
4
+ data.tar.gz: 54e3c27c6e5f06a3c310a12e2e20e51080df1ffb3d577ec5a1f378904fc59fa6
5
5
  SHA512:
6
- metadata.gz: 30d808eb7dfdd285a1a19e272ccf9853930a6315cd2211cc1779f9a86d114fc7084a77ba5127aaf5b55bc386e8b67e99993c33c730a3f4cd6edd9308e959c7ae
7
- data.tar.gz: f020032152aa32a964b57080b8ff73a2b72bc9690d152cef3562b22df3d6dd832f4a8c9ceb617b515f0e43ac094660059794d71c5ed39c81a215aadfc258f989
6
+ metadata.gz: 294bfaa8b3772c8a4507c4168638b2aff9b2466592494ea68ed31abae6f205f41d038e0c9c946f7405711345921f9c6ae27e809d659e5b9b4485acc38850f6ca
7
+ data.tar.gz: '058a98333e8ee3506d93ed85d95a61a2c4a8316f53cebc85d2824968031a92b1b003b9bcbfcce697c42405e9f8a7e4061b343609b22ae22f6beed885f594dbba'
@@ -99,6 +99,7 @@ module Metanorma
99
99
  topic: @config.topic,
100
100
  repos: @config.repos,
101
101
  token: @config.token,
102
+ cache_dir: @config.cache_dir,
102
103
  )
103
104
 
104
105
  metadata_filter = MetadataFilter.new(
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "digest"
4
+
3
5
  module Metanorma
4
6
  module Release
5
7
  module Platform
@@ -13,8 +15,9 @@ module Metanorma
13
15
  class ReleaseFetcher
14
16
  include Metanorma::Release::ReleaseFetcher
15
17
 
16
- def initialize(client:)
18
+ def initialize(client:, download_cache_dir: nil)
17
19
  @client = client
20
+ @download_cache_dir = download_cache_dir
18
21
  end
19
22
 
20
23
  def fetch(repo, etag: nil)
@@ -67,11 +70,28 @@ module Metanorma
67
70
  end
68
71
 
69
72
  def download_asset(url)
70
- @client.get(url, accept: "application/octet-stream")
73
+ cache_path = cache_file_path(url)
74
+ if cache_path && File.exist?(cache_path)
75
+ return File.binread(cache_path)
76
+ end
77
+
78
+ data = @client.get(url, accept: "application/octet-stream")
79
+ if cache_path && data
80
+ FileUtils.mkdir_p(File.dirname(cache_path))
81
+ File.binwrite(cache_path, data)
82
+ end
83
+ data
71
84
  rescue StandardError => e
72
85
  warn "Warning: Failed to download asset #{url}: #{e.message}"
73
86
  nil
74
87
  end
88
+
89
+ def cache_file_path(url)
90
+ return nil unless @download_cache_dir
91
+
92
+ hash = Digest::SHA256.hexdigest(url)
93
+ File.join(@download_cache_dir, hash)
94
+ end
75
95
  end
76
96
  end
77
97
  end
@@ -31,9 +31,12 @@ module Metanorma
31
31
  )
32
32
  end
33
33
 
34
+ download_cache = opts[:cache_dir] ? File.join(opts[:cache_dir], "downloads") : nil
35
+
34
36
  {
35
37
  discoverer: discoverer,
36
- fetcher: Platform::GitHub::ReleaseFetcher.new(client: client),
38
+ fetcher: Platform::GitHub::ReleaseFetcher.new(client: client,
39
+ download_cache_dir: download_cache),
37
40
  manifest_reader: Platform::GitHub::ManifestReader.new(client: client),
38
41
  }
39
42
  },
@@ -102,6 +102,7 @@ module Metanorma
102
102
  }
103
103
  add_format_flags(base, formats)
104
104
  add_display_category(base, doctype)
105
+ add_contributors(base, bib)
105
106
  base
106
107
  end
107
108
 
@@ -169,6 +170,63 @@ module Metanorma
169
170
 
170
171
  @org_config.display_category_for(doctype)
171
172
  end
173
+
174
+ def add_contributors(hash, bib)
175
+ contribs = bib["contributor"] || []
176
+ persons, committees = partition_contributors(contribs)
177
+ hash["authors"] = persons
178
+ hash["committee"] = committees.first
179
+ end
180
+
181
+ def partition_contributors(contribs)
182
+ persons = contribs.filter_map { |c| parse_person(c) }
183
+ committees = contribs.filter_map { |c| parse_committee(c) }
184
+ [persons, committees]
185
+ end
186
+
187
+ def parse_person(contrib)
188
+ return nil unless contrib["person"]
189
+
190
+ name = extract_person_name(contrib["person"])
191
+ return nil unless name
192
+
193
+ role = (contrib["role"] || []).first&.fetch("type", nil)
194
+ { "name" => name, "role" => role }
195
+ end
196
+
197
+ def parse_committee(contrib)
198
+ return nil unless contrib["organization"]
199
+
200
+ extract_org_subdivision(contrib["organization"])
201
+ end
202
+
203
+ def extract_person_name(person)
204
+ n = person["name"] || {}
205
+ complete = n["completename"]
206
+ return complete["content"] if complete.is_a?(Hash) && complete["content"]
207
+ return complete if complete.is_a?(String)
208
+
209
+ surname = n["surname"]
210
+ given = n["given"]
211
+ given_str = given.is_a?(Hash) ? given["content"].to_s : given.to_s
212
+ parts = [given_str, surname].compact
213
+ parts.empty? ? nil : parts.join(" ")
214
+ end
215
+
216
+ def extract_org_subdivision(org)
217
+ subs = org["subdivision"]
218
+ return nil unless subs&.any?
219
+
220
+ sd = subs.first
221
+ sd_name = sd["name"]
222
+ if sd_name.is_a?(Array)
223
+ sd_name.first&.dig("content")
224
+ elsif sd_name.is_a?(Hash)
225
+ sd_name["content"]
226
+ else
227
+ sd_name.to_s
228
+ end
229
+ end
172
230
  end
173
231
  end
174
232
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Metanorma
4
4
  module Release
5
- VERSION = "0.2.18"
5
+ VERSION = "0.2.20"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-release
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.18
4
+ version: 0.2.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.