Skip to content

Commit 151b5df

Browse files
committed
fix: fix reading last notes from changelog
1 parent 889a33a commit 151b5df

8 files changed

Lines changed: 107 additions & 56 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pnpm release
8686

8787
| Options | Description | Default |
8888
|---------|-------------|---------|
89-
| titleRegExp | Regular expression to find release title in changelog. Must contain capture group, which will be used to detect release version. As fallback, version will read from package.json. | `/^#+ \[([^\]]*\d+\.\d+\.\d+[^\]]*)\]/` |
89+
| titleRegExp | Regular expression to find release title in changelog. Must contain capture group, which will be used to detect release version. As fallback, version will read from package.json. | not required |
9090
| includeTitle | Include release title into release notes. | `false` |
9191
| remoteUrl | GitHub repository remote url. | From local environment. |
9292
| host | Custom API host. | `'github.com'` |

src/changelog.spec.ts

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@ import { readLastChangesFromStream } from './changelog'
55
describe('changelog', () => {
66
describe('readLastChangesFromStream', () => {
77
it('should read last changes from file', async () => {
8-
const stream = fs.createReadStream(path.join('test', 'mocks', 'CHANGELOG.md'))
8+
const stream = fs.createReadStream(path.join('test', 'mocks', 'CHANGELOG_0.md'))
99

1010
expect(await readLastChangesFromStream(stream)).toMatchInlineSnapshot(`
1111
Array [
1212
"8.0.0-alpha.2",
1313
"### Bug Fixes
1414
1515
* **deps:** update dependency dotenv to v11 ([#16](https://github.com/TrigenSoftware/scripts/issues/16)) ([27e4ce7](https://github.com/TrigenSoftware/scripts/commit/27e4ce7414f6d50fec9fe363238d771cf49b4cd7))
16-
* **deps:** update dependency eslint to v8 ([#17](https://github.com/TrigenSoftware/scripts/issues/17)) ([9dac68c](https://github.com/TrigenSoftware/scripts/commit/9dac68c423a53a53f6ccbd5c19905cdb851b6ea5))
17-
* **deps:** update dependency eslint-plugin-jest-dom to v4 ([#15](https://github.com/TrigenSoftware/scripts/issues/15)) ([8133db1](https://github.com/TrigenSoftware/scripts/commit/8133db151811134b8fc2a22df5efd63bb8d51387))
18-
* **deps:** update typescript-eslint monorepo to v5 ([#18](https://github.com/TrigenSoftware/scripts/issues/18)) ([87f8d42](https://github.com/TrigenSoftware/scripts/commit/87f8d42f749665b8df0daa1c1631b9ac9ca57048))
19-
2016
2117
### Features
2218
@@ -27,7 +23,7 @@ Array [
2723
})
2824

2925
it('should read last changes from file with header', async () => {
30-
const stream = fs.createReadStream(path.join('test', 'mocks', 'CHANGELOG.md'))
26+
const stream = fs.createReadStream(path.join('test', 'mocks', 'CHANGELOG_0.md'))
3127
const options = {
3228
includeTitle: true
3329
}
@@ -37,20 +33,52 @@ Array [
3733
"8.0.0-alpha.2",
3834
"# [8.0.0-alpha.2](https://github.com/TrigenSoftware/scripts/compare/v8.0.0-alpha.1...v8.0.0-alpha.2) (2022-01-14)
3935
40-
4136
### Bug Fixes
4237
4338
* **deps:** update dependency dotenv to v11 ([#16](https://github.com/TrigenSoftware/scripts/issues/16)) ([27e4ce7](https://github.com/TrigenSoftware/scripts/commit/27e4ce7414f6d50fec9fe363238d771cf49b4cd7))
44-
* **deps:** update dependency eslint to v8 ([#17](https://github.com/TrigenSoftware/scripts/issues/17)) ([9dac68c](https://github.com/TrigenSoftware/scripts/commit/9dac68c423a53a53f6ccbd5c19905cdb851b6ea5))
45-
* **deps:** update dependency eslint-plugin-jest-dom to v4 ([#15](https://github.com/TrigenSoftware/scripts/issues/15)) ([8133db1](https://github.com/TrigenSoftware/scripts/commit/8133db151811134b8fc2a22df5efd63bb8d51387))
46-
* **deps:** update typescript-eslint monorepo to v5 ([#18](https://github.com/TrigenSoftware/scripts/issues/18)) ([87f8d42](https://github.com/TrigenSoftware/scripts/commit/87f8d42f749665b8df0daa1c1631b9ac9ca57048))
47-
4839
4940
### Features
5041
5142
* **browserslist-config:** update queries, add esm queries ([3031c6b](https://github.com/TrigenSoftware/scripts/commit/3031c6b322330be57654bdebc1012bddc20e7972))
5243
",
5344
]
45+
`)
46+
})
47+
48+
it('should split titile without link', async () => {
49+
const stream = fs.createReadStream(path.join('test', 'mocks', 'CHANGELOG_1.md'))
50+
51+
expect(await readLastChangesFromStream(stream)).toMatchInlineSnapshot(`
52+
Array [
53+
"0.0.1-1",
54+
"### Bug Fixes
55+
56+
* **cli:** fix config file loading ([8603c2f](https://github.com/TrigenSoftware/simple-github-release/commit/8603c2fde4aeb53619fae8bb9feba53093f51c65))
57+
",
58+
]
59+
`)
60+
})
61+
62+
it('should read keep a changelog', async () => {
63+
const stream = fs.createReadStream(path.join('test', 'mocks', 'CHANGELOG_2.md'))
64+
65+
expect(await readLastChangesFromStream(stream)).toMatchInlineSnapshot(`
66+
Array [
67+
"1.0.0",
68+
"### Added
69+
- Version navigation.
70+
- Links to latest released version in previous versions.
71+
- \\"Why keep a changelog?\\" section.
72+
73+
### Changed
74+
- Start using \\"changelog\\" over \\"change log\\" since it's the common usage.
75+
- Start versioning based on the current English version at 0.3.0 to help
76+
translation authors keep things up-to-date.
77+
78+
### Removed
79+
- Section about \\"changelog\\" vs \\"CHANGELOG\\".
80+
",
81+
]
5482
`)
5583
})
5684
})

src/changelog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Options } from './types'
1010
*/
1111
export async function readLastChangesFromStream(stream: Readable, options: Pick<Options, 'titleRegExp' | 'includeTitle'> = {}) {
1212
const {
13-
titleRegExp = /^#+ \[([^\]]*\d+\.\d+\.\d+[^\]]*)\]/,
13+
titleRegExp = /^#+ \[?([^[\]()\s]*\d+\.\d+\.\d+[^[\]()\s]*)\]?/,
1414
includeTitle = false
1515
} = options
1616
let inLastChanges = false

src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export interface Options {
33
* Regular expression to find release title in changelog.
44
* Must contain capture group, which will be used to detect release version.
55
* As fallback, version will read from package.json.
6-
* @default /^#+ \[([^\]]*\d+\.\d+\.\d+[^\]]*)\]/
76
*/
87
titleRegExp?: RegExp
98
/**

test/mocks/CHANGELOG.md

Lines changed: 0 additions & 42 deletions
This file was deleted.

test/mocks/CHANGELOG_0.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5+
6+
# [8.0.0-alpha.2](https://github.com/TrigenSoftware/scripts/compare/v8.0.0-alpha.1...v8.0.0-alpha.2) (2022-01-14)
7+
8+
### Bug Fixes
9+
10+
* **deps:** update dependency dotenv to v11 ([#16](https://github.com/TrigenSoftware/scripts/issues/16)) ([27e4ce7](https://github.com/TrigenSoftware/scripts/commit/27e4ce7414f6d50fec9fe363238d771cf49b4cd7))
11+
12+
### Features
13+
14+
* **browserslist-config:** update queries, add esm queries ([3031c6b](https://github.com/TrigenSoftware/scripts/commit/3031c6b322330be57654bdebc1012bddc20e7972))
15+
16+
# [8.0.0-alpha.1](https://github.com/TrigenSoftware/scripts/compare/v8.0.0-alpha.0...v8.0.0-alpha.1) (2022-01-12)
17+
18+
**Note:** Version bump only for package scripts

test/mocks/CHANGELOG_1.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4+
5+
### [0.0.1-1](https://github.com/TrigenSoftware/simple-github-release/compare/v0.0.1-0...v0.0.1-1) (2022-01-18)
6+
7+
### Bug Fixes
8+
9+
* **cli:** fix config file loading ([8603c2f](https://github.com/TrigenSoftware/simple-github-release/commit/8603c2fde4aeb53619fae8bb9feba53093f51c65))
10+
11+
### 0.0.1-0 (2022-01-18)

test/mocks/CHANGELOG_2.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased]
8+
9+
## [1.0.0] - 2017-06-20
10+
### Added
11+
- Version navigation.
12+
- Links to latest released version in previous versions.
13+
- "Why keep a changelog?" section.
14+
15+
### Changed
16+
- Start using "changelog" over "change log" since it's the common usage.
17+
- Start versioning based on the current English version at 0.3.0 to help
18+
translation authors keep things up-to-date.
19+
20+
### Removed
21+
- Section about "changelog" vs "CHANGELOG".
22+
23+
## [0.3.0] - 2015-12-03
24+
### Added
25+
- RU translation from [@aishek](https://github.com/aishek).
26+
- pt-BR translation from [@tallesl](https://github.com/tallesl).
27+
- es-ES translation from [@ZeliosAriex](https://github.com/ZeliosAriex).
28+
29+
## [0.2.0] - 2015-10-06
30+
### Changed
31+
- Remove exclusionary mentions of "open source" since this project can
32+
benefit both "open" and "closed" source projects equally.
33+
34+
[Unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...HEAD
35+
[1.0.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.3.0...v1.0.0
36+
[0.3.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.2.0...v0.3.0
37+
[0.2.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.1.0...v0.2.0

0 commit comments

Comments
 (0)