class RepositoryMerger::RepositoryCommitMap

Constants

CannotSaveWithoutPathError

Attributes

monorepo[R]
path[R]

Public Class Methods

new(monorepo:, path: nil) click to toggle source
# File lib/repository_merger/repository_commit_map.rb, line 14
def initialize(monorepo:, path: nil)
  @path = path
  @monorepo = monorepo
end

Public Instance Methods

map() click to toggle source
# File lib/repository_merger/repository_commit_map.rb, line 19
def map
  @map ||=
    if path && File.exist?(path)
      json = File.read(path)
      JSON.parse(json)
    else
      {}
    end
end
merge!(branch_local_commit_map) click to toggle source
# File lib/repository_merger/repository_commit_map.rb, line 29
def merge!(branch_local_commit_map)
  branch_local_commit_map.map.each do |original_commit_key, monorepo_commit_id|
    map[original_commit_key] ||= []
    next if map[original_commit_key].include?(monorepo_commit_id)
    map[original_commit_key] << monorepo_commit_id
  end
end
monorepo_commit_ids_for(original_commit) click to toggle source
# File lib/repository_merger/repository_commit_map.rb, line 48
def monorepo_commit_ids_for(original_commit)
  map[original_commit_key(original_commit)] || []
end
monorepo_commits_for(original_commit) click to toggle source
# File lib/repository_merger/repository_commit_map.rb, line 43
def monorepo_commits_for(original_commit)
  commit_ids = monorepo_commit_ids_for(original_commit)
  commit_ids.map { |id| monorepo.commit_for(id) }
end
save() click to toggle source
# File lib/repository_merger/repository_commit_map.rb, line 37
def save
  raise CannotSaveWithoutPathError unless path
  json = JSON.pretty_generate(map)
  File.write(path, json)
end