Sha256: 667a684db011e48c07687725c7e857c6c4a33731ba5174773c574f6d9b25f23b

Contents?: true

Size: 1.31 KB

Versions: 9

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require "tempfile"
require "json"
require "active_support/core_ext/hash"
require "rake"
require_relative "../deprecation_toolkit/read_write_helper"

class CIRecorder
  include Rake::DSL
  include DeprecationToolkit::ReadWriteHelper

  def initialize
    namespace(:deprecation_toolkit) do
      desc("Parse a file generated with the CIOutputHelper and generate deprecations out of it")
      task(:record_from_ci_output) do
        raw_file = ENV.fetch("FILEPATH")

        deprecations = extract_deprecations_output(raw_file) do |file|
          parse_file(file)
        end

        generate_deprecations_file(deprecations)
      end
    end
  end

  private

  def extract_deprecations_output(file)
    tmp_file = Tempfile.new
    shell_command = "cat #{file} | sed -n -e 's/^.* \\[DeprecationToolkit\\] \\(.*\\)/\\1/p' > #{tmp_file.path}"

    raise "Couldn't extract deprecations from output" unless system(shell_command)

    yield(tmp_file)
  ensure
    tmp_file.delete
  end

  def parse_file(file)
    file.each.with_object({}) do |line, hash|
      hash.deep_merge!(JSON.parse(line))
    end
  end

  def generate_deprecations_file(deprecations_to_record)
    deprecations_to_record.each do |filename, deprecations|
      write(Pathname(filename), deprecations)
    end
  end
end

CIRecorder.new

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
deprecation_toolkit-2.2.2 lib/tasks/ci_recorder.rake
deprecation_toolkit-2.2.1 lib/tasks/ci_recorder.rake
deprecation_toolkit-2.2.0 lib/tasks/ci_recorder.rake
deprecation_toolkit-2.1.0 lib/tasks/ci_recorder.rake
deprecation_toolkit-2.0.4 lib/tasks/ci_recorder.rake
deprecation_toolkit-2.0.3 lib/tasks/ci_recorder.rake
deprecation_toolkit-2.0.2 lib/tasks/ci_recorder.rake
deprecation_toolkit-2.0.1 lib/tasks/ci_recorder.rake
deprecation_toolkit-2.0.0 lib/tasks/ci_recorder.rake