2014-03-24 10:12:19 -04:00
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
2014-03-24 10:12:19 -04:00
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 . collect { | 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
2014-03-25 09:23:12 -04:00
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 "
2014-03-24 10:12:19 -04:00
end
end
@github
end
end
end
end