1
- local function populate_section (content , name , list )
1
+ local function populate_section (content , name , list , format )
2
2
if # list == 0 then
3
3
return
4
4
end
5
- content [# content + 1 ] = ' *** ' .. name
5
+ local heading = format == ' md' and ' ### ' or ' *** '
6
+ content [# content + 1 ] = heading .. name
6
7
vim .list_extend (
7
8
content ,
8
9
vim .tbl_map (function (item )
@@ -12,11 +13,18 @@ local function populate_section(content, name, list)
12
13
content [# content + 1 ] = ' '
13
14
end
14
15
15
- local function get_changes (latest_tag )
16
- if not latest_tag then
17
- latest_tag = vim .fn .system (' git describe --tags `git rev-list --tags --max-count=1`' ):gsub (' \n ' , ' ' )
16
+ --- @param format ' org' | ' md'
17
+ --- @param latest_tag ? string
18
+ --- @return string[]
19
+ local function get_changes (format , latest_tag )
20
+ format = format or ' org'
21
+ latest_tag = latest_tag or vim .fn .system (' git describe --tags `git rev-list --tags --max-count=1`' ):gsub (' \n ' , ' ' )
22
+ local commit_format = ' [[https://github.com/nvim-orgmode/orgmode/commit/%h][%h]]'
23
+ if format == ' md' then
24
+ commit_format = ' [%h](https://github.com/nvim-orgmode/orgmode/commit/%h)'
18
25
end
19
- local commits = vim .fn .systemlist (' git log ' .. latest_tag .. " ..master --pretty=format:'%s'" )
26
+
27
+ local commits = vim .fn .systemlist ((" git log %s..master --pretty=format:'%%s (%s)'" ):format (latest_tag , commit_format ))
20
28
local fixes = {}
21
29
local features = {}
22
30
local breaking_changes = {}
@@ -37,9 +45,9 @@ local function get_changes(latest_tag)
37
45
end
38
46
local content = {}
39
47
40
- populate_section (content , ' Breaking changes' , breaking_changes )
41
- populate_section (content , ' Features' , features )
42
- populate_section (content , ' Bug fixes' , fixes )
48
+ populate_section (content , ' Breaking changes' , breaking_changes , format )
49
+ populate_section (content , ' Features' , features , format )
50
+ populate_section (content , ' Bug fixes' , fixes , format )
43
51
44
52
return content
45
53
end
@@ -49,13 +57,15 @@ local function generate_changelog()
49
57
local new_tag = arg [1 ]
50
58
51
59
local new_content = {
52
- ' ** ' .. new_tag ,
53
- ' - Date: [[' .. os.date (' %Y-%m-%d' ) .. ' ]]' ,
54
- (' - [[https://github.com/nvim-orgmode/orgmode/compare/%s...%s][Compare]]' ):format (latest_tag , new_tag ),
55
- (' - [[https://github.com/nvim-orgmode/orgmode/releases/tag/%s][Link to release]]' ):format (new_tag ),
56
- ' ' ,
60
+ (' ** [[https://github.com/nvim-orgmode/orgmode/compare/%s...%s][%s]] (%s)' ):format (latest_tag , new_tag , new_tag , os.date (' %Y-%m-%d' )),
57
61
}
58
- vim .list_extend (new_content , get_changes (latest_tag ))
62
+
63
+ local changes = get_changes (' org' , latest_tag )
64
+ if # changes == 0 then
65
+ print (' No changes since last release\n ' )
66
+ return os.exit (1 )
67
+ end
68
+ vim .list_extend (new_content , changes )
59
69
60
70
local changelog = vim .fn .readfile (' ./docs/changelog.org' )
61
71
local start = { unpack (changelog , 1 , 2 ) }
@@ -65,10 +75,11 @@ local function generate_changelog()
65
75
new_changelog = vim .list_extend (new_changelog , remaining )
66
76
67
77
vim .fn .writefile (new_changelog , ' ./docs/changelog.org' )
78
+ return os.exit ()
68
79
end
69
80
70
81
if arg [2 ] and arg [2 ] == ' print' then
71
- return io.write (table.concat (get_changes (), ' \n ' ))
82
+ return io.write (table.concat (get_changes (' md ' ), ' \n ' ))
72
83
end
73
84
74
85
generate_changelog ()
0 commit comments