UNPKG

@cjbarth/github-release-notes

Version:

Create a release from a tag and uses issues or commits to creating the release notes. It also can generate a CHANGELOG.md file based on the release notes (or generate a brand new).

135 lines (130 loc) 5.7 kB
Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _child_process = require("child_process"); var _chalk = _interopRequireDefault(require("chalk")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); } function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /** Class retrieving GitHub informations from the folder where .git is initialised. */ var GitHubInfo = /*#__PURE__*/function () { function GitHubInfo() { _classCallCheck(this, GitHubInfo); } return _createClass(GitHubInfo, [{ key: "options", get: /** * Getter for the options * * @return {Promise.all} */ function get() { return Promise.all([this._repo(), this._token()]); } /** * Getter for the token * * @return {Promise} */ }, { key: "token", get: function get() { return this._token(); } /** * Getter for the repo * * @return {Promise} */ }, { key: "repo", get: function get() { return this._repo(); } /** * Execute a command in the bash and run a callback * * @since 0.5.0 * @private * * @param {string} command The command to execute * @param {Function} callback The callback which returns the stdout * * @return {Promise} */ }, { key: "_executeCommand", value: function _executeCommand(command, callback) { return new Promise(function (resolve, reject) { (0, _child_process.exec)(command, function (err, stdout, stderr) { if (err || stderr) { reject(err || stderr); } else { resolve(stdout.replace("\n", "")); } }); }).then(callback) // eslint-disable-line promise/no-callback-in-promise ["catch"](function (error) { throw new Error(_chalk["default"].red(error) + _chalk["default"].yellow("\nMake sure you're running the command from the repo folder, or you using the --username and --repo flags.")); }); } /** * Get repo informations * * @since 0.5.0 * @public * * @param {Function} callback * * @return {Promise} The promise that resolves repo informations ({user: user, name: name}) */ }, { key: "_repo", value: function _repo(callback) { return this._executeCommand("git config remote.origin.url", function (repo) { var regex = /([\w-.]+)\/([\w-.]+?)(\.git)?$/g; var matches = _toConsumableArray(repo.matchAll(regex)); if (!matches[0]) { return Promise.reject(new Error("No repo found")); } var user = matches[0][1]; var name = matches[0][2]; return { username: user, repo: name }; }).then(callback); // eslint-disable-line promise/no-callback-in-promise } /** * Get token informations * * @since 0.5.0 * @public * * @param {Function} callback * * @return {Promise} The promise that resolves token informations ({token: token}) */ }, { key: "_token", value: function _token() { var token = process.env.GREN_GITHUB_TOKEN; return token ? Promise.resolve({ token: token }) : Promise.resolve(null); } }]); }(); var _default = exports["default"] = GitHubInfo;