Skip to content
Open
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
35 changes: 35 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 15.x]

steps:
- uses: actions/checkout@v2
with:
# Need commit history test for cli-tests
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run build --if-present
- run: npm run test-ci
env:
CI: true
- run: bash <(curl -s https://codecov.io/bash)
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

21 changes: 10 additions & 11 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const usage = require('help')()

if (parsed.help) {
usage()
process.exit(0)
}

if (parsed.version) {
Expand All @@ -47,29 +46,29 @@ if (parsed.version) {
}

const args = parsed.argv.remain
if (!args.length) { args.push('HEAD') }
if (!parsed.help && !args.length) { args.push('HEAD') }

function load (sha, cb) {
const parsed = new URL(sha)
if (parsed.protocol) {
try {
const parsed = new URL(sha)
return loadPatch(parsed, cb)
} catch (_) {
exec(`git show --quiet --format=medium ${sha}`, (err, stdout, stderr) => {
if (err) return cb(err)
cb(null, stdout.trim())
})
}

exec(`git show --quiet --format=medium ${sha}`, (err, stdout, stderr) => {
if (err) return cb(err)
cb(null, stdout.trim())
})
}

function loadPatch (uri, cb) {
let h = http
if (~uri.protocol.indexOf('https')) {
h = https
}
uri.headers = {
const headers = {
'user-agent': 'core-validate-commit'
}
h.get(uri, (res) => {
h.get(uri, { headers }, (res) => {
let buf = ''
res.on('data', (chunk) => {
buf += chunk
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/subsystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const validSubsystems = [
'meta',
'msi',
'node',
'n-api',
'node-api',
'perfctr',
'policy',
'src',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "core-validate-commit",
"version": "3.13.1",
"version": "3.13.3",
"description": "Validate the commit message for a particular commit in node core",
"main": "index.js",
"scripts": {
Expand Down
61 changes: 60 additions & 1 deletion test/cli-test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use strict'

const { test } = require('tap')
const { readFileSync } = require('fs')
const { spawn } = require('child_process')
const subsystems = require('../lib/rules/subsystem')

test('Test cli flags', (t) => {
t.test('test list-subsystems', (tt) => {
const ls = spawn('./bin/cmd.js', ['--list-subsystems'], {
env: { FORCE_COLOR: 0 }
env: { ...process.env, FORCE_COLOR: 0 }
})
let compiledData = ''
ls.stdout.on('data', (data) => {
Expand Down Expand Up @@ -42,6 +43,64 @@ test('Test cli flags', (t) => {
})
})

t.test('test help output', (tt) => {
const usage = readFileSync('bin/usage.txt', { encoding: 'utf8' })
const ls = spawn('./bin/cmd.js', ['--help'])
let compiledData = ''
ls.stdout.on('data', (data) => {
compiledData += data
})

ls.stderr.on('data', (data) => {
tt.fail('This should not happen')
})

ls.on('close', (code) => {
tt.equal(compiledData.trim(),
usage.trim(),
'--help output is as expected')
tt.end()
})
})

t.test('test sha', (tt) => {
const ls = spawn('./bin/cmd.js', ['--no-validate-metadata', '2b98d02b52'])
let compiledData = ''
ls.stdout.on('data', (data) => {
compiledData += data
})

ls.stderr.on('data', (data) => {
tt.fail('This should not happen')
})

ls.on('close', (code) => {
tt.match(compiledData.trim(),
/2b98d02b52/,
'output is as expected')
tt.end()
})
})

t.test('test url', (tt) => {
const ls = spawn('./bin/cmd.js', ['--no-validate-metadata', 'https://api.github.com/repos/nodejs/core-validate-commit/commits/2b98d02b52'])
let compiledData = ''
ls.stdout.on('data', (data) => {
compiledData += data
})

ls.stderr.on('data', (data) => {
tt.fail('This should not happen')
})

ls.on('close', (code) => {
tt.match(compiledData.trim(),
/2b98d02b52/,
'output is as expected')
tt.end()
})
})

t.test('test version flag', (tt) => {
const ls = spawn('./bin/cmd.js', ['--version'])
let compiledData = ''
Expand Down