async function updateChangelog({ changelogContent, currentVersion, repoUrl, isReleaseCandidate, projectRootDirectory, }) {
    if (isReleaseCandidate && !currentVersion) {
        throw new Error(`A version must be specified if 'isReleaseCandidate' is set.`);
    }
    const changelog = parse_changelog_1.parseChangelog({ changelogContent, repoUrl });
    // Ensure we have all tags on remote
    await runCommand('git', ['fetch', '--tags']);
    const mostRecentTag = await getMostRecentTag();
    if (isReleaseCandidate && mostRecentTag === `v${currentVersion}`) {
        throw new Error(`Current version already has tag, which is unexpected for a release candidate.`);
    }
    const commitRange = mostRecentTag === null ? 'HEAD' : `${mostRecentTag}..HEAD`;
    const commitsHashesSinceLastRelease = await getCommitHashesInRange(commitRange, projectRootDirectory);
    const commits = await getCommits(commitsHashesSinceLastRelease);
    const loggedPrNumbers = getAllLoggedPrNumbers(changelog);
    const newCommits = commits.filter(({ prNumber }) => prNumber === undefined || !loggedPrNumbers.includes(prNumber));
    const hasUnreleasedChanges = Object.keys(changelog.getUnreleasedChanges()).length !== 0;
    if (newCommits.length === 0 &&
        (!isReleaseCandidate || hasUnreleasedChanges)) {
        return undefined;
    }
    // Ensure release header exists, if necessary
    if (isReleaseCandidate &&
        !changelog
            .getReleases()
            .find((release) => release.version === currentVersion)) {
        // Typecast: currentVersion will be defined here due to type guard at the
        // top of this function.
        changelog.addRelease({ version: currentVersion });
    }
    if (isReleaseCandidate && hasUnreleasedChanges) {
        // Typecast: currentVersion will be defined here due to type guard at the
        // top of this function.
        changelog.migrateUnreleasedChangesToRelease(currentVersion);
    }
    const newChangeEntries = newCommits.map(({ prNumber, description }) => {
        if (prNumber) {
            const suffix = `([#${prNumber}](${repoUrl}/pull/${prNumber}))`;
            return `${description} ${suffix}`;
        }
        return description;
    });
    for (const description of newChangeEntries.reverse()) {
        changelog.addChange({
            version: isReleaseCandidate ? currentVersion : undefined,
            category: constants_1.ChangeCategory.Uncategorized,
            description,
        });
    }
    return changelog.toString();
}
/**
 * Update a changelog with any commits made since the last release. Commits for
 * PRs that are already included in the changelog are omitted.
 * @param options
 * @param options.changelogContent - The current changelog
 * @param options.currentVersion - The current version. Required if
 * `isReleaseCandidate` is set, but optional otherwise.
 * @param options.repoUrl - The GitHub repository URL for the current project.
 * @param options.isReleaseCandidate - Denotes whether the current project.
 * is in the midst of release preparation or not. If this is set, any new
 * changes are listed under the current release header. Otherwise, they are
 * listed under the 'Unreleased' section.
 * @param options.projectRootDirectory - The root project directory, used to
 * filter results from various git commands. This path is assumed to be either
 * absolute, or relative to the current directory. Defaults to the root of the
 * current git repository.
 * @returns The updated changelog text
 */
