Skip to content

Commit 2bf7851

Browse files
committed
build: add option to parse-commits utility to set git log flags
1 parent 635e38f commit 2bf7851

File tree

14 files changed

+340
-25
lines changed

14 files changed

+340
-25
lines changed

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

Lines changed: 37 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,20 @@ 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': '--since="last month"'
83+
});
84+
// returns {...}
85+
86+
changelog = generate( '@stdlib/ndarray', {
87+
'flags': '--author="Athan Reines"'
88+
});
89+
// returns {...}
90+
```
91+
6992
</section>
7093

7194
<!-- /.usage -->
@@ -92,7 +115,9 @@ var releaseType = changelog.releaseType;
92115
// returns null
93116

94117
// Generate a changelog for a new release:
95-
changelog = generate( '@stdlib/utils/curry', 'patch' );
118+
changelog = generate( '@stdlib/utils/curry', {
119+
'releaseType': 'patch'
120+
});
96121
content = changelog.content;
97122
// returns '...'
98123

@@ -103,6 +128,13 @@ releaseType = changelog.releaseType;
103128
changelog = generate( '@stdlib/string/base' );
104129
content = changelog.content;
105130
// returns '...'
131+
132+
// Generate a changelog restricted to a single author:
133+
changelog = generate( '@stdlib/string/base', {
134+
'flags': '--author="Athan Reines"'
135+
});
136+
content = changelog.content;
137+
// returns '...'
106138
```
107139

108140
</section>

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

Lines changed: 10 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,10 @@ 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': '--author="Athan Reines"'
54+
});
55+
content = changelog.content;
56+
console.log( content );

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

Lines changed: 27 additions & 5 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 {string} [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
@@ -234,11 +237,12 @@ function packageSummaryWrapper( pkg, version, name, summary ) {
234237
* var changelog = generate( '@stdlib/utils/curry', 'major' );
235238
* // returns {...}
236239
*/
237-
function generate( pkg, releaseType ) {
240+
function generate( pkg, options ) {
238241
var isNamespacePkg;
239242
var releaseCommits;
240243
var newestRelease;
241244
var bySubpackage;
245+
var releaseType;
242246
var nextVersion;
243247
var standalone;
244248
var unreleased;
@@ -247,14 +251,24 @@ function generate( pkg, releaseType ) {
247251
var commits;
248252
var version;
249253
var summary;
254+
var opts;
250255
var name;
251256
var str;
257+
var err;
252258
var i;
253259
var j;
254260

255261
if ( !isString( pkg ) ) {
256262
throw new TypeError( format( 'invalid argument. Must provide a string. Value: `%s`.', pkg ) );
257263
}
264+
opts = {};
265+
if ( arguments.length > 1 ) {
266+
err = validate( opts, options );
267+
if ( err ) {
268+
throw err;
269+
}
270+
}
271+
258272
if ( pkg === '@stdlib' || pkg === '@stdlib/stdlib' ) {
259273
// Case: root package
260274
isNamespacePkg = true;
@@ -275,9 +289,16 @@ function generate( pkg, releaseType ) {
275289
str = '# CHANGELOG\n\n';
276290
str += '> Package changelog.\n\n';
277291

278-
commits = parseCommits({
279-
'dir': join( STDLIB_LIB_DIR, pkg )
280-
});
292+
if ( opts.flags ) {
293+
commits = parseCommits({
294+
'dir': join( STDLIB_LIB_DIR, pkg ),
295+
'flags': opts.flags
296+
});
297+
} else {
298+
commits = parseCommits({
299+
'dir': join( STDLIB_LIB_DIR, pkg )
300+
});
301+
}
281302
if ( commits.length === 0 ) {
282303
throw new Error( format( 'invalid argument. Unable to parse commits for package: `%s`.', pkg ) );
283304
}
@@ -291,6 +312,7 @@ function generate( pkg, releaseType ) {
291312
commits.unreleased = [];
292313
}
293314

315+
releaseType = opts.releaseType;
294316
if ( releaseType === 'auto' ) {
295317
releaseType = recommendVersionBump( commits.unreleased );
296318

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 format = require( '@stdlib/string/format' );
27+
28+
29+
// MAIN //
30+
31+
/**
32+
* Validates function options.
33+
*
34+
* @private
35+
* @param {Object} opts - destination for function options
36+
* @param {Options} options - function options
37+
* @param {string} [options.releaseType] - release type
38+
* @param {string} [options.flags] - `git log` options used to retrieve commits
39+
* @returns {(Error|null)} error or null
40+
*
41+
* @example
42+
* var opts = {};
43+
* var options = {
44+
* 'month': '01-2025'
45+
* };
46+
* var err = validate( opts, options );
47+
* if ( err ) {
48+
* throw err;
49+
* }
50+
*/
51+
function validate( opts, options ) {
52+
if ( !isObject( options ) ) {
53+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
54+
}
55+
if ( hasOwnProp( options, 'releaseType' ) ) {
56+
opts.releaseType = options.releaseType;
57+
if ( !isString( opts.releaseType ) ) {
58+
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'releaseType', opts.releaseType ) );
59+
}
60+
}
61+
if ( hasOwnProp( options, 'flags' ) ) {
62+
opts.flags = options.flags;
63+
if ( !isString( opts.flags ) ) {
64+
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'flags', opts.flags ) );
65+
}
66+
}
67+
return null;
68+
}
69+
70+
71+
// EXPORTS //
72+
73+
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)