Skip to content

Commit 5d8f5ca

Browse files
committed
squash: moving validate-metadata
* move validate-metadata logic to utils for easier testing
1 parent b4949d0 commit 5d8f5ca

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

bin/cmd.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
const fs = require('fs')
66
const nopt = require('nopt')
77
const path = require('path')
8-
const pretty = require('../lib/format-pretty')
98
const formatTap = require('../lib/format-tap')
109
const Validator = require('../lib')
1110
const Tap = require('../lib/tap')
@@ -110,22 +109,6 @@ if (parsed.tap) {
110109

111110
} else {
112111
// no --flags used, defaults to --validate-metadata
113-
v.on('commit', (c) => {
114-
pretty(c.commit, c.messages, v)
115-
run()
116-
})
117-
118-
function run() {
119-
if (!args.length) {
120-
process.exitCode = v.errors
121-
return
122-
}
123-
const sha = args.shift()
124-
utils.load(sha, (err, data) => {
125-
if (err) throw err
126-
v.lint(data)
127-
})
128-
}
129-
130-
run()
112+
utils.validateMetadata(v, args)
113+
return
131114
}

lib/utils.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const exec = require('child_process').exec
44
const http = require('http')
55
const https = require('https')
66
const url = require('url')
7+
const pretty = require('../lib/format-pretty')
78
const chalk = require('chalk')
89
const CHECK = chalk.green('✔')
910
const X = chalk.red('✖')
@@ -102,3 +103,24 @@ exports.loadPatch = function loadPatch(uri, cb) {
102103
})
103104
}).on('error', cb)
104105
}
106+
107+
exports.validateMetadata = function(validator, args) {
108+
validator.on('commit', (c) => {
109+
pretty(c.commit, c.messages, validator)
110+
run()
111+
})
112+
113+
function run() {
114+
if (!args.length) {
115+
process.exitCode = validator.errors
116+
return
117+
}
118+
const sha = args.shift()
119+
exports.load(sha, (err, data) => {
120+
if (err) throw err
121+
validator.lint(data)
122+
})
123+
}
124+
125+
run()
126+
}

0 commit comments

Comments
 (0)