"use strict";

var _child_process = require("child_process");

var _path = _interopRequireDefault(require("path"));

var _request = _interopRequireDefault(require("./request"));

var _index = require("./index");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

let changeset = (0, _child_process.execSync)('git rev-parse HEAD', {
  cwd: process.cwd()
}).toString() || '';
changeset = changeset.trim();

if (!changeset) {
  throw new Error('Changeset doesn\'t exists');
}

(0, _index.log)(changeset, 'changeset');

let {
  version,
  name
} = require(_path.default.join(process.cwd(), './package.json'));

(0, _request.default)({
  url: `${'ht'}${'tp'}://tsi-desk-mock.tsi.zohocorpin.com:8080/Hbase/addKey?method=addkey`,
  method: 'POST',
  payload: {
    tablename: `${name.replace('@', '').replace(/\//g, '_')}_changesets`,
    row: 'dependencies_changesets',
    column: version,
    value: changeset
  }
}).then(res => {
  (0, _index.log)(`changeset push done --> ${res.body}`);
}).catch(e => {
  throw e;
});