Sha256: 2bfeb0eaec9547abba34e44664e692bb197a9cceb6fe0c0113768decb669c2c3

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

require 'structured_changelog'
require 'structured_changelog/core_ext/string'
require 'structured_changelog/core_ext/gem'
require 'git'

task "changelog:compile", [:repo_path, :changelog_path] do |_task, arguments|
  repo_path      = arguments.to_h.fetch(:repo_path)      { Pathname.pwd }
  changelog_path = arguments.to_h.fetch(:changelog_path) { Pathname.pwd/"CHANGELOG.md" }

  current_version = StructuredChangelog.new(changelog_path).version

  repo = Git.open(repo_path)

  commit_messages = repo.log.between("v#{current_version}").map(&:message).select do |message|
    message.match?(/^\[CHANGELOG\]\n\n\*\ /)
  end

  abort("No [CHANGELOG] commits since the last release") if commit_messages.empty?

  message = commit_messages.flat_map do |message|
    message.sub(/^\[CHANGELOG\]\n\n/, "")
  end.join("\n")

  new_version = if message.match?(/^*\ BREAKING:/)
                  current_version.bump_major
                elsif message.match?(/^*\ FEATURE:/)
                  current_version.bump_minor
                elsif message.match?(/^*\ FIX:/)
                  current_version.bump_patch
                elsif message.match?(/^*\ ENHANCEMENT:/)
                  current_version.bump_patch
                elsif message.match?(/^*\ DEPRECATION:/)
                  current_version.bump_patch
                end

  changelog_path.write(
    changelog_path.read.sub(
      /^##\ RELEASE\ #{current_version}/,
      "## RELEASE #{new_version}\n\n#{message}\n\n## RELEASE #{current_version}"
    )
  )
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
structured_changelog-0.10.1 lib/structured_changelog/tasks/compile.rb