1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/tasks/github_release_task.rb

67 lines
1.7 KiB
Ruby
Raw Permalink Normal View History

require "rake"
require "rake/tasklib"
require 'octokit'
require 'netrc'
module Fog
module Rake
2014-04-01 10:29:05 -04:00
class GithubReleaseTask < ::Rake::TaskLib
def initialize
desc "Update the changelog since the last release"
task(:github_release) do
File.open('CHANGELOG.md', 'r') do |file|
file.each_line do |line|
@current_line = line
if release_header?
create_release if !release_exists? && @release
@release_tag = release_match[1]
@release = line
else
@release << line
end
end
end
end
end
private
def create_release
github.create_release "fog/fog", "v#{@release_tag}", {:name => "v#{@release_tag}", :body => @release}
puts "creating release #{@release_tag}"
end
def releases
return @releases if @releases
response = github.releases("fog/fog")
@releases = response.map {|r| r.tag_name }
end
def release_exists?
releases.find {|r| r == "v#{@release_tag}" } != nil
end
def release_header?
release_match != nil
end
def release_match
@current_line.match (/## (\d+\.\d+\.\d+) \d+\/\d+\d+/)
end
def github
unless @github
Octokit.auto_paginate = true
@github = Octokit::Client.new :netrc => true
unless @github.login
@github = nil
raise "Please create a ~/.netrc file to authenticate with github. For more information please see https://github.com/octokit/octokit.rb/blob/master/README.md#using-a-netrc-file"
end
end
@github
end
end
end
end