Files

Return to Package Diff Home.
Brought to you by Intrinsic.

Package Diff: @cypress/commit-message-install @ 2.4.2 .. 2.6.2

bin/commit-message-install.js

@@ -1,71 +0,0 @@
-#!/usr/bin/env node
-
-'use strict'
-
-const debug = require('debug')('commit-message-install')
-const execa = require('execa')
-
-const api = require('..')
-const getMessage = api.getMessage
-const getJsonBlock = api.getJsonBlock
-const npmInstall = api.npmInstall
-
-function onError (e) {
- console.error(e)
- process.exit(1)
-}
-
-function commitMessageInstall (cliArguments) {
- if (!cliArguments) {
- cliArguments = process.argv.slice(2)
- }
-
- const args = require('minimist')(cliArguments, {
- alias: {
- file: 'f',
- sha: 'commit'
- },
- string: ['file', 'else', 'sha']
- })
-
- let start
- if (args.file) {
- console.log('loading message from file', args.file)
- const fs = require('fs')
- const message = fs.readFileSync(args.file, 'utf8')
- start = Promise.resolve(message)
- } else {
- start = getMessage(args.sha)
- }
- return start
- .then(getJsonBlock)
- .then(json => {
- if (!json) {
- debug('nothing to do from the commit message')
- if (args.else) {
- debug('have --else command')
- debug(args.else)
- const options = {
- stdio: 'inherit'
- }
- return execa.shell(args.else, options)
- }
- return
- }
- // alias for API simplicity
- json.packages = json.packages || json.package
- if (json.package) {
- delete json.package
- }
- console.log('got json block from the git commit message')
- console.log(JSON.stringify(json, null, 2))
- return npmInstall(json)
- })
- .catch(onError)
-}
-
-if (!module.parent) {
- commitMessageInstall()
-}
-
-module.exports = commitMessageInstall

bin/commit-message-run.js

@@ -1,59 +0,0 @@
-#!/usr/bin/env node
-
-'use strict'
-
-// runs any command if commit message
-// a: does not contain JSON
-// b: JSON does not specify a platform that disallows it
-// for example if commit message has
-// {"platform": "win32"}
-// and CI command has
-// run-if echo "I am running on Windows"
-// then Windows CI will show the message, and other CIs
-// will skip it
-
-const debug = require('debug')('commit-message-install')
-
-const allArgs = process.argv.slice(2)
-const args = require('minimist')(allArgs, {
- alias: {
- file: 'f',
- sha: 'commit'
- },
- string: ['file', 'sha']
-})
-
-const api = require('..')
-const getMessage = api.getMessage
-const getJsonBlock = api.getJsonBlock
-const getCommand = api.getCommand
-const runIf = api.runIf
-
-const actualCommand = getCommand(allArgs)
-debug('command to run:', actualCommand)
-
-function onError (e) {
- console.error(e)
- process.exit(1)
-}
-
-let start
-if (args.file) {
- console.log('loading message from file', args.file)
- const fs = require('fs')
- const message = fs.readFileSync(args.file, 'utf8')
- start = Promise.resolve(message)
-} else {
- start = getMessage(args.sha)
-}
-start
- .then(getJsonBlock)
- .then(json => {
- if (!json) {
- return runIf(actualCommand, {})
- }
- console.log('got json block from the git commit message')
- console.log(JSON.stringify(json, null, 2))
- return runIf(actualCommand, json)
- })
- .catch(onError)

bin/set-commit-status.js

