class Chandler::Commands::Push
Iterates over a given array of tags, fetches the corresponding notes from the CHANGELOG, and creates (or updates) the release notes for that tag on GitHub
.
Attributes
config[R]
Public Class Methods
new(tags:, config:)
click to toggle source
# File lib/chandler/commands/push.rb, line 21 def initialize(tags:, config:) @tags = tags @config = config end
Public Instance Methods
call()
click to toggle source
# File lib/chandler/commands/push.rb, line 26 def call exit_with_warning if tags.empty? each_tag_with_version_and_notes do |tag, version, notes| github.create_or_update_release( :tag => tag, :title => version.version_number, :description => notes ) end end
Private Instance Methods
changelog_version_and_notes_for_tag(tag)
click to toggle source
# File lib/chandler/commands/push.rb, line 58 def changelog_version_and_notes_for_tag(tag) version = tag_mapper.call(tag) notes = strip_surrounding_empty_lines(changelog.fetch(version)) [version, notes] rescue Chandler::Changelog::NoMatchingVersion info("Skip #{tag} (no #{version} entry in #{changelog.basename})".gray) nil end
each_tag_with_version_and_notes() { |tag, version, notes| ... }
click to toggle source
# File lib/chandler/commands/push.rb, line 40 def each_tag_with_version_and_notes width = tags.map(&:length).max tags.each do |tag| version, notes = changelog_version_and_notes_for_tag(tag) next if notes.nil? ellipsis = "…".ljust(1 + width - tag.length) benchmark("Push #{tag.blue}#{ellipsis}") do yield(tag, version, notes) end end end
exit_with_warning()
click to toggle source
# File lib/chandler/commands/push.rb, line 53 def exit_with_warning error("No version tags found.") exit(1) end
strip_surrounding_empty_lines(str)
click to toggle source
Returns a new string with leading and trailing empty lines removed. A line is empty if it is zero-length or contains only whitespace.
# File lib/chandler/commands/push.rb, line 69 def strip_surrounding_empty_lines(str) str.sub(/\A[[:space:]]*^/, "") .sub(/$[[:space:]]*\z/, "") end