Class: ReleaseHx::RHYML::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/releasehx/rhyml/adapter.rb

Overview

Transforms raw API payloads into structured RHYML Release objects. Uses RHYML mapping definitions to extract, transform, and normalize data from various issue management systems into a consistent Release structure.

Constant Summary collapse

SCHEMA_PATH =
File.expand_path('../../../specs/data/rhyml-mapping-schema.yaml', __dir__)
MAPPING_SCHEMA =
SchemaGraphy::Loader.load_yaml_with_tags(SCHEMA_PATH)['$schema']
SKIP_KEYS =
%w[$meta $config changes_array_path].freeze

Instance Method Summary collapse

Constructor Details

#initialize(mapping:, config:) ⇒ Adapter

Initializes a new adapter instance with mapping configuration and runtime config.

Parameters:

  • mapping (Hash)
    The RHYML mapping definition containing field transformations.
  • config (Hash)
    Application runtime configuration.


28
29
30
31
32
# File 'lib/releasehx/rhyml/adapter.rb', line 28

def initialize mapping:, config:
  @mapping = mapping
  @config = config
  @defaults = load_defaults
end

Instance Method Details

#to_release(payload, release_code:, release_date: nil, release_hash: nil, release_memo: nil, scan: false) ⇒ Release

Transforms a raw data payload into a Release object with mapped changes.

Parameters:

  • payload (Hash)
    The raw data payload to transform (ex: GitHub API response).
  • release_code (String)
    The release identifier/version code.
  • release_date (String, nil) (defaults to: nil)
    Optional release date.
  • release_hash (String, nil) (defaults to: nil)
    Optional git commit hash for the release.
  • release_memo (String, nil) (defaults to: nil)
    Optional release memo/description.
  • scan (Boolean) (defaults to: false)
    Whether to enable detailed debug logging (default: false).

Returns:

  • (Release)
    A Release object containing the mapped changes.


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/releasehx/rhyml/adapter.rb', line 43

def to_release payload, release_code:, release_date: nil, release_hash: nil, release_memo: nil, scan: false
  ReleaseHx.logger.debug "Adapter.to_release called (scan = #{scan})"
  array_path = mapping['changes_array_path']
  raw_items = resolve_path(array_path, payload)

  if raw_items.nil?
    payload_info = payload.is_a?(Hash) ? payload.keys.inspect : payload.class.name
    ReleaseHx.logger.error "Failed to extract items from path '#{array_path}'. Payload: #{payload_info}"
    raw_items = []
  end

  ReleaseHx.logger.debug "Extracted raw_items (#{raw_items.size}) from path '#{array_path}'"
  ReleaseHx.logger.dump "First raw item: #{raw_items.first.inspect}"

  release = Release.new(
    code: release_code,
    date: release_date,
    hash: release_hash,
    memo: release_memo,
    changes: [])

  ReleaseHx.logger.debug "Mapping #{raw_items.size} raw items..."

  changes = raw_items.map { |raw| transform_change(raw, release: release, scan: scan) }.compact

  if changes.empty?
    ReleaseHx.logger.warn(
      'All mapped changes were nil after transformation. ' \
      "No changes attached to release #{release_code}.")
  else
    with_notes = changes.count { |c| c.note.to_s.strip != '' }
    ReleaseHx.logger.info(
      "Transformed #{changes.size} changes for release #{release_code} (#{with_notes} with notes)")
  end

  ReleaseHx.logger.debug "Adding #{changes.size} changes to release" if scan
  ReleaseHx.logger.debug "First change keys: #{changes.first.to_h.keys.inspect}" if scan && changes.any?
  release.instance_variable_set(:@changes, changes)

  release
end