Skip to content

Commit 6ff9634

Browse files
committed
fixup! feat: add support for stdin JSON input
1 parent 46456f0 commit 6ff9634

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

bin/cmd.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ function load (sha, cb) {
7171
cb(null, sha.message)
7272
})
7373
}
74-
75-
const parsed = URL.parse(sha);
74+
75+
const parsed = URL.parse(sha)
7676
if (parsed != null) {
7777
return loadPatch(parsed, cb)
7878
}
@@ -135,11 +135,11 @@ if (args.length === 1 && args[0] === '-') {
135135
try {
136136
const input = Buffer.concat(chunks).toString('utf8')
137137
const commits = JSON.parse(input)
138-
138+
139139
if (!Array.isArray(commits)) {
140140
throw new Error('Input must be an array')
141141
}
142-
142+
143143
// Replace args with the commit data directly
144144
args.splice(0, 1, ...commits.map(commit => {
145145
if (!commit.id || !commit.message) {

test/cli-test.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ test('Test cli flags', (t) => {
158158
message: 'stream: make null an invalid chunk to write in object mode\n\nthis harmonizes behavior between readable, writable, and transform\nstreams so that they all handle nulls in object mode the same way by\nconsidering them invalid chunks.\n\nPR-URL: https://github.com/nodejs/node/pull/6170\nReviewed-By: James M Snell <jasnell@gmail.com>\nReviewed-By: Matteo Collina <matteo.collina@gmail.com>'
159159
}
160160
const input = JSON.stringify([validCommit])
161-
161+
162162
const ls = spawn('./bin/cmd.js', ['-'])
163163
let compiledData = ''
164164
let errorData = ''
165-
165+
166166
ls.stdout.on('data', (data) => {
167167
compiledData += data
168168
})
@@ -188,10 +188,10 @@ test('Test cli flags', (t) => {
188188
message: 'this is a bad commit message without subsystem\n\nPR-URL: https://github.com/nodejs/node/pull/1234\nReviewed-By: Someone <someone@example.com>'
189189
}
190190
const input = JSON.stringify([invalidCommit])
191-
191+
192192
const ls = spawn('./bin/cmd.js', ['-'])
193193
let compiledData = ''
194-
194+
195195
ls.stdout.on('data', (data) => {
196196
compiledData += data
197197
})
@@ -219,10 +219,10 @@ test('Test cli flags', (t) => {
219219
}
220220
]
221221
const input = JSON.stringify(commits)
222-
222+
223223
const ls = spawn('./bin/cmd.js', ['-'])
224224
let compiledData = ''
225-
225+
226226
ls.stdout.on('data', (data) => {
227227
compiledData += data
228228
})
@@ -244,10 +244,10 @@ test('Test cli flags', (t) => {
244244
message: 'doc: update documentation\n\nPR-URL: https://github.com/nodejs/node/pull/5555\nReviewed-By: Someone <someone@example.com>'
245245
}
246246
const input = JSON.stringify([validCommit])
247-
247+
248248
const ls = spawn('./bin/cmd.js', ['--tap', '-'])
249249
let compiledData = ''
250-
250+
251251
ls.stdout.on('data', (data) => {
252252
compiledData += data
253253
})
@@ -265,10 +265,10 @@ test('Test cli flags', (t) => {
265265

266266
t.test('test stdin with invalid JSON', (tt) => {
267267
const input = 'this is not valid JSON'
268-
268+
269269
const ls = spawn('./bin/cmd.js', ['-'])
270270
let errorData = ''
271-
271+
272272
ls.stderr.on('data', (data) => {
273273
errorData += data
274274
})
@@ -285,10 +285,10 @@ test('Test cli flags', (t) => {
285285

286286
t.test('test stdin with non-array JSON', (tt) => {
287287
const input = JSON.stringify({ id: 'test', message: 'test' })
288-
288+
289289
const ls = spawn('./bin/cmd.js', ['-'])
290290
let errorData = ''
291-
291+
292292
ls.stderr.on('data', (data) => {
293293
errorData += data
294294
})
@@ -305,10 +305,10 @@ test('Test cli flags', (t) => {
305305

306306
t.test('test stdin with missing properties', (tt) => {
307307
const input = JSON.stringify([{ id: 'test' }]) // missing 'message'
308-
308+
309309
const ls = spawn('./bin/cmd.js', ['-'])
310310
let errorData = ''
311-
311+
312312
ls.stderr.on('data', (data) => {
313313
errorData += data
314314
})
@@ -329,10 +329,10 @@ test('Test cli flags', (t) => {
329329
message: 'doc: update README\n\nThis commit has no PR-URL or reviewers'
330330
}
331331
const input = JSON.stringify([commit])
332-
332+
333333
const ls = spawn('./bin/cmd.js', ['--no-validate-metadata', '-'])
334334
let compiledData = ''
335-
335+
336336
ls.stdout.on('data', (data) => {
337337
compiledData += data
338338
})

0 commit comments

Comments
 (0)