Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

match release-plan test for Changelog header #60

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions bin/bin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ describe('main binary', function () {
);
});

it('does not modify if an existing prefix exists anywhere on the line and has different casing in CHANGELOG.md', async function () {
project.files['CHANGELOG.md'] =
`# the most mighty CHANgELOG you have ever seen\n\n## v1.2.0\n* Foo bar`;
project.writeSync();

await exec(['--no-install', '--no-label-updates']);

expect(fs.readFileSync('CHANGELOG.md', { encoding: 'utf8' })).toBe(
'# the most mighty CHANgELOG you have ever seen\n\n## v1.2.0\n* Foo bar'
);
});

describe('package.json', function () {
it('adds repository info when discoverable from `.git/config`', async function () {
project.files['.git'] = {
Expand Down
11 changes: 4 additions & 7 deletions bin/release-plan-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import util from 'util';
import { execa } from 'execa';
import sortPackageJson from 'sort-package-json';
import gitconfiglocal from 'gitconfiglocal';
import { fromMarkdown } from 'mdast-util-from-markdown';
import findRepoURL from '../lib/findRepoUrl.js';
import getDependencyRange from '../lib/getDependencyRange.js';
import ejs from 'ejs';
Expand Down Expand Up @@ -158,13 +157,11 @@ try {
}

if (hasChangelog && !labelsOnly) {
let changelogContent = fs.readFileSync('CHANGELOG.md', { encoding: 'utf8' });
let ast = fromMarkdown(changelogContent);
let changelogContent = fs.readFileSync('CHANGELOG.md', { encoding: 'utf8' }).split('\n');
const changelogPreamblePattern = /#.*Changelog.*$/i;

let hasH1 = ast.children.find((it) => it.type === 'heading' && it.depth === 1);

if (!hasH1) {
fs.writeFileSync('CHANGELOG.md', `# Changelog\n\n${changelogContent}`, {
if (!changelogPreamblePattern.test(changelogContent[0])) {
fs.writeFileSync('CHANGELOG.md', `# Changelog\n\n${changelogContent.join('\n')}`, {
encoding: 'utf8',
});
}
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"github-label-sync": "^2.3.1",
"hosted-git-info": "^7.0.1",
"lodash.template": "^4.5.0",
"mdast-util-from-markdown": "^2.0.0",
"semver": "^7.3.5",
"sort-package-json": "^2.6.0",
"which": "^4.0.0"
Expand Down
252 changes: 2 additions & 250 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading