-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#20 Resolve unexpected autorun behaviour caused by initialize
- Loading branch information
Showing
6 changed files
with
106 additions
and
92 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,15 @@ | ||
#!/usr/bin/env ruby | ||
|
||
COMMIT_URL='../../commit/' | ||
ISSUE_URL='../../issues/' | ||
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib")) | ||
|
||
def git_repository? | ||
initialized = `git rev-parse --is-inside-work-tree`.chomp | ||
require 'katip' | ||
require 'katip/change_logger' | ||
|
||
if initialized != 'true' | ||
initialized = false | ||
puts 'Exiting. Nothing to create log file.' | ||
end | ||
initialized | ||
if ARGV.size > 0 | ||
change_logger = Katip::ChangeLogger.new(ARGV.first) | ||
else | ||
change_logger = Katip::ChangeLogger.new() | ||
end | ||
|
||
def write_file(output) | ||
|
||
file_name='CHANGELOG.md' | ||
|
||
if ARGV.length > 0 | ||
file_name=ARGV[0] | ||
end | ||
|
||
begin | ||
file = File.open(file_name, 'w') | ||
file.puts output | ||
|
||
puts "Create #{file_name}" | ||
rescue IOError => e | ||
#some error occur, dir not writable etc. | ||
ensure | ||
file.close unless file == nil | ||
end | ||
end | ||
|
||
def parse_change_log | ||
|
||
output = [] | ||
|
||
tags=`git for-each-ref --sort='*authordate' --format='%(tag)' refs/tags | grep -v '^$'` | ||
|
||
tags = tags.split | ||
|
||
tags.reverse! | ||
|
||
output << "\n#### [Current]" | ||
|
||
previous_tag='' | ||
tags.each do |tag| | ||
current_tag = tag | ||
|
||
unless previous_tag.empty? | ||
output << "\n#### #{previous_tag}" | ||
end | ||
|
||
output << `git log --pretty=format:" * [%h](#{COMMIT_URL}%h) - __(%an)__ %s%n%n%-b" "#{current_tag}".."#{previous_tag}" | grep -v "Merge branch "` | ||
|
||
previous_tag = current_tag | ||
end | ||
|
||
output << "\n#### #{previous_tag}" | ||
|
||
output << `git log --pretty=format:" * [%h](#{COMMIT_URL}%h) - __(%an)__ %s%n%n%-b" #{previous_tag} | grep -v "Merge branch "` | ||
|
||
output.each do |line| | ||
|
||
line.encode!('utf-8', invalid: :replace, undef: :replace, replace: '') | ||
|
||
if line.index(/#[1-9][0-9]*/) | ||
line.gsub!(/#[1-9][0-9]*/) {|s| "[#{s}](#{ISSUE_URL}#{s[-(s.length-1)..-1]})"} | ||
end | ||
end | ||
|
||
output | ||
end | ||
|
||
if git_repository? | ||
write_file parse_change_log | ||
end | ||
change_logger.log_changes | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,6 @@ | ||
require 'katip/version' | ||
require 'katip/change_logger' | ||
require 'katip/railtie' | ||
|
||
module Katip | ||
require 'katip/railtie' if defined?(Rails) | ||
|
||
@@katip = `katip` | ||
|
||
def self.set(param) | ||
@@katip = param | ||
end | ||
|
||
def self.get | ||
@@katip | ||
end | ||
|
||
def self.get_file(file_name) | ||
@@katip = "katip #{file_name}" | ||
end | ||
|
||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# encoding: utf-8 | ||
require 'katip' | ||
require 'katip/change_logger' | ||
module Katip | ||
class ChangeLogger | ||
COMMIT_URL='../../commit/' | ||
ISSUE_URL='../../issues/' | ||
|
||
# initialize | ||
# | ||
# @param [String] file_name with path | ||
def initialize(file_name='CHANGELOG.md') | ||
@file_name = file_name | ||
end | ||
|
||
def log_changes | ||
if git_repository? | ||
write_file parse_change_log | ||
end | ||
end | ||
|
||
private | ||
def git_repository? | ||
initialized = `git rev-parse --is-inside-work-tree`.chomp | ||
|
||
if initialized != 'true' | ||
initialized = false | ||
puts 'Exiting. Nothing to create log file.' | ||
end | ||
initialized | ||
end | ||
|
||
def write_file(output) | ||
|
||
begin | ||
file = File.open(@file_name, 'w') | ||
file.puts output | ||
|
||
puts "Create #{@file_name}" | ||
rescue IOError => e | ||
#some error occur, dir not writable etc. | ||
ensure | ||
file.close unless file == nil | ||
end | ||
end | ||
|
||
def parse_change_log | ||
|
||
output = [] | ||
|
||
tags=`git for-each-ref --sort='*authordate' --format='%(tag)' refs/tags | grep -v '^$'` | ||
|
||
tags = tags.split | ||
|
||
tags.reverse! | ||
|
||
output << "\n#### [Current]" | ||
|
||
previous_tag='' | ||
tags.each do |tag| | ||
current_tag = tag | ||
|
||
unless previous_tag.empty? | ||
output << "\n#### #{previous_tag}" | ||
end | ||
|
||
output << `git log --pretty=format:" * [%h](#{COMMIT_URL}%h) - __(%an)__ %s%n%n%-b" "#{current_tag}".."#{previous_tag}" | grep -v "Merge branch "` | ||
|
||
previous_tag = current_tag | ||
end | ||
|
||
output << "\n#### #{previous_tag}" | ||
|
||
output << `git log --pretty=format:" * [%h](#{COMMIT_URL}%h) - __(%an)__ %s%n%n%-b" #{previous_tag} | grep -v "Merge branch "` | ||
|
||
output.each do |line| | ||
|
||
line.encode!('utf-8', invalid: :replace, undef: :replace, replace: '') | ||
|
||
if line.index(/#[1-9][0-9]*/) | ||
line.gsub!(/#[1-9][0-9]*/) {|s| "[#{s}](#{ISSUE_URL}#{s[-(s.length-1)..-1]})"} | ||
end | ||
end | ||
|
||
output | ||
end | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
namespace :katip do | ||
desc 'Create CHANGELOG.md' | ||
desc 'Create change log' | ||
task :create => [:environment] do | ||
|
||
file_name = ENV['file'] || 'CHANGELOG.md' | ||
|
||
exec Katip.get_file(file_name) | ||
change_logger = Katip::ChangeLogger.new(file_name) | ||
|
||
change_logger.log_changes | ||
end | ||
end |