git-raw-commits 3.0.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -81
- package/package.json +19 -21
- package/src/cli.js +37 -0
- package/src/index.js +59 -0
- package/cli.js +0 -19
- package/index.js +0 -100
package/README.md
CHANGED
|
@@ -1,101 +1,60 @@
|
|
|
1
|
-
#
|
|
1
|
+
# git-raw-commits
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[![ESM-only package][package]][package-url]
|
|
4
|
+
[![NPM version][npm]][npm-url]
|
|
5
|
+
[![Node version][node]][node-url]
|
|
6
|
+
[![Dependencies status][deps]][deps-url]
|
|
7
|
+
[![Install size][size]][size-url]
|
|
8
|
+
[![Build status][build]][build-url]
|
|
9
|
+
[![Coverage status][coverage]][coverage-url]
|
|
4
10
|
|
|
11
|
+
[package]: https://img.shields.io/badge/package-ESM--only-ffe536.svg
|
|
12
|
+
[package-url]: https://nodejs.org/api/esm.html
|
|
5
13
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
```sh
|
|
9
|
-
$ npm install --save git-raw-commits
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
```js
|
|
16
|
-
var gitRawCommits = require('git-raw-commits');
|
|
17
|
-
|
|
18
|
-
gitRawCommits(options)
|
|
19
|
-
.pipe(...);
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
## API
|
|
24
|
-
|
|
25
|
-
### gitRawCommits(gitOpts, [execOpts])
|
|
26
|
-
|
|
27
|
-
Returns a readable stream. Stream is split to break on each commit.
|
|
28
|
-
|
|
29
|
-
#### gitOpts
|
|
30
|
-
|
|
31
|
-
Type: `object`
|
|
32
|
-
|
|
33
|
-
Please check the available options at http://git-scm.com/docs/git-log.
|
|
34
|
-
**NOTE:** Single dash arguments are not supported because of https://github.com/sindresorhus/dargs/blob/master/index.js#L5.
|
|
35
|
-
|
|
36
|
-
*NOTE*: for `<revision range>` we can also use `<from>..<to>` pattern, and this module has the following extra options for shortcut of this pattern:
|
|
37
|
-
|
|
38
|
-
##### gitOpts.from
|
|
39
|
-
|
|
40
|
-
Type: `string` Default: `''`
|
|
14
|
+
[npm]: https://img.shields.io/npm/v/git-raw-commits.svg
|
|
15
|
+
[npm-url]: https://npmjs.com/package/git-raw-commits
|
|
41
16
|
|
|
42
|
-
|
|
17
|
+
[node]: https://img.shields.io/node/v/git-raw-commits.svg
|
|
18
|
+
[node-url]: https://nodejs.org
|
|
43
19
|
|
|
44
|
-
|
|
20
|
+
[deps]: https://img.shields.io/librariesio/release/npm/git-raw-commits
|
|
21
|
+
[deps-url]: https://libraries.io/npm/git-raw-commits/tree
|
|
45
22
|
|
|
46
|
-
|
|
23
|
+
[size]: https://packagephobia.com/badge?p=git-raw-commits
|
|
24
|
+
[size-url]: https://packagephobia.com/result?p=git-raw-commits
|
|
47
25
|
|
|
48
|
-
|
|
26
|
+
[build]: https://img.shields.io/github/actions/workflow/status/conventional-changelog/conventional-changelog/tests.yaml?branch=master
|
|
27
|
+
[build-url]: https://github.com/conventional-changelog/conventional-changelog/actions
|
|
49
28
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
Please check http://git-scm.com/docs/git-log for format options.
|
|
53
|
-
|
|
54
|
-
##### gitOpts.debug
|
|
55
|
-
|
|
56
|
-
Type: `function`
|
|
57
|
-
|
|
58
|
-
A function to get debug information.
|
|
59
|
-
|
|
60
|
-
##### gitOpts.path
|
|
61
|
-
|
|
62
|
-
Type: `string`
|
|
63
|
-
|
|
64
|
-
Filter commits to the path provided.
|
|
65
|
-
|
|
66
|
-
##### execOpts
|
|
67
|
-
|
|
68
|
-
Options to pass to `git` `childProcess`
|
|
69
|
-
|
|
70
|
-
Type: `object`
|
|
71
|
-
|
|
72
|
-
##### execOpts.cwd
|
|
29
|
+
[coverage]: https://coveralls.io/repos/github/conventional-changelog/conventional-changelog/badge.svg?branch=master
|
|
30
|
+
[coverage-url]: https://coveralls.io/github/conventional-changelog/conventional-changelog?branch=master
|
|
73
31
|
|
|
74
|
-
|
|
32
|
+
Get raw git commits out of your repository using git-log(1).
|
|
75
33
|
|
|
76
|
-
|
|
34
|
+
## Install
|
|
77
35
|
|
|
36
|
+
```bash
|
|
37
|
+
# pnpm
|
|
38
|
+
pnpm add git-raw-commits
|
|
39
|
+
# yarn
|
|
40
|
+
yarn add git-raw-commits
|
|
41
|
+
# npm
|
|
42
|
+
npm i git-raw-commits
|
|
43
|
+
```
|
|
78
44
|
|
|
79
45
|
## CLI
|
|
80
46
|
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
|
|
47
|
+
```bash
|
|
48
|
+
# Example
|
|
49
|
+
git-raw-commits --from HEAD~2 --to HEAD^
|
|
50
|
+
# For more details
|
|
51
|
+
git-raw-commits --help
|
|
84
52
|
```
|
|
85
53
|
|
|
54
|
+
## API
|
|
55
|
+
|
|
56
|
+
For JS API see [@conventional-changelog/git-client](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/git-client).
|
|
86
57
|
|
|
87
58
|
## License
|
|
88
59
|
|
|
89
60
|
MIT © [Steve Mao](https://github.com/stevemao)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
[npm-image]: https://badge.fury.io/js/git-raw-commits.svg
|
|
93
|
-
[npm-url]: https://npmjs.org/package/git-raw-commits
|
|
94
|
-
[travis-image]: https://travis-ci.org/conventional-changelog/git-raw-commits.svg?branch=master
|
|
95
|
-
[travis-url]: https://travis-ci.org/conventional-changelog/git-raw-commits
|
|
96
|
-
[appveyor-image]: https://ci.appveyor.com/api/projects/status/4qm3bjmg41k3dsbv/branch/master?svg=true
|
|
97
|
-
[appveyor-url]: https://ci.appveyor.com/project/stevemao/git-raw-commits/branch/master
|
|
98
|
-
[daviddm-image]: https://david-dm.org/conventional-changelog/git-raw-commits.svg?theme=shields.io
|
|
99
|
-
[daviddm-url]: https://david-dm.org/conventional-changelog/git-raw-commits
|
|
100
|
-
[coverage-image]: https://coveralls.io/repos/github/conventional-changelog/conventional-changelog/badge.svg?branch=master
|
|
101
|
-
[coverage-url]: https://coveralls.io/github/conventional-changelog/conventional-changelog?branch=master
|
package/package.json
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "git-raw-commits",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"url": "https://github.com/conventional-changelog/conventional-changelog/issues"
|
|
7
|
-
},
|
|
8
|
-
"homepage": "https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/git-raw-commits#readme",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "5.0.0",
|
|
5
|
+
"description": "Get raw git commits out of your repository using git-log(1).",
|
|
9
6
|
"author": {
|
|
10
7
|
"name": "Steve Mao",
|
|
11
8
|
"email": "maochenyan@gmail.com",
|
|
12
9
|
"url": "https://github.com/stevemao"
|
|
13
10
|
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"homepage": "https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/git-raw-commits#readme",
|
|
14
13
|
"repository": {
|
|
15
14
|
"type": "git",
|
|
16
|
-
"url": "https://github.com/conventional-changelog/conventional-changelog.git"
|
|
15
|
+
"url": "https://github.com/conventional-changelog/conventional-changelog.git",
|
|
16
|
+
"directory": "packages/git-raw-commits"
|
|
17
17
|
},
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
"node": ">=14"
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/conventional-changelog/conventional-changelog/issues"
|
|
21
20
|
},
|
|
22
|
-
"files": [
|
|
23
|
-
"index.js",
|
|
24
|
-
"cli.js"
|
|
25
|
-
],
|
|
26
21
|
"keywords": [
|
|
27
22
|
"git-raw-commits",
|
|
28
23
|
"raw",
|
|
@@ -32,15 +27,18 @@
|
|
|
32
27
|
"log",
|
|
33
28
|
"git-log"
|
|
34
29
|
],
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"meow": "^8.1.2",
|
|
38
|
-
"split2": "^3.2.2"
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18"
|
|
39
32
|
},
|
|
40
33
|
"bin": {
|
|
41
|
-
"git-raw-commits": "cli.js"
|
|
34
|
+
"git-raw-commits": "./src/cli.js"
|
|
42
35
|
},
|
|
43
|
-
"
|
|
44
|
-
|
|
36
|
+
"exports": "./src/index.js",
|
|
37
|
+
"files": [
|
|
38
|
+
"src"
|
|
39
|
+
],
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"meow": "^13.0.0",
|
|
42
|
+
"@conventional-changelog/git-client": "^1.0.0"
|
|
45
43
|
}
|
|
46
44
|
}
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { pipeline } from 'stream/promises'
|
|
3
|
+
import meow from 'meow'
|
|
4
|
+
import { getRawCommits } from './index.js'
|
|
5
|
+
|
|
6
|
+
const cli = meow(`
|
|
7
|
+
Usage
|
|
8
|
+
git-raw-commits [<git-log(1)-options>]
|
|
9
|
+
|
|
10
|
+
Example
|
|
11
|
+
git-raw-commits --from HEAD~2 --to HEAD^
|
|
12
|
+
`, {
|
|
13
|
+
importMeta: import.meta,
|
|
14
|
+
flags: {
|
|
15
|
+
ignore: {
|
|
16
|
+
type: 'string'
|
|
17
|
+
},
|
|
18
|
+
path: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
isMultiple: true
|
|
21
|
+
},
|
|
22
|
+
from: {
|
|
23
|
+
type: 'string'
|
|
24
|
+
},
|
|
25
|
+
to: {
|
|
26
|
+
type: 'string'
|
|
27
|
+
},
|
|
28
|
+
format: {
|
|
29
|
+
type: 'string'
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
await pipeline(
|
|
35
|
+
getRawCommits(cli.flags),
|
|
36
|
+
process.stdout
|
|
37
|
+
)
|
package/src/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Readable } from 'stream'
|
|
2
|
+
import { GitClient } from '@conventional-changelog/git-client'
|
|
3
|
+
|
|
4
|
+
function getFinalOptions (options = {}) {
|
|
5
|
+
const finalOptions = {
|
|
6
|
+
cwd: process.cwd(),
|
|
7
|
+
...options
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (options.debug) {
|
|
11
|
+
finalOptions.debug = (args) => {
|
|
12
|
+
options.debug('Your git-log command is:\ngit ' + args.join(' '))
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return finalOptions
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get raw commits from git-log.
|
|
21
|
+
* @param {*} options
|
|
22
|
+
* @param {string} [options.cwd=process.cwd()] - Current working directory to run git.
|
|
23
|
+
* @param {false | ((log: string) => void)} [options.debug=false] - A function to get debug information.
|
|
24
|
+
* @param {string | RegExp} [options.ignore] - Ignore commits that match provided string or RegExp.
|
|
25
|
+
* @param {string | string[]} [options.path] - Only commits that are modifying this path.
|
|
26
|
+
* @param {string} [options.from=''] - Starting commit reference or hash.
|
|
27
|
+
* @param {string} [options.to='HEAD'] - Ending commit reference or hash.
|
|
28
|
+
* @param {string} [options.format='%B'] - Format of the commit.
|
|
29
|
+
* @yields {string} - Raw commit.
|
|
30
|
+
*/
|
|
31
|
+
export async function * getRawCommits (options) {
|
|
32
|
+
const { cwd, debug, ...finalOptions } = getFinalOptions(options)
|
|
33
|
+
const client = new GitClient(cwd, debug)
|
|
34
|
+
let commit
|
|
35
|
+
|
|
36
|
+
if (typeof finalOptions.ignore === 'string') {
|
|
37
|
+
finalOptions.ignore = new RegExp(finalOptions.ignore)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
for await (commit of client.getRawCommits(finalOptions)) {
|
|
41
|
+
yield commit
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Get raw commits stream from git-log.
|
|
47
|
+
* @param {*} options
|
|
48
|
+
* @param {string} [options.cwd=process.cwd()] - Current working directory to run git.
|
|
49
|
+
* @param {false | ((log: string) => void)} [options.debug=false] - A function to get debug information.
|
|
50
|
+
* @param {string | RegExp} [options.ignore] - Ignore commits that match provided string or RegExp.
|
|
51
|
+
* @param {string | string[]} [options.path] - Only commits that are modifying this path.
|
|
52
|
+
* @param {string} [options.from=''] - Starting commit reference or hash.
|
|
53
|
+
* @param {string} [options.to='HEAD'] - Ending commit reference or hash.
|
|
54
|
+
* @param {string} [options.format='%B'] - Format of the commit.
|
|
55
|
+
* @returns {Readable} - Raw commits stream.
|
|
56
|
+
*/
|
|
57
|
+
export function getRawCommitsStream (options) {
|
|
58
|
+
return Readable.from(getRawCommits(options))
|
|
59
|
+
}
|
package/cli.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict'
|
|
3
|
-
const meow = require('meow')
|
|
4
|
-
const gitRawCommits = require('./')
|
|
5
|
-
|
|
6
|
-
const cli = meow(`
|
|
7
|
-
Usage
|
|
8
|
-
git-raw-commits [<git-log(1)-options>]
|
|
9
|
-
|
|
10
|
-
Example
|
|
11
|
-
git-raw-commits --from HEAD~2 --to HEAD^`
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
gitRawCommits(cli.flags)
|
|
15
|
-
.on('error', function (err) {
|
|
16
|
-
process.stderr.write(err)
|
|
17
|
-
process.exit(1)
|
|
18
|
-
})
|
|
19
|
-
.pipe(process.stdout)
|
package/index.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const dargs = require('dargs')
|
|
4
|
-
const execFile = require('child_process').execFile
|
|
5
|
-
const split = require('split2')
|
|
6
|
-
const { Readable, Transform } = require('stream')
|
|
7
|
-
|
|
8
|
-
const DELIMITER = '------------------------ >8 ------------------------'
|
|
9
|
-
|
|
10
|
-
function normalizeExecOpts (execOpts) {
|
|
11
|
-
execOpts = execOpts || {}
|
|
12
|
-
execOpts.cwd = execOpts.cwd || process.cwd()
|
|
13
|
-
return execOpts
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function normalizeGitOpts (gitOpts) {
|
|
17
|
-
gitOpts = gitOpts || {}
|
|
18
|
-
gitOpts.format = gitOpts.format || '%B'
|
|
19
|
-
gitOpts.from = gitOpts.from || ''
|
|
20
|
-
gitOpts.to = gitOpts.to || 'HEAD'
|
|
21
|
-
return gitOpts
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function getGitArgs (gitOpts) {
|
|
25
|
-
const gitFormat = `--format=${gitOpts.format || ''}%n${DELIMITER}`
|
|
26
|
-
const gitFromTo = [gitOpts.from, gitOpts.to].filter(Boolean).join('..')
|
|
27
|
-
|
|
28
|
-
const gitArgs = ['log', gitFormat, gitFromTo]
|
|
29
|
-
.concat(dargs(gitOpts, {
|
|
30
|
-
excludes: ['debug', 'from', 'to', 'format', 'path']
|
|
31
|
-
}))
|
|
32
|
-
|
|
33
|
-
// allow commits to focus on a single directory
|
|
34
|
-
// this is useful for monorepos.
|
|
35
|
-
if (gitOpts.path) {
|
|
36
|
-
gitArgs.push('--', gitOpts.path)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return gitArgs
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function gitRawCommits (rawGitOpts, rawExecOpts) {
|
|
43
|
-
const readable = new Readable()
|
|
44
|
-
readable._read = function () {}
|
|
45
|
-
|
|
46
|
-
const gitOpts = normalizeGitOpts(rawGitOpts)
|
|
47
|
-
const execOpts = normalizeExecOpts(rawExecOpts)
|
|
48
|
-
const args = getGitArgs(gitOpts)
|
|
49
|
-
|
|
50
|
-
if (gitOpts.debug) {
|
|
51
|
-
gitOpts.debug('Your git-log command is:\ngit ' + args.join(' '))
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
let isError = false
|
|
55
|
-
|
|
56
|
-
const child = execFile('git', args, {
|
|
57
|
-
cwd: execOpts.cwd,
|
|
58
|
-
maxBuffer: Infinity
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
child.stdout
|
|
62
|
-
.pipe(split(DELIMITER + '\n'))
|
|
63
|
-
.pipe(
|
|
64
|
-
new Transform({
|
|
65
|
-
transform (chunk, enc, cb) {
|
|
66
|
-
readable.push(chunk)
|
|
67
|
-
isError = false
|
|
68
|
-
|
|
69
|
-
cb()
|
|
70
|
-
},
|
|
71
|
-
flush (cb) {
|
|
72
|
-
setImmediate(function () {
|
|
73
|
-
if (!isError) {
|
|
74
|
-
readable.push(null)
|
|
75
|
-
readable.emit('close')
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
cb()
|
|
79
|
-
})
|
|
80
|
-
}
|
|
81
|
-
})
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
child.stderr
|
|
85
|
-
.pipe(
|
|
86
|
-
new Transform({
|
|
87
|
-
objectMode: true,
|
|
88
|
-
highWaterMark: 16,
|
|
89
|
-
transform (chunk) {
|
|
90
|
-
isError = true
|
|
91
|
-
readable.emit('error', new Error(chunk))
|
|
92
|
-
readable.emit('close')
|
|
93
|
-
}
|
|
94
|
-
})
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
return readable
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
module.exports = gitRawCommits
|