Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
outofambit committed Mar 2, 2020
1 parent 54ce5e9 commit 3a4e446
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions script/draft-release/run.ts
Expand Up @@ -111,7 +111,7 @@ export async function run(args: ReadonlyArray<string>): Promise<void> {
const noChangesFound = lines.every(l => l.trim().length === 0)

if (noChangesFound) {
console.warn('No new changes found to add to the changelog.')
console.warn('No new changes found to add to the changelog. Aborting.')
// print instructions with no changelog included
printInstructions(nextVersion, [])
return
Expand All @@ -133,13 +133,17 @@ export async function run(args: ReadonlyArray<string>): Promise<void> {
}

const currentChangelog = require(changelogPath)
const newEntries = await getNewEntries(previousVersion, channel, lines)
const newEntries = await makeNewChangelogEntries(
previousVersion,
channel,
lines
)

if (currentChangelog.releases[nextVersion] === undefined) {
console.log('Adding draft release notes to changelog.json...')
const changelog = makeNewChangelog(
nextVersion,
currentChangelog.releases,
currentChangelog,
newEntries
)
try {
Expand All @@ -166,7 +170,14 @@ export async function run(args: ReadonlyArray<string>): Promise<void> {
console.log("Here's what you should do next:\n")
}

async function getNewEntries(
/**
* Formats git log lines into our changelog format,
*
* @param previousVersion last version released
* @param channel the release channel ('production' or something else)
* @param lines git log entries (from `getLogLines`)
*/
async function makeNewChangelogEntries(
previousVersion: string,
channel: string,
lines: ReadonlyArray<string>
Expand All @@ -184,10 +195,12 @@ async function getNewEntries(
*/
function makeNewChangelog(
nextVersion: string,
currentChangelogEntries: any,
currentChangelog: { releases: Object },
entries: ReadonlyArray<string>
) {
const newChangelogEntries: any = {}
newChangelogEntries[nextVersion] = entries
return { releases: { ...newChangelogEntries, ...currentChangelogEntries } }
return {
releases: { ...newChangelogEntries, ...currentChangelog.releases },
}
}

0 comments on commit 3a4e446

Please sign in to comment.