5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/git_changelog_generator.rb', line 5
def self.generate_changelog output
is_git_directory = File.directory? '.git'
if is_git_directory
tags = (`git tag --sort=taggerdate --list --format='%(refname:short)'`.split("\n") << "HEAD").reverse
message = ''
tags.each_with_index { |tag, index|
if index < tags.length-1
cmd =`git log #{tags[index+1]}...#{tag} --format=" * %s (%an <%ae>)"`
else
cmd = `git log #{tag} --format=" * %s (%an <%ae>)"`
end
unless cmd.strip.empty?
message += index == 0 ? "Version #{tag} (" : "\nVersion #{tag[0..-1]} ("
message += `git log #{tag} --format='%aD' -1`
message = message[0..-2] + "):\n\n"
message += cmd
end
}
File.open(output, 'wb+') { |f|
f << message
}
puts "Created changelog. File is available under #{File.expand_path output}"
else
puts 'Not a git repository. Run this command inside a valid git directory.'
end
end
|