@@ -1,56 +0,0 @@
-#!/usr/bin/env node
-
-'use strict'
-
-const debug = require('debug')('commit-message-install')
-
-const allArgs = process.argv.slice(2)
-const args = require('minimist')(allArgs, {
- alias: {
- file: 'f',
- sha: 'commit',
- description: 'd'
- },
- string: ['file', 'sha', 'state', 'label', 'description']
-})
-
-const api = require('..')
-const getMessage = api.getMessage
-const getJsonBlock = api.getJsonBlock
-const setCommitStatus = api.setCommitStatus
-
-function onError (e) {
- console.error(e)
- process.exit(1)
-}
-
-let start
-if (args.file) {
- console.log('loading message from file', args.file)
- const fs = require('fs')
- const message = fs.readFileSync(args.file, 'utf8')
- start = Promise.resolve(message)
-} else {
- start = getMessage(args.sha)
-}
-start
- .then(getJsonBlock)
- .then(json => {
- if (!json) {
- debug('could not find JSON block in the Git message')
- return
- }
-
- const status = json.status
- if (!status) {
- debug('could not find status object in the block %o', json)
- return
- }
-
- if (!status.context) {
- throw new Error('missing "context" property on status object')
- }
-
- return setCommitStatus(args.state, args.description, status)
- })
- .catch(onError)

package.json

@@ -1,102 +1,53 @@
{
"name": "@cypress/commit-message-install",
+ "version": "2.6.2",
"description": "NPM install a package by name taken from the last commit message",
- "version": "2.4.2",
- "author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>",
- "bugs": "https://github.com/cypress-io/commit-message-install/issues",
- "bin": {
- "commit-message-install": "bin/commit-message-install.js",
- "cmi": "bin/commit-message-install.js",
- "run-if": "bin/commit-message-run.js",
- "set-status": "bin/set-commit-status.js"
- },
- "config": {
- "pre-git": {
- "commit-msg": "simple",
- "pre-commit": [
- "npm prune",
- "npm run deps",
- "npm test",
- "git add src/*.js bin/*.js",
- "npm run ban"
- ],
- "pre-push": [
- "npm run secure",
- "npm run license",
- "npm run ban -- --all",
- "npm run size"
- ],
- "post-commit": [],
- "post-merge": []
- }
- },
- "engines": {
- "node": ">=6"
- },
- "files": [
- "bin",
- "src/*.js",
- "!src/*-spec.js"
- ],
- "homepage": "https://github.com/cypress-io/commit-message-install#readme",
"keywords": [
"ci",
- "commit",
"git",
- "install",
"npm",
- "utility"
+ "install"
],
+ "author": "Gleb Bahmutov <gleb.bahmutov@gmail.com> (https://glebbahmutov.com)",
+ "homepage": "https://github.com/cypress-io/release-automations",
"license": "MIT",
- "main": "src/",
- "publishConfig": {
- "registry": "http://registry.npmjs.org/"
+ "main": "src/index.js",
+ "directories": {
+ "lib": "src"
+ },
+ "files": [
+ "src",
+ "!src/**/*spec.js*"
+ ],
+ "bin": {
+ "commit-message-install": "src/bin/commit-message-install.js",
+ "cmi": "src/bin/commit-message-install.js",
+ "run-if": "src/bin/commit-message-run.js",
+ "set-status": "src/bin/set-commit-status.js"
},
"repository": {
"type": "git",
- "url": "https://github.com/cypress-io/commit-message-install.git"
+ "url": "git+https://github.com/cypress-io/release-automations.git"
},
"scripts": {
- "ban": "ban",
- "deps": "deps-ok && dependency-check --no-dev .",
- "issues": "git-issues",
- "license": "license-checker --production --onlyunknown --csv",
- "lint": "standard --verbose --fix src/*.js bin/*.js",
- "prelint": "npm run pretty",
- "pretest": "npm run lint",
- "pretty": "echo ⚠️ disable prettier-standard 'src/*.js' 'bin/*.js'",
- "secure": "echo disabled nsp check",
- "size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";",
- "test": "npm run unit",
- "unit": "mocha src/*-spec.js",
- "semantic-release": "semantic-release",
- "demo": "node bin/commit-message-run.js -f test/run-if.txt echo Foo is \\$FOO",
- "demo-status": "node bin/set-commit-status.js -f test/status.txt --state success --description \"just demo\""
+ "test": "bin-up mocha src/*-spec.js",
+ "tsc": "bin-up tsc --build",
+ "prepare": "bin-up tsc --build"
+ },
+ "bugs": {
+ "url": "https://github.com/cypress-io/release-automations/issues"
},
"devDependencies": {
- "ban-sensitive-files": "1.9.0",
- "common-tags": "1.5.1",
- "dependency-check": "2.9.1",
- "deps-ok": "1.4.1",
- "git-issues": "1.3.1",
- "if-node-version": "1.1.1",
- "license-checker": "15.0.0",
- "mocha": "4.0.1",
- "nsp": "2.8.1",
- "prettier-standard": "7.0.3",
- "schema-shot": "1.9.0",
- "semantic-release": "15.13.3",
- "snap-shot-it": "6.3.2",
- "standard": "12.0.1",
- "stub-spawn-once": "2.3.0"
+ "bin-up": "1.1.0"
},
"dependencies": {
- "@cypress/set-commit-status": "1.1.1",
+ "@cypress/github-commit-status-check": "^1.4.1",
"chalk": "2.4.2",
"check-more-types": "2.24.0",
"debug": "4.1.1",
"execa": "0.8.0",
"lazy-ass": "1.6.0",
"minimist": "1.2.0"
- }
+ },
+ "gitHead": "8cb59efff119a3abfb3468392ad4e315d55f6cdb"
}

