glossarist 2.14.15 → 2.14.17
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/.github/workflows/release.yml +7 -0
- data/docs/data-format.adoc +22 -8
- data/glossarist.gemspec +3 -0
- data/lib/glossarist/cli/proposal_command.rb +131 -0
- data/lib/glossarist/cli/units_import_command.rb +40 -0
- data/lib/glossarist/cli.rb +40 -0
- data/lib/glossarist/concept.rb +4 -0
- data/lib/glossarist/default_materialization.rb +62 -0
- data/lib/glossarist/errors/invalid_proposal_error.rb +10 -0
- data/lib/glossarist/errors.rb +1 -0
- data/lib/glossarist/gcr_metadata.rb +5 -0
- data/lib/glossarist/managed_concept.rb +4 -0
- data/lib/glossarist/managed_concept_collection.rb +5 -0
- data/lib/glossarist/proposals/change.rb +44 -0
- data/lib/glossarist/proposals/git_bridge.rb +78 -0
- data/lib/glossarist/proposals/github_bridge.rb +76 -0
- data/lib/glossarist/proposals/payload.rb +25 -0
- data/lib/glossarist/proposals/pr_description.rb +51 -0
- data/lib/glossarist/proposals.rb +15 -0
- data/lib/glossarist/register_data.rb +7 -1
- data/lib/glossarist/resolution_adapter/bibliography.rb +6 -1
- data/lib/glossarist/sts/importer.rb +9 -9
- data/lib/glossarist/units/ingestor.rb +428 -0
- data/lib/glossarist/units/quantity_kind.rb +49 -0
- data/lib/glossarist/units/unit.rb +58 -0
- data/lib/glossarist/units/unit_prefix.rb +42 -0
- data/lib/glossarist/units.rb +21 -0
- data/lib/glossarist/v1/concept.rb +3 -0
- data/lib/glossarist/v1/cross_references.rb +3 -0
- data/lib/glossarist/v2/localized_concept.rb +5 -0
- data/lib/glossarist/v2/managed_concept.rb +5 -0
- data/lib/glossarist/v3/localized_concept.rb +5 -0
- data/lib/glossarist/v3/managed_concept.rb +5 -0
- data/lib/glossarist/version.rb +1 -1
- data/lib/glossarist.rb +3 -0
- metadata +31 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 491de16e587a90ca1acf8f2b038f000e78b3e5481ffaa13c958eb373ad0be707
|
|
4
|
+
data.tar.gz: dce9098ee3a79be528d436e2a52d72ee4d9e4c86379350e82b2017c0c9137088
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 246ffe012bb8be5df7c00601147eb6109d0974eddf3475bcacc8d53314264bc44e605c035bcbdccf9441caf4475a76c97b977bc9ffecd3119e3287036eac720e
|
|
7
|
+
data.tar.gz: 2abb2430868d5b48b3077d8da4ceb2f30cc31008375a8a32d05ee12d5f0445b4af2e4c2922440b29f7cf72a8da4a2ef72fb80a0b106f8c17908b44ad57c22c42
|
|
@@ -3,6 +3,7 @@ name: release
|
|
|
3
3
|
permissions:
|
|
4
4
|
contents: write
|
|
5
5
|
id-token: write
|
|
6
|
+
pull-requests: write
|
|
6
7
|
|
|
7
8
|
on:
|
|
8
9
|
workflow_dispatch:
|
|
@@ -15,6 +16,12 @@ on:
|
|
|
15
16
|
default: 'skip'
|
|
16
17
|
repository_dispatch:
|
|
17
18
|
types: [ do-release ]
|
|
19
|
+
# The publish leg: when the release PR (head branch release/v*) merges,
|
|
20
|
+
# metanorma/ci tags the merge commit and publishes (metanorma/ci#515).
|
|
21
|
+
# Ordinary PR closes are skipped inside the reusable workflow.
|
|
22
|
+
pull_request:
|
|
23
|
+
types:
|
|
24
|
+
- closed
|
|
18
25
|
|
|
19
26
|
jobs:
|
|
20
27
|
release:
|
data/docs/data-format.adoc
CHANGED
|
@@ -150,24 +150,38 @@ Both snake_case and camelCase keys are accepted on read; the writer emits snake_
|
|
|
150
150
|
|
|
151
151
|
== Relations (relations/)
|
|
152
152
|
|
|
153
|
-
One file per n-ary relation, named `<slug>.yaml` under the comprehensive concept's id:
|
|
153
|
+
One file per n-ary relation (hyperedge), named `<criterion-slug>.yaml` under the comprehensive concept's id. The `type` field distinguishes the relation kind (`partitive_relation`, `generic_relation`, ...):
|
|
154
154
|
|
|
155
155
|
[,yaml]
|
|
156
156
|
----
|
|
157
157
|
---
|
|
158
|
+
type: partitive_relation
|
|
158
159
|
comprehensive:
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
source: VIM
|
|
161
|
+
id: '112-02-09'
|
|
162
|
+
members:
|
|
163
|
+
- ref:
|
|
164
|
+
source: VIM
|
|
165
|
+
id: '112-02-10'
|
|
166
|
+
presence: required # or optional (ISO 704 line style)
|
|
167
|
+
count: exactly_one # or at_least_one / multiple
|
|
163
168
|
is_delimiting: false
|
|
164
|
-
- ref:
|
|
169
|
+
- ref:
|
|
170
|
+
source: VIM
|
|
171
|
+
id: '112-03-26'
|
|
165
172
|
completeness: complete # or partial
|
|
166
173
|
criterion:
|
|
167
|
-
eng:
|
|
174
|
+
eng: measurement result composition
|
|
168
175
|
----
|
|
169
176
|
|
|
170
|
-
ISO 704 requires at least two
|
|
177
|
+
ISO 704 requires at least two members per relation; `Validation::Rules` enforces structural invariants (GLS-2xx series).
|
|
178
|
+
|
|
179
|
+
A single comprehensive concept can carry N hyperedges (one per criterion of subdivision), each in its own file under `relations/<comprehensive-id>/`. Legacy files with a `partitives:` key (member list with the `multiplicity` enum instead of the `presence`/`count` decomposition) are read for backward compatibility; the writer emits the `members` form above.
|
|
180
|
+
|
|
181
|
+
[NOTE]
|
|
182
|
+
--
|
|
183
|
+
*Remaining transition step.* The concept-model shapes' property path still reads `hasPartitiveRelation`; the v3.3 shape bump renames it to `hasMember` (the native ontology property). The wire keys and semantics shown here are current.
|
|
184
|
+
--
|
|
171
185
|
|
|
172
186
|
== bibliography.yaml
|
|
173
187
|
|
data/glossarist.gemspec
CHANGED
|
@@ -44,5 +44,8 @@ Gem::Specification.new do |spec|
|
|
|
44
44
|
spec.add_dependency "table_tennis", "~> 0.0"
|
|
45
45
|
spec.add_dependency "tbx", "~> 0.1"
|
|
46
46
|
spec.add_dependency "thor"
|
|
47
|
+
# Units/quantities ingest (Glossarist::Units::Ingestor) wraps the
|
|
48
|
+
# unitsdb gem (unitsml/unitsdb-ruby) for parsing unitsdb data dirs.
|
|
49
|
+
spec.add_dependency "unitsdb", "~> 2.2"
|
|
47
50
|
spec.add_dependency "yeptris", "~> 0.6.59"
|
|
48
51
|
end
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "net/http"
|
|
5
|
+
|
|
6
|
+
module Glossarist
|
|
7
|
+
class CLI
|
|
8
|
+
# `glossarist proposal ACTION` — editorial proposal bridge
|
|
9
|
+
# (glossarist-ruby#285, pairs with glossarist-server#45).
|
|
10
|
+
#
|
|
11
|
+
# Actions:
|
|
12
|
+
# open PAYLOAD apply a proposal payload to a dataset repository
|
|
13
|
+
# as a proposal branch; --push / --pr hand it to GitHub
|
|
14
|
+
# status [ID] list (or detail) proposals from a Glossarist server
|
|
15
|
+
class ProposalCommand
|
|
16
|
+
def initialize(action, args, options)
|
|
17
|
+
@action = action
|
|
18
|
+
@args = args
|
|
19
|
+
@options = options
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def run
|
|
23
|
+
case @action
|
|
24
|
+
when "open" then open
|
|
25
|
+
when "status" then status
|
|
26
|
+
else
|
|
27
|
+
raise Errors::CliError,
|
|
28
|
+
"unknown proposal action #{@action.inspect} (expected: open, status)"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# -- open ----------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
def open
|
|
35
|
+
payload = read_payload
|
|
36
|
+
repo = require_option(:repo, "--repo PATH to the dataset repository")
|
|
37
|
+
branch = @options[:branch] || "proposal/#{payload.id}"
|
|
38
|
+
|
|
39
|
+
bridge = Proposals::GitBridge.new(repo)
|
|
40
|
+
result = bridge.open(payload, branch: branch)
|
|
41
|
+
puts "opened #{result[:branch]} on #{result[:base]} (#{result[:commit][0, 10]})"
|
|
42
|
+
|
|
43
|
+
if @options[:push]
|
|
44
|
+
bridge.push(result[:branch])
|
|
45
|
+
puts "pushed #{result[:branch]} to origin"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
open_pull_request(payload, bridge, result) if @options[:pr]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def open_pull_request(payload, bridge, result)
|
|
52
|
+
title = "proposal #{payload.id}: #{payload.title}"
|
|
53
|
+
body = Proposals::PrDescription.render(payload)
|
|
54
|
+
remote_url = bridge.remote_url
|
|
55
|
+
repo_full = @options[:github] || Proposals::GithubBridge.repo_from_remote(remote_url)
|
|
56
|
+
|
|
57
|
+
pr = Proposals::GithubBridge.new(repo_full).open_pr(
|
|
58
|
+
branch: result[:branch], base: result[:base], title: title, body: body,
|
|
59
|
+
)
|
|
60
|
+
puts "pull request ##{pr[:number]}: #{pr[:url]}"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# -- status --------------------------------------------------------------
|
|
64
|
+
|
|
65
|
+
def status
|
|
66
|
+
server = @options[:server] || ENV.fetch("GLOSSARIST_SERVER_URL", nil)
|
|
67
|
+
unless server
|
|
68
|
+
raise Errors::CliError,
|
|
69
|
+
"no server given; pass --server URL or set $GLOSSARIST_SERVER_URL"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
text = fetch_status(server)
|
|
73
|
+
if @args[0]
|
|
74
|
+
puts self.class.render_detail(text)
|
|
75
|
+
else
|
|
76
|
+
puts self.class.render_list(text, register: @options[:register])
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Pure renderers (tested without network).
|
|
81
|
+
|
|
82
|
+
def self.render_list(text, register: nil)
|
|
83
|
+
rows = JSON.parse(text)
|
|
84
|
+
rows = rows.select { |p| p["register"] == register } if register
|
|
85
|
+
return "no proposals" if rows.empty?
|
|
86
|
+
|
|
87
|
+
rows.map do |p|
|
|
88
|
+
format("%<id>-38s %<register>-16s %<state>-14s %<title>s",
|
|
89
|
+
id: p["id"], register: p["register"], state: p["state"], title: p["title"])
|
|
90
|
+
end.join("\n")
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def self.render_detail(text)
|
|
94
|
+
p = JSON.parse(text)
|
|
95
|
+
lines = [format("%<id>s [%<state>s] %<title>s", id: p["id"], state: p["state"], title: p["title"])]
|
|
96
|
+
(p["events"] || []).each do |e|
|
|
97
|
+
lines << format(" %<at>s %<state>s %<note>s",
|
|
98
|
+
at: e["at"], state: e["state"], note: e["note"])
|
|
99
|
+
end
|
|
100
|
+
lines.join("\n")
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
private
|
|
104
|
+
|
|
105
|
+
def read_payload
|
|
106
|
+
path = @args[0] || raise(Errors::CliError, "usage: glossarist proposal open PAYLOAD --repo PATH")
|
|
107
|
+
payload = Proposals::Payload.from_yaml(File.read(path))
|
|
108
|
+
payload.validate!
|
|
109
|
+
payload
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def require_option(key, hint)
|
|
113
|
+
@options[key] || raise(Errors::CliError, "missing option #{hint}")
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def fetch_status(server)
|
|
117
|
+
id = @args[0]
|
|
118
|
+
path = id ? "/v1/proposals/#{id}" : "/v1/proposals"
|
|
119
|
+
uri = URI.join(server, path)
|
|
120
|
+
uri.query = URI.encode_www_form("register" => @options[:register]) if !id && @options[:register]
|
|
121
|
+
|
|
122
|
+
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
|
|
123
|
+
http.get(uri, "Accept" => "application/json")
|
|
124
|
+
end
|
|
125
|
+
raise Errors::CliError, "server returned #{response.code} for #{path}" unless response.is_a?(Net::HTTPSuccess)
|
|
126
|
+
|
|
127
|
+
response.body
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Glossarist
|
|
4
|
+
class CLI
|
|
5
|
+
# `glossarist import-unitsdb SOURCE --output DIR` — ingest unitsdb
|
|
6
|
+
# units, quantities and prefixes into a glossarist dataset.
|
|
7
|
+
class UnitsImportCommand
|
|
8
|
+
def initialize(source, options)
|
|
9
|
+
@source = source
|
|
10
|
+
@options = options
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def run
|
|
14
|
+
unless @options[:output]
|
|
15
|
+
raise Errors::CliError, "--output is required"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
ingestor = Units::Ingestor.new(@source).ingest
|
|
19
|
+
ingestor.write_to(
|
|
20
|
+
@options[:output],
|
|
21
|
+
shortname: @options[:shortname],
|
|
22
|
+
version: @options[:version],
|
|
23
|
+
)
|
|
24
|
+
print_summary(ingestor, @options[:output])
|
|
25
|
+
rescue ArgumentError => e
|
|
26
|
+
raise Errors::CliError, e.message
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def print_summary(ingestor, output)
|
|
32
|
+
puts "Imported #{ingestor.concepts.length} concepts " \
|
|
33
|
+
"(#{ingestor.units.length} units, " \
|
|
34
|
+
"#{ingestor.quantity_kinds.length} quantities, " \
|
|
35
|
+
"#{ingestor.unit_prefixes.length} prefixes) " \
|
|
36
|
+
"to #{output}"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
data/lib/glossarist/cli.rb
CHANGED
|
@@ -10,6 +10,8 @@ module Glossarist
|
|
|
10
10
|
autoload :ImportCommand, "#{__dir__}/cli/import_command"
|
|
11
11
|
autoload :ExportCommand, "#{__dir__}/cli/export_command"
|
|
12
12
|
autoload :CompareCommand, "#{__dir__}/cli/compare_command"
|
|
13
|
+
autoload :UnitsImportCommand, "#{__dir__}/cli/units_import_command"
|
|
14
|
+
autoload :ProposalCommand, "#{__dir__}/cli/proposal_command"
|
|
13
15
|
desc "generate_latex", "Convert Concepts to Latex format"
|
|
14
16
|
|
|
15
17
|
option :concepts_path, aliases: :p, required: true,
|
|
@@ -103,6 +105,24 @@ module Glossarist
|
|
|
103
105
|
CLI::ImportCommand.new(files, options).run
|
|
104
106
|
end
|
|
105
107
|
|
|
108
|
+
desc "import-unitsdb SOURCE", "Import units, quantities and prefixes from a unitsdb data directory"
|
|
109
|
+
long_desc <<-DESC
|
|
110
|
+
Ingest unitsdb data (https://github.com/unitsml/unitsdb) as first-class
|
|
111
|
+
dataset concepts. SOURCE is a unitsdb data directory (holding units.yaml,
|
|
112
|
+
quantities.yaml, prefixes.yaml, dimensions.yaml, unit_systems.yaml) or a
|
|
113
|
+
ZIP archive of one; when omitted, the data bundled in the unitsdb gem is
|
|
114
|
+
used.
|
|
115
|
+
DESC
|
|
116
|
+
option :output, aliases: :o, required: true,
|
|
117
|
+
desc: "Output directory or .gcr file path"
|
|
118
|
+
option :shortname, type: :string,
|
|
119
|
+
desc: "Dataset shortname (required for GCR output)"
|
|
120
|
+
option :version, type: :string,
|
|
121
|
+
desc: "Dataset version (required for GCR output)"
|
|
122
|
+
def import_unitsdb(source = nil)
|
|
123
|
+
CLI::UnitsImportCommand.new(source, options).run
|
|
124
|
+
end
|
|
125
|
+
|
|
106
126
|
desc "export PATH", "Export concepts in machine-readable formats"
|
|
107
127
|
option :format, type: :string, required: true,
|
|
108
128
|
desc: "Output format(s), comma-separated (json, jsonld, turtle, tbx, jsonl, yaml)"
|
|
@@ -142,6 +162,26 @@ module Glossarist
|
|
|
142
162
|
CLI::CompareCommand.new(new_path, old_path, options).run
|
|
143
163
|
end
|
|
144
164
|
|
|
165
|
+
desc "proposal ACTION [ARGS]",
|
|
166
|
+
"Open or track editorial proposals as PRs (FERIN register procedure)"
|
|
167
|
+
option :repo, type: :string,
|
|
168
|
+
desc: "Path to the dataset repository (local git checkout)"
|
|
169
|
+
option :branch, type: :string,
|
|
170
|
+
desc: "Proposal branch name (default: proposal/<id>)"
|
|
171
|
+
option :push, type: :boolean, default: false,
|
|
172
|
+
desc: "Push the proposal branch to origin"
|
|
173
|
+
option :pr, type: :boolean, default: false,
|
|
174
|
+
desc: "Open a GitHub pull request for the proposal branch (needs GITHUB_TOKEN)"
|
|
175
|
+
option :github, type: :string,
|
|
176
|
+
desc: "GitHub repository as owner/name (default: derived from origin remote)"
|
|
177
|
+
option :server, type: :string,
|
|
178
|
+
desc: "Glossarist server URL for status (default: $GLOSSARIST_SERVER_URL)"
|
|
179
|
+
option :register, type: :string,
|
|
180
|
+
desc: "Filter status listing by register"
|
|
181
|
+
def proposal(action, *args)
|
|
182
|
+
CLI::ProposalCommand.new(action, args, options).run
|
|
183
|
+
end
|
|
184
|
+
|
|
145
185
|
desc "version", "Show Glossarist version"
|
|
146
186
|
def version
|
|
147
187
|
puts Glossarist::VERSION
|
data/lib/glossarist/concept.rb
CHANGED
|
@@ -30,6 +30,10 @@ module Glossarist
|
|
|
30
30
|
map :identifier, to: :id, with: { to: :id_to_yaml, from: :id_from_yaml }
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
# lutaml-model#1272 hardening — see DefaultMaterialization. Prepended
|
|
34
|
+
# (not included) so it wraps the accessor `attribute :data` generated.
|
|
35
|
+
prepend DefaultMaterialization
|
|
36
|
+
|
|
33
37
|
def self.of_yaml(hash, options = {})
|
|
34
38
|
if hash.is_a?(Hash)
|
|
35
39
|
extensions = hash.select do |key, _value|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Glossarist
|
|
4
|
+
# Hardening against the silent-serialization-loss trap documented in
|
|
5
|
+
# lutaml/lutaml-model#1272.
|
|
6
|
+
#
|
|
7
|
+
# lutaml-model's render policy skips attributes that are still flagged as
|
|
8
|
+
# using their default value, and only a setter call clears that flag. A
|
|
9
|
+
# model built via bare `.new` therefore keeps its default `data` object
|
|
10
|
+
# flagged forever: in-place mutation of the materialized default
|
|
11
|
+
# (`data.definition << ...`, `data.domains = ...`) never clears the flag,
|
|
12
|
+
# and serialization silently drops the whole `data` key.
|
|
13
|
+
#
|
|
14
|
+
# The same trap hits plain-Hash defaults (`RegisterData#subregisters`,
|
|
15
|
+
# `GcrMetadata#translations`): their readers hand out the materialized
|
|
16
|
+
# default Hash for in-place mutation (`rd.subregisters["01"] = ...`),
|
|
17
|
+
# which never clears the flag, so the mutated entries silently vanish.
|
|
18
|
+
#
|
|
19
|
+
# This module intercepts the readers: reading a still-default object
|
|
20
|
+
# marks it writer-set (lutaml-model's public `value_set_for`) before
|
|
21
|
+
# handing it out, so every delegating accessor — and every direct
|
|
22
|
+
# mutation by callers — serializes the mutated content. Models built
|
|
23
|
+
# through the load path are unaffected: the deserializer already clears
|
|
24
|
+
# the flag through its setter calls.
|
|
25
|
+
#
|
|
26
|
+
# `DefaultMaterialization` itself hardens the `data` reader. Each
|
|
27
|
+
# plain-Hash default gets its own submodule below, prepended only by the
|
|
28
|
+
# class that declares the attribute (a shared module would advertise
|
|
29
|
+
# readers its host does not declare).
|
|
30
|
+
#
|
|
31
|
+
# Prepend AFTER the `attribute` declarations in every class that
|
|
32
|
+
# (re)declares the attribute — the declaration (re)defines the accessor
|
|
33
|
+
# on the declaring class, which would otherwise shadow the hardening
|
|
34
|
+
# inherited from a parent class.
|
|
35
|
+
module DefaultMaterialization
|
|
36
|
+
def data(*args)
|
|
37
|
+
value = super
|
|
38
|
+
if !value.nil? && using_default?(:data)
|
|
39
|
+
value_set_for(:data)
|
|
40
|
+
end
|
|
41
|
+
value
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# RegisterData's `subregisters` (plain-Hash default) — see above.
|
|
45
|
+
module SubregistersDefault
|
|
46
|
+
def subregisters(*args)
|
|
47
|
+
value = super
|
|
48
|
+
value_set_for(:subregisters) if !value.nil? && using_default?(:subregisters)
|
|
49
|
+
value
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# GcrMetadata's `translations` (plain-Hash default) — see above.
|
|
54
|
+
module TranslationsDefault
|
|
55
|
+
def translations(*args)
|
|
56
|
+
value = super
|
|
57
|
+
value_set_for(:translations) if !value.nil? && using_default?(:translations)
|
|
58
|
+
value
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
data/lib/glossarist/errors.rb
CHANGED
|
@@ -46,6 +46,11 @@ module Glossarist
|
|
|
46
46
|
map :translations, to: :translations
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
+
# lutaml-model#1272 hardening for the plain-Hash default — see
|
|
50
|
+
# DefaultMaterialization. Prepended (not included) so it wraps the
|
|
51
|
+
# accessor `attribute :translations` generated.
|
|
52
|
+
prepend DefaultMaterialization::TranslationsDefault
|
|
53
|
+
|
|
49
54
|
def self.from_concepts(concepts, register_data: nil, options: {})
|
|
50
55
|
stats = GcrStatistics.from_concepts(concepts)
|
|
51
56
|
rd = register_data
|
|
@@ -47,6 +47,10 @@ module Glossarist
|
|
|
47
47
|
map :schema_version, to: :schema_version
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
+
# lutaml-model#1272 hardening — see DefaultMaterialization. Prepended
|
|
51
|
+
# (not included) so it wraps the accessor `attribute :data` generated.
|
|
52
|
+
prepend DefaultMaterialization
|
|
53
|
+
|
|
50
54
|
def localizations
|
|
51
55
|
data.localizations
|
|
52
56
|
end
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Glossarist
|
|
4
|
+
# Deprecated: retained for ABI compatibility only. No internal callers
|
|
5
|
+
# remain — build concepts as a plain Array and persist through
|
|
6
|
+
# GlossaryStore. Removal is slated for the next major release.
|
|
4
7
|
class ManagedConceptCollection
|
|
5
8
|
include Enumerable
|
|
6
9
|
|
|
7
10
|
attr_accessor :managed_concepts
|
|
8
11
|
|
|
9
12
|
def initialize(file_key: nil)
|
|
13
|
+
warn "[glossarist] ManagedConceptCollection is deprecated; use a " \
|
|
14
|
+
"plain Array and GlossaryStore (removal slated for 3.0)"
|
|
10
15
|
@managed_concepts = []
|
|
11
16
|
@managed_concepts_ids = {}
|
|
12
17
|
@file_key = file_key
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Glossarist
|
|
4
|
+
module Proposals
|
|
5
|
+
# One atomic concept change inside a {Payload}: the new on-disk content
|
|
6
|
+
# of one concept file in the dataset repository. `op` records intent
|
|
7
|
+
# (add / update / deprecate); the bridge writes `content` to
|
|
8
|
+
# `path` (default: concepts/<uuid>.yaml).
|
|
9
|
+
class Change < Lutaml::Model::Serializable
|
|
10
|
+
attribute :op, :string
|
|
11
|
+
attribute :uuid, :string
|
|
12
|
+
attribute :path, :string
|
|
13
|
+
attribute :content, :string
|
|
14
|
+
|
|
15
|
+
OPS = %w[add update deprecate].freeze
|
|
16
|
+
private_constant :OPS
|
|
17
|
+
|
|
18
|
+
def validate!
|
|
19
|
+
raise Errors::InvalidProposalError, "change op must be one of #{OPS.join(', ')}" unless OPS.include?(op)
|
|
20
|
+
raise Errors::InvalidProposalError, "change uuid is required" if uuid.nil? || uuid.empty?
|
|
21
|
+
raise Errors::InvalidProposalError, "change content is required" if content.nil?
|
|
22
|
+
|
|
23
|
+
validate_path!
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def resolve_path
|
|
27
|
+
path || "concepts/#{uuid}.yaml"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
# The path lands under the dataset repository root; a proposal
|
|
33
|
+
# payload is untrusted input at the CLI boundary.
|
|
34
|
+
def validate_path!
|
|
35
|
+
return if path.nil?
|
|
36
|
+
|
|
37
|
+
candidate = Pathname.new(path)
|
|
38
|
+
if candidate.absolute? || candidate.each_filename.include?("..")
|
|
39
|
+
raise Errors::InvalidProposalError, "change path must be relative to the dataset root and cannot traverse up: #{path}"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "open3"
|
|
4
|
+
|
|
5
|
+
module Glossarist
|
|
6
|
+
module Proposals
|
|
7
|
+
# Opens a proposal payload as a commit on a proposal branch of a local
|
|
8
|
+
# dataset repository (the git SSOT), and merges it back — the local
|
|
9
|
+
# contract twin of GithubBridge. Used by the CLI `proposal open` and
|
|
10
|
+
# `proposal merge`; the production path pushes the same branch and
|
|
11
|
+
# opens a pull request instead.
|
|
12
|
+
class GitBridge
|
|
13
|
+
def initialize(repo_path)
|
|
14
|
+
@repo_path = repo_path
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Applies the payload to a proposal branch off the default branch,
|
|
18
|
+
# commits with FERIN trailers, and returns to the default branch.
|
|
19
|
+
def open(payload, branch: nil)
|
|
20
|
+
payload.validate!
|
|
21
|
+
branch ||= "proposal/#{payload.id}"
|
|
22
|
+
base = default_branch
|
|
23
|
+
git("checkout", "-b", branch, base)
|
|
24
|
+
payload.changes.each do |change|
|
|
25
|
+
write_change(change)
|
|
26
|
+
git("add", change.resolve_path)
|
|
27
|
+
end
|
|
28
|
+
git("commit", "-m", PrDescription.commit_message(payload))
|
|
29
|
+
git("checkout", base)
|
|
30
|
+
{ branch: branch, base: base, commit: rev_parse(branch) }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Merges the proposal branch into the default branch (the local
|
|
34
|
+
# deliberation→published transition) and returns the published sha.
|
|
35
|
+
def merge(branch)
|
|
36
|
+
base = default_branch
|
|
37
|
+
git("checkout", base)
|
|
38
|
+
git("merge", "--no-edit", branch)
|
|
39
|
+
{ base: base, commit: rev_parse("HEAD") }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def push(branch, remote: "origin")
|
|
43
|
+
git("push", "-u", remote, branch)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def remote_url(name = "origin")
|
|
47
|
+
git("remote", "get-url", name)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def default_branch
|
|
51
|
+
%w[main master].each do |candidate|
|
|
52
|
+
return candidate if rev_parse(candidate)
|
|
53
|
+
end
|
|
54
|
+
raise Errors::CliError, "no main or master branch found in #{@repo_path}"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def write_change(change)
|
|
60
|
+
file = File.join(@repo_path, change.resolve_path)
|
|
61
|
+
FileUtils.mkdir_p(File.dirname(file))
|
|
62
|
+
File.write(file, change.content)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def rev_parse(rev)
|
|
66
|
+
out, _err, status = Open3.capture3("git", "rev-parse", "--verify", rev, chdir: @repo_path)
|
|
67
|
+
status.success? ? out.strip : nil
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def git(*args)
|
|
71
|
+
out, err, status = Open3.capture3("git", *args, chdir: @repo_path)
|
|
72
|
+
raise Errors::CliError, "git #{args.first} failed: #{err.strip}" unless status.success?
|
|
73
|
+
|
|
74
|
+
out.strip
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "net/http"
|
|
5
|
+
|
|
6
|
+
module Glossarist
|
|
7
|
+
module Proposals
|
|
8
|
+
# Opens a proposal branch as a GitHub pull request against the dataset
|
|
9
|
+
# repository (the production deliberation step of the register
|
|
10
|
+
# procedure). Credentials come from the environment only — never code.
|
|
11
|
+
class GithubBridge
|
|
12
|
+
DEFAULT_API = "https://api.github.com"
|
|
13
|
+
|
|
14
|
+
attr_reader :repo, :api
|
|
15
|
+
|
|
16
|
+
def initialize(repo, token: ENV.fetch("GITHUB_TOKEN", nil), api: DEFAULT_API)
|
|
17
|
+
@repo = repo
|
|
18
|
+
@token = token
|
|
19
|
+
@api = api
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def open_pr(branch:, base:, title:, body:)
|
|
23
|
+
unless @token
|
|
24
|
+
raise Errors::CliError,
|
|
25
|
+
"GITHUB_TOKEN is not set; export it (or use a keychain-fed env) to open pull requests"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
_method, path, payload = self.class.pr_request(
|
|
29
|
+
repo: @repo, branch: branch, base: base, title: title, body: body,
|
|
30
|
+
)
|
|
31
|
+
response = http_request("POST", path, payload)
|
|
32
|
+
{ number: response["number"], url: response["html_url"] }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Pure request builder (tested without network): the exact call the
|
|
36
|
+
# bridge makes against the GitHub REST API.
|
|
37
|
+
def self.pr_request(repo:, branch:, base:, title:, body:)
|
|
38
|
+
["POST", "/repos/#{repo}/pulls",
|
|
39
|
+
{ "title" => title, "head" => branch, "base" => base, "body" => body }]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Derives "owner/name" from a git remote URL (SSH or HTTPS form).
|
|
43
|
+
# Bounded character classes only — the URL is uncontrolled input.
|
|
44
|
+
def self.repo_from_remote(url)
|
|
45
|
+
match = %r{\A(?:git@github\.com:|https://github\.com/)([A-Za-z0-9_.-]+)/([A-Za-z0-9_.-]+?)(?:\.git)?/?\z}.match(url)
|
|
46
|
+
raise Errors::CliError, "cannot derive a GitHub repository from remote: #{url}" unless match
|
|
47
|
+
|
|
48
|
+
"#{match[1]}/#{match[2]}"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def http_request(method, path, payload)
|
|
54
|
+
uri = URI.join(@api, path)
|
|
55
|
+
request = Net::HTTP.const_get(method.capitalize).new(uri)
|
|
56
|
+
request["Authorization"] = "Bearer #{@token}"
|
|
57
|
+
request["Accept"] = "application/vnd.github+json"
|
|
58
|
+
request["Content-Type"] = "application/json"
|
|
59
|
+
request.body = JSON.generate(payload)
|
|
60
|
+
|
|
61
|
+
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
|
|
62
|
+
http.request(request)
|
|
63
|
+
end
|
|
64
|
+
handle_response(response)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def handle_response(response)
|
|
68
|
+
body = JSON.parse(response.body)
|
|
69
|
+
return body if response.is_a?(Net::HTTPSuccess)
|
|
70
|
+
|
|
71
|
+
message = body["message"] || response.class.name
|
|
72
|
+
raise Errors::CliError, "GitHub API #{response.code}: #{message}"
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|