@atomist/sdm-pack-aspect
Version:
an Atomist SDM Extension Pack for visualizing drift across an organization
171 lines • 8.34 kB
JavaScript
;
/*
* Copyright © 2019 Atomist, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
};
Object.defineProperty(exports, "__esModule", { value: true });
const slocReport_1 = require("@atomist/sdm-pack-sloc/lib/slocReport");
const _ = require("lodash");
const codeMetrics_1 = require("../aspect/common/codeMetrics");
const TreeBuilder_1 = require("../tree/TreeBuilder");
const bands_1 = require("../util/bands");
const groupByLoc = ar => {
const cm = codeMetrics_1.findCodeMetricsData(ar);
if (!cm) {
return undefined;
}
return bands_1.bandFor({
small: { upTo: 2000 },
tall: { upTo: 8000 },
grande: { upTo: 20000 },
venti: "default",
}, cm.lines);
};
/**
* Custom reporters against our repo cohort.
* Add your own here
*/
exports.CustomReporters = {
langs: {
summary: "Language breakdown across all projects",
description: "See the number of lines of code in each language, across all repos",
builder: TreeBuilder_1.treeBuilder("languages")
.customGroup({
name: "language", to: (ars) => { var ars_1, ars_1_1; return __awaiter(this, void 0, void 0, function* () {
var e_1, _a;
const cms = [];
try {
for (ars_1 = __asyncValues(ars); ars_1_1 = yield ars_1.next(), !ars_1_1.done;) {
const ar = ars_1_1.value;
const cm = codeMetrics_1.findCodeMetricsData(ar);
if (cm) {
cms.push(...cm.languages);
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (ars_1_1 && !ars_1_1.done && (_a = ars_1.return)) yield _a.call(ars_1);
}
finally { if (e_1) throw e_1.error; }
}
const distinctLanguages = _.uniqBy(_.flatten(cms.map(cm => cm.language)), l => l.name);
const s = {};
distinctLanguages.forEach(lang => s[lang.name] = [slocReport_1.consolidate(lang, cms)]);
return s;
}); },
})
.map({
mapping(cs, originalQuery) {
return __asyncGenerator(this, arguments, function* mapping_1() {
var e_2, _a, e_3, _b;
// TODO don't materialize this
const source = [];
try {
for (var _c = __asyncValues(originalQuery()), _d; _d = yield __await(_c.next()), !_d.done;) {
const pa = _d.value;
source.push(pa);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) yield __await(_a.call(_c));
}
finally { if (e_2) throw e_2.error; }
}
try {
for (var cs_1 = __asyncValues(cs), cs_1_1; cs_1_1 = yield __await(cs_1.next()), !cs_1_1.done;) {
const s = cs_1_1.value;
for (const r of source.filter(ar => {
const cm = codeMetrics_1.findCodeMetricsData(ar) || { languages: [] };
return cm.languages.some(l => l.language.name === s.language.name);
})
.map(ar => (Object.assign({}, ar, { lang: s.language.name })))) {
yield yield __await(r);
}
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (cs_1_1 && !cs_1_1.done && (_b = cs_1.return)) yield __await(_b.call(cs_1));
}
finally { if (e_3) throw e_3.error; }
}
});
},
})
.renderWith(ar => {
const cm = codeMetrics_1.findCodeMetricsData(ar) || { languages: [] };
const size = cm.languages.find(l => l.language.name === ar.lang).total;
return {
name: ar.id.repo,
size,
url: `/projects/${ar.id.owner}/${ar.id.repo}`,
owner: ar.id.owner,
repoUrl: ar.id.url,
};
}),
},
loc: {
summary: "Drill into repositories",
description: "Compare the size and language breakdowns of your repos",
builder: TreeBuilder_1.treeBuilder("loc")
.group({ name: "size", by: groupByLoc })
.split({
splitter: ar => {
const cm = codeMetrics_1.findCodeMetricsData(ar) || { languages: [] };
return cm.languages;
},
namer: a => a.id.repo,
})
.renderWith(cs => {
return {
name: `${cs.language.name} (${cs.source})`,
// url: ar.analysis.id.url,
size: cs.source,
};
}),
},
};
//# sourceMappingURL=customReporters.js.map