├── .gitignore ├── .gitattributes ├── .travis.yml ├── .editorconfig ├── readme.md ├── package.json ├── license └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - iojs 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # angular-precommit [![Build Status](https://travis-ci.org/ajoslin/angular-precommit.svg?branch=master)](https://travis-ci.org/ajoslin/angular-precommit) 2 | 3 | > Pre commit with angular conventions 4 | 5 | ## Install 6 | 7 | ``` 8 | $ npm install angular-precommit --save-dev 9 | $ ln -s node_modules/angular-precommit/index.js .git/hooks/commit-msg 10 | ``` 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-precommit", 3 | "main": "index.js", 4 | "version": "1.0.0", 5 | "description": "Pre commit with angular conventions", 6 | "license": "MIT", 7 | "repository": "ajoslin/angular-precommit", 8 | "bin": "./index.js", 9 | "author": { 10 | "name": "Andrew Joslin", 11 | "email": "andrewtjoslin@gmail.com", 12 | "url": "ajoslin.com" 13 | }, 14 | "scripts": { 15 | "test": "standard && tape test.js" 16 | }, 17 | "keywords": [ 18 | "precommit" 19 | ], 20 | "devDependencies": { 21 | "tape": "^4.0.0", 22 | "standard": "^4.0.0" 23 | }, 24 | "files": [ 25 | "index.js" 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Andrew Joslin (ajoslin.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 4 | var fs = require('fs') 5 | var util = require('util') 6 | 7 | var MAX_LENGTH = 100 8 | var PATTERN = /^(?:fixup!\s*)?(\w*)(\(([\w\$\.\*/-]*)\))?\: (.*)$/ 9 | var IGNORED = /^WIP\:/ 10 | var TYPES = { 11 | amend: true, 12 | feat: true, 13 | fix: true, 14 | docs: true, 15 | style: true, 16 | refactor: true, 17 | perf: true, 18 | test: true, 19 | chore: true, 20 | revert: true 21 | } 22 | 23 | 24 | function displayError () { 25 | // gitx does not display it 26 | // http://gitx.lighthouseapp.com/projects/17830/tickets/294-feature-display-hook-error-message-when-hook-fails 27 | // https://groups.google.com/group/gitx/browse_thread/thread/a03bcab60844b812 28 | console.error('INVALID COMMIT MSG: ' + util.format.apply(null, arguments)) 29 | } 30 | 31 | 32 | var validateMessage = function(message) { 33 | var isValid = true 34 | 35 | if (IGNORED.test(message)) { 36 | console.log('Commit message validation ignored.') 37 | return true 38 | } 39 | 40 | if (message.length > MAX_LENGTH) { 41 | displayError('is longer than %d characters !', MAX_LENGTH) 42 | isValid = false 43 | } 44 | 45 | var match = PATTERN.exec(message) 46 | 47 | if (!match) { 48 | displayError('does not match "(): " ! was: ' + message) 49 | return false 50 | } 51 | 52 | var type = match[1] 53 | var scope = match[3] 54 | var subject = match[4] 55 | 56 | if (!TYPES.hasOwnProperty(type)) { 57 | displayError('"%s" is not allowed type !', type) 58 | return false 59 | } 60 | 61 | // Some more ideas, do want anything like this ? 62 | // - allow only specific scopes (eg. fix(docs) should not be allowed ? 63 | // - auto correct the type to lower case ? 64 | // - auto correct first letter of the subject to lower case ? 65 | // - auto add empty line after subject ? 66 | // - auto remove empty () ? 67 | // - auto correct typos in type ? 68 | // - store incorrect messages, so that we can learn 69 | 70 | return isValid 71 | } 72 | 73 | function firstLineFromBuffer (buffer) { 74 | return buffer.toString().split('\n').shift() 75 | } 76 | --------------------------------------------------------------------------------