UNPKG

@tricoteuses/assemblee

Version:

Retrieve, clean up & handle French Assemblée nationale's open data

595 lines (594 loc) 94.8 kB
"use strict"; require("core-js/modules/es.symbol.js"); require("core-js/modules/es.symbol.description.js"); require("core-js/modules/es.symbol.async-iterator.js"); require("core-js/modules/es.symbol.iterator.js"); require("core-js/modules/es.symbol.to-primitive.js"); require("core-js/modules/es.symbol.to-string-tag.js"); require("core-js/modules/es.array.for-each.js"); require("core-js/modules/es.array.from.js"); require("core-js/modules/es.array.is-array.js"); require("core-js/modules/es.array.iterator.js"); require("core-js/modules/es.array.reverse.js"); require("core-js/modules/es.array.slice.js"); require("core-js/modules/es.date.to-primitive.js"); require("core-js/modules/es.date.to-string.js"); require("core-js/modules/es.function.name.js"); require("core-js/modules/es.json.to-string-tag.js"); require("core-js/modules/es.math.to-string-tag.js"); require("core-js/modules/es.object.create.js"); require("core-js/modules/es.object.define-property.js"); require("core-js/modules/es.object.get-own-property-descriptor.js"); require("core-js/modules/es.object.get-prototype-of.js"); require("core-js/modules/es.object.set-prototype-of.js"); require("core-js/modules/es.object.to-string.js"); require("core-js/modules/es.promise.js"); require("core-js/modules/es.regexp.to-string.js"); require("core-js/modules/es.string.iterator.js"); require("core-js/modules/es.weak-map.js"); require("core-js/modules/web.dom-collections.for-each.js"); require("core-js/modules/web.dom-collections.iterator.js"); 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); } Object.defineProperty(exports, "__esModule", { value: true }); exports.BugsHelper = void 0; exports.checkoutFix = checkoutFix; exports.main = main; exports.mergeFix = mergeFix; require("core-js/modules/es.array.concat.js"); require("core-js/modules/es.array.includes.js"); require("core-js/modules/es.array.join.js"); require("core-js/modules/es.number.constructor.js"); require("core-js/modules/es.object.keys.js"); require("core-js/modules/es.regexp.exec.js"); require("core-js/modules/es.string.ends-with.js"); require("core-js/modules/es.string.includes.js"); var _fsExtra = _interopRequireDefault(require("fs-extra")); var _commandLineArgs = _interopRequireDefault(require("command-line-args")); var _commandLineUsage = _interopRequireDefault(require("command-line-usage")); var _file_systems = require("../file_systems"); var _bugs = require("../../src/bugs"); var git = _interopRequireWildcard(require("../../src/git")); var _datasets = require("../../src/datasets"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; } function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } 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 _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 asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); } function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } 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 _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, 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); } function parseArgs(argv) { var optionsDefinitions = [{ description: "pathname to the directory containing the dataset", defaultOption: true, name: "data", type: String }, { description: "pathname to the directory containing the HTML comptes rendus de seance", name: "cr", type: String }, { description: "pathname to the directory to commit", name: "commit", type: String }, { description: "only consider this bug", name: "bug", type: String }, { description: "pathname to the directory where the check outputs will be stored", name: "output", type: String }, { description: "dataset (possible values must include exactly one of ".concat((0, _datasets.getDatasets)(), ")"), name: "dataset", type: String }, { description: "schema (possible values are ".concat((0, _datasets.getSchemas)(), ")"), name: "schema", type: String }, { description: "directory in which bugs are found (default .)", name: "bugs-dir", type: String }, { description: "increase verbosity", name: "verbose", type: Boolean }, { description: "debug information", name: "debug", type: Boolean }, { description: "check", name: "check", type: Boolean }, { description: "fix", name: "fix", type: Boolean }, { name: "help", description: "Print this usage guide." }]; var sections = [{ header: "Cross check data consistency and fix problems", content: "" }, { header: "Options", optionList: optionsDefinitions }]; var options = (0, _commandLineArgs["default"])(optionsDefinitions, { argv: argv }); if (options.dataset) { if (!(0, _datasets.validDataset)(options.dataset)) { console.error("--dataset ".concat(options.dataset)); options.help = true; } } if (options.schema) { if (!(0, _datasets.getSchemas)().includes(options.schema)) { console.error("--schema ".concat(options.schema)); options.help = true; } } if (options.commit) { if (!_fsExtra["default"].existsSync(options.commit)) { console.error("".concat(options.commit, " does not exist")); options.help = true; } } if (options.debug) options.verbose = true; if ("help" in options) { var usage = (0, _commandLineUsage["default"])(sections); console.warn(usage); return null; } return options; } var BugsHelper = exports.BugsHelper = /*#__PURE__*/function () { function BugsHelper(options) { _classCallCheck(this, BugsHelper); _defineProperty(this, "options", void 0); _defineProperty(this, "bugs", void 0); this.options = options; this.bugs = new _bugs.SchemaBugs(this.options); } return _createClass(BugsHelper, [{ key: "check", value: function () { var _check = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() { var analysis, _iterator, _step, file, content; return _regeneratorRuntime().wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: analysis = {}; _context.next = 3; return this.bugs.preCheck(); case 3: if (this.options.verbose) console.log("check ".concat(this.options.data)); _iterator = _createForOfIteratorHelper((0, _file_systems.getFiles)([this.options.data])); _context.prev = 5; _iterator.s(); case 7: if ((_step = _iterator.n()).done) { _context.next = 15; break; } file = _step.value; content = (0, _file_systems.load)(file); _context.next = 12; return this.bugs.check(content, file); case 12: analysis[file] = _context.sent; case 13: _context.next = 7; break; case 15: _context.next = 20; break; case 17: _context.prev = 17; _context.t0 = _context["catch"](5); _iterator.e(_context.t0); case 20: _context.prev = 20; _iterator.f(); return _context.finish(20); case 23: _context.next = 25; return this.bugs.postCheck(analysis); case 25: _context.next = 27; return this.show(analysis); case 27: if (!this.options.output) { _context.next = 30; break; } _context.next = 30; return this.store(analysis); case 30: return _context.abrupt("return", 0); case 31: case "end": return _context.stop(); } }, _callee, this, [[5, 17, 20, 23]]); })); function check() { return _check.apply(this, arguments); } return check; }() }, { key: "show", value: function () { var _show = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(analysis) { var _i, _Object$keys, filename, bug, _i2, _Object$keys2, name, result, log; return _regeneratorRuntime().wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: for (_i = 0, _Object$keys = Object.keys(analysis); _i < _Object$keys.length; _i++) { filename = _Object$keys[_i]; bug = analysis[filename]; for (_i2 = 0, _Object$keys2 = Object.keys(bug); _i2 < _Object$keys2.length; _i2++) { name = _Object$keys2[_i2]; result = bug[name]; if (result != null) { log = void 0; if (result["status"] == "needs-fixing") { log = console.error; } else if (this.options.verbose) { log = console.log; } if (log != undefined) { log("".concat(name, " finds ").concat(filename, " ").concat(result["status"])); log(result["info"].join("\n")); } } } } case 1: case "end": return _context2.stop(); } }, _callee2, this); })); function show(_x) { return _show.apply(this, arguments); } return show; }() }, { key: "store", value: function () { var _store = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(analysis) { var name2reports, _i3, _Object$keys3, filename, bug, _i4, _Object$keys4, name, _i5, _Object$keys5, _name, reports, n, lines, status2lines, _i6, _Object$keys6, _filename, report, status, l, _iterator2, _step2, info, _i7, _arr, _arr$_i, _status, label, output; return _regeneratorRuntime().wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: name2reports = {}; for (_i3 = 0, _Object$keys3 = Object.keys(analysis); _i3 < _Object$keys3.length; _i3++) { filename = _Object$keys3[_i3]; bug = analysis[filename]; for (_i4 = 0, _Object$keys4 = Object.keys(bug); _i4 < _Object$keys4.length; _i4++) { name = _Object$keys4[_i4]; if (!(name in name2reports)) name2reports[name] = {}; name2reports[name][filename] = bug[name]; } } _i5 = 0, _Object$keys5 = Object.keys(name2reports); case 3: if (!(_i5 < _Object$keys5.length)) { _context3.next = 30; break; } _name = _Object$keys5[_i5]; reports = name2reports[_name]; n = _name.split("-")[1]; lines = ["## Bug [".concat(_name, "](https://git.en-root.org/tricoteuses/tricoteuses-assemblee-qa/issues/").concat(Number(n), ")"), "This report was created by the **check** function of [".concat(_name, "](https://git.en-root.org/tricoteuses/tricoteuses-assemblee/-/blob/master/src/bugs/").concat(_name, ".ts).")]; status2lines = { "needs-fixing": [], "will-be-fixed": [], "already-fixed": [] }; _i6 = 0, _Object$keys6 = Object.keys(reports); case 10: if (!(_i6 < _Object$keys6.length)) { _context3.next = 24; break; } _filename = _Object$keys6[_i6]; report = reports[_filename]; if (!(report == null || report["status"] == "ok")) { _context3.next = 15; break; } return _context3.abrupt("continue", 21); case 15: if (!(report["status"] in status2lines)) console.error("".concat(_filename, " status ").concat(report["status"], " unknown")); status = report["status"]; l = status2lines[status]; if (status == "will-be-fixed") l.push("* ".concat((0, _datasets.diffUpstream)(_filename)));else l.push("* ".concat((0, _datasets.masterUrl)(_filename))); _iterator2 = _createForOfIteratorHelper(report["info"]); try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { info = _step2.value; l.push(" * ".concat(info)); } } catch (err) { _iterator2.e(err); } finally { _iterator2.f(); } case 21: _i6++; _context3.next = 10; break; case 24: for (_i7 = 0, _arr = [["needs-fixing", "The following files must be fixed"], ["already-fixed", "The following files no longer need a fix"], ["will-be-fixed", "The following files have been successfully fixed"]]; _i7 < _arr.length; _i7++) { _arr$_i = _slicedToArray(_arr[_i7], 2), _status = _arr$_i[0], label = _arr$_i[1]; lines.push("### ".concat(label)); lines = lines.concat(status2lines[_status]); } output = "".concat(this.options.output, "/").concat(_name, ".md"); _fsExtra["default"].writeFileSync(output, lines.join("\n"), { encoding: "utf8" }); case 27: _i5++; _context3.next = 3; break; case 30: case "end": return _context3.stop(); } }, _callee3, this); })); function store(_x2) { return _store.apply(this, arguments); } return store; }() }, { key: "fix", value: function () { var _fix = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() { return _regeneratorRuntime().wrap(function _callee4$(_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: _context4.next = 2; return this.bugs.preFix(); case 2: _context4.next = 4; return this.bugs.fix((0, _file_systems.getFiles)([this.options.data])); case 4: return _context4.abrupt("return", 0); case 5: case "end": return _context4.stop(); } }, _callee4, this); })); function fix() { return _fix.apply(this, arguments); } return fix; }() }, { key: "main", value: function () { var _main = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() { return _regeneratorRuntime().wrap(function _callee5$(_context5) { while (1) switch (_context5.prev = _context5.next) { case 0: if (!this.options.check) { _context5.next = 4; break; } return _context5.abrupt("return", this.check()); case 4: return _context5.abrupt("return", this.fix()); case 5: case "end": return _context5.stop(); } }, _callee5, this); })); function main() { return _main.apply(this, arguments); } return main; }() }]); }(); function checkoutFix(_x3) { return _checkoutFix.apply(this, arguments); } function _checkoutFix() { _checkoutFix = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(options) { var c, v; return _regeneratorRuntime().wrap(function _callee6$(_context6) { while (1) switch (_context6.prev = _context6.next) { case 0: c = options.commit; if (!(c == undefined)) { _context6.next = 3; break; } return _context6.abrupt("return"); case 3: v = options.verbose; git.run(c, "checkout --quiet master", v); if (/tmp/.test(git.run(c, "branch", v))) git.run(c, "branch -D tmp", v); git.run(c, "checkout --quiet -b tmp master", v); if (/Merge bugfixes/.test(git.run(c, "log --oneline -1", v))) git.run(c, "revert --mainline 1 --no-edit HEAD", v); git.run(c, "merge --no-ff -m 'Merge upstream' upstream/uid", v); if (/bugfixes/.test(git.run(c, "branch", v))) git.run(c, "branch -D bugfixes", v); git.run(c, "checkout --quiet -b bugfixes", v); case 11: case "end": return _context6.stop(); } }, _callee6); })); return _checkoutFix.apply(this, arguments); } function mergeFix(_x4) { return _mergeFix.apply(this, arguments); } function _mergeFix() { _mergeFix = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(options) { var c, v; return _regeneratorRuntime().wrap(function _callee7$(_context7) { while (1) switch (_context7.prev = _context7.next) { case 0: c = options.commit; if (!(c == undefined)) { _context7.next = 3; break; } return _context7.abrupt("return"); case 3: v = options.verbose; git.run(c, "checkout --quiet tmp", v); git.run(c, "merge --no-ff -m 'Merge bugfixes' bugfixes", v); git.run(c, "branch -D bugfixes", v); git.run(c, "checkout --quiet master", v); if (!git.test(c, "diff --quiet tmp master", v)) git.run(c, "merge --ff-only tmp", v); git.run(c, "branch -D tmp", v); case 10: case "end": return _context7.stop(); } }, _callee7); })); return _mergeFix.apply(this, arguments); } function main(_x5) { return _main2.apply(this, arguments); } /* istanbul ignore if */ function _main2() { _main2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(argv) { var options, directorySchema, _iterator3, _step3, d, helper, status; return _regeneratorRuntime().wrap(function _callee8$(_context8) { while (1) switch (_context8.prev = _context8.next) { case 0: options = parseArgs(argv); if (!(options === null)) { _context8.next = 3; break; } return _context8.abrupt("return", 1); case 3: directorySchema = []; if (!options.schema) { _context8.next = 8; break; } directorySchema = [[options.data, options.schema]]; _context8.next = 14; break; case 8: if (!options.dataset) { _context8.next = 12; break; } directorySchema = (0, _datasets.datasetDirectorySchema)(options.dataset); _context8.next = 14; break; case 12: console.error("either --schema or --dataset is required"); return _context8.abrupt("return", 1); case 14: _context8.next = 16; return checkoutFix(options); case 16: _iterator3 = _createForOfIteratorHelper(directorySchema); _context8.prev = 17; _iterator3.s(); case 19: if ((_step3 = _iterator3.n()).done) { _context8.next = 42; break; } d = _step3.value; options.schema = d[1]; options.data = d[0]; if (options.debug) console.log("working on ".concat(options.data, " with schema ").concat(options.schema)); helper = void 0; _context8.prev = 25; helper = new BugsHelper(options); _context8.next = 34; break; case 29: _context8.prev = 29; _context8.t0 = _context8["catch"](25); if (_context8.t0 instanceof _file_systems.GetFileNotFoundError) { _context8.next = 33; break; } throw _context8.t0; case 33: return _context8.abrupt("continue", 40); case 34: if (options.verbose) console.log("working on files ".concat(options.data, " with schema ").concat(options.schema)); _context8.next = 37; return helper.main(); case 37: status = _context8.sent; if (!(status != 0)) { _context8.next = 40; break; } return _context8.abrupt("return", status); case 40: _context8.next = 19; break; case 42: _context8.next = 47; break; case 44: _context8.prev = 44; _context8.t1 = _context8["catch"](17); _iterator3.e(_context8.t1); case 47: _context8.prev = 47; _iterator3.f(); return _context8.finish(47); case 50: _context8.next = 52; return mergeFix(options); case 52: return _context8.abrupt("return", 0); case 53: case "end": return _context8.stop(); } }, _callee8, null, [[17, 44, 47, 50], [25, 29]]); })); return _main2.apply(this, arguments); } if (process.argv[1].endsWith("bugs_helper.ts")) main(process.argv).then(function (exitCode) { process.exit(exitCode); })["catch"](function (error) { console.error(error); process.exit(1); }); //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfZnNFeHRyYSIsIl9pbnRlcm9wUmVxdWlyZURlZmF1bHQiLCJyZXF1aXJlIiwiX2NvbW1hbmRMaW5lQXJncyIsIl9jb21tYW5kTGluZVVzYWdlIiwiX2ZpbGVfc3lzdGVtcyIsIl9idWdzIiwiZ2l0IiwiX2ludGVyb3BSZXF1aXJlV2lsZGNhcmQiLCJfZGF0YXNldHMiLCJfZ2V0UmVxdWlyZVdpbGRjYXJkQ2FjaGUiLCJlIiwiV2Vha01hcCIsInIiLCJ0IiwiX19lc01vZHVsZSIsIl90eXBlb2YiLCJoYXMiLCJnZXQiLCJuIiwiX19wcm90b19fIiwiYSIsIk9iamVjdCIsImRlZmluZVByb3BlcnR5IiwiZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yIiwidSIsImhhc093blByb3BlcnR5IiwiY2FsbCIsImkiLCJzZXQiLCJfc2xpY2VkVG9BcnJheSIsIl9hcnJheVdpdGhIb2xlcyIsIl9pdGVyYWJsZVRvQXJyYXlMaW1pdCIsIl91bnN1cHBvcnRlZEl0ZXJhYmxlVG9BcnJheSIsIl9ub25JdGVyYWJsZVJlc3QiLCJUeXBlRXJyb3IiLCJsIiwiU3ltYm9sIiwiaXRlcmF0b3IiLCJmIiwibyIsIm5leHQiLCJkb25lIiwicHVzaCIsInZhbHVlIiwibGVuZ3RoIiwiQXJyYXkiLCJpc0FycmF5IiwiX3JlZ2VuZXJhdG9yUnVudGltZSIsInByb3RvdHlwZSIsImMiLCJhc3luY0l0ZXJhdG9yIiwidG9TdHJpbmdUYWciLCJkZWZpbmUiLCJlbnVtZXJhYmxlIiwiY29uZmlndXJhYmxlIiwid3JpdGFibGUiLCJ3cmFwIiwiR2VuZXJ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