Skip to content

Commit 4a2ea48

Browse files
fix: Display changelog for manual releases (#30)
1 parent 18a59e0 commit 4a2ea48

1 file changed

Lines changed: 65 additions & 71 deletions

File tree

src/publish/index.js

Lines changed: 65 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -237,78 +237,72 @@ export const publish = async (options) => {
237237
}
238238
}
239239

240-
const changelogCommitsMd = tag
241-
? `Manual Release: ${tag}`
242-
: await Promise.all(
243-
Object.entries(
244-
commitsSinceLatestTag.reduce((acc, next) => {
245-
const type = next.parsed.type?.toLowerCase() ?? 'other'
246-
247-
return {
248-
...acc,
249-
[type]: [...(acc[type] || []), next],
240+
const changelogCommitsMd = await Promise.all(
241+
Object.entries(
242+
commitsSinceLatestTag.reduce((acc, next) => {
243+
const type = next.parsed.type?.toLowerCase() ?? 'other'
244+
245+
return {
246+
...acc,
247+
[type]: [...(acc[type] || []), next],
248+
}
249+
}, /** @type {Record<string, import('./types.js').Commit[]>} */ ({})),
250+
)
251+
.sort(
252+
getSorterFn([
253+
([d]) =>
254+
[
255+
'other',
256+
'examples',
257+
'docs',
258+
'chore',
259+
'refactor',
260+
'perf',
261+
'fix',
262+
'feat',
263+
].indexOf(d),
264+
]),
265+
)
266+
.reverse()
267+
.map(async ([type, commits]) => {
268+
return Promise.all(
269+
commits.map(async (commit) => {
270+
let username = ''
271+
272+
if (ghToken) {
273+
const query = `${commit.author.email || commit.committer.email}`
274+
275+
const res = await fetch(
276+
`https://api.github.com/search/users?q=${query}`,
277+
{
278+
headers: {
279+
Authorization: `token ${ghToken}`,
280+
},
281+
},
282+
)
283+
/** @type {any} */
284+
const data = await res.json()
285+
username = data.items[0]?.login
250286
}
251-
}, /** @type {Record<string, import('./types.js').Commit[]>} */ ({})),
252-
)
253-
.sort(
254-
getSorterFn([
255-
([d]) =>
256-
[
257-
'other',
258-
'examples',
259-
'docs',
260-
'chore',
261-
'refactor',
262-
'perf',
263-
'fix',
264-
'feat',
265-
].indexOf(d),
266-
]),
267-
)
268-
.reverse()
269-
.map(async ([type, commits]) => {
270-
return Promise.all(
271-
commits.map(async (commit) => {
272-
let username = ''
273-
274-
if (ghToken) {
275-
const query = `${
276-
commit.author.email || commit.committer.email
277-
}`
278-
279-
const res = await fetch(
280-
`https://api.github.com/search/users?q=${query}`,
281-
{
282-
headers: {
283-
Authorization: `token ${ghToken}`,
284-
},
285-
},
286-
)
287-
/** @type {any} */
288-
const data = await res.json()
289-
username = data.items[0]?.login
290-
}
291-
292-
const scope = commit.parsed.scope
293-
? `${commit.parsed.scope}: `
294-
: ''
295-
const subject = commit.parsed.subject || commit.subject
296-
297-
return `- ${scope}${subject} (${commit.commit.short}) ${
298-
username
299-
? `by @${username}`
300-
: `by ${commit.author.name || commit.author.email}`
301-
}`
302-
}),
303-
).then((c) => /** @type {const} */ ([type, c]))
287+
288+
const scope = commit.parsed.scope ? `${commit.parsed.scope}: ` : ''
289+
const subject = commit.parsed.subject || commit.subject
290+
291+
return `- ${scope}${subject} (${commit.commit.short}) ${
292+
username
293+
? `by @${username}`
294+
: `by ${commit.author.name || commit.author.email}`
295+
}`
304296
}),
305-
).then((groups) => {
306-
return groups
307-
.map(([type, commits]) => {
308-
return [`### ${capitalize(type)}`, commits.join('\n')].join('\n\n')
309-
})
310-
.join('\n\n')
297+
).then((c) => /** @type {const} */ ([type, c]))
298+
}),
299+
).then((groups) => {
300+
return groups
301+
.map(([type, commits]) => {
302+
return [`### ${capitalize(type)}`, commits.join('\n')].join('\n\n')
311303
})
304+
.join('\n\n')
305+
})
312306

313307
if (tag && recommendedReleaseLevel === -1) {
314308
recommendedReleaseLevel = 0
@@ -341,9 +335,9 @@ export const publish = async (options) => {
341335
const changelogMd = [
342336
`Version ${version} - ${DateTime.now().toLocaleString(
343337
DateTime.DATETIME_SHORT,
344-
)}`,
338+
)}${tag ? ' (Manual Release)' : undefined}`,
345339
'## Changes',
346-
changelogCommitsMd,
340+
changelogCommitsMd ? changelogCommitsMd : '- None',
347341
'## Packages',
348342
changedPackages.map((d) => `- ${d.name}@${version}`).join('\n'),
349343
].join('\n\n')

0 commit comments

Comments
 (0)