Skip to content

Commit

Permalink
Remove "Unreleased" title when version was not released
Browse files Browse the repository at this point in the history
  • Loading branch information
screendriver committed Jan 14, 2024
1 parent a0b7c74 commit 235d49a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
7 changes: 4 additions & 3 deletions source/lib/create-changelog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const changelogOptionsFactory = Factory.define<ChangelogOptions>(() => {
};
});

test('contains "Unreleased" with no version number and the formatted date when version was released', (t) => {
test('contains no title when version was not released', (t) => {
const createChangelog = createChangelogFactory({
getCurrentDate: () => {
return new Date(0);
Expand All @@ -25,10 +25,11 @@ test('contains "Unreleased" with no version number and the formatted date when v
unreleased: true,
versionNumber: Maybe.nothing()
});

const changelog = createChangelog(options);
const expectedTitle = '## Unreleased (January 1, 1970)';
const expected = '';

t.true(changelog.includes(expectedTitle));
t.is(changelog, expected);
});

test('contains a title with the version number and the formatted date when version was released', (t) => {
Expand Down
19 changes: 15 additions & 4 deletions source/lib/create-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,24 @@ export function createChangelogFactory(dependencies: Dependencies): CreateChange
const { getCurrentDate, packageInfo } = dependencies;
const dateFormat = getConfigValueFromPackageInfo(packageInfo, 'dateFormat', defaultDateFormat);

function createChangelogTitle(options: ChangelogOptions): string {
const { unreleased } = options;

if (unreleased) {
return '';
}

const date = formatDate(getCurrentDate(), dateFormat, { locale: enLocale });
const title = `## ${options.versionNumber.value} (${date})`;

return `${title}\n\n`;
}

return function createChangelog(options) {
const { validLabels, mergedPullRequests, githubRepo, unreleased } = options;
const { validLabels, mergedPullRequests, githubRepo } = options;
const groupedPullRequests = groupByLabel(mergedPullRequests);
const date = formatDate(getCurrentDate(), dateFormat, { locale: enLocale });
const title = unreleased ? `## Unreleased (${date})` : `## ${options.versionNumber.value} (${date})`;

let changelog = `${title}\n\n`;
let changelog = createChangelogTitle(options);

for (const [label, displayLabel] of validLabels) {
const pullRequests = groupedPullRequests[label];
Expand Down

0 comments on commit 235d49a

Please sign in to comment.