Skip to content

Commit f907f8c

Browse files
committed
build: add option to parse-commits utility to set git log flags
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 635e38f commit f907f8c

File tree

15 files changed

+390
-27
lines changed

15 files changed

+390
-27
lines changed

lib/node_modules/@stdlib/_tools/changelog/generate/README.md

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ limitations under the License.
3030
var generate = require( '@stdlib/_tools/changelog/generate' );
3131
```
3232

33-
#### generate( pkg\[, releaseType] )
33+
#### generate( pkg\[, options] )
3434

3535
Generates a Markdown formatted changelog for a specified package.
3636

@@ -44,13 +44,22 @@ The function returns an object with the following properties:
4444
- **content**: Markdown formatted changelog.
4545
- **releaseType**: release type (`null` if changelog is for a non-release).
4646

47-
To generate a changelog for an upcoming release, provide a valid release type as the second argument.
47+
The function accepts the following `options`:
48+
49+
- **releaseType**: a release type for which to generate the changelog for.
50+
- **flags**: `git log` options used to retrieve commits to generate the changelog for.
51+
52+
By default, the changelog is generated for a non-release. To generate a changelog for an upcoming release, provide a valid release type:
4853

4954
```javascript
50-
var changelog = generate( '@stdlib/assert/contains', 'patch' );
55+
var changelog = generate( '@stdlib/assert/contains', {
56+
'releaseType': 'patch'
57+
});
5158
// returns {...}
5259

53-
changelog = generate( '@stdlib/assert/contains', 'minor' );
60+
changelog = generate( '@stdlib/assert/contains', {
61+
'releaseType': 'minor'
62+
});
5463
// returns {...}
5564
```
5665

@@ -66,6 +75,24 @@ The following release types are supported:
6675
- `auto`: automatically determine the release type based on parsed commit messages.
6776
- `none`: no release (equivalent to not specifying a release type).
6877

78+
Under the hood, the changelog leverages `git log` to retrieve the commits from which to assemble the changelog. The `flags` option allows passing any options to the `git log` command, e.g. to generate a changelog for a specified time interval or for an individual contributor.
79+
80+
```js
81+
var changelog = generate( '@stdlib/ndarray', {
82+
'flags': {
83+
'since': 'last month'
84+
}
85+
});
86+
// returns {...}
87+
88+
changelog = generate( '@stdlib/ndarray', {
89+
'flags': {
90+
'author': 'Athan Reines <[email protected]>'
91+
}
92+
});
93+
// returns {...}
94+
```
95+
6996
</section>
7097

7198
<!-- /.usage -->
@@ -92,7 +119,9 @@ var releaseType = changelog.releaseType;
92119
// returns null
93120

94121
// Generate a changelog for a new release:
95-
changelog = generate( '@stdlib/utils/curry', 'patch' );
122+
changelog = generate( '@stdlib/utils/curry', {
123+
'releaseType': 'patch'
124+
});
96125
content = changelog.content;
97126
// returns '...'
98127

@@ -103,6 +132,15 @@ releaseType = changelog.releaseType;
103132
changelog = generate( '@stdlib/string/base' );
104133
content = changelog.content;
105134
// returns '...'
135+
136+
// Generate a changelog restricted to a single author:
137+
changelog = generate( '@stdlib/string/base', {
138+
'flags': {
139+
'author': 'Athan Reines <[email protected]>'
140+
}
141+
});
142+
content = changelog.content;
143+
// returns '...'
106144
```
107145

108146
</section>

lib/node_modules/@stdlib/_tools/changelog/generate/examples/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ console.log( releaseType );
3131
// => null
3232

3333
// Generate a changelog for a new release:
34-
changelog = generate( '@stdlib/utils/curry', 'patch' );
34+
changelog = generate( '@stdlib/utils/curry', {
35+
'releaseType': 'patch'
36+
});
3537
content = changelog.content;
3638
console.log( content );
3739
// => '...'
@@ -45,3 +47,12 @@ changelog = generate( '@stdlib/string/base' );
4547
content = changelog.content;
4648
console.log( content );
4749
// => '...'
50+
51+
// Generate a changelog restricted to a single author:
52+
changelog = generate( '@stdlib/string/base', {
53+
'flags': {
54+
'author': 'Athan Reines <[email protected]>'
55+
}
56+
});
57+
content = changelog.content;
58+
console.log( content );

