Created
March 12, 2014 16:55
-
-
Save krames/9511243 to your computer and use it in GitHub Desktop.
This gist creates releases for opscode/knife-rackspace based on the changelog.txt file. You will need to supply a username and a personal access token.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'singleton' | |
require 'octokit' | |
class ReleaseNotesGenerator | |
include Singleton | |
def release_header? | |
release_match != nil | |
end | |
def release_match | |
@current_line.match(/##\s*v(\d+\.\d+\.\d+)/) | |
end | |
# def print_release | |
# puts "+" * 50 | |
# puts "====[#{@release_tag}]" | |
# puts @release | |
# puts "+" * 50 | |
# puts "The is space is blank\n" | |
# end | |
def github | |
@client ||= ::Octokit::Client.new :login => USERNAME, :password => PERSONAL_ACCESS_TOKEN | |
end | |
def add_release | |
github.create_release "krames/knife-rackspace", @release_tag, {:name => @release_tag, :body => @release} | |
puts "creating release #{@release_tag}" | |
end | |
def set_release_vars | |
@header = @current_line | |
@release_tag = release_match[1] | |
@release_tag = "v0.7.0" if @release_tag == "0.7.0" | |
end | |
def section_header? | |
@current_line.match(/\[[^\]]+\]/) != nil | |
end | |
def inside_release_details? | |
@inside_release_details | |
end | |
def reset_variables | |
@release = "" | |
@inside_release_details = false | |
end | |
def parse(file_name) | |
File.open(file_name) do |file| | |
@file = file | |
@release = nil | |
@releases = [] | |
file.each_line do |line| | |
@current_line = line | |
if release_header? | |
add_release if @release | |
# print_release if @release | |
set_release_vars | |
reset_variables | |
else | |
@inside_release_details ||= section_header? | |
@release << @current_line | |
end | |
end | |
end | |
end | |
end | |
ReleaseNotesGenerator.instance.parse '/Users/krames/Projects/knife-rackspace/CHANGELOG.md' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment