lib/chandler/commands/push.rb in chandler-0.1.2 vs lib/chandler/commands/push.rb in chandler-0.2.0
- old
+ new
@@ -1,15 +1,19 @@
require "chandler/logging"
require "chandler/refinements/color"
require "chandler/refinements/version_format"
+require "forwardable"
module Chandler
module Commands
# 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.
class Push
+ extend Forwardable
+ def_delegators :config, :github, :changelog, :tag_mapper
+
include Logging
using Chandler::Refinements::Color
using Chandler::Refinements::VersionFormat
attr_reader :tags, :config
@@ -18,36 +22,46 @@
@tags = tags
@config = config
end
def call
- benchmarking_each_tag do |tag|
+ exit_with_warning if tags.empty?
+
+ each_tag_with_version_and_notes do |tag, version, notes|
github.create_or_update_release(
:tag => tag,
- :title => tag.version_number,
- :description => changelog.fetch(tag).strip
+ :title => version.version_number,
+ :description => notes
)
end
end
private
- def github
- config.github
- end
-
- def changelog
- config.changelog
- end
-
- def benchmarking_each_tag
+ 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)
+ yield(tag, version, notes)
end
end
+ end
+
+ def exit_with_warning
+ error("No version tags found.")
+ exit(1)
+ end
+
+ def changelog_version_and_notes_for_tag(tag)
+ version = tag_mapper.call(tag)
+ [version, changelog.fetch(version).strip]
+ rescue Chandler::Changelog::NoMatchingVersion
+ info("Skip #{tag} (no #{version} entry in #{changelog.basename})".gray)
+ nil
end
end
end
end