-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGenerateChangeLog.pl
More file actions
131 lines (108 loc) · 3.26 KB
/
GenerateChangeLog.pl
File metadata and controls
131 lines (108 loc) · 3.26 KB
1
2
3
4
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env perl
## git changelog generator
## -----------------------
## Usage: GenerateChangeLog [commit hash]
## -----------------------
## Copyright : Jaufré Devosse
## License : MIT
## -----------------------
## base on this convention : "AngularJS Git Commit Message Conventions" at https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit
## -----------------------
#####################################################################
########################## Configuration ##################################
#####################################################################
# Set key searched inside the commit message and set the label written in the Markdown
%types = ("feat" => "Features", "fix" => "Bug Fixes");
# Set the markdown style of every Tag found
$versionMd = "#";
# Set the markdown style of every types found
$titleMd = "##";
# Set the markdown style of every subject found
$enumMd = "-";
#####################################################################
######################### Global variable ##################################
#####################################################################
$stop = $ARGV[0];
$prevTag = "";
@tagArray = ();
@tagDate = ();
$date = "";
@typeKeys = keys %types;
#####################################################################
########################### Function ####################################
#####################################################################
sub getTag {
if (@_[0] =~ m/tag: (.*?)[,)]/s) {
return $1;
}
return "";
}
sub initTag{
my $tag = $_[0];
if($$tag eq ""){
$$tag = $prevTag;
}
if($$tag eq ""){
$prevTag = $$tag = "Last Release";
}
}
sub saveTagData{
if($prevTag ne ""){
# Save Tag & Date
push(@tagArray, $prevTag);
push(@tagDate, $date);
# push table inside tag array
foreach $type (@typeKeys){
if( scalar @{$type}){
push(@{$prevTag.$type}, @{$type});
undef(@{$type});
}
}
}
}
#####################################################################
########################### Process #################################
#####################################################################
print "Git changelog generator\n";
print "-----------------------\n";
my $result = `git log --pretty=tformat:"#COMMIT#%+d%+cd%+H%n subject:%s%n body:%b%n" --date=short --decorate=short`;
@array = split(/#COMMIT#/, $result);
$pattern = '(.*?)\n(\d{4})-(\d{2})-(\d{2})\n(\w*)\n subject:(' . join("|", @typeKeys) . ') \((.*?)\):(.*?)\n body:(.*?)';
foreach $line (@array){
if ($line =~ m/$pattern/i) {
# --------------------
# Get Group values
$tag = getTag($1);
initTag(\$tag);
$hash = $5;
$type = lc $6;
$scope = lc $7;
$subjet = lc $8;
$body = $9;
# --------------------
if($tag ne $prevTag){
saveTagData();
$prevTag = $tag;
$date = "$4/$3/$2";
}
push(@{$type}, $subjet);
}
if($stop){
last if $hash eq $stop;
}
}
saveTagData();
for($i = 0; $i < @tagArray; $i++){
$tag = @tagArray[$i];
$date = @tagDate[$i];
print("\n$versionMd Version : $tag ($date)\n");
foreach $type (@typeKeys){
@array = @{$tag.$type};
if ( scalar @array){
$type = ucfirst $types{$type};
print("\n$titleMd$type\n$enumMd ");
print(join("\n$enumMd ", @array));
print("\n");
}
}
}