Update a changelog with any commits made since the last release. Commits for
PRs that are already included in the changelog are omitted.
@param options
@param options.changelogContent - The current changelog
@param options.currentVersion - The current version. Required if
`isReleaseCandidate` is set, but optional otherwise.
@param options.repoUrl - The GitHub repository URL for the current project.
@param options.isReleaseCandidate - Denotes whether the current project.
is in the midst of release preparation or not. If this is set, any new
changes are listed under the current release header. Otherwise, they are
listed under the 'Unreleased' section.
@param options.projectRootDirectory - The root project directory, used to
filter results from various git commands. This path is assumed to be either
absolute, or relative to the current directory. Defaults to the root of the
current git repository.
@returns The updated changelog text
Update a changelog with any commits made since the last release . Commits for PRs that are already included in the changelog are omitted . @param options @param options . changelogContent - The current changelog @param options . currentVersion - The current version . Required if ` isReleaseCandidate ` is set but optional otherwise . @param options . repoUrl - The GitHub repository URL for the current project . @param options . isReleaseCandidate - Denotes whether the current project . is in the midst of release preparation or not . If this is set any new changes are listed under the current release header . Otherwise they are listed under the ' Unreleased ' section . @param options . projectRootDirectory - The root project directory used to filter results from various git commands . This path is assumed to be either absolute or relative to the current directory . Defaults to the root of the current git repository . @returns The updated changelog text
async function updateChangelog({ changelogContent, currentVersion, repoUrl, isReleaseCandidate, projectRootDirectory, }) {
    if (isReleaseCandidate && !currentVersion) {
        throw new Error(`A version must be specified if 'isReleaseCandidate' is set.`);
    }
    const changelog = parse_changelog_1.parseChangelog({ changelogContent, repoUrl });
    await runCommand('git', ['fetch', '--tags']);
    const mostRecentTag = await getMostRecentTag();
    if (isReleaseCandidate && mostRecentTag === `v${currentVersion}`) {
        throw new Error(`Current version already has tag, which is unexpected for a release candidate.`);
    }
    const commitRange = mostRecentTag === null ? 'HEAD' : `${mostRecentTag}..HEAD`;
    const commitsHashesSinceLastRelease = await getCommitHashesInRange(commitRange, projectRootDirectory);
    const commits = await getCommits(commitsHashesSinceLastRelease);
    const loggedPrNumbers = getAllLoggedPrNumbers(changelog);
    const newCommits = commits.filter(({ prNumber }) => prNumber === undefined || !loggedPrNumbers.includes(prNumber));
    const hasUnreleasedChanges = Object.keys(changelog.getUnreleasedChanges()).length !== 0;
    if (newCommits.length === 0 &&
        (!isReleaseCandidate || hasUnreleasedChanges)) {
        return undefined;
    }
    if (isReleaseCandidate &&
        !changelog
            .getReleases()
            .find((release) => release.version === currentVersion)) {
        changelog.addRelease({ version: currentVersion });
    }
    if (isReleaseCandidate && hasUnreleasedChanges) {
        changelog.migrateUnreleasedChangesToRelease(currentVersion);
    }
    const newChangeEntries = newCommits.map(({ prNumber, description }) => {
        if (prNumber) {
            const suffix = `([#${prNumber}](${repoUrl}/pull/${prNumber}))`;
            return `${description} ${suffix}`;
        }
        return description;
    });
    for (const description of newChangeEntries.reverse()) {
        changelog.addChange({
            version: isReleaseCandidate ? currentVersion : undefined,
            category: constants_1.ChangeCategory.Uncategorized,
            description,
        });
    }
    return changelog.toString();
}
async function updateChangelog ( { changelogContent , currentVersion , repoUrl , isReleaseCandidate , projectRootDirectory , } ) { if ( isReleaseCandidate && ! currentVersion ) { throw new Error ( ` ` ) ; } const changelog = parse_changelog_1 . parseChangelog ( { changelogContent , repoUrl } ) ; await runCommand ( 'git' , [ 'fetch' , '--tags' ] ) ; const mostRecentTag = await getMostRecentTag ( ) ; if ( isReleaseCandidate && mostRecentTag === ` ${ currentVersion } ` ) { throw new Error ( ` ` ) ; } const commitRange = mostRecentTag === null ? 'HEAD' : ` ${ mostRecentTag } ` ; const commitsHashesSinceLastRelease = await getCommitHashesInRange ( commitRange , projectRootDirectory ) ; const commits = await getCommits ( commitsHashesSinceLastRelease ) ; const loggedPrNumbers = getAllLoggedPrNumbers ( changelog ) ; const newCommits = commits . filter ( ( { prNumber } ) => prNumber === undefined || ! loggedPrNumbers . includes ( prNumber ) ) ; const hasUnreleasedChanges = Object . keys ( changelog . getUnreleasedChanges ( ) ) . length !== 0 ; if ( newCommits . length === 0 && ( ! isReleaseCandidate || hasUnreleasedChanges ) ) { return undefined ; } if ( isReleaseCandidate && ! changelog . getReleases ( ) . find ( ( release ) => release . version === currentVersion ) ) { changelog . addRelease ( { version : currentVersion } ) ; } if ( isReleaseCandidate && hasUnreleasedChanges ) { changelog . migrateUnreleasedChangesToRelease ( currentVersion ) ; } const newChangeEntries = newCommits . map ( ( { prNumber , description } ) => { if ( prNumber ) { const suffix = ` ${ prNumber } ${ repoUrl } ${ prNumber } ` ; return ` ${ description } ${ suffix } ` ; } return description ; } ) ; for ( const description of newChangeEntries . reverse ( ) ) { changelog . addChange ( { version : isReleaseCandidate ? currentVersion : undefined , category : constants_1 . ChangeCategory . Uncategorized , description , } ) ; } return changelog . toString ( ) ; }
Update a changelog with any commits made since the last release.
Update a changelog with any commits made since the last release .
// Ensure we have all tags on remote // Ensure release header exists, if necessary // Typecast: currentVersion will be defined here due to type guard at the // top of this function. // Typecast: currentVersion will be defined here due to type guard at the // top of this function.