glossarist 2.14.16 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a584d4edbe83762292055fa2a0e6af624d66a277b511a28ad34e01f03e4c05fc
4
- data.tar.gz: d5e638432a0d281469f4531b4ded63047b68b8005cbdaeade9d09a32c75172dd
3
+ metadata.gz: 491de16e587a90ca1acf8f2b038f000e78b3e5481ffaa13c958eb373ad0be707
4
+ data.tar.gz: dce9098ee3a79be528d436e2a52d72ee4d9e4c86379350e82b2017c0c9137088
5
5
  SHA512:
6
- metadata.gz: c1804db5d0ea4deaf8e87a35545570856a42d66593d8cf07e93bf43a1e81b464a13bd875590f022c6f548c0438a595f5b74d1e98ab394eed22f7d478cc229903
7
- data.tar.gz: 6d5db078479e2824d7dfd82baa39a127e86f04bcfd1eee56be26000d6b5f372a23a31f0a39e5bdd66cdb765d241f5c80981d748fe7883cb093c0c11bcb6ddbc3
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/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
@@ -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
@@ -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
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module Errors
5
+ # Raised when a proposal payload fails structural validation
6
+ # (unknown op, unsafe path, missing identity fields).
7
+ class InvalidProposalError < Base
8
+ end
9
+ end
10
+ end
@@ -11,5 +11,6 @@ module Glossarist
11
11
  autoload :CacheVersionMismatchError,
12
12
  "glossarist/errors/cache_version_mismatch_error"
13
13
  autoload :CliError, "glossarist/errors/cli_error"
14
+ autoload :InvalidProposalError, "glossarist/errors/invalid_proposal_error"
14
15
  end
15
16
  end
@@ -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
@@ -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
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module Proposals
5
+ # An editorial proposal: metadata (id, title, requester, register) plus
6
+ # the concept changes to apply to the dataset repository. Serializes
7
+ # from YAML or JSON through lutaml-model.
8
+ class Payload < Lutaml::Model::Serializable
9
+ attribute :id, :string
10
+ attribute :title, :string
11
+ attribute :requester, :string
12
+ attribute :register, :string
13
+ attribute :changes, Change, collection: true
14
+
15
+ def validate!
16
+ raise Errors::InvalidProposalError, "proposal id is required" if id.nil? || id.empty?
17
+ raise Errors::InvalidProposalError, "proposal title is required" if title.nil? || title.empty?
18
+ raise Errors::InvalidProposalError, "proposal requester is required" if requester.nil? || requester.empty?
19
+ raise Errors::InvalidProposalError, "proposal needs at least one change" if changes.nil? || changes.empty?
20
+
21
+ changes.each(&:validate!)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module Proposals
5
+ # Renders the pull-request body for a proposal: a human summary plus
6
+ # the FERIN register-process metadata block. Accepting the PR is the
7
+ # deliberation→published transition of the register procedure.
8
+ module PrDescription
9
+ SUBMISSION_STAGE = "proposal-input"
10
+
11
+ module_function
12
+
13
+ def render(payload)
14
+ <<~BODY
15
+ ## Proposal
16
+
17
+ #{payload.title}
18
+
19
+ Submitted by #{payload.requester} under the FERIN register
20
+ procedure (#{SUBMISSION_STAGE} stage). Merging this pull request
21
+ moves the proposal to the published stage of the register.
22
+
23
+ ## Changes
24
+
25
+ #{payload.changes.map { |c| "- #{c.op} `#{c.resolve_path}`" }.join("\n")}
26
+
27
+ ## FERIN process metadata
28
+
29
+ - Register: #{payload.register}
30
+ - Proposal ID: #{payload.id}
31
+ - Requester: #{payload.requester}
32
+ - Stage at submission: #{SUBMISSION_STAGE}
33
+ BODY
34
+ end
35
+
36
+ # Commit-message trailers mirroring the metadata above, so the
37
+ # proposal provenance travels with the change even when the PR body
38
+ # is rewritten by a merge.
39
+ def commit_message(payload)
40
+ <<~MSG
41
+ proposal #{payload.id}: #{payload.title}
42
+
43
+ FERIN-Proposal: #{payload.id}
44
+ FERIN-Register: #{payload.register}
45
+ FERIN-Requester: #{payload.requester}
46
+ FERIN-Stage: #{SUBMISSION_STAGE}
47
+ MSG
48
+ end
49
+ end
50
+ end
51
+ end