Skip to content

Commit e1feea2

Browse files
committed
chore(): copyright year changes and added git hooks
1 parent 0940be7 commit e1feea2

File tree

6 files changed

+130
-5
lines changed

6 files changed

+130
-5
lines changed

LICENSE.txt renamed to LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2013 Varun Malhotra
1+
Copyright (c) 2013-2021 Varun Malhotra
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
json2html
22
=========
33

4-
Python wrapper to convert ``JSON`` into a human readable ``HTML Table`` representation.
4+
Python module to convert ``JSON`` into a human readable ``HTML Table`` representation.
55

66
|Latest Version| |Downloads| |Build|
77

@@ -232,7 +232,7 @@ Copyright and License
232232

233233
The `MIT license <https://opensource.org/licenses/MIT>`_
234234

235-
Copyright (c) 2014-2017 Varun Malhotra
235+
Copyright (c) 2013-2021 Varun Malhotra
236236

237237
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
238238

git-hooks/commit-msg

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Name: validate-commit-message.
5+
* Description: Validate commit message before git commit
6+
* Authors: Angular Team (Note: this script was originally written by Vojta for AngularJS)
7+
* URL: https://github.com/angular/angular/blob/master/tools/validate-commit-message/validate-commit-message.js
8+
* LICENSE: MIT License
9+
*
10+
* Copyright Google Inc. All Rights Reserved.
11+
*
12+
* Use of this source code is governed by an MIT-style license that can be
13+
* found in the LICENSE file at https://angular.io/license
14+
*/
15+
16+
'use strict';
17+
18+
let fs = require('fs');
19+
let util = require('util');
20+
21+
22+
let MAX_LENGTH = 100;
23+
let IGNORED_TEXT = '[maven-release-plugin]';
24+
let PATTERN = /^(?:fixup!\s*)?(\w*)(\(([\w\$\.\:\*/-]*)\))?\: (.*)$/;
25+
let IGNORED = /^WIP\:/;
26+
let TYPES = {
27+
feat: true,
28+
fix: true,
29+
docs: true,
30+
style: true,
31+
refactor: true,
32+
perf: true,
33+
test: true,
34+
chore: true,
35+
cleanup: true,
36+
revert: true,
37+
tracking: true
38+
};
39+
40+
41+
let error = function() {
42+
// gitx does not display it
43+
// http://gitx.lighthouseapp.com/projects/17830/tickets/294-feature-display-hook-error-message-when-hook-fails
44+
// https://groups.google.com/group/gitx/browse_thread/thread/a03bcab60844b812
45+
console.error('INVALID COMMIT MSG: ' + util.format.apply(null, arguments));
46+
};
47+
48+
49+
let validateMessage = function(message) {
50+
let isValid = true;
51+
52+
if (IGNORED.test(message) || message.includes(IGNORED_TEXT)) {
53+
console.log('Commit message validation ignored.');
54+
return true;
55+
}
56+
57+
let match = PATTERN.exec(message),
58+
isATagCommit = /^\d+.\d+.\d+$/.exec(message),
59+
isMergeCommit = /^Merge remote-tracking branch.*/.exec(message);
60+
61+
if (!isMergeCommit && message.length > MAX_LENGTH) {
62+
error('is longer than %d characters by %d character!', MAX_LENGTH, message.length - MAX_LENGTH);
63+
isValid = false;
64+
}
65+
66+
let isCommitMessageBypassed = isATagCommit || isMergeCommit;
67+
// Allow version commit without scope restriction and allow merge commits too
68+
match = match || isCommitMessageBypassed;
69+
if (!match) {
70+
error('does not match "<type>(<scope>): <subject>" ! was: ' + message);
71+
return false;
72+
}
73+
74+
let type = match[1];
75+
let scope = match[3];
76+
let subject = match[4];
77+
78+
if (!isCommitMessageBypassed && !TYPES.hasOwnProperty(type)) {
79+
error('"%s" is not allowed type !', type);
80+
return false;
81+
}
82+
83+
// Some more ideas, do want anything like this ?
84+
// - allow only specific scopes (eg. fix(docs) should not be allowed ?
85+
// - auto correct the type to lower case ?
86+
// - auto correct first letter of the subject to lower case ?
87+
// - auto add empty line after subject ?
88+
// - auto remove empty () ?
89+
// - auto correct typos in type ?
90+
// - store incorrect messages, so that we can learn
91+
92+
return isValid;
93+
};
94+
95+
96+
let firstLineFromBuffer = function(buffer) {
97+
return buffer.toString().split('\n').shift();
98+
};
99+
100+
101+
102+
// publish for testing
103+
exports.validateMessage = validateMessage;
104+
105+
// hacky start if not run by jasmine :-D
106+
if (process.argv.join('').indexOf('jasmine-node') === -1) {
107+
let commitMsgFile = process.argv[2];
108+
let incorrectLogFile = commitMsgFile.replace('COMMIT_EDITMSG', 'logs/incorrect-commit-msgs');
109+
110+
fs.readFile(commitMsgFile, function(err, buffer) {
111+
let msg = firstLineFromBuffer(buffer);
112+
113+
if (!validateMessage(msg)) {
114+
fs.appendFile(incorrectLogFile, msg + '\n', function() {
115+
process.exit(1);
116+
});
117+
} else {
118+
process.exit(0);
119+
}
120+
});
121+
}

git-hooks/pre-push

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
cd test/;
4+
python run_tests.py;

json2html/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'''
22
python wrapper for JSON to HTML-Table convertor
3-
(c) 2013-17 Varun Malhotra. MIT License
3+
(c) 2013-2021 Varun Malhotra. MIT License
44
'''
55

66
from .jsonconv import *

json2html/jsonconv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
JSON 2 HTML Converter
55
=====================
66
7-
(c) Varun Malhotra 2013
7+
(c) Varun Malhotra 2013-2021
88
Source Code: https://github.com/softvar/json2html
99
1010

0 commit comments

Comments
 (0)