Class: Reissue::FragmentHandler::GitFragmentHandler

Inherits:
Reissue::FragmentHandler show all
Defined in:
lib/reissue/fragment_handler/git_fragment_handler.rb

Overview

Handles reading changelog entries from git commit trailers

Constant Summary collapse

DEFAULT_TAG_PATTERN =

Default pattern for matching version tags (e.g., “v1.2.3”)

/^v(\d+\.\d+\.\d+.*)$/

Instance Method Summary collapse

Methods inherited from Reissue::FragmentHandler

for

Constructor Details

#initialize(tag_pattern: nil) ⇒ GitFragmentHandler

Initialize the handler with optional tag pattern for custom tag formats

Parameters:

  • tag_pattern (Regexp, nil) (defaults to: nil)

    Optional regex pattern for matching version tags. Must include a capture group for the version number. Examples:

    - /^v(\d+\.\d+\.\d+.*)$/ matches "v1.2.3" (default)
    - /^myapp-v(\d+\.\d+\.\d+.*)$/ matches "myapp-v1.2.3"
    - /^qualified-v(\d+\.\d+\.\d+.*)$/ matches "qualified-v0.3.5"
    


18
19
20
# File 'lib/reissue/fragment_handler/git_fragment_handler.rb', line 18

def initialize(tag_pattern: nil)
  @tag_pattern = tag_pattern || DEFAULT_TAG_PATTERN
end

Instance Method Details

#clearnil

Clear operation is a no-op for git trailers

Returns:

  • (nil)


35
36
37
# File 'lib/reissue/fragment_handler/git_fragment_handler.rb', line 35

def clear
  nil
end

#last_tagString?

Get the last version tag used for comparison

Returns:

  • (String, nil)

    The most recent version tag or nil if no tags found



42
43
44
45
# File 'lib/reissue/fragment_handler/git_fragment_handler.rb', line 42

def last_tag
  return nil unless git_available? && in_git_repo?
  find_last_tag
end

#last_tag_versionGem::Version?

Get the version from the last git tag

Returns:

  • (Gem::Version, nil)

    The version from the last tag, or nil if no tags exist



60
61
62
63
64
65
66
67
68
69
# File 'lib/reissue/fragment_handler/git_fragment_handler.rb', line 60

def last_tag_version
  tag = last_tag
  return nil unless tag

  # Extract version number from tag using the pattern's capture group
  match = tag.match(@tag_pattern)
  return nil unless match && match[1]

  ::Gem::Version.new(match[1])
end

#readHash

Read changelog entries from git commit trailers

Returns:

  • (Hash)

    A hash of changelog entries organized by section



25
26
27
28
29
30
# File 'lib/reissue/fragment_handler/git_fragment_handler.rb', line 25

def read
  return {} unless git_available? && in_git_repo?

  commits = commits_since_last_tag
  parse_trailers_from_commits(commits)
end

#read_version_bumpSymbol?

Read version bump from git commit trailers

Returns:

  • (Symbol, nil)

    One of :major, :minor, :patch, or nil if none found



50
51
52
53
54
55
# File 'lib/reissue/fragment_handler/git_fragment_handler.rb', line 50

def read_version_bump
  return nil unless git_available? && in_git_repo?

  commits = commits_since_last_tag
  parse_version_bump_from_commits(commits)
end