Module: RailsAuditLog::Graphql::ReleaseTooling Private

Defined in:
lib/rails_audit_log/graphql/release_tooling.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Constant Summary collapse

VERSION_PATTERN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/VERSION = "[^"]+"/
SEMVER_PATTERN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/\A\d+\.\d+\.\d+(?:[-.][0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?\z/
UNRELEASED_HEADING =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"## [Unreleased]"

Class Method Summary collapse

Class Method Details

.extract_release_notes(contents, version) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (ArgumentError)


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/rails_audit_log/graphql/release_tooling.rb', line 57

def extract_release_notes(contents, version)
  normalized = normalize_version(version)
  lines = contents.lines
  release_heading = /^## \[#{Regexp.escape(normalized)}\](?: - .+)?$/
  start_index = lines.index { |line| line.match?(release_heading) }

  raise ArgumentError, "CHANGELOG.md is missing release notes for #{normalized}" unless start_index

  body = lines[(start_index + 1)..].take_while { |line| !line.start_with?("## [") }.join.strip
  body = "- No changes listed." if body.empty?

  <<~MARKDOWN
    ## RailsAuditLog::Graphql #{normalized}

    #{body}
  MARKDOWN
end

.finalize_changelog(contents, version, date = Date.today) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rails_audit_log/graphql/release_tooling.rb', line 29

def finalize_changelog(contents, version, date = Date.today)
  normalized = normalize_version(version)
  release_heading = "## [#{normalized}] - #{date.iso8601}"

  raise ArgumentError, "CHANGELOG.md must contain an Unreleased heading" unless contents.include?(UNRELEASED_HEADING)

  if contents.match?(/^## \[#{Regexp.escape(normalized)}\](?: - .+)?$/)
    raise ArgumentError, "CHANGELOG.md already contains #{normalized}"
  end

  contents.sub(UNRELEASED_HEADING, "#{UNRELEASED_HEADING}\n\n#{release_heading}")
end

.normalize_version(version) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (ArgumentError)


15
16
17
18
19
20
# File 'lib/rails_audit_log/graphql/release_tooling.rb', line 15

def normalize_version(version)
  normalized = version.to_s.sub(/\Av/, "")
  raise ArgumentError, "version must look like x.y.z" unless normalized.match?(SEMVER_PATTERN)

  normalized
end

.prune_roadmap(contents) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Removes milestone sections from ROADMAP.md where all feature bullets have been implemented (i.e. no remaining “- **” bullet points).



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rails_audit_log/graphql/release_tooling.rb', line 44

def prune_roadmap(contents)
  separator = "\n\n---\n\n"
  sections = contents.split(separator)

  pruned = sections.reject do |section|
    next false unless section.lstrip.match?(/\A## \d+\.\d+\.\d+/)

    !section.include?("- **")
  end

  pruned.join(separator)
end

.update_version_file(contents, version) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (ArgumentError)


22
23
24
25
26
27
# File 'lib/rails_audit_log/graphql/release_tooling.rb', line 22

def update_version_file(contents, version)
  normalized = normalize_version(version)
  raise ArgumentError, "version file does not define VERSION" unless contents.match?(VERSION_PATTERN)

  contents.sub(VERSION_PATTERN, %(VERSION = "#{normalized}"))
end