class Everyleaf::EmbulkHelper::Tasks::Generator::Changelog
Constants
- DEFAULT_CHANGELOG_TEMPLATE
Public Instance Methods
bump_version()
click to toggle source
# File lib/everyleaf/embulk_helper/tasks/generator/changelog.rb, line 37 def bump_version logger.info "Version bump '#{current_version}' to '#{next_version}'" old_content = gemspec_path.read new_content = old_content.gsub(/(spec\.version += *)".*?"/, %Q!\\1"#{next_version}"!) File.open(gemspec_path, "w") do |f| f.write new_content end end
changelog()
click to toggle source
# File lib/everyleaf/embulk_helper/tasks/generator/changelog.rb, line 30 def changelog content = new_changelog File.open(changelog_path, "w") do |f| f.write content end end
install_tasks()
click to toggle source
# File lib/everyleaf/embulk_helper/tasks/generator/changelog.rb, line 12 def install_tasks namespace :generate do desc "Generate chengelog then bump version" task :prepare_release => [:changelog, :bump_version] desc "Generate CHANGELOG.md from previous release" task :changelog do changelog end desc "Bump version. UP=major to do major version up, UP=minor, UP=patch(default) so on." task :bump_version do bump_version update_gemfile_lock end end end
Private Instance Methods
changelog_path()
click to toggle source
# File lib/everyleaf/embulk_helper/tasks/generator/changelog.rb, line 115 def changelog_path root_dir.join("CHANGELOG.md") end
changes()
click to toggle source
# File lib/everyleaf/embulk_helper/tasks/generator/changelog.rb, line 95 def changes pull_request_numbers.map do |number| payload = pull_request_info(number) "* [] #{payload["title"]} [##{number}](https://github.com/#{github_name}/pull/#{number})" end end
current_version()
click to toggle source
# File lib/everyleaf/embulk_helper/tasks/generator/changelog.rb, line 52 def current_version ENV["CURRENT_VER"] || Gem::Version.new(gemspec_path.read[/spec\.version += *"([0-9]+\.[0-9]+\.[0-9]+)"/, 1]) end
github_name()
click to toggle source
# File lib/everyleaf/embulk_helper/tasks/generator/changelog.rb, line 79 def github_name options[:github_name] end
new_changelog()
click to toggle source
# File lib/everyleaf/embulk_helper/tasks/generator/changelog.rb, line 102 def new_changelog <<-HEADER ## #{next_version} - #{Time.now.strftime("%Y-%m-%d")} #{changes.join("\n")} #{changelog_path.read.chomp} HEADER end
next_version()
click to toggle source
# File lib/everyleaf/embulk_helper/tasks/generator/changelog.rb, line 56 def next_version return ENV["NEXT_VER"] if ENV["NEXT_VER"] major, minor, patch = current_version.segments ver = case version_target when "patch" [major, minor, patch + 1].join(".") when "minor" [major, minor + 1, 0].join(".") when "major" [major + 1, 0, 0].join(".") end Gem::Version.new(ver) end
pull_request_info(number)
click to toggle source
# File lib/everyleaf/embulk_helper/tasks/generator/changelog.rb, line 90 def pull_request_info(number) body = open("https://api.github.com/repos/#{github_name}/issues/#{number}").read JSON.parse(body) end
pull_request_numbers()
click to toggle source
# File lib/everyleaf/embulk_helper/tasks/generator/changelog.rb, line 83 def pull_request_numbers sync_git_repo `git log v#{current_version}..origin/master --oneline`.scan(/#[0-9]+/).map do |num_with_hash| num_with_hash[/[0-9]+/] end end
required_options()
click to toggle source
# File lib/everyleaf/embulk_helper/tasks/generator/changelog.rb, line 48 def required_options %w(github_name) end
sync_git_repo()
click to toggle source
# File lib/everyleaf/embulk_helper/tasks/generator/changelog.rb, line 111 def sync_git_repo system('git fetch --all') end
update_gemfile_lock()
click to toggle source
# File lib/everyleaf/embulk_helper/tasks/generator/changelog.rb, line 75 def update_gemfile_lock system("bundle install") end
version_target()
click to toggle source
# File lib/everyleaf/embulk_helper/tasks/generator/changelog.rb, line 71 def version_target ENV["UP"] || options[:version_target] || "patch" end