chlog 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/exe/chlog +82 -0
- data/lib/chlog/version.rb +16 -0
- data/lib/chlog.rb +340 -8
- metadata +8 -7
- data/bin/chlog +0 -422
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c501c040c85ebeba5c6171f5dfb6dcb6fddec08798166cd1beb0fce54dd27df
|
4
|
+
data.tar.gz: ec9bc451993d99992ae38d5ee2db80190e1fc55e5853d8665e6d31186be941cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bc058d3d29b835fdfea8577cec9195e75b2b30069f2b8ca4e49f942a228b3de600c741fdf302701dc02579cb9db62685990297a0c330b69d8993ecd838b1ecb
|
7
|
+
data.tar.gz: d8517e795b3bb1e4d9b9666bbeabcf92ac987e3a280275644ac5779e03e8fd68149f62d28c3c447da38087ddf5c2a6f9de67d55350b18845cdb5a6f531f6407e
|
data/exe/chlog
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# ------------------------------------------------------
|
3
|
+
# File : chlog.rb
|
4
|
+
# Authors : Aoran Zeng <ccmywish@qq.com>
|
5
|
+
# Created on : <2022-03-18>
|
6
|
+
# Last modified : <2023-05-09>
|
7
|
+
#
|
8
|
+
# chlog:
|
9
|
+
#
|
10
|
+
# Maintain your project's Changelog on the cli.
|
11
|
+
# ------------------------------------------------------
|
12
|
+
|
13
|
+
require 'chlog'
|
14
|
+
|
15
|
+
module Chlog::CLI
|
16
|
+
|
17
|
+
def self.run
|
18
|
+
|
19
|
+
args = $*.dup
|
20
|
+
|
21
|
+
if args.size == 0
|
22
|
+
help or exit
|
23
|
+
end
|
24
|
+
|
25
|
+
action = args[0]
|
26
|
+
|
27
|
+
case action
|
28
|
+
when "-h", "--help" then help or exit end
|
29
|
+
|
30
|
+
logger = Chlog::Logger.new
|
31
|
+
|
32
|
+
case action
|
33
|
+
when "-g" then exit logger.generate_changelog
|
34
|
+
when "-r" then exit logger.release_new_version(args[1])
|
35
|
+
end
|
36
|
+
|
37
|
+
if args[1] =~ /^--(.*)/
|
38
|
+
logger.sub_category = $1
|
39
|
+
logger.log = args[2..].join(' ')
|
40
|
+
else
|
41
|
+
logger.sub_category = nil
|
42
|
+
logger.log = args[1..].join(' ')
|
43
|
+
end
|
44
|
+
|
45
|
+
case action
|
46
|
+
when /-[nebscd]/
|
47
|
+
logger.take_action(action)
|
48
|
+
else
|
49
|
+
# action =~ /^-[^-]*$/
|
50
|
+
abort "chlog: Unknown option!"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
def self.help
|
56
|
+
puts <<~EOH
|
57
|
+
chlog (v#{Chlog::GEM_VERSION}): Help maintain the Changelog of your projects
|
58
|
+
|
59
|
+
Usage:
|
60
|
+
|
61
|
+
chlog -g Generate CHANGELOG.md in git root
|
62
|
+
chlog -r <3.14> Release version to v3.14
|
63
|
+
|
64
|
+
Add log:
|
65
|
+
|
66
|
+
chlog <-main category> [--sub category] <log>
|
67
|
+
|
68
|
+
Main Category:
|
69
|
+
|
70
|
+
-n Add log to New features
|
71
|
+
-e Add log to Enhancements
|
72
|
+
-b Add log to Bug fixes
|
73
|
+
-s Add log to Security
|
74
|
+
-c Add log to Compatibility
|
75
|
+
-d Add log to Deprecations
|
76
|
+
|
77
|
+
EOH
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
Chlog::CLI.run
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# ---------------------------------------------------------------
|
2
|
+
# File : version.rb
|
3
|
+
# Authors : Aoran Zeng <ccmywish@qq.com>
|
4
|
+
# Created on : <2023-05-09>
|
5
|
+
# Last modified : <2023-05-09>
|
6
|
+
#
|
7
|
+
# version:
|
8
|
+
#
|
9
|
+
# Lib version
|
10
|
+
# ---------------------------------------------------------------
|
11
|
+
|
12
|
+
module Chlog
|
13
|
+
|
14
|
+
GEM_VERSION = "0.9.0"
|
15
|
+
|
16
|
+
end
|
data/lib/chlog.rb
CHANGED
@@ -1,20 +1,15 @@
|
|
1
1
|
# ------------------------------------------------------
|
2
2
|
# File : chlog.rb
|
3
|
-
# Authors :
|
3
|
+
# Authors : Aoran Zeng <ccmywish@qq.com>
|
4
4
|
# Created on : <2022-04-15>
|
5
|
-
# Last modified : <2023-
|
5
|
+
# Last modified : <2023-05-09>
|
6
6
|
#
|
7
7
|
# chlog:
|
8
8
|
#
|
9
9
|
# Maintain your project's Changelog on the cli.
|
10
10
|
# ------------------------------------------------------
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
GEM_VERSION = "0.8.1"
|
15
|
-
|
16
|
-
end
|
17
|
-
|
12
|
+
require_relative 'chlog/version'
|
18
13
|
|
19
14
|
class Chlog::Logger
|
20
15
|
|
@@ -83,3 +78,340 @@ class Chlog::Logger
|
|
83
78
|
end
|
84
79
|
|
85
80
|
end
|
81
|
+
|
82
|
+
|
83
|
+
class Chlog::Logger
|
84
|
+
|
85
|
+
def match_unreleased?(str)
|
86
|
+
str =~ /^## \[Unreleased\]\(.*\) \(\d{4}-\d\d-\d\d\)/
|
87
|
+
end
|
88
|
+
|
89
|
+
def match_unreleased_fail!(str)
|
90
|
+
unless match_unreleased?(str)
|
91
|
+
puts "chlog: Unmatched format with chlog"
|
92
|
+
puts
|
93
|
+
# "#{lns[1][1..]}"
|
94
|
+
abort "Unreleased version must be the third line"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def match_new_features?(str)
|
99
|
+
str =~ /^### New features:/
|
100
|
+
end
|
101
|
+
|
102
|
+
def match_enhancements?(str)
|
103
|
+
str =~ /^### Enhancements:/
|
104
|
+
end
|
105
|
+
|
106
|
+
def match_bug_fixes?(str)
|
107
|
+
str =~ /^### Bug fixes:/
|
108
|
+
end
|
109
|
+
|
110
|
+
def match_security?(str)
|
111
|
+
str =~ /^### Security:/
|
112
|
+
end
|
113
|
+
|
114
|
+
def match_compatibility?(str)
|
115
|
+
str =~ /^### Compatibility:/
|
116
|
+
end
|
117
|
+
|
118
|
+
def match_deprecations?(str)
|
119
|
+
str =~ /^### Deprecations:/
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
def next_version_index(lns_array)
|
124
|
+
nvi = lns_array[3..].each_with_index {break _2 if _1.start_with?("## [") }
|
125
|
+
nvi += 3
|
126
|
+
end
|
127
|
+
|
128
|
+
def next_category_index(lns_array)
|
129
|
+
nci = lns_array[3...nvi].each_with_index {break _2 if _1.start_with?("### ") }
|
130
|
+
|
131
|
+
# The not match return value is not nil!! But an array!!
|
132
|
+
if nci.is_a(Integer) then nci += 3
|
133
|
+
else nil end
|
134
|
+
end
|
135
|
+
|
136
|
+
=begin
|
137
|
+
### New features:
|
138
|
+
|
139
|
+
- xaaaaa
|
140
|
+
- xbbbbb
|
141
|
+
- xccccc [-> this]
|
142
|
+
=end
|
143
|
+
def find_main_category_last_list_item_index(lns,
|
144
|
+
main_cat_index,
|
145
|
+
first_lower_order_category_index)
|
146
|
+
mci = main_cat_index
|
147
|
+
nci = first_lower_order_category_index
|
148
|
+
|
149
|
+
list_i = lns[mci+2..nci].each_with_index do
|
150
|
+
break _2 if _1 !~ /^- .*/
|
151
|
+
end
|
152
|
+
list_i += mci+2 - 1
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
LIST__Feature = %w[
|
157
|
+
new_features enhancements bug_fixes
|
158
|
+
security compatibility deprecations
|
159
|
+
]
|
160
|
+
|
161
|
+
# New features
|
162
|
+
# Enhancements
|
163
|
+
# Bug fixes
|
164
|
+
# Security
|
165
|
+
# Compatibility
|
166
|
+
# Deprecations
|
167
|
+
LIST__Main_Category = LIST__Feature.map do
|
168
|
+
_1.split('_').join(' ').capitalize
|
169
|
+
end
|
170
|
+
|
171
|
+
# match_new_features?
|
172
|
+
# match_enhancements?
|
173
|
+
# match_ ...
|
174
|
+
LIST__Match_Method = LIST__Feature.map do
|
175
|
+
('match_' + _1 + '?').to_sym
|
176
|
+
end
|
177
|
+
|
178
|
+
=begin
|
179
|
+
{
|
180
|
+
1 => :add_to_new_features,
|
181
|
+
2 => :add_to_enhancements,
|
182
|
+
...
|
183
|
+
}
|
184
|
+
=end
|
185
|
+
HASH__Order_To_AddTo_Method = ([1,2,3,4,5,6].zip LIST__Feature.map {|m| ('add_to_' + m).to_sym }).to_h
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
def take_action(action)
|
190
|
+
options = "nebscd"
|
191
|
+
|
192
|
+
=begin
|
193
|
+
{
|
194
|
+
"-n" => "new_features", "-e" => "enhancements", "-b" => "bug_fixes",
|
195
|
+
"-s" => "security", "-c" => "compatibility", "-d" => "deprecations"
|
196
|
+
}
|
197
|
+
=end
|
198
|
+
action_table = options.chars.map do |op|
|
199
|
+
'-' + op
|
200
|
+
end.zip(LIST__Feature).to_h
|
201
|
+
|
202
|
+
public_send "add_to_#{action_table[action]}"
|
203
|
+
end
|
204
|
+
|
205
|
+
|
206
|
+
def first_lower_order_category_index(lns_array, category_order)
|
207
|
+
|
208
|
+
o = category_order
|
209
|
+
|
210
|
+
nvi = next_version_index(lns_array)
|
211
|
+
|
212
|
+
while o < LIST__Match_Method.size
|
213
|
+
lns_array[0...nvi].each_with_index do
|
214
|
+
return _2 if send(LIST__Match_Method[o], _1)
|
215
|
+
end
|
216
|
+
o += 1
|
217
|
+
end
|
218
|
+
|
219
|
+
# Next version above
|
220
|
+
return (nvi - 2)
|
221
|
+
end
|
222
|
+
|
223
|
+
|
224
|
+
# A meta function: do the real work other 6 functions delegate
|
225
|
+
#
|
226
|
+
# This function detect the main category, and then handle the
|
227
|
+
# sub category.
|
228
|
+
def meta_add_to_a_category(log, main_category_order, category)
|
229
|
+
|
230
|
+
content = get_changelog
|
231
|
+
lns = content.lines
|
232
|
+
|
233
|
+
match_unreleased_fail!(lns[2])
|
234
|
+
|
235
|
+
nvi = next_version_index(lns)
|
236
|
+
# To find the existing category line
|
237
|
+
main_cat_i = lns[0...nvi].each_with_index do
|
238
|
+
# Adjust to index of the order table
|
239
|
+
break _2 if send(LIST__Match_Method[main_category_order-1], _1)
|
240
|
+
end
|
241
|
+
|
242
|
+
#
|
243
|
+
# Always update to latest time when making a log
|
244
|
+
#
|
245
|
+
# We must add a "\n" because every element of the array
|
246
|
+
# is a sentence with a trailing newline, then they can
|
247
|
+
# be 'joined' to a working long string
|
248
|
+
#
|
249
|
+
lns[2] = UNRELEASED_TITLE + "\n"
|
250
|
+
|
251
|
+
f_l_o_c_i = first_lower_order_category_index(lns, main_category_order)
|
252
|
+
|
253
|
+
if main_cat_i.class != Integer
|
254
|
+
################################################################################
|
255
|
+
# The main category not exists
|
256
|
+
################################################################################
|
257
|
+
|
258
|
+
|
259
|
+
########################################
|
260
|
+
if @sub_category
|
261
|
+
|
262
|
+
# Because the main category not exists,
|
263
|
+
# nor does the sub category
|
264
|
+
#
|
265
|
+
sub_cat_i = f_l_o_c_i
|
266
|
+
to_wr = lns[0...sub_cat_i].join + "### #{category}:\n\n" + "**#{@sub_category}**\n\n" + ' - ' + log + "\n\n"
|
267
|
+
File.write(@changelog, to_wr + lns[sub_cat_i..].join)
|
268
|
+
|
269
|
+
puts "chlog: Add log to #{category}/#{@sub_category}"
|
270
|
+
return
|
271
|
+
end # end of if @sub_category
|
272
|
+
########################################
|
273
|
+
|
274
|
+
# situation: no sub category
|
275
|
+
|
276
|
+
# Not need adjust to the index of the order table
|
277
|
+
log_loc = f_l_o_c_i
|
278
|
+
puts "chlog: Add '#{category}' category"
|
279
|
+
to_wr = lns[0...(log_loc)].join + "### #{category}:\n\n" + '- ' + log + "\n"
|
280
|
+
File.write(@changelog, to_wr + lns[log_loc-1..].join)
|
281
|
+
|
282
|
+
else
|
283
|
+
################################################################################
|
284
|
+
# The main category exists
|
285
|
+
################################################################################
|
286
|
+
|
287
|
+
|
288
|
+
########################################
|
289
|
+
if @sub_category
|
290
|
+
|
291
|
+
# from first list item to next main cat
|
292
|
+
# search if sub cat already exists
|
293
|
+
sub_cat_i = lns[main_cat_i+2...f_l_o_c_i].each_with_index do
|
294
|
+
break _2 if _1 =~ /^\*\*#{@sub_category}\*\*/
|
295
|
+
end
|
296
|
+
|
297
|
+
if !sub_cat_i.is_a?(Integer)
|
298
|
+
# the sub category not exists
|
299
|
+
|
300
|
+
sub_cat_i = 2 + find_main_category_last_list_item_index(lns,main_cat_i,f_l_o_c_i)
|
301
|
+
to_wr = lns[0...sub_cat_i].join + "**#{@sub_category}**\n\n" + ' - ' + log + "\n\n"
|
302
|
+
File.write(@changelog, to_wr + lns[sub_cat_i..].join)
|
303
|
+
else
|
304
|
+
# the sub category exists
|
305
|
+
|
306
|
+
sub_cat_i += main_cat_i+2
|
307
|
+
to_wr = lns[0..sub_cat_i+1].join + ' - ' + log + "\n"
|
308
|
+
File.write(@changelog, to_wr + lns[sub_cat_i+2..].join)
|
309
|
+
end
|
310
|
+
|
311
|
+
puts "chlog: Add log to #{category}/#{@sub_category}"
|
312
|
+
return
|
313
|
+
end # end of if @sub_category
|
314
|
+
########################################
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
# situation: no sub category
|
319
|
+
|
320
|
+
to_wr = lns[0..main_cat_i+1].join + '- ' + log + "\n"
|
321
|
+
|
322
|
+
# main category list should be separated with
|
323
|
+
# sub category
|
324
|
+
if lns[main_cat_i+2] =~ /\*\*.*/
|
325
|
+
to_wr += "\n"
|
326
|
+
end
|
327
|
+
File.write(@changelog, to_wr + lns[main_cat_i+2..].join)
|
328
|
+
end
|
329
|
+
|
330
|
+
puts "chlog: Add log to #{category}"
|
331
|
+
end
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
# main category order: 1
|
336
|
+
def add_to_new_features
|
337
|
+
meta_add_to_a_category(@log, 1, "New features")
|
338
|
+
end
|
339
|
+
|
340
|
+
# main category order: 2
|
341
|
+
def add_to_enhancements
|
342
|
+
meta_add_to_a_category(@log, 2, "Enhancements")
|
343
|
+
end
|
344
|
+
|
345
|
+
# main_category_order: 3
|
346
|
+
def add_to_bug_fixes
|
347
|
+
meta_add_to_a_category(@log, 3, "Bug fixes")
|
348
|
+
end
|
349
|
+
|
350
|
+
# main_category_order: 4
|
351
|
+
def add_to_security
|
352
|
+
meta_add_to_a_category(@log, 4, "Security")
|
353
|
+
end
|
354
|
+
|
355
|
+
# main_category_order: 5
|
356
|
+
def add_to_compatibility
|
357
|
+
meta_add_to_a_category(@log, 5, "Compatibility")
|
358
|
+
end
|
359
|
+
|
360
|
+
# The last of order table
|
361
|
+
# main_category_order: 6
|
362
|
+
def add_to_deprecations
|
363
|
+
meta_add_to_a_category(@log, 6, "Deprecations")
|
364
|
+
end
|
365
|
+
|
366
|
+
# Release a version
|
367
|
+
def release_new_version(ver)
|
368
|
+
if ver.nil?
|
369
|
+
puts "chlog: No version supplied!"; puts; abort "Use chlog -r <version>!"
|
370
|
+
end
|
371
|
+
|
372
|
+
if !ver.downcase.start_with?('v') and ver[0].match? /\d/
|
373
|
+
ver = 'v' + ver
|
374
|
+
end
|
375
|
+
|
376
|
+
content = get_changelog
|
377
|
+
lns = content.lines
|
378
|
+
|
379
|
+
match_unreleased_fail!(lns[2])
|
380
|
+
|
381
|
+
header = <<~EOF
|
382
|
+
# Changelog
|
383
|
+
|
384
|
+
## [Unreleased](#) (#{TODAY})
|
385
|
+
|
386
|
+
<br>
|
387
|
+
|
388
|
+
EOF
|
389
|
+
|
390
|
+
new_version = "## [#{ver}](#) (#{TODAY})\n"
|
391
|
+
new_cont = header + new_version + lns[3..].join('')
|
392
|
+
File.write(@changelog, new_cont)
|
393
|
+
puts "chlog: Release #{ver} in Changelog!" or return true
|
394
|
+
end
|
395
|
+
|
396
|
+
|
397
|
+
# Help user interactively
|
398
|
+
def ask_user_category
|
399
|
+
category = @highline.choose do |menu|
|
400
|
+
menu.index_color = :rgb_77bbff
|
401
|
+
menu.prompt = "What main category?"
|
402
|
+
# return number!!! not string!!!
|
403
|
+
menu.choices(*LIST__Main_Category)
|
404
|
+
end
|
405
|
+
|
406
|
+
option = LIST__Main_Category.index(category)
|
407
|
+
|
408
|
+
if @sub_category.nil?
|
409
|
+
sub = @highline.ask "What sub category? [NIL/sub]"
|
410
|
+
case sub
|
411
|
+
when '' then @sub_category = nil
|
412
|
+
else @sub_category = sub end
|
413
|
+
end
|
414
|
+
return option
|
415
|
+
end
|
416
|
+
|
417
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chlog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Aoran Zeng
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -34,8 +34,9 @@ executables:
|
|
34
34
|
extensions: []
|
35
35
|
extra_rdoc_files: []
|
36
36
|
files:
|
37
|
-
-
|
37
|
+
- exe/chlog
|
38
38
|
- lib/chlog.rb
|
39
|
+
- lib/chlog/version.rb
|
39
40
|
homepage: https://github.com/ccmywish/chlog
|
40
41
|
licenses:
|
41
42
|
- MIT
|
@@ -57,8 +58,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
58
|
- !ruby/object:Gem::Version
|
58
59
|
version: '0'
|
59
60
|
requirements: []
|
60
|
-
rubygems_version: 3.
|
61
|
+
rubygems_version: 3.4.8
|
61
62
|
signing_key:
|
62
63
|
specification_version: 4
|
63
|
-
summary:
|
64
|
+
summary: Help maintain Changelog on the command line!
|
64
65
|
test_files: []
|
data/bin/chlog
DELETED
@@ -1,422 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# ------------------------------------------------------
|
3
|
-
# File : chlog.rb
|
4
|
-
# Authors : ccmywish <ccmywish@qq.com>
|
5
|
-
# Created on : <2022-03-18>
|
6
|
-
# Last modified : <2023-02-12>
|
7
|
-
#
|
8
|
-
# chlog:
|
9
|
-
#
|
10
|
-
# Maintain your project's Changelog on the cli.
|
11
|
-
# ------------------------------------------------------
|
12
|
-
|
13
|
-
require 'chlog'
|
14
|
-
|
15
|
-
class Chlog::CliHandler
|
16
|
-
|
17
|
-
def initialize(args)
|
18
|
-
|
19
|
-
if args.size == 0
|
20
|
-
help or exit
|
21
|
-
end
|
22
|
-
|
23
|
-
action = args[0]
|
24
|
-
|
25
|
-
case action
|
26
|
-
when "-h", "--help" then help or exit end
|
27
|
-
|
28
|
-
logger = Chlog::Logger.new
|
29
|
-
|
30
|
-
case action
|
31
|
-
when "-g" then exit logger.generate_changelog
|
32
|
-
when "-r" then exit logger.release_new_version(args[1])
|
33
|
-
end
|
34
|
-
|
35
|
-
if args[1] =~ /^--(.*)/
|
36
|
-
logger.sub_category = $1
|
37
|
-
logger.log = args[2..].join(' ')
|
38
|
-
else
|
39
|
-
logger.sub_category = nil
|
40
|
-
logger.log = args[1..].join(' ')
|
41
|
-
end
|
42
|
-
|
43
|
-
case action
|
44
|
-
when /-[nebscd]/
|
45
|
-
logger.take_action(action)
|
46
|
-
else
|
47
|
-
# action =~ /^-[^-]*$/
|
48
|
-
abort "chlog: Unknown option!"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
def help
|
54
|
-
puts <<~EOH
|
55
|
-
chlog (v#{Chlog::GEM_VERSION}): Help maintain the Changelog of your projects
|
56
|
-
|
57
|
-
Usage:
|
58
|
-
|
59
|
-
chlog -g Generate CHANGELOG.md in git root
|
60
|
-
chlog -r <3.14> Release version to v3.14
|
61
|
-
|
62
|
-
Add log:
|
63
|
-
|
64
|
-
chlog <-main category> [--sub category] <log>
|
65
|
-
|
66
|
-
Main Category:
|
67
|
-
|
68
|
-
-n Add log to New features
|
69
|
-
-e Add log to Enhancements
|
70
|
-
-b Add log to Bug fixes
|
71
|
-
-s Add log to Security
|
72
|
-
-c Add log to Compatibility
|
73
|
-
-d Add log to Deprecations
|
74
|
-
|
75
|
-
EOH
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
class Chlog::Logger
|
83
|
-
|
84
|
-
def match_unreleased?(str)
|
85
|
-
str =~ /^## \[Unreleased\]\(.*\) \(\d{4}-\d\d-\d\d\)/
|
86
|
-
end
|
87
|
-
|
88
|
-
def match_unreleased_fail!(str)
|
89
|
-
unless match_unreleased?(str)
|
90
|
-
puts "chlog: Unmatched format with chlog"
|
91
|
-
puts
|
92
|
-
# "#{lns[1][1..]}"
|
93
|
-
abort "Unreleased version must be the third line"
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def match_new_features?(str)
|
98
|
-
str =~ /^### New features:/
|
99
|
-
end
|
100
|
-
|
101
|
-
def match_enhancements?(str)
|
102
|
-
str =~ /^### Enhancements:/
|
103
|
-
end
|
104
|
-
|
105
|
-
def match_bug_fixes?(str)
|
106
|
-
str =~ /^### Bug fixes:/
|
107
|
-
end
|
108
|
-
|
109
|
-
def match_security?(str)
|
110
|
-
str =~ /^### Security:/
|
111
|
-
end
|
112
|
-
|
113
|
-
def match_compatibility?(str)
|
114
|
-
str =~ /^### Compatibility:/
|
115
|
-
end
|
116
|
-
|
117
|
-
def match_deprecations?(str)
|
118
|
-
str =~ /^### Deprecations:/
|
119
|
-
end
|
120
|
-
|
121
|
-
|
122
|
-
def next_version_index(lns_array)
|
123
|
-
nvi = lns_array[3..].each_with_index {break _2 if _1.start_with?("## [") }
|
124
|
-
nvi += 3
|
125
|
-
end
|
126
|
-
|
127
|
-
def next_category_index(lns_array)
|
128
|
-
nci = lns_array[3...nvi].each_with_index {break _2 if _1.start_with?("### ") }
|
129
|
-
|
130
|
-
# The not match return value is not nil!! But an array!!
|
131
|
-
if nci.is_a(Integer) then nci += 3
|
132
|
-
else nil end
|
133
|
-
end
|
134
|
-
|
135
|
-
=begin
|
136
|
-
### New features:
|
137
|
-
|
138
|
-
- xaaaaa
|
139
|
-
- xbbbbb
|
140
|
-
- xccccc [-> this]
|
141
|
-
=end
|
142
|
-
def find_main_category_last_list_item_index(lns,
|
143
|
-
main_cat_index,
|
144
|
-
first_lower_order_category_index)
|
145
|
-
mci = main_cat_index
|
146
|
-
nci = first_lower_order_category_index
|
147
|
-
|
148
|
-
list_i = lns[mci+2..nci].each_with_index do
|
149
|
-
break _2 if _1 !~ /^- .*/
|
150
|
-
end
|
151
|
-
list_i += mci+2 - 1
|
152
|
-
end
|
153
|
-
|
154
|
-
|
155
|
-
LIST__Feature = %w[
|
156
|
-
new_features enhancements bug_fixes
|
157
|
-
security compatibility deprecations
|
158
|
-
]
|
159
|
-
|
160
|
-
# New features
|
161
|
-
# Enhancements
|
162
|
-
# Bug fixes
|
163
|
-
# Security
|
164
|
-
# Compatibility
|
165
|
-
# Deprecations
|
166
|
-
LIST__Main_Category = LIST__Feature.map do
|
167
|
-
_1.split('_').join(' ').capitalize
|
168
|
-
end
|
169
|
-
|
170
|
-
# match_new_features?
|
171
|
-
# match_enhancements?
|
172
|
-
# match_ ...
|
173
|
-
LIST__Match_Method = LIST__Feature.map do
|
174
|
-
('match_' + _1 + '?').to_sym
|
175
|
-
end
|
176
|
-
|
177
|
-
=begin
|
178
|
-
{
|
179
|
-
1 => :add_to_new_features,
|
180
|
-
2 => :add_to_enhancements,
|
181
|
-
...
|
182
|
-
}
|
183
|
-
=end
|
184
|
-
HASH__Order_To_AddTo_Method = ([1,2,3,4,5,6].zip LIST__Feature.map {|m| ('add_to_' + m).to_sym }).to_h
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
def take_action(action)
|
189
|
-
options = "nebscd"
|
190
|
-
|
191
|
-
=begin
|
192
|
-
{
|
193
|
-
"-n" => "new_features", "-e" => "enhancements", "-b" => "bug_fixes",
|
194
|
-
"-s" => "security", "-c" => "compatibility", "-d" => "deprecations"
|
195
|
-
}
|
196
|
-
=end
|
197
|
-
action_table = options.chars.map do |op|
|
198
|
-
'-' + op
|
199
|
-
end.zip(LIST__Feature).to_h
|
200
|
-
|
201
|
-
public_send "add_to_#{action_table[action]}"
|
202
|
-
end
|
203
|
-
|
204
|
-
|
205
|
-
def first_lower_order_category_index(lns_array, category_order)
|
206
|
-
|
207
|
-
o = category_order
|
208
|
-
|
209
|
-
nvi = next_version_index(lns_array)
|
210
|
-
|
211
|
-
while o < LIST__Match_Method.size
|
212
|
-
lns_array[0...nvi].each_with_index do
|
213
|
-
return _2 if send(LIST__Match_Method[o], _1)
|
214
|
-
end
|
215
|
-
o += 1
|
216
|
-
end
|
217
|
-
|
218
|
-
# Next version above
|
219
|
-
return (nvi - 2)
|
220
|
-
end
|
221
|
-
|
222
|
-
|
223
|
-
# A meta function: do the real work other 6 functions delegate
|
224
|
-
#
|
225
|
-
# This function detect the main category, and then handle the
|
226
|
-
# sub category.
|
227
|
-
def meta_add_to_a_category(log, main_category_order, category)
|
228
|
-
|
229
|
-
content = get_changelog
|
230
|
-
lns = content.lines
|
231
|
-
|
232
|
-
match_unreleased_fail!(lns[2])
|
233
|
-
|
234
|
-
nvi = next_version_index(lns)
|
235
|
-
# To find the existing category line
|
236
|
-
main_cat_i = lns[0...nvi].each_with_index do
|
237
|
-
# Adjust to index of the order table
|
238
|
-
break _2 if send(LIST__Match_Method[main_category_order-1], _1)
|
239
|
-
end
|
240
|
-
|
241
|
-
#
|
242
|
-
# Always update to latest time when making a log
|
243
|
-
#
|
244
|
-
# We must add a "\n" because every element of the array
|
245
|
-
# is a sentence with a trailing newline, then they can
|
246
|
-
# be 'joined' to a working long string
|
247
|
-
#
|
248
|
-
lns[2] = UNRELEASED_TITLE + "\n"
|
249
|
-
|
250
|
-
f_l_o_c_i = first_lower_order_category_index(lns, main_category_order)
|
251
|
-
|
252
|
-
if main_cat_i.class != Integer
|
253
|
-
################################################################################
|
254
|
-
# The main category not exists
|
255
|
-
################################################################################
|
256
|
-
|
257
|
-
|
258
|
-
########################################
|
259
|
-
if @sub_category
|
260
|
-
|
261
|
-
# Because the main category not exists,
|
262
|
-
# nor does the sub category
|
263
|
-
#
|
264
|
-
sub_cat_i = f_l_o_c_i
|
265
|
-
to_wr = lns[0...sub_cat_i].join + "### #{category}:\n\n" + "**#{@sub_category}**\n\n" + ' - ' + log + "\n\n"
|
266
|
-
File.write(@changelog, to_wr + lns[sub_cat_i..].join)
|
267
|
-
|
268
|
-
puts "chlog: Add log to #{category}/#{@sub_category}"
|
269
|
-
return
|
270
|
-
end # end of if @sub_category
|
271
|
-
########################################
|
272
|
-
|
273
|
-
# situation: no sub category
|
274
|
-
|
275
|
-
# Not need adjust to the index of the order table
|
276
|
-
log_loc = f_l_o_c_i
|
277
|
-
puts "chlog: Add '#{category}' category"
|
278
|
-
to_wr = lns[0...(log_loc)].join + "### #{category}:\n\n" + '- ' + log + "\n"
|
279
|
-
File.write(@changelog, to_wr + lns[log_loc-1..].join)
|
280
|
-
|
281
|
-
else
|
282
|
-
################################################################################
|
283
|
-
# The main category exists
|
284
|
-
################################################################################
|
285
|
-
|
286
|
-
|
287
|
-
########################################
|
288
|
-
if @sub_category
|
289
|
-
|
290
|
-
# from first list item to next main cat
|
291
|
-
# search if sub cat already exists
|
292
|
-
sub_cat_i = lns[main_cat_i+2...f_l_o_c_i].each_with_index do
|
293
|
-
break _2 if _1 =~ /^\*\*#{@sub_category}\*\*/
|
294
|
-
end
|
295
|
-
|
296
|
-
if !sub_cat_i.is_a?(Integer)
|
297
|
-
# the sub category not exists
|
298
|
-
|
299
|
-
sub_cat_i = 2 + find_main_category_last_list_item_index(lns,main_cat_i,f_l_o_c_i)
|
300
|
-
to_wr = lns[0...sub_cat_i].join + "**#{@sub_category}**\n\n" + ' - ' + log + "\n\n"
|
301
|
-
File.write(@changelog, to_wr + lns[sub_cat_i..].join)
|
302
|
-
else
|
303
|
-
# the sub category exists
|
304
|
-
|
305
|
-
sub_cat_i += main_cat_i+2
|
306
|
-
to_wr = lns[0..sub_cat_i+1].join + ' - ' + log + "\n"
|
307
|
-
File.write(@changelog, to_wr + lns[sub_cat_i+2..].join)
|
308
|
-
end
|
309
|
-
|
310
|
-
puts "chlog: Add log to #{category}/#{@sub_category}"
|
311
|
-
return
|
312
|
-
end # end of if @sub_category
|
313
|
-
########################################
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
# situation: no sub category
|
318
|
-
|
319
|
-
to_wr = lns[0..main_cat_i+1].join + '- ' + log + "\n"
|
320
|
-
|
321
|
-
# main category list should be separated with
|
322
|
-
# sub category
|
323
|
-
if lns[main_cat_i+2] =~ /\*\*.*/
|
324
|
-
to_wr += "\n"
|
325
|
-
end
|
326
|
-
File.write(@changelog, to_wr + lns[main_cat_i+2..].join)
|
327
|
-
end
|
328
|
-
|
329
|
-
puts "chlog: Add log to #{category}"
|
330
|
-
end
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
# main category order: 1
|
335
|
-
def add_to_new_features
|
336
|
-
meta_add_to_a_category(@log, 1, "New features")
|
337
|
-
end
|
338
|
-
|
339
|
-
# main category order: 2
|
340
|
-
def add_to_enhancements
|
341
|
-
meta_add_to_a_category(@log, 2, "Enhancements")
|
342
|
-
end
|
343
|
-
|
344
|
-
# main_category_order: 3
|
345
|
-
def add_to_bug_fixes
|
346
|
-
meta_add_to_a_category(@log, 3, "Bug fixes")
|
347
|
-
end
|
348
|
-
|
349
|
-
# main_category_order: 4
|
350
|
-
def add_to_security
|
351
|
-
meta_add_to_a_category(@log, 4, "Security")
|
352
|
-
end
|
353
|
-
|
354
|
-
# main_category_order: 5
|
355
|
-
def add_to_compatibility
|
356
|
-
meta_add_to_a_category(@log, 5, "Compatibility")
|
357
|
-
end
|
358
|
-
|
359
|
-
# The last of order table
|
360
|
-
# main_category_order: 6
|
361
|
-
def add_to_deprecations
|
362
|
-
meta_add_to_a_category(@log, 6, "Deprecations")
|
363
|
-
end
|
364
|
-
|
365
|
-
# Release a version
|
366
|
-
def release_new_version(ver)
|
367
|
-
if ver.nil?
|
368
|
-
puts "chlog: No version supplied!"; puts; abort "Use chlog -r <version>!"
|
369
|
-
end
|
370
|
-
|
371
|
-
if !ver.downcase.start_with?('v') and ver[0].match? /\d/
|
372
|
-
ver = 'v' + ver
|
373
|
-
end
|
374
|
-
|
375
|
-
content = get_changelog
|
376
|
-
lns = content.lines
|
377
|
-
|
378
|
-
match_unreleased_fail!(lns[2])
|
379
|
-
|
380
|
-
header = <<~EOF
|
381
|
-
# Changelog
|
382
|
-
|
383
|
-
## [Unreleased](#) (#{TODAY})
|
384
|
-
|
385
|
-
<br>
|
386
|
-
|
387
|
-
EOF
|
388
|
-
|
389
|
-
new_version = "## [#{ver}](#) (#{TODAY})\n"
|
390
|
-
new_cont = header + new_version + lns[3..].join('')
|
391
|
-
File.write(@changelog, new_cont)
|
392
|
-
puts "chlog: Release #{ver} in Changelog!" or return true
|
393
|
-
end
|
394
|
-
|
395
|
-
|
396
|
-
# Help user interactively
|
397
|
-
def ask_user_category
|
398
|
-
category = @highline.choose do |menu|
|
399
|
-
menu.index_color = :rgb_77bbff
|
400
|
-
menu.prompt = "What main category?"
|
401
|
-
# return number!!! not string!!!
|
402
|
-
menu.choices(*LIST__Main_Category)
|
403
|
-
end
|
404
|
-
|
405
|
-
option = LIST__Main_Category.index(category)
|
406
|
-
|
407
|
-
if @sub_category.nil?
|
408
|
-
sub = @highline.ask "What sub category? [NIL/sub]"
|
409
|
-
case sub
|
410
|
-
when '' then @sub_category = nil
|
411
|
-
else @sub_category = sub end
|
412
|
-
end
|
413
|
-
return option
|
414
|
-
end
|
415
|
-
|
416
|
-
end
|
417
|
-
|
418
|
-
#############
|
419
|
-
# main
|
420
|
-
#############
|
421
|
-
Chlog::CliHandler.new $*
|
422
|
-
exit(true)
|