Skip to content

Commit 632117c

Browse files
committed
#20 Resolve unexpected autorun behaviour caused by initialize
1 parent 373b26a commit 632117c

File tree

6 files changed

+106
-92
lines changed

6 files changed

+106
-92
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

22
#### [Current]
3+
4+
5+
#### 1.2.1
6+
* [05b92d4](../../commit/05b92d4) - __(Murat Kemal BAYGÜN)__ Release 1.2.1
37
* [6391f34](../../commit/6391f34) - __(Murat Kemal BAYGÜN)__ [#21](../../issues/21) Add multiline commit support
48

59
Multiline commit note support added as referenced in common

bin/katip

Lines changed: 8 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,15 @@
11
#!/usr/bin/env ruby
22

3-
COMMIT_URL='../../commit/'
4-
ISSUE_URL='../../issues/'
3+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
54

6-
def git_repository?
7-
initialized = `git rev-parse --is-inside-work-tree`.chomp
5+
require 'katip'
6+
require 'katip/change_logger'
87

9-
if initialized != 'true'
10-
initialized = false
11-
puts 'Exiting. Nothing to create log file.'
12-
end
13-
initialized
8+
if ARGV.size > 0
9+
change_logger = Katip::ChangeLogger.new(ARGV.first)
10+
else
11+
change_logger = Katip::ChangeLogger.new()
1412
end
1513

16-
def write_file(output)
17-
18-
file_name='CHANGELOG.md'
19-
20-
if ARGV.length > 0
21-
file_name=ARGV[0]
22-
end
23-
24-
begin
25-
file = File.open(file_name, 'w')
26-
file.puts output
27-
28-
puts "Create #{file_name}"
29-
rescue IOError => e
30-
#some error occur, dir not writable etc.
31-
ensure
32-
file.close unless file == nil
33-
end
34-
end
35-
36-
def parse_change_log
37-
38-
output = []
39-
40-
tags=`git for-each-ref --sort='*authordate' --format='%(tag)' refs/tags | grep -v '^$'`
41-
42-
tags = tags.split
43-
44-
tags.reverse!
45-
46-
output << "\n#### [Current]"
47-
48-
previous_tag=''
49-
tags.each do |tag|
50-
current_tag = tag
51-
52-
unless previous_tag.empty?
53-
output << "\n#### #{previous_tag}"
54-
end
55-
56-
output << `git log --pretty=format:" * [%h](#{COMMIT_URL}%h) - __(%an)__ %s%n%n%-b" "#{current_tag}".."#{previous_tag}" | grep -v "Merge branch "`
57-
58-
previous_tag = current_tag
59-
end
60-
61-
output << "\n#### #{previous_tag}"
62-
63-
output << `git log --pretty=format:" * [%h](#{COMMIT_URL}%h) - __(%an)__ %s%n%n%-b" #{previous_tag} | grep -v "Merge branch "`
64-
65-
output.each do |line|
66-
67-
line.encode!('utf-8', invalid: :replace, undef: :replace, replace: '')
68-
69-
if line.index(/#[1-9][0-9]*/)
70-
line.gsub!(/#[1-9][0-9]*/) {|s| "[#{s}](#{ISSUE_URL}#{s[-(s.length-1)..-1]})"}
71-
end
72-
end
73-
74-
output
75-
end
76-
77-
if git_repository?
78-
write_file parse_change_log
79-
end
14+
change_logger.log_changes
8015

lib/katip.rb

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
require 'katip/version'
2+
require 'katip/change_logger'
3+
require 'katip/railtie'
24

35
module Katip
4-
require 'katip/railtie' if defined?(Rails)
5-
6-
@@katip = `katip`
7-
8-
def self.set(param)
9-
@@katip = param
10-
end
11-
12-
def self.get
13-
@@katip
14-
end
15-
16-
def self.get_file(file_name)
17-
@@katip = "katip #{file_name}"
18-
end
19-
206
end

lib/katip/change_logger.rb

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# encoding: utf-8
2+
require 'katip'
3+
require 'katip/change_logger'
4+
module Katip
5+
class ChangeLogger
6+
COMMIT_URL='../../commit/'
7+
ISSUE_URL='../../issues/'
8+
9+
# initialize
10+
#
11+
# @param [String] file_name with path
12+
def initialize(file_name='CHANGELOG.md')
13+
@file_name = file_name
14+
end
15+
16+
def log_changes
17+
if git_repository?
18+
write_file parse_change_log
19+
end
20+
end
21+
22+
private
23+
def git_repository?
24+
initialized = `git rev-parse --is-inside-work-tree`.chomp
25+
26+
if initialized != 'true'
27+
initialized = false
28+
puts 'Exiting. Nothing to create log file.'
29+
end
30+
initialized
31+
end
32+
33+
def write_file(output)
34+
35+
begin
36+
file = File.open(@file_name, 'w')
37+
file.puts output
38+
39+
puts "Create #{@file_name}"
40+
rescue IOError => e
41+
#some error occur, dir not writable etc.
42+
ensure
43+
file.close unless file == nil
44+
end
45+
end
46+
47+
def parse_change_log
48+
49+
output = []
50+
51+
tags=`git for-each-ref --sort='*authordate' --format='%(tag)' refs/tags | grep -v '^$'`
52+
53+
tags = tags.split
54+
55+
tags.reverse!
56+
57+
output << "\n#### [Current]"
58+
59+
previous_tag=''
60+
tags.each do |tag|
61+
current_tag = tag
62+
63+
unless previous_tag.empty?
64+
output << "\n#### #{previous_tag}"
65+
end
66+
67+
output << `git log --pretty=format:" * [%h](#{COMMIT_URL}%h) - __(%an)__ %s%n%n%-b" "#{current_tag}".."#{previous_tag}" | grep -v "Merge branch "`
68+
69+
previous_tag = current_tag
70+
end
71+
72+
output << "\n#### #{previous_tag}"
73+
74+
output << `git log --pretty=format:" * [%h](#{COMMIT_URL}%h) - __(%an)__ %s%n%n%-b" #{previous_tag} | grep -v "Merge branch "`
75+
76+
output.each do |line|
77+
78+
line.encode!('utf-8', invalid: :replace, undef: :replace, replace: '')
79+
80+
if line.index(/#[1-9][0-9]*/)
81+
line.gsub!(/#[1-9][0-9]*/) {|s| "[#{s}](#{ISSUE_URL}#{s[-(s.length-1)..-1]})"}
82+
end
83+
end
84+
85+
output
86+
end
87+
end
88+
end

lib/katip/railtie.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Railtie < Rails::Railtie
66
railtie_name :katip
77

88
rake_tasks do
9-
load "tasks/katip.rake"
9+
load 'tasks/katip.rake'
1010
end
1111
end
1212
end

lib/tasks/katip.rake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
namespace :katip do
2-
desc 'Create CHANGELOG.md'
2+
desc 'Create change log'
33
task :create => [:environment] do
44

55
file_name = ENV['file'] || 'CHANGELOG.md'
66

7-
exec Katip.get_file(file_name)
7+
change_logger = Katip::ChangeLogger.new(file_name)
88

9+
change_logger.log_changes
910
end
1011
end

0 commit comments

Comments
 (0)