Skip to content

Commit 8990d8a

Browse files
committed
fix semver regex (#62)
Closes #61 Reviewed-on: https://git.justinelmore.dev/jelmore1674/build-changelog/pulls/62 Co-authored-by: Justin Elmore <[email protected]> Co-committed-by: Justin Elmore <[email protected]>
1 parent b40f6e8 commit 8990d8a

File tree

8 files changed

+53
-11
lines changed

8 files changed

+53
-11
lines changed

changelog/author.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 1.4.0
2+
release_date: 2025-01-02
3+
author: Justin Elmore
4+
5+
added:
6+
feature:
7+
- Author linking inside of action! 🚀
8+
9+
references:
10+
- type: pull_request
11+
reference: 62

changelog/regex.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 1.4.0
2+
release_date: 2025-01-02
3+
author: Justin Elmore
4+
5+
fixed:
6+
bug:
7+
- Resolve bug where versions with more than 1 digit was not being parsed correctly.
8+
9+
references:
10+
- type: issue
11+
reference: 61
12+
- type: pull_request
13+
reference: 62

generate/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

notes/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jelmore1674/build-changelog",
3-
"version": "1.3.1",
3+
"version": "1.4.0",
44
"description": "",
55
"main": "dist/index.js",
66
"files": [

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const program = new Command();
1010
program
1111
.name("build-changelog")
1212
.description("cli tool to generate changelogs")
13-
.version("1.3.1");
13+
.version("1.4.0");
1414

1515
program
1616
.command("init")

src/lib/generate.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { rl } from "./readline";
1212

1313
const GITHUB_SERVER_URL = process.env.GITHUB_SERVER_URL;
1414
const GITHUB_REPOSITORY = process.env.GITHUB_REPOSITORY;
15+
const GITHUB_ACTOR = process.env.GITHUB_ACTOR;
1516

1617
/** Properties we will not use when adding changes to the changelog */
1718
const YAML_KEY_FILTER = ["release_date", "version", "notice", "references", "author"];
@@ -121,6 +122,15 @@ function generateReferences(references: Reference[]): string {
121122
}).join(", ");
122123
}
123124

125+
/**
126+
* Generate the link for the author.
127+
*
128+
* @param author - author name.
129+
*/
130+
function generateAuthorLink(author: string) {
131+
return `[${author}](${GITHUB_SERVER_URL}/${GITHUB_ACTOR})`;
132+
}
133+
124134
/**
125135
* The generate command will read the existing `yaml|yml` files in the
126136
* `changelogDir`, write them to the `CHANGELOG.md`, and will remove the
@@ -193,7 +203,11 @@ function generateCommand() {
193203

194204
// Add author to the change.
195205
if (author) {
196-
renderedChange = `${renderedChange} (${author})`;
206+
if (GITHUB_ACTOR) {
207+
renderedChange = `${renderedChange} (${generateAuthorLink(author)})`;
208+
} else {
209+
renderedChange = `${renderedChange} (${author})`;
210+
}
197211
}
198212

199213
if (config.flags?.[flag]) {

src/lib/parseChangelog.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { existsSync, readFileSync } from "node:fs";
2-
import path from "node:path";
32
import { Keywords, Version } from "./mustache";
43

5-
// semver versioning
6-
const versionRegex = /\d\.\d\.\d/gism;
4+
/**
5+
* semver versioning.
6+
* Regex is from [semver](https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string)
7+
* The only change from semver is added check for unreleased.
8+
*/
9+
const versionRegex =
10+
/((0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?|unreleased)/gism;
711
// release version section.
812
const versionSectionRegex = /(?=^#{2} .*?$)/gism;
913
// date: looks for either 2024-12-06 or 12-06-2024
@@ -58,7 +62,7 @@ function parseChangelog(changelogPath: string) {
5862
"",
5963
).trim().split("\n- ")
6064
.map((change: string) =>
61-
change.replace(/^\[(\d\.\d\.\d|unreleased).*/gism, "")
65+
change.replace(/^\[(\d{1,4}\.\d{1,4}\.\d{1,4}|unreleased).*/gism, "")
6266
.replace(/^- /g, "")
6367
.replace(/\n /g, "")
6468
.trim()

0 commit comments

Comments
 (0)