Skip to content

Commit 17ad291

Browse files
ci: update generate changelog script
1 parent 0f844bc commit 17ad291

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

scripts/generate_changelog.lua

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
local function populate_section(content, name, list)
1+
local function populate_section(content, name, list, format)
22
if #list == 0 then
33
return
44
end
5-
content[#content + 1] = '*** ' .. name
5+
local heading = format == 'md' and '### ' or '*** '
6+
content[#content + 1] = heading .. name
67
vim.list_extend(
78
content,
89
vim.tbl_map(function(item)
@@ -12,11 +13,18 @@ local function populate_section(content, name, list)
1213
content[#content + 1] = ''
1314
end
1415

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)'
1825
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))
2028
local fixes = {}
2129
local features = {}
2230
local breaking_changes = {}
@@ -37,9 +45,9 @@ local function get_changes(latest_tag)
3745
end
3846
local content = {}
3947

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)
4351

4452
return content
4553
end
@@ -49,13 +57,15 @@ local function generate_changelog()
4957
local new_tag = arg[1]
5058

5159
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')),
5761
}
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)
5969

6070
local changelog = vim.fn.readfile('./docs/changelog.org')
6171
local start = { unpack(changelog, 1, 2) }
@@ -65,10 +75,11 @@ local function generate_changelog()
6575
new_changelog = vim.list_extend(new_changelog, remaining)
6676

6777
vim.fn.writefile(new_changelog, './docs/changelog.org')
78+
return os.exit()
6879
end
6980

7081
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'))
7283
end
7384

7485
generate_changelog()

0 commit comments

Comments
 (0)