Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'daily'
commit-message:
prefix: 'chore'
include: 'scope'
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: 'daily'
commit-message:
prefix: 'chore'
include: 'scope'
63 changes: 63 additions & 0 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Test & Maybe Release
on: [push, pull_request]
jobs:
test:
strategy:
fail-fast: false
matrix:
node: [16.x, 18.x, lts/*, current]
os: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v3.5.1
with:
node-version: ${{ matrix.node }}
- name: Install Dependencies
run: |
npm install --no-progress
- name: Run tests
run: |
npm config set script-shell bash
npm run test:ci
release:
name: Release
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3.5.1
with:
node-version: lts/*
- name: Install dependencies
run: |
npm install --no-progress --no-package-lock --no-save
- name: Build
run: |
npm run build
- name: Install plugins
run: |
npm install \
@semantic-release/commit-analyzer \
conventional-changelog-conventionalcommits \
@semantic-release/release-notes-generator \
@semantic-release/npm \
@semantic-release/github \
@semantic-release/git \
@semantic-release/changelog \
--no-progress --no-package-lock --no-save
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
package-lock.json
6 changes: 2 additions & 4 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
The MIT License (MIT)
=====================
# The MIT License (MIT)

Copyright (c) 2015 Rod Vagg
---------------------------
## Copyright (c) 2015 Rod Vagg

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
31 changes: 15 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,38 @@ Intended to be used on a standard log format (not a simplified one using one of
Typical usage:

```js
var spawn = require('child_process').spawn
, split2 = require('split2')
, listStream = require('list-stream')
import { spawn } from 'node:child_process'
import split2 from 'split2'
import listStream from 'list-stream'

spawn('bash', [ '-c', 'git log' ])
spawn('bash', ['-c', 'git log'])
.stdout.pipe(split2()) // break up by newline characters
.pipe(commitStream('rvagg', 'commit-stream'))
.pipe(listStream.obj(onCommitList))


function onCommitList (err, list) {
// list is an array of objects
}
```

Commit object properties:

* `sha`: the full commit sha
* `author`: an object representing the author of the commit
- `sha`: the full commit sha
- `author`: an object representing the author of the commit
- `name`: the name of the committer
- `email`: the email of the committer
* `authors`: a list of such objects representing the authors of the commit, supporting multiple authors through `Co-authored-by:`
* `authorDate`: a string representing the date of the original commit by the author (never change)
* `commitDate`: a string representing the date of the last change of the commit
* `summary`: the one-line summary of the commit
* `description`: the free-form text content of the summary, minus specific metadata lines
* `reviewers`: an array containing objects with `name` and `email` properties if the commit metadata contains reviewers in a `Reviewed-By: Foo Bar <baz@boom>` format.
* `changes`: if `--stat` data is included in the git log, an object containing change stats:
- `authors`: a list of such objects representing the authors of the commit, supporting multiple authors through `Co-authored-by:`
- `authorDate`: a string representing the date of the original commit by the author (never change)
- `commitDate`: a string representing the date of the last change of the commit
- `summary`: the one-line summary of the commit
- `description`: the free-form text content of the summary, minus specific metadata lines
- `reviewers`: an array containing objects with `name` and `email` properties if the commit metadata contains reviewers in a `Reviewed-By: Foo Bar <baz@boom>` format.
- `changes`: if `--stat` data is included in the git log, an object containing change stats:
- `files`: the number of files changed
- `insertions`: the number of new lines inserted
- `deletions`: the number of old lines removed
* `prUrl`: a URL pointing to a pull-request where this change was made if the commit metadata contains a `PR-URL: https://github.com/user/project/pull/XX` line. Note that whatever proceeds the `PR-URL: ` string will be collected in this property; one exception being that if a shortened `#XX` version is found and you have supplied `defaultGitHubUser` and `defaultGitHubProject` arguments to the constructor then a full GitHub pull-request will be reconstituted in its place.
* `ghUser`, `ghProject, `ghIssue`: if a proper GitHub pull request is found for the `prUrl` property (including shortened `#XX` ones), these properties will be added to point to the original user, project and issue (pull-request) for this change, as extracted from the URL.
- `prUrl`: a URL pointing to a pull-request where this change was made if the commit metadata contains a `PR-URL: https://github.com/user/project/pull/XX` line. Note that whatever proceeds the `PR-URL: ` string will be collected in this property; one exception being that if a shortened `#XX` version is found and you have supplied `defaultGitHubUser` and `defaultGitHubProject` arguments to the constructor then a full GitHub pull-request will be reconstituted in its place.
- `ghUser`, `ghProject`, `ghIssue`: if a proper GitHub pull request is found for the `prUrl` property (including shortened `#XX` ones), these properties will be added to point to the original user, project and issue (pull-request) for this change, as extracted from the URL.

## License

Expand Down
121 changes: 71 additions & 50 deletions commit-stream.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,116 @@
const through2 = require('through2')
, stripAnsi = require('strip-ansi')
import through2 from 'through2'
import stripAnsi from 'strip-ansi'


module.exports = commitStream


function commitStream (ghUser, ghProject) {
var commit
export default function commitStream (ghUser, ghProject) {
let commit

return through2.obj(onLine, onEnd)

function addLine (line) {
line = stripAnsi(line)

if (!line)
return
if (line.length === 0) return

var old, m
let old, m

if (/^commit \w+$/.test(line)) {
old = commit
commit = {
sha: line.split(' ')[1]
commit = { sha: line.split(' ')[1] }
} else if ((m = line.match(/^CommitDate:\s+(.*)$/)) !== null) {
if (commit === undefined || commit === null) {
throw new Error('Something unexpected occurred')
}
} else if (m = line.match(/^CommitDate:\s+(.*)$/)) {
if (!commit)
throw new Error('wut?')
commit.commitDate = m[1].trim()
} else if (m = line.match(/^\s*(?:Author|Co[- ]?authored[- ]?by):?\s*([^<]+) <([^>]+)>\s*$/i)) {
if (!commit)
throw new Error('wut?')
if (!commit.authors)
} else if (
(m = line.match(
/^\s*(?:Author|Co[- ]?authored[- ]?by):?\s*([^<]+) <([^>]+)>\s*$/i
)) !== null
) {
if (commit === undefined || commit === null) {
throw new Error('Something unexpected occurred')
}
if (commit.authors === undefined || commit.authors === null) {
commit.authors = []
}
commit.authors.push({ name: m[1], email: m[2] })
} else if (m = line.match(/^AuthorDate:\s+(.*)$/)) {
if (!commit)
throw new Error('wut?')
commit.authorDate = m[1].trim()
} else if (m = line.match(/^Date:\s+(.*)$/)) {
if (!commit)
throw new Error('wut?')
} else if ((m = line.match(/^(?:AuthorDate|Date):\s+(.*)$/)) !== null) {
if (commit === undefined || commit === null) {
throw new Error('Something unexpected occurred')
}
commit.authorDate = m[1].trim()
} else if (m = line.match(/^\s+Reviewed[- ]?By:?\s*([^<]+) <([^>]+)>\s*$/i)) {
if (!commit.reviewers)
} else if (
(m = line.match(/^\s+Reviewed[- ]?By:?\s*([^<]+) <([^>]+)>\s*$/i)) !==
null
) {
if (commit.reviewers === undefined || commit.reviewers === null) {
commit.reviewers = []
}
commit.reviewers.push({ name: m[1], email: m[2] })
} else if (m = line.match(/^\s+PR(?:[- ]?URL)?:?\s*(.+)\s*$/)) {
} else if ((m = line.match(/^\s+PR(?:[- ]?URL)?:?\s*(.+)\s*$/)) !== null) {
commit.prUrl = m[1]
if (ghUser && ghProject && (m = commit.prUrl.match(/^\s*#?(\d+)\s*$/))) {
commit.prUrl = 'https://github.com/' + ghUser + '/' + ghProject + '/pull/' + m[1]
if (
typeof ghUser === 'string' &&
ghUser.length !== 0 &&
typeof ghProject === 'string' &&
ghProject.length !== 0 &&
(m = commit.prUrl.match(/^\s*#?(\d+)\s*$/)) !== null
) {
commit.prUrl = `https://github.com/${ghUser}/${ghProject}/pull/${m[1]}`
}
if (m = commit.prUrl.match(/^(https?:\/\/.+\/([^\/]+)\/([^\/]+))\/\w+\/(\d+)(\/)?$/i)) {
commit.ghIssue = +m[4]
commit.ghUser = m[2]
if (
(m = commit.prUrl.match(
/^(https?:\/\/.+\/([^/]+)\/([^/]+))\/\w+\/(\d+)(\/)?$/i
)) !== null
) {
commit.ghIssue = parseInt(m[4])
commit.ghUser = m[2]
commit.ghProject = m[3]
}
} else if (/^ /.test(line) && (line = line.trim()).length) {
if (!commit.summary) {
} else if (/^ {4}/.test(line) && (line = line.trim()).length !== 0) {
if (commit.summary === undefined || commit.summary === null) {
commit.summary = line
} else {
if (!commit.description)
if (commit.description === undefined || commit.description === null) {
commit.description = []
}
commit.description.push(line)
}
} else if (/^ [^ ]/.test(line) && (line = line.trim()).length) {
if (m = line.match(/^(\d+) files? changed(?:, (\d+) insertions?\(\+\))?(?:, (\d+) deletions?\(-\))?/)) {
commit.changes = {
files : Number(m[1])
, insertions : Number(m[2] || 0)
, deletions : Number(m[3] || 0)
}
} else if (
/^ [^ ]/.test(line) &&
(line = line.trim()).length !== 0 &&
(m = line.match(
/^(\d+) files? changed(?:, (\d+) insertions?\(\+\))?(?:, (\d+) deletions?\(-\))?/
)) !== null
) {
commit.changes = {
files: parseInt(m[1]),
insertions: parseInt(m[2] ?? 0),
deletions: parseInt(m[3] ?? 0)
}
}

return old
}

function onLine (line, _, callback) {
var commit = addLine(line)
if (commit && commit.authors && commit.authors.length > 0)
const commit = addLine(line)

if (commit?.authors?.length > 0) {
commit.author = commit.authors[0]
if (commit)

this.push(commit)
}

callback()
}

function onEnd (callback) {
if (commit && commit.authors && commit.authors.length > 0)
if (commit?.authors?.length > 0) {
commit.author = commit.authors[0]
if (commit)

this.push(commit)
}

callback()
}
}
Loading