jira-precommit-hook
Version:
Git commit hook to verify commit messages are tagged with a JIRA issue number
97 lines (79 loc) • 2.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getAuthentication = exports.getAPIConfig = undefined;
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
var getAPIConfig = exports.getAPIConfig = function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(filePath) {
var config;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return (0, _fsUtils.readJSON)(filePath);
case 2:
config = _context.sent;
return _context.abrupt('return', validateAPIConfig(config));
case 4:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
return function getAPIConfig(_x) {
return _ref.apply(this, arguments);
};
}();
var getAuthentication = exports.getAuthentication = function () {
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(filePath) {
var config;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return (0, _fsUtils.readJSON)(filePath);
case 2:
config = _context2.sent;
return _context2.abrupt('return', validateAuthentication(config));
case 4:
case 'end':
return _context2.stop();
}
}
}, _callee2, this);
}));
return function getAuthentication(_x2) {
return _ref2.apply(this, arguments);
};
}();
exports.validateAPIConfig = validateAPIConfig;
exports.validateAuthentication = validateAuthentication;
var _fsUtils = require('./fs-utils.js');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function validateAPIConfig(config) {
// validate that this is a proper .jirarc file
if (!config.host) {
throw new Error('.jirarc missing host url. Please check the README for details');
}
if (!config.projectName) {
throw new Error('.jirarc missing project name. Please check the README for details');
}
return config;
}
function validateAuthentication(authConfig) {
// validate that there are proper credentials
if (!authConfig.username) {
throw new Error('.userconfig missing username');
}
if (!authConfig.password) {
throw new Error('.userconfig missing password');
}
return authConfig;
}