Skip to content

Commit

Permalink
feat(refs): improve references list
Browse files Browse the repository at this point in the history
  • Loading branch information
innocenzi committed Jun 30, 2022
1 parent 8d8d914 commit 0ecc673
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions src/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
import { partition } from '@antfu/utils'
import type { Commit, ResolvedChangelogOptions } from './types'

function formatReferences(references: string[], github: string, type: 'pr' | 'hash'): string {
const refs = references
.filter((ref) => {
if (type === 'pr')
return ref[0] === '#'

return ref[0] !== '#'
})
.map((ref) => {
if (!github)
return ref

if (type === 'pr')
return `https://github.com/${github}/issues/${ref.slice(1)}`

return `[${ref}](https://github.com/${github}/commit/${ref})`
})

const referencesString = join(refs).trim()

if (type === 'pr')
return referencesString && `in ${referencesString}`

return referencesString && `(${referencesString})`
}

function formatLine(commit: Commit, options: ResolvedChangelogOptions) {
const refs = commit.references.map((r) => {
if (!options.github)
return `\`${r}\``
const url = r[0] === '#'
? `https://github.com/${options.github}/issues/${r.slice(1)}`
: `https://github.com/${options.github}/commit/${r}`
return `[\`${r}\`](${url})`
}).join(' ')
const prRefs = formatReferences(commit.references, options.github, 'pr')
const hashRefs = formatReferences(commit.references, options.github, 'hash')

let authors = join(commit.resolvedAuthors?.map(i => i.login ? `@${i.login}` : `**${i.name}**`))?.trim()
if (authors)
authors = `by ${authors}`

const description = options.capitalize ? capitalize(commit.description) : commit.description

return [description, refs, authors].filter(i => i?.trim()).join(' ')
return [description, authors, prRefs, hashRefs].filter(i => i?.trim()).join(' ')
}

function formatTitle(name: string) {
Expand Down

0 comments on commit 0ecc673

Please sign in to comment.