lib/node_modules/@stdlib/_tools/changelog/generate/lib/main.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var formatCommits = require( './format_commits.js' );
4848
var npmReleases = require( './npm_releases.js' );
4949
var sectionStart = require( './section_start.js' );
5050
var sectionEnd = require( './section_end.js' );
51+
var validate = require( './validate.js' );
5152
var heading = require( './heading.js' );
5253

5354

@@ -208,7 +209,9 @@ function packageSummaryWrapper( pkg, version, name, summary ) {
208209
* Generates a Markdown formatted changelog for a specified stdlib package.
209210
*
210211
* @param {string} pkg - package name
211-
* @param {string} [releaseType] - release type (`patch`, `minor`, `major`, `prerelease`, `prepatch`, `preminor`, `premajor`, or `auto`)
212+
* @param {Options} options - function options
213+
* @param {string} [options.releaseType] - release type (`patch`, `minor`, `major`, `prerelease`, `prepatch`, `preminor`, `premajor`, or `auto`)
214+
* @param {Options} [options.flags] - `git log` options used to retrieve commits
212215
* @throws {TypeError} must provide a string
213216
* @throws {Error} must provide a valid package name
214217
* @throws {TypeError} must provide a recognized release type
@@ -227,18 +230,23 @@ function packageSummaryWrapper( pkg, version, name, summary ) {
227230
* // returns {...}
228231
*
229232
* @example
230-
* var changelog = generate( '@stdlib/utils/curry', 'patch' );
233+
* var changelog = generate( '@stdlib/utils/curry', {
234+
* 'releaseType': 'patch'
235+
* });
231236
* // returns {...}
232237
*
233238
* @example
234-
* var changelog = generate( '@stdlib/utils/curry', 'major' );
239+
* var changelog = generate( '@stdlib/utils/curry', {
240+
* 'releaseType': 'major'
241+
* });
235242
* // returns {...}
236243
*/
237-
function generate( pkg, releaseType ) {
244+
function generate( pkg, options ) {
238245
var isNamespacePkg;
239246
var releaseCommits;
240247
var newestRelease;
241248
var bySubpackage;
249+
var releaseType;
242250
var nextVersion;
243251
var standalone;
244252
var unreleased;
@@ -247,14 +255,24 @@ function generate( pkg, releaseType ) {
247255
var commits;
248256
var version;
249257
var summary;
258+
var opts;
250259
var name;
251260
var str;
261+
var err;
252262
var i;
253263
var j;
254264

255265
if ( !isString( pkg ) ) {
256266
throw new TypeError( format( 'invalid argument. Must provide a string. Value: `%s`.', pkg ) );
257267
}
268+
opts = {};
269+
if ( arguments.length > 1 ) {
270+
err = validate( opts, options );
271+
if ( err ) {
272+
throw err;
273+
}
274+
}
275+
258276
if ( pkg === '@stdlib' || pkg === '@stdlib/stdlib' ) {
259277
// Case: root package
260278
isNamespacePkg = true;
@@ -275,9 +293,16 @@ function generate( pkg, releaseType ) {
275293
str = '# CHANGELOG\n\n';
276294
str += '> Package changelog.\n\n';
277295

278-
commits = parseCommits({
279-
'dir': join( STDLIB_LIB_DIR, pkg )
280-
});
296+
if ( opts.flags ) {
297+
commits = parseCommits({
298+
'dir': join( STDLIB_LIB_DIR, pkg ),
299+
'flags': opts.flags
300+
});
301+
} else {
302+
commits = parseCommits({
303+
'dir': join( STDLIB_LIB_DIR, pkg )
304+
});
305+
}
281306
if ( commits.length === 0 ) {
282307
throw new Error( format( 'invalid argument. Unable to parse commits for package: `%s`.', pkg ) );
283308
}
@@ -291,6 +316,7 @@ function generate( pkg, releaseType ) {
291316
commits.unreleased = [];
292317
}
293318

319+
releaseType = opts.releaseType;
294320
if ( releaseType === 'auto' ) {
295321
releaseType = recommendVersionBump( commits.unreleased );
296322

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var isObject = require( '@stdlib/assert/is-plain-object' );
24+
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
25+
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
26+
var isPlainObject = require( '@stdlib/assert/is-plain-object' );
27+
var format = require( '@stdlib/string/format' );
28+
29+
30+
// MAIN //
31+
32+
/**
33+
* Validates function options.
34+
*
35+
* @private
36+
* @param {Object} opts - destination for function options
37+
* @param {Options} options - function options
38+
* @param {string} [options.releaseType] - release type
39+
* @param {string} [options.flags] - `git log` options used to retrieve commits
40+
* @returns {(Error|null)} error or null
41+
*
42+
* @example
43+
* var opts = {};
44+
* var options = {
45+
* 'month': '01-2025'
46+
* };
47+
* var err = validate( opts, options );
48+
* if ( err ) {
49+
* throw err;
50+
* }
51+
*/
52+
function validate( opts, options ) {
53+
if ( !isObject( options ) ) {
54+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
55+
}
56+
if ( hasOwnProp( options, 'releaseType' ) ) {
57+
opts.releaseType = options.releaseType;
58+
if ( !isString( opts.releaseType ) ) {
59+
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'releaseType', opts.releaseType ) );
60+
}
61+
}
62+
if ( hasOwnProp( options, 'flags' ) ) {
63+
opts.flags = options.flags;
64+
if ( !isPlainObject( opts.flags ) ) {
65+
return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'flags', opts.flags ) );
66+
}
67+
}
68+
return null;
69+
}
70+
71+
72+
// EXPORTS //
73+
74+
module.exports = validate;

lib/node_modules/@stdlib/_tools/changelog/generate/test/test.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ tape( 'the function throws an error if provided an invalid release type', functi
101101

102102
function badValue( value ) {
103103
return function badValue() {
104-
generate( '@stdlib/utils/curry', value );
104+
generate( '@stdlib/utils/curry', {
105+
'releaseType': value
106+
});
105107
};
106108
}
107109
});
@@ -126,17 +128,23 @@ tape( 'the function generates a changelog', function test( t ) {
126128
});
127129

128130
tape( 'the function generates a changelog for a new release', function test( t ) {
129-
var out = generate( '@stdlib/utils/noop', 'patch' );
131+
var out = generate( '@stdlib/utils/noop', {
132+
'releaseType': 'patch'
133+
});
130134
t.strictEqual( isObject( out ), true, 'returns expected value' );
131135
t.strictEqual( typeof out.content, 'string', 'returns expected value' );
132136
t.strictEqual( out.releaseType, 'patch', 'returns expected value' );
133137

134-
out = generate( '@stdlib/utils/noop', 'minor' );
138+
out = generate( '@stdlib/utils/noop', {
139+
'releaseType': 'minor'
140+
});
135141
t.strictEqual( isObject( out ), true, 'returns expected value' );
136142
t.strictEqual( typeof out.content, 'string', 'returns expected value' );
137143
t.strictEqual( out.releaseType, 'minor', 'returns expected value' );
138144

139-
out = generate( '@stdlib/utils/noop', 'major' );
145+
out = generate( '@stdlib/utils/noop', {
146+
'releaseType': 'major'
147+
});
140148
t.strictEqual( isObject( out ), true, 'returns expected value' );
141149
t.strictEqual( typeof out.content, 'string', 'returns expected value' );
142150
t.strictEqual( out.releaseType, 'major', 'returns expected value' );
@@ -145,13 +153,26 @@ tape( 'the function generates a changelog for a new release', function test( t )
145153
});
146154

147155
tape( 'the function generates a changelog for a new release (auto)', function test( t ) {
148-
var out = generate( '@stdlib/utils/noop', 'auto' );
156+
var out = generate( '@stdlib/utils/noop', {
157+
'releaseType': 'auto'
158+
});
149159
t.strictEqual( isObject( out ), true, 'returns expected value' );
150160
t.strictEqual( typeof out.content, 'string', 'returns expected value' );
151161

152-
out = generate( '@stdlib/array/base/slice', 'auto' );
162+
out = generate( '@stdlib/array/base/slice', {
163+
'releaseType': 'auto'
164+
});
153165
t.strictEqual( isObject( out ), true, 'returns expected value' );
154166
t.strictEqual( typeof out.content, 'string', 'returns expected value' );
155167

156168
t.end();
157169
});
170+
171+
tape( 'the function generates a changelog for a specific author', function test( t ) {
172+
var out = generate( '@stdlib/ndarray/base', {
173+
'flags': '--author="Athan Reines"'
174+
});
175+
t.strictEqual( isObject( out ), true, 'returns expected value' );
176+
t.strictEqual( typeof out.content, 'string', 'returns expected value' );
177+
t.end();
178+
});

0 commit comments

Comments
 (0)