node-hooks
Advanced tools
| var request = require('request'); | ||
| var colors = require("colors"); | ||
| var main = function(args){ | ||
| var listFile = "https://raw.github.com/mcwhittemore/node-hooks/master/list.json"; | ||
| request(listFile, function (error, response, body) { | ||
| if (!error && response.statusCode == 200) { | ||
| try{ | ||
| var data = JSON.parse(body); | ||
| showAll(data); | ||
| } | ||
| catch(err){ | ||
| console.error("There seems to be an error with the list file. Please report this bug: ", "https://github.com/mcwhittemore/node-hooks/issues?state=open", err); | ||
| } | ||
| } | ||
| else{ | ||
| console.error("There seems to be an error with getting the file from github. Are they down?", listFile); | ||
| } | ||
| }); | ||
| } | ||
| var showAll = function(data){ | ||
| process.stdout.write('\u001B[2J\u001B[0;0f'); | ||
| var hook_modules = Object.keys(data); | ||
| var i = hook_modules.length; | ||
| while(i--){ | ||
| showOne(hook_modules[i], data[hook_modules[i]]); | ||
| } | ||
| console.log(">".blue, "If you do not see a hook here that you want please feel free to build your own:".green); | ||
| console.log(">".blue, "\t", "https://github.com/mcwhittemore/node-hooks/blob/master/docs/readme.md".yellow); | ||
| } | ||
| var showOne = function(name, data){ | ||
| console.log(">".blue ,name.green); | ||
| console.log(">".blue ,data.desc.yellow); | ||
| console.log(">".blue ,"Works with:".yellow); | ||
| for(var i=0; i<data["valid-for"].length; i++){ | ||
| console.log(">".blue ,"\t", data["valid-for"][i].blue); | ||
| } | ||
| var add = data.sources.npm || data.sources.github; | ||
| console.log(">".blue ,"To Add:".yellow, ("hooks add "+add).green); | ||
| console.log(""); | ||
| } | ||
| module.exports = main; |
| # Building Hook Modules | ||
| Hook modules are passed at least one argument. Since Node.js modules are automatically passed two arguments, if you are writing your hook module in node this argument is at position two. | ||
| Some git-hooks also pass around their own arguments. If the hook that is being run is one of these the arguments will be passed after the hook argument. If you are unsure what the arguments your hook are being passed mean, [check out this overview](https://www.kernel.org/pub/software/scm/git/docs/githooks.html). | ||
| One of the powers of git hooks is being able to stop the git process if something seems wrong. To do that with hooks, send an exit code of 1. | ||
| **Listing your Hook Module in Hooks** | ||
| Please issue a pull request this [list.json](https://github.com/mcwhittemore/node-hooks/blob/master/list.json) file. | ||
| ## Example: Node.js | ||
| **index.js** | ||
| ``` | ||
| //define what hooks your module is valid for. | ||
| var validHooks = ["post-checkout", "pre-commit"]; | ||
| //get the hook that is being run | ||
| var hook = process.argv[2]; | ||
| //get the args git is passing to the hook | ||
| var args = process.argv.splice(3); | ||
| //don't your your code if you don't want it to work with other hooks. | ||
| if(validHooks.indexOf(hook)==-1){ | ||
| console.log("This hook module is not valid for "+hook+" so its not running"); | ||
| } | ||
| else if(hook=="post-checkout"){ | ||
| console.log("Did you forget your receipt?"); | ||
| console.log("Try these:", args); | ||
| } | ||
| else{ | ||
| console.log("Thanks for running "+hook+". Currently this is not implemented."); | ||
| process.exit(1); | ||
| } | ||
| ``` | ||
| **package.json** | ||
| ``` | ||
| { | ||
| "name": "example-hook-module.hook", | ||
| "version": "0.0.0", | ||
| "description": "a hook that won't let you commit, and prints hook data for a checkout", | ||
| "hook-module": { | ||
| "script-type": "node", | ||
| "valid-for": [ | ||
| "pre-commit", | ||
| "post-checkout" | ||
| ] | ||
| } | ||
| } | ||
| ``` |
+14
| { | ||
| "pull-checkout-merge-command.hook": { | ||
| "desc": "Run scripts after `pull`, `merge` and `checkout` succeed. Great for compiled source management between branches and automating migrations", | ||
| "valid-for": [ | ||
| "post-merge", | ||
| "post-checkout" | ||
| ], | ||
| "sources": { | ||
| "npm": "pull-checkout-merge-command.hook", | ||
| "github": "https://github.com/mcwhittemore/pull-checkout-merge-command.hook/tarball/master" | ||
| }, | ||
| "author": "Matthew Chase Whittemore <mcwhittemore@gmail.com>" | ||
| } | ||
| } |
+2
-1
@@ -10,3 +10,4 @@ #!/usr/bin/env node | ||
| "add", | ||
| "remove" | ||
| "remove", | ||
| "list" | ||
| ] | ||
@@ -13,0 +14,0 @@ |
+3
-2
| { | ||
| "name": "node-hooks", | ||
| "version": "0.0.8", | ||
| "version": "0.0.9", | ||
| "preferGlobal": true, | ||
@@ -11,3 +11,4 @@ "description": "An NPM for git hooks.", | ||
| "dependencies": { | ||
| "colors": "~0.6.1" | ||
| "colors": "~0.6.1", | ||
| "request": "~2.27.0" | ||
| }, | ||
@@ -14,0 +15,0 @@ "devDependencies": { |
+22
-21
@@ -29,8 +29,10 @@ # Hooks | ||
| * pull-checkout-merge-command.hook: Run scripts after certain git commands are used. Great for compiled source mangeagement between branches and automating magrations. | ||
| `hooks list` | ||
| ## How to write a git hooks for `Hooks` | ||
| The [hook-module sepcs](https://github.com/mcwhittemore/node-hooks/blob/master/docs/hook-module-specification.md) should cover some of the basics while the [hook-module best practices](https://github.com/mcwhittemore/node-hooks/blob/master/docs/hook-module-best-practices.md) doc will help you avoid trip ups. | ||
| Check out this README for a quick intro. For more depth checkout the [hook-module sepcs](https://github.com/mcwhittemore/node-hooks/blob/master/docs/hook-module-specification.md) which covers the hook module requirements. | ||
| There is also a [hook-module best practices](https://github.com/mcwhittemore/node-hooks/blob/master/docs/hook-module-best-practices.md) doc which should help you avoid trip ups. | ||
| ## Is there a way to search npm for hook-modules only? | ||
@@ -77,2 +79,10 @@ | ||
| ### hooks list | ||
| Lists the hook modules registered with node-hooks. | ||
| ### hooks search key words | ||
| does an npm search for modules tagged git-hooks | ||
| ### hooks run {git-hook} | ||
@@ -90,10 +100,9 @@ | ||
| ### globals | ||
| * hooks add --global: Add a hook module to the global scope. | ||
| * hooks remove --global: Remove a hook module from the global scope. | ||
| * hooks run --global: Run a hook module that is in the global scope. | ||
| * hooks list --global: Lists the hook modules in your global scope. | ||
| * hooks list --local: Lists the hook modules as they are setup in the current project. | ||
| * hooks list --hook {git-hook}: limits results to hook modules for the specified git hook. | ||
| * hooks install --global | ||
| * hooks uninstall --global | ||
| * hooks add --global | ||
| * hooks remove --global | ||
| * hooks run --global | ||
| ### hooks skip {hook-module} [options] | ||
@@ -108,14 +117,2 @@ | ||
| ### hooks list [options] | ||
| Lists the module hooks as they are currently set up in the active project | ||
| #### Options | ||
| * --global: Lists the module hooks as they are currently setup in the defaults folder. | ||
| ### hooks search key words | ||
| does an npm search for modules tagged git-hooks | ||
| ## Change Log | ||
@@ -138,1 +135,5 @@ | ||
| * Update to run, not exiting if hooks.json can't be found. | ||
| ### 0.0.8 | ||
| * Bug fix concerning adding npm data to the hooks.json file |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
53666
8.25%36
9.09%1447
3.88%135
0.75%2
100%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added