Skip to content

Commit

Permalink
fix: no more partial version match. updates footer
Browse files Browse the repository at this point in the history
  • Loading branch information
iowillhoit committed Nov 17, 2021
1 parent 9a6a517 commit 010c4f3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
12 changes: 4 additions & 8 deletions messages/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ Display release notes for the CLI version that corresponds to a tag (%s):
`,
],
footer: `---
Run \`%s whatsnew\` to manually view the current release notes.
You can also view them on GitHub by visiting the [forcedotcom/cli](%s) repo.
Silence notes by setting the \`%s\` env var to \`true\`.
Hide this footer by setting the \`%s\` env var to \`true\`.
- Run \`%s whatsnew\` to manually view the current release notes.
- You can also view them on GitHub by visiting the [forcedotcom/cli](%s) repo.
- Silence notes by setting the \`%s\` env var to \`true\`.
- Hide this footer by setting the \`%s\` env var to \`true\`.
---`,
};
9 changes: 8 additions & 1 deletion src/shared/parseReleaseNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ const parseReleaseNotes = (notes: string, version: string, baseUrl: string): mar

const parsed = marked.lexer(notes);

// https://stackoverflow.com/a/6969486
const escapeRegExp = (string: string): string => {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
};

const regexp = new RegExp(`\\b${escapeRegExp(version)}\\b`);

const tokens = parsed.filter((token) => {
// TODO: Could make header depth (2) a setting in oclif.info.releasenotes
if (token.type === 'heading' && token.depth === 2) {
if (token.text.includes(version)) {
if (regexp.exec(token.text)) {
found = true;

return token;
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 13.3.1 (Aug 3, 2023)

- test for matching full version (`3.3.1 !== 13.3.1`)

## 7.125.0 (Nov 4, 2021)

- testing a nested
Expand Down
3 changes: 2 additions & 1 deletion test/shared/getInfoConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as Sinon from 'sinon';
import * as SinonChai from 'sinon-chai';
import { stubMethod, spyMethod } from '@salesforce/ts-sinon';
import { fs } from '@salesforce/core';
import { shouldThrow } from '@salesforce/core/lib/testSetup';
import { getInfoConfig, PjsonWithInfo } from '../../src/shared/getInfoConfig';

chaiUse(SinonChai);
Expand Down Expand Up @@ -75,7 +76,7 @@ describe('getInfoConfig tests', () => {
readJsonStub.returns({ oclif: {} });

try {
await getInfoConfig(path);
await shouldThrow(getInfoConfig(path));
} catch (err) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(err.message).to.equal('getInfoConfig() failed to find pjson.oclif.info config');
Expand Down
25 changes: 21 additions & 4 deletions test/shared/parseReleaseNotes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ describe('parseReleaseNotes tests', () => {
sandbox.restore();
});

it('calls lexer with raw release notes', async () => {
it('calls lexer with raw release notes', () => {
parseReleaseNotes(notes, '7.121.8', baseUrl);

expect(lexerSpy.called).to.be.true;
expect(lexerSpy.args[0][0]).to.deep.equal(notes);
});

it('filters out correct version from tokens', async () => {
it('filters out correct version from tokens', () => {
const tokens = parseReleaseNotes(notes, '7.121.8', baseUrl);

const results = JSON.stringify(tokens, null, ' ');
Expand All @@ -49,7 +49,7 @@ describe('parseReleaseNotes tests', () => {
expect(results).to.not.include('7.120.0');
});

it('throws error if version is not found', async () => {
it('throws error if version is not found', () => {
try {
parseReleaseNotes(notes, '1.2.3', baseUrl);
} catch (err) {
Expand All @@ -58,7 +58,24 @@ describe('parseReleaseNotes tests', () => {
}
});

it('fixes relative links in releasenotes', async () => {
it('matches entire version, not partial', () => {
const tokens = parseReleaseNotes(notes, '13.3.1', baseUrl);

const results = JSON.stringify(tokens, null, ' ');

expect(tokens[0].raw).to.include('13.3.1');
expect(results).to.include('- test for matching full version (`3.3.1 !== 13.3.1`)');

try {
// Won't find partial version (3.3.1 is part of 13.3.1)
parseReleaseNotes(notes, '3.3.1', baseUrl);
} catch (err) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(err.message).to.equal(`Didn't find version '3.3.1'. View release notes online at: ${baseUrl}`);
}
});

it('fixes relative links in releasenotes', () => {
const tokens = parseReleaseNotes(notes, '7.121.8', baseUrl);

const results = JSON.stringify(tokens, null, ' ');
Expand Down

0 comments on commit 010c4f3

Please sign in to comment.