README.md

@@ -7,14 +7,13 @@
[![Build status][ci-image] ][ci-url]
[![semantic-release][semantic-image] ][semantic-url]
[![js-standard-style][standard-image]][standard-url]
-[![renovate-app badge][renovate-badge]][renovate-app]
## Install
Requires [Node](https://nodejs.org/en/) version 6 or above.
```sh
-npm install --save-dev commit-message-install
+npm install --save-dev @cypress/commit-message-install
```
## Use
@@ -35,7 +34,7 @@
If commit message is this
-```
+````
this will install package debug and chalk and while
installing them will set environment variable FOO to "bar".
The install will happen on all platforms
@@ -49,7 +48,7 @@
```
Happy installation
-```
+````
**note** `platform` can be `*` or specific one like `darwin` (from Node `os.platform()`) or a list of several platforms like `darwin,linux`. `architecture` is usually 64 bit `x64` as returned by `os.arch()`.
@@ -63,7 +62,7 @@
### Alternative command
-You can specify a command to run *if commit message has no JSON block*. For example you can
+You can specify a command to run _if commit message has no JSON block_. For example you can
install default dependency
```bash
@@ -118,11 +117,10 @@
Extracts JSON block from the current Git message text
```js
-const {getJsonFromGit} = require('@cypress/commit-message-install')
-getJsonFromGit()
- .then(json => {
+const { getJsonFromGit } = require('@cypress/commit-message-install')
+getJsonFromGit().then((json) => {
// {platform: 'win32', packages: 'foo', branch: 'test-branch'}
- })
+})
```
If there is no valid JSON object in the message, resolves with `undefined`.
@@ -133,24 +131,29 @@
the commit message using provided function
```js
-const {getInstallJson} = require('@cypress/commit-message-install')
+const { getInstallJson } = require('@cypress/commit-message-install')
// package(s), env, platform, branch name (optional)
-const json = getInstallJson('foo',
- {foo: 42}, 'linux', 'test-branch', 'b7ccfd8')
+const json = getInstallJson(
+ 'foo',
+ { foo: 42 },
+ 'linux',
+ 'test-branch',
+ 'b7ccfd8'
+)
// returns an object
- // {
- // platform: "linux",
- // env: {foo: 42},
- // packages: "foo",
- // branch: "test-branch",
- // commit: "b7ccfd8"
- // }
+// {
+// platform: "linux",
+// env: {foo: 42},
+// packages: "foo",
+// branch: "test-branch",
+// commit: "b7ccfd8"
+// }
```
You can pass individual package name like `debug` or several as a single string
`debug chalk` or a list `['debug', 'chalk']`
-You can pass for platform either individual `os.platform()` or a "*"" for all, and even
+You can pass for platform either individual `os.platform()` or a "\*"" for all, and even
several platforms like `win32,linux` or `linux|darwin`.
### npmInstall
@@ -158,9 +161,11 @@
After getting JSON from a commit message you can install dependencies
```js
-const {getInstallJson, npmInstall} = require('@cypress/commit-message-install')
-getInstallJson()
- .then(npmInstall)
+const {
+ getInstallJson,
+ npmInstall,
+} = require('@cypress/commit-message-install')
+getInstallJson().then(npmInstall)
```
## Debugging
@@ -172,9 +177,9 @@
Author: Gleb Bahmutov &lt;gleb.bahmutov@gmail.com&gt; &copy; 2017
-* [@bahmutov](https://twitter.com/bahmutov)
-* [glebbahmutov.com](https://glebbahmutov.com)
-* [blog](https://glebbahmutov.com/blog)
+- [@bahmutov](https://twitter.com/bahmutov)
+- [glebbahmutov.com](https://glebbahmutov.com)
+- [blog](https://glebbahmutov.com/blog)
License: MIT - do anything with the code, but don't blame me if it does not work.
@@ -214,5 +219,3 @@
[semantic-url]: https://github.com/semantic-release/semantic-release
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg
[standard-url]: http://standardjs.com/
-[renovate-badge]: https://img.shields.io/badge/renovate-app-blue.svg
-[renovate-app]: https://renovateapp.com/

src/bin/commit-message-install.js

@@ -0,0 +1,71 @@
+#!/usr/bin/env node
+
+'use strict'
+
+const debug = require('debug')('commit-message-install')
+const execa = require('execa')
+
+const api = require('..')
+const getMessage = api.getMessage
+const getJsonBlock = api.getJsonBlock
+const npmInstall = api.npmInstall
+
+function onError (e) {
+ console.error(e)
+ process.exit(1)
+}
+
+function commitMessageInstall (cliArguments) {
+ if (!cliArguments) {
+ cliArguments = process.argv.slice(2)
+ }
+
+ const args = require('minimist')(cliArguments, {
+ alias: {
+ file: 'f',
+ sha: 'commit'
+ },
+ string: ['file', 'else', 'sha']
+ })
+
+ let start
+ if (args.file) {
+ console.log('loading message from file', args.file)
+ const fs = require('fs')
+ const message = fs.readFileSync(args.file, 'utf8')
+ start = Promise.resolve(message)
+ } else {
+ start = getMessage(args.sha)
+ }
+ return start
+ .then(getJsonBlock)
+ .then(json => {
+ if (!json) {
+ debug('nothing to do from the commit message')
+ if (args.else) {
+ debug('have --else command')
+ debug(args.else)
+ const options = {
+ stdio: 'inherit'
+ }
+ return execa.shell(args.else, options)
+ }
+ return
+ }
+ // alias for API simplicity
+ json.packages = json.packages || json.package
+ if (json.package) {
+ delete json.package
+ }
+ console.log('got json block from the git commit message')
+ console.log(JSON.stringify(json, null, 2))
+ return npmInstall(json)
+ })
+ .catch(onError)
+}
+
+if (!module.parent) {
+ commitMessageInstall()
+}
+
+module.exports = commitMessageInstall

src/bin/commit-message-run.js

@@ -0,0 +1,59 @@
+#!/usr/bin/env node
+
+'use strict'
+
+// runs any command if commit message
+// a: does not contain JSON
+// b: JSON does not specify a platform that disallows it
+// for example if commit message has
+// {"platform": "win32"}
+// and CI command has
+// run-if echo "I am running on Windows"
+// then Windows CI will show the message, and other CIs
+// will skip it
+
+const debug = require('debug')('commit-message-install')
+
+const allArgs = process.argv.slice(2)
+const args = require('minimist')(allArgs, {
+ alias: {
+ file: 'f',
+ sha: 'commit'
+ },
+ string: ['file', 'sha']
+})
+
+const api = require('..')
+const getMessage = api.getMessage
+const getJsonBlock = api.getJsonBlock
+const getCommand = api.getCommand
+const runIf = api.runIf
+
+const actualCommand = getCommand(allArgs)
+debug('command to run:', actualCommand)
+
+function onError (e) {
+ console.error(e)
+ process.exit(1)
+}
+
+let start
+if (args.file) {
+ console.log('loading message from file', args.file)
+ const fs = require('fs')
+ const message = fs.readFileSync(args.file, 'utf8')
+ start = Promise.resolve(message)
+} else {
+ start = getMessage(args.sha)
+}
+start
+ .then(getJsonBlock)
+ .then(json => {
+ if (!json) {
+ return runIf(actualCommand, {})
+ }
+ console.log('got json block from the git commit message')
+ console.log(JSON.stringify(json, null, 2))
+ return runIf(actualCommand, json)
+ })
+ .catch(onError)

src/bin/set-commit-status.js

@@ -0,0 +1,56 @@
+#!/usr/bin/env node
+
+'use strict'
+
+const debug = require('debug')('commit-message-install')
+
+const allArgs = process.argv.slice(2)
+const args = require('minimist')(allArgs, {
+ alias: {
+ file: 'f',
+ sha: 'commit',
+ description: 'd'
+ },
+ string: ['file', 'sha', 'state', 'label', 'description', 'url']
+})
+
+const api = require('..')
+const getMessage = api.getMessage
+const getJsonBlock = api.getJsonBlock
+const setCommitStatus = api.setCommitStatus
+
+function onError (e) {
+ console.error(e)
+ process.exit(1)
+}
+
+let start
+if (args.file) {
+ console.log('loading message from file', args.file)
+ const fs = require('fs')
+ const message = fs.readFileSync(args.file, 'utf8')
+ start = Promise.resolve(message)
+} else {
+ start = getMessage(args.sha)
+}
+start
+ .then(getJsonBlock)
+ .then(json => {
+ if (!json) {
+ debug('could not find JSON block in the Git message')
+ return
+ }
+
+ const status = json.status
+ if (!status) {
+ debug('could not find status object in the block %o', json)
+ return
+ }
+
+ if (!status.context) {
+ throw new Error('missing "context" property on status object')
+ }
+
+ return setCommitStatus(args.state, args.description, status, args.url)
+ })
+ .catch(onError)

src/index.js

@@ -8,7 +8,7 @@
const chalk = require('chalk')
const getInstallJson = require('./get-install-json')
const isNpmInstall = require('./utils').isNpmInstall
-const scs = require('@cypress/set-commit-status').setCommitStatus
+const scs = require('@cypress/github-commit-status-check').setCommitStatus
const prop = name => object => object[name]
@@ -136,7 +136,7 @@
return command
}
-function setCommitStatus (state, description, status) {
+function setCommitStatus (state, description, status, targetUrl) {
la(is.maybe.unemptyString(description), 'invalid description', description)
const isValidState = is.oneOf(['error', 'pending', 'failure', 'success'])
@@ -146,15 +146,19 @@
console.log('setting status for commit %s', status.sha)
console.log('context: %s', context)
console.log('state: %s', state)
+ if (targetUrl) {
+ console.log('target url: %s', targetUrl)
+ la(is.webUrl(targetUrl), 'expected target url, got', targetUrl)
+ }
- // TODO: pass targetUrl
const options = {
owner: status.owner,
repo: status.repo,
sha: status.sha,
state,
context,
- description
+ description,
+ targetUrl
}
debug('setting commit status %o', options)