feat: add option to generate explicit URLs in the release notes (#16126)
This commit is contained in:
parent
ddc38eda26
commit
df0381e76c
2 changed files with 33 additions and 23 deletions
|
@ -120,7 +120,7 @@ const getPreviousPoint = async (point) => {
|
|||
}
|
||||
}
|
||||
|
||||
async function getReleaseNotes (range) {
|
||||
async function getReleaseNotes (range, explicitLinks) {
|
||||
const rangeList = range.split('..') || ['HEAD']
|
||||
const to = rangeList.pop()
|
||||
const from = rangeList.pop() || (await getPreviousPoint(to))
|
||||
|
@ -128,7 +128,7 @@ async function getReleaseNotes (range) {
|
|||
|
||||
const notes = await notesGenerator.get(from, to)
|
||||
const ret = {
|
||||
text: notesGenerator.render(notes)
|
||||
text: notesGenerator.render(notes, explicitLinks)
|
||||
}
|
||||
|
||||
if (notes.unknown.length) {
|
||||
|
@ -139,13 +139,15 @@ async function getReleaseNotes (range) {
|
|||
}
|
||||
|
||||
async function main () {
|
||||
if (process.argv.length > 3) {
|
||||
console.log('Use: script/release-notes/index.js [tag | tag1..tag2]')
|
||||
// TODO: minimist/commander
|
||||
const explicitLinks = process.argv.slice(2).some(arg => arg === '--explicit-links')
|
||||
if (process.argv.length > 4) {
|
||||
console.log('Use: script/release-notes/index.js [--explicit-links] [tag | tag1..tag2]')
|
||||
return 1
|
||||
}
|
||||
|
||||
const range = process.argv[2] || 'HEAD'
|
||||
const notes = await getReleaseNotes(range)
|
||||
const notes = await getReleaseNotes(range, explicitLinks)
|
||||
console.log(notes.text)
|
||||
if (notes.warning) {
|
||||
throw new Error(notes.warning)
|
||||
|
|
|
@ -496,7 +496,28 @@ const getNotes = async (fromRef, toRef) => {
|
|||
**** Render
|
||||
***/
|
||||
|
||||
const renderCommit = commit => {
|
||||
const renderLink = (commit, explicitLinks) => {
|
||||
let link
|
||||
const pr = commit.originalPr
|
||||
if (pr) {
|
||||
const { owner, repo, number } = pr
|
||||
const url = `https://github.com/${owner}/${repo}/pull/${number}`
|
||||
const text = owner === 'electron' && repo === 'electron'
|
||||
? `#${number}`
|
||||
: `${owner}/${repo}#${number}`
|
||||
link = explicitLinks ? `[${text}](${url})` : text
|
||||
} else {
|
||||
const { owner, repo, hash } = commit
|
||||
const url = `https://github.com/${owner}/${repo}/commit/${hash}`
|
||||
const text = owner === 'electron' && repo === 'electron'
|
||||
? `${hash.slice(0, 8)}`
|
||||
: `${owner}/${repo}@${hash.slice(0, 8)}`
|
||||
link = explicitLinks ? `[${text}](${url})` : text
|
||||
}
|
||||
return link
|
||||
}
|
||||
|
||||
const renderCommit = (commit, explicitLinks) => {
|
||||
// clean up the note
|
||||
let note = commit.note || commit.subject
|
||||
note = note.trim()
|
||||
|
@ -535,21 +556,12 @@ const renderCommit = commit => {
|
|||
}
|
||||
}
|
||||
|
||||
// make a GH-markdown-friendly link
|
||||
let link
|
||||
const pr = commit.originalPr
|
||||
if (!pr) {
|
||||
link = `https://github.com/${commit.owner}/${commit.repo}/commit/${commit.hash}`
|
||||
} else if (pr.owner === 'electron' && pr.repo === 'electron') {
|
||||
link = `#${pr.number}`
|
||||
} else {
|
||||
link = `[${pr.owner}/${pr.repo}:${pr.number}](https://github.com/${pr.owner}/${pr.repo}/pull/${pr.number})`
|
||||
}
|
||||
const link = renderLink(commit, explicitLinks)
|
||||
|
||||
return { note, link }
|
||||
}
|
||||
|
||||
const renderNotes = notes => {
|
||||
const renderNotes = (notes, explicitLinks) => {
|
||||
const rendered = [ `# Release Notes for ${notes.ref}\n\n` ]
|
||||
|
||||
const renderSection = (title, commits) => {
|
||||
|
@ -557,7 +569,7 @@ const renderNotes = notes => {
|
|||
return
|
||||
}
|
||||
const notes = new Map()
|
||||
for (const note of commits.map(commit => renderCommit(commit))) {
|
||||
for (const note of commits.map(commit => renderCommit(commit, explicitLinks))) {
|
||||
if (!notes.has(note.note)) {
|
||||
notes.set(note.note, [note.link])
|
||||
} else {
|
||||
|
@ -576,11 +588,7 @@ const renderNotes = notes => {
|
|||
renderSection('Other Changes', notes.other)
|
||||
|
||||
if (notes.docs.length) {
|
||||
const docs = notes.docs.map(commit => {
|
||||
return commit.pr && commit.pr.number
|
||||
? `#${commit.pr.number}`
|
||||
: `https://github.com/electron/electron/commit/${commit.hash}`
|
||||
}).sort()
|
||||
const docs = notes.docs.map(commit => renderLink(commit, explicitLinks)).sort()
|
||||
rendered.push('## Documentation\n\n', ` * Documentation changes: ${docs.join(', ')}\n`, '\n')
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue