UNPKG

coveralls-api

Version:
105 lines (91 loc) 3.2 kB
"use strict"; exports.__esModule = true; exports.getGitData = getGitData; var _exec = require("@bconnorwhite/exec"); function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } function getBranch() { return _getBranch.apply(this, arguments); } function _getBranch() { _getBranch = _asyncToGenerator(function* () { return (0, _exec.exec)("git", ["rev-parse", { "abbrev-ref": "HEAD" }], { silent: true }).then(function (result) { return result.textOutput.trim(); }); }); return _getBranch.apply(this, arguments); } function getCommitInfo() { return _getCommitInfo.apply(this, arguments); } function _getCommitInfo() { _getCommitInfo = _asyncToGenerator(function* () { return (0, _exec.exec)("git", [{ "no-pager": "log" }, "-1", { "pretty=format:'%H,%an,%ae,%s,%cn,%ce'": true, "decorate=full": true }], { silent: true }).then(function (result) { var _result$textOutput$re = result.textOutput.replace(/^(')|(')$/g, "").split(","), id = _result$textOutput$re[0], author_name = _result$textOutput$re[1], author_email = _result$textOutput$re[2], message = _result$textOutput$re[3], committer_name = _result$textOutput$re[4], committer_email = _result$textOutput$re[5]; return { id: id, author_name: author_name, author_email: author_email, message: message, committer_name: committer_name, committer_email: committer_email }; }); }); return _getCommitInfo.apply(this, arguments); } function getRemotes() { return _getRemotes.apply(this, arguments); } function _getRemotes() { _getRemotes = _asyncToGenerator(function* () { return (0, _exec.exec)("git", ["remote", { v: true }], { silent: true }).then(function (result) { return result.textOutput.split("\n").filter(function (remote) { return remote.endsWith("(fetch)"); }).map(function (remote) { var _remote$split = remote.split(/\s+/), name = _remote$split[0], url = _remote$split[1]; return { name: name, url: url }; }); }); }); return _getRemotes.apply(this, arguments); } function getGitData() { return _getGitData.apply(this, arguments); } function _getGitData() { _getGitData = _asyncToGenerator(function* () { return { head: yield getCommitInfo(), branch: yield getBranch(), remotes: yield getRemotes() }; }); return _getGitData.apply(this, arguments); }