openspec-stat 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +234 -0
- package/README.zh-CN.md +234 -0
- package/dist/cjs/branch-selector.d.ts +7 -0
- package/dist/cjs/branch-selector.js +124 -0
- package/dist/cjs/cli.d.ts +2 -0
- package/dist/cjs/cli.js +151 -0
- package/dist/cjs/config.d.ts +3 -0
- package/dist/cjs/config.js +66 -0
- package/dist/cjs/formatters.d.ts +7 -0
- package/dist/cjs/formatters.js +222 -0
- package/dist/cjs/git-analyzer.d.ts +10 -0
- package/dist/cjs/git-analyzer.js +170 -0
- package/dist/cjs/i18n/index.d.ts +7 -0
- package/dist/cjs/i18n/index.js +84 -0
- package/dist/cjs/i18n/locales/en.json +72 -0
- package/dist/cjs/i18n/locales/zh-CN.json +72 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +50 -0
- package/dist/cjs/stats-aggregator.d.ts +7 -0
- package/dist/cjs/stats-aggregator.js +117 -0
- package/dist/cjs/time-utils.d.ts +6 -0
- package/dist/cjs/time-utils.js +55 -0
- package/dist/cjs/types.d.ts +77 -0
- package/dist/cjs/types.js +17 -0
- package/dist/esm/branch-selector.d.ts +7 -0
- package/dist/esm/branch-selector.js +218 -0
- package/dist/esm/cli.d.ts +2 -0
- package/dist/esm/cli.js +157 -0
- package/dist/esm/config.d.ts +3 -0
- package/dist/esm/config.js +78 -0
- package/dist/esm/formatters.d.ts +7 -0
- package/dist/esm/formatters.js +207 -0
- package/dist/esm/git-analyzer.d.ts +10 -0
- package/dist/esm/git-analyzer.js +335 -0
- package/dist/esm/i18n/index.d.ts +7 -0
- package/dist/esm/i18n/index.js +49 -0
- package/dist/esm/i18n/locales/en.json +72 -0
- package/dist/esm/i18n/locales/zh-CN.json +72 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/stats-aggregator.d.ts +7 -0
- package/dist/esm/stats-aggregator.js +149 -0
- package/dist/esm/time-utils.d.ts +6 -0
- package/dist/esm/time-utils.js +31 -0
- package/dist/esm/types.d.ts +77 -0
- package/dist/esm/types.js +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
7
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
9
|
+
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); }
|
|
10
|
+
import Table from 'cli-table3';
|
|
11
|
+
import chalk from 'chalk';
|
|
12
|
+
import { t } from "./i18n/index.js";
|
|
13
|
+
export var OutputFormatter = /*#__PURE__*/function () {
|
|
14
|
+
function OutputFormatter() {
|
|
15
|
+
_classCallCheck(this, OutputFormatter);
|
|
16
|
+
}
|
|
17
|
+
_createClass(OutputFormatter, [{
|
|
18
|
+
key: "formatTable",
|
|
19
|
+
value: function formatTable(result) {
|
|
20
|
+
var verbose = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
21
|
+
var output = '';
|
|
22
|
+
output += chalk.bold(t('output.title'));
|
|
23
|
+
output += chalk.gray(t('output.timeRange', {
|
|
24
|
+
since: result.timeRange.since.toLocaleString('zh-CN', {
|
|
25
|
+
hour12: false
|
|
26
|
+
}),
|
|
27
|
+
until: result.timeRange.until.toLocaleString('zh-CN', {
|
|
28
|
+
hour12: false
|
|
29
|
+
})
|
|
30
|
+
}));
|
|
31
|
+
output += chalk.gray(t('output.branches', {
|
|
32
|
+
branches: result.branches.join(', ')
|
|
33
|
+
}));
|
|
34
|
+
output += chalk.gray(t('output.totalCommits', {
|
|
35
|
+
count: String(result.totalCommits)
|
|
36
|
+
}));
|
|
37
|
+
var sortedAuthors = Array.from(result.authors.values()).sort(function (a, b) {
|
|
38
|
+
return b.commits - a.commits;
|
|
39
|
+
});
|
|
40
|
+
var _iterator = _createForOfIteratorHelper(sortedAuthors),
|
|
41
|
+
_step;
|
|
42
|
+
try {
|
|
43
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
44
|
+
var stats = _step.value;
|
|
45
|
+
output += chalk.bold.cyan("\n".concat(stats.author, "\n"));
|
|
46
|
+
if (stats.branchStats && stats.branchStats.size > 0) {
|
|
47
|
+
var branchTable = new Table({
|
|
48
|
+
head: [chalk.cyan(t('table.branch')), chalk.cyan(t('table.commits')), chalk.cyan(t('table.proposals')), chalk.cyan(t('table.codeFiles')), chalk.cyan(t('table.additions')), chalk.cyan(t('table.deletions')), chalk.cyan(t('table.netChanges'))],
|
|
49
|
+
style: {
|
|
50
|
+
head: [],
|
|
51
|
+
border: []
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
var sortedBranches = Array.from(stats.branchStats.values()).sort(function (a, b) {
|
|
55
|
+
return b.commits - a.commits;
|
|
56
|
+
});
|
|
57
|
+
var _iterator2 = _createForOfIteratorHelper(sortedBranches),
|
|
58
|
+
_step2;
|
|
59
|
+
try {
|
|
60
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
61
|
+
var branchStat = _step2.value;
|
|
62
|
+
branchTable.push([branchStat.branch, branchStat.commits.toString(), branchStat.openspecProposals.size.toString(), branchStat.codeFilesChanged.toString(), chalk.green("+".concat(branchStat.additions)), chalk.red("-".concat(branchStat.deletions)), branchStat.netChanges >= 0 ? chalk.green("+".concat(branchStat.netChanges)) : chalk.red("".concat(branchStat.netChanges))]);
|
|
63
|
+
}
|
|
64
|
+
} catch (err) {
|
|
65
|
+
_iterator2.e(err);
|
|
66
|
+
} finally {
|
|
67
|
+
_iterator2.f();
|
|
68
|
+
}
|
|
69
|
+
branchTable.push([chalk.bold.yellow(t('table.totalDeduplicated')), chalk.bold(stats.commits.toString()), chalk.bold(stats.openspecProposals.size.toString()), chalk.bold(stats.codeFilesChanged.toString()), chalk.bold.green("+".concat(stats.additions)), chalk.bold.red("-".concat(stats.deletions)), stats.netChanges >= 0 ? chalk.bold.green("+".concat(stats.netChanges)) : chalk.bold.red("".concat(stats.netChanges))]);
|
|
70
|
+
output += branchTable.toString() + '\n';
|
|
71
|
+
} else {
|
|
72
|
+
var simpleTable = new Table({
|
|
73
|
+
head: [chalk.cyan(t('table.period')), chalk.cyan(t('table.commits')), chalk.cyan(t('table.proposals')), chalk.cyan(t('table.codeFiles')), chalk.cyan(t('table.additions')), chalk.cyan(t('table.deletions')), chalk.cyan(t('table.netChanges'))],
|
|
74
|
+
style: {
|
|
75
|
+
head: [],
|
|
76
|
+
border: []
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
simpleTable.push([stats.statisticsPeriod || '-', stats.commits.toString(), stats.openspecProposals.size.toString(), stats.codeFilesChanged.toString(), chalk.green("+".concat(stats.additions)), chalk.red("-".concat(stats.deletions)), stats.netChanges >= 0 ? chalk.green("+".concat(stats.netChanges)) : chalk.red("".concat(stats.netChanges))]);
|
|
80
|
+
output += simpleTable.toString() + '\n';
|
|
81
|
+
}
|
|
82
|
+
if (verbose && stats.openspecProposals.size > 0) {
|
|
83
|
+
output += chalk.gray(t('output.proposals', {
|
|
84
|
+
proposals: Array.from(stats.openspecProposals).join(', ')
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
} catch (err) {
|
|
89
|
+
_iterator.e(err);
|
|
90
|
+
} finally {
|
|
91
|
+
_iterator.f();
|
|
92
|
+
}
|
|
93
|
+
return output;
|
|
94
|
+
}
|
|
95
|
+
}, {
|
|
96
|
+
key: "formatJSON",
|
|
97
|
+
value: function formatJSON(result) {
|
|
98
|
+
var data = {
|
|
99
|
+
timeRange: {
|
|
100
|
+
since: result.timeRange.since.toISOString(),
|
|
101
|
+
until: result.timeRange.until.toISOString()
|
|
102
|
+
},
|
|
103
|
+
branches: result.branches,
|
|
104
|
+
totalCommits: result.totalCommits,
|
|
105
|
+
authors: Array.from(result.authors.values()).map(function (stats) {
|
|
106
|
+
var _stats$lastCommitDate;
|
|
107
|
+
return {
|
|
108
|
+
author: stats.author,
|
|
109
|
+
commits: stats.commits,
|
|
110
|
+
openspecProposals: Array.from(stats.openspecProposals),
|
|
111
|
+
proposalCount: stats.openspecProposals.size,
|
|
112
|
+
codeFilesChanged: stats.codeFilesChanged,
|
|
113
|
+
additions: stats.additions,
|
|
114
|
+
deletions: stats.deletions,
|
|
115
|
+
netChanges: stats.netChanges,
|
|
116
|
+
lastCommitDate: (_stats$lastCommitDate = stats.lastCommitDate) === null || _stats$lastCommitDate === void 0 ? void 0 : _stats$lastCommitDate.toISOString()
|
|
117
|
+
};
|
|
118
|
+
})
|
|
119
|
+
};
|
|
120
|
+
return JSON.stringify(data, null, 2);
|
|
121
|
+
}
|
|
122
|
+
}, {
|
|
123
|
+
key: "formatCSV",
|
|
124
|
+
value: function formatCSV(result) {
|
|
125
|
+
var rows = [];
|
|
126
|
+
rows.push("".concat(t('table.author'), ",").concat(t('table.period'), ",").concat(t('table.commits'), ",").concat(t('table.proposalsCount'), ",").concat(t('table.proposalsList'), ",").concat(t('table.codeFiles'), ",").concat(t('table.additions'), ",").concat(t('table.deletions'), ",").concat(t('table.netChanges'), ",").concat(t('table.lastCommitDate')));
|
|
127
|
+
var sortedAuthors = Array.from(result.authors.values()).sort(function (a, b) {
|
|
128
|
+
return b.commits - a.commits;
|
|
129
|
+
});
|
|
130
|
+
var _iterator3 = _createForOfIteratorHelper(sortedAuthors),
|
|
131
|
+
_step3;
|
|
132
|
+
try {
|
|
133
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
134
|
+
var _stats$lastCommitDate2;
|
|
135
|
+
var stats = _step3.value;
|
|
136
|
+
var proposals = Array.from(stats.openspecProposals).join(';');
|
|
137
|
+
rows.push([stats.author, stats.statisticsPeriod || '-', stats.commits, stats.openspecProposals.size, "\"".concat(proposals, "\""), stats.codeFilesChanged, stats.additions, stats.deletions, stats.netChanges, ((_stats$lastCommitDate2 = stats.lastCommitDate) === null || _stats$lastCommitDate2 === void 0 ? void 0 : _stats$lastCommitDate2.toISOString()) || ''].join(','));
|
|
138
|
+
}
|
|
139
|
+
} catch (err) {
|
|
140
|
+
_iterator3.e(err);
|
|
141
|
+
} finally {
|
|
142
|
+
_iterator3.f();
|
|
143
|
+
}
|
|
144
|
+
return rows.join('\n');
|
|
145
|
+
}
|
|
146
|
+
}, {
|
|
147
|
+
key: "formatMarkdown",
|
|
148
|
+
value: function formatMarkdown(result) {
|
|
149
|
+
var md = '';
|
|
150
|
+
md += t('markdown.title');
|
|
151
|
+
md += t('markdown.timeRange', {
|
|
152
|
+
since: result.timeRange.since.toLocaleString('zh-CN', {
|
|
153
|
+
hour12: false
|
|
154
|
+
}),
|
|
155
|
+
until: result.timeRange.until.toLocaleString('zh-CN', {
|
|
156
|
+
hour12: false
|
|
157
|
+
})
|
|
158
|
+
});
|
|
159
|
+
md += t('markdown.branches', {
|
|
160
|
+
branches: result.branches.join(', ')
|
|
161
|
+
});
|
|
162
|
+
md += t('markdown.totalCommits', {
|
|
163
|
+
count: String(result.totalCommits)
|
|
164
|
+
});
|
|
165
|
+
md += t('markdown.statistics');
|
|
166
|
+
md += "| ".concat(t('table.author'), " | ").concat(t('table.period'), " | ").concat(t('table.commits'), " | ").concat(t('table.proposals'), " | ").concat(t('table.codeFiles'), " | ").concat(t('table.additions'), " | ").concat(t('table.deletions'), " | ").concat(t('table.netChanges'), " |\n");
|
|
167
|
+
md += '|--------|--------|---------|-----------|------------|-----------|-----------|-------------|\n';
|
|
168
|
+
var sortedAuthors = Array.from(result.authors.values()).sort(function (a, b) {
|
|
169
|
+
return b.commits - a.commits;
|
|
170
|
+
});
|
|
171
|
+
var _iterator4 = _createForOfIteratorHelper(sortedAuthors),
|
|
172
|
+
_step4;
|
|
173
|
+
try {
|
|
174
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
175
|
+
var stats = _step4.value;
|
|
176
|
+
md += "| ".concat(stats.author, " | ").concat(stats.statisticsPeriod || '-', " | ").concat(stats.commits, " | ").concat(stats.openspecProposals.size, " | ").concat(stats.codeFilesChanged, " | +").concat(stats.additions, " | -").concat(stats.deletions, " | ").concat(stats.netChanges >= 0 ? '+' : '').concat(stats.netChanges, " |\n");
|
|
177
|
+
}
|
|
178
|
+
} catch (err) {
|
|
179
|
+
_iterator4.e(err);
|
|
180
|
+
} finally {
|
|
181
|
+
_iterator4.f();
|
|
182
|
+
}
|
|
183
|
+
md += t('markdown.proposalDetails');
|
|
184
|
+
var _iterator5 = _createForOfIteratorHelper(sortedAuthors),
|
|
185
|
+
_step5;
|
|
186
|
+
try {
|
|
187
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
188
|
+
var _stats = _step5.value;
|
|
189
|
+
if (_stats.openspecProposals.size > 0) {
|
|
190
|
+
md += "### ".concat(_stats.author, "\n\n");
|
|
191
|
+
for (var _i = 0, _Array$from = Array.from(_stats.openspecProposals); _i < _Array$from.length; _i++) {
|
|
192
|
+
var proposal = _Array$from[_i];
|
|
193
|
+
md += "- ".concat(proposal, "\n");
|
|
194
|
+
}
|
|
195
|
+
md += '\n';
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
} catch (err) {
|
|
199
|
+
_iterator5.e(err);
|
|
200
|
+
} finally {
|
|
201
|
+
_iterator5.f();
|
|
202
|
+
}
|
|
203
|
+
return md;
|
|
204
|
+
}
|
|
205
|
+
}]);
|
|
206
|
+
return OutputFormatter;
|
|
207
|
+
}();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CommitInfo, CommitAnalysis, Config } from './types.js';
|
|
2
|
+
export declare class GitAnalyzer {
|
|
3
|
+
private git;
|
|
4
|
+
private config;
|
|
5
|
+
constructor(repoPath: string, config: Config);
|
|
6
|
+
getCommits(since: Date, until: Date, branches: string[]): Promise<CommitInfo[]>;
|
|
7
|
+
getCommitBranches(commitHash: string, targetBranches: string[]): Promise<string[]>;
|
|
8
|
+
analyzeCommit(commit: CommitInfo): Promise<CommitAnalysis | null>;
|
|
9
|
+
getActiveAuthors(weeks?: number): Promise<Set<string>>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
|
|
3
|
+
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."); }
|
|
4
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
6
|
+
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 new 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 new 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 new 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; }
|
|
7
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
8
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
9
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
10
|
+
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); } }
|
|
11
|
+
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); }); }; }
|
|
12
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
14
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
15
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
16
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
17
|
+
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); }
|
|
18
|
+
import simpleGit from 'simple-git';
|
|
19
|
+
import { normalizeAuthor } from "./config.js";
|
|
20
|
+
export var GitAnalyzer = /*#__PURE__*/function () {
|
|
21
|
+
function GitAnalyzer(repoPath, config) {
|
|
22
|
+
_classCallCheck(this, GitAnalyzer);
|
|
23
|
+
_defineProperty(this, "git", void 0);
|
|
24
|
+
_defineProperty(this, "config", void 0);
|
|
25
|
+
this.git = simpleGit(repoPath);
|
|
26
|
+
this.config = config;
|
|
27
|
+
}
|
|
28
|
+
_createClass(GitAnalyzer, [{
|
|
29
|
+
key: "getCommits",
|
|
30
|
+
value: function () {
|
|
31
|
+
var _getCommits = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(since, until, branches) {
|
|
32
|
+
var sinceStr, untilStr, logOptions, _iterator, _step, branch, log, commits, _iterator2, _step2, commit, commitBranches;
|
|
33
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
34
|
+
while (1) switch (_context.prev = _context.next) {
|
|
35
|
+
case 0:
|
|
36
|
+
sinceStr = since.toISOString();
|
|
37
|
+
untilStr = until.toISOString();
|
|
38
|
+
logOptions = {
|
|
39
|
+
'--since': sinceStr,
|
|
40
|
+
'--until': untilStr,
|
|
41
|
+
'--all': null
|
|
42
|
+
};
|
|
43
|
+
if (branches.length > 0) {
|
|
44
|
+
_iterator = _createForOfIteratorHelper(branches);
|
|
45
|
+
try {
|
|
46
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
47
|
+
branch = _step.value;
|
|
48
|
+
logOptions["--remotes=".concat(branch)] = null;
|
|
49
|
+
}
|
|
50
|
+
} catch (err) {
|
|
51
|
+
_iterator.e(err);
|
|
52
|
+
} finally {
|
|
53
|
+
_iterator.f();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
_context.next = 6;
|
|
57
|
+
return this.git.log(logOptions);
|
|
58
|
+
case 6:
|
|
59
|
+
log = _context.sent;
|
|
60
|
+
commits = [];
|
|
61
|
+
_iterator2 = _createForOfIteratorHelper(log.all);
|
|
62
|
+
_context.prev = 9;
|
|
63
|
+
_iterator2.s();
|
|
64
|
+
case 11:
|
|
65
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
66
|
+
_context.next = 19;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
commit = _step2.value;
|
|
70
|
+
_context.next = 15;
|
|
71
|
+
return this.getCommitBranches(commit.hash, branches);
|
|
72
|
+
case 15:
|
|
73
|
+
commitBranches = _context.sent;
|
|
74
|
+
commits.push({
|
|
75
|
+
hash: commit.hash,
|
|
76
|
+
author: commit.author_name,
|
|
77
|
+
email: commit.author_email,
|
|
78
|
+
date: new Date(commit.date),
|
|
79
|
+
message: commit.message,
|
|
80
|
+
branches: commitBranches
|
|
81
|
+
});
|
|
82
|
+
case 17:
|
|
83
|
+
_context.next = 11;
|
|
84
|
+
break;
|
|
85
|
+
case 19:
|
|
86
|
+
_context.next = 24;
|
|
87
|
+
break;
|
|
88
|
+
case 21:
|
|
89
|
+
_context.prev = 21;
|
|
90
|
+
_context.t0 = _context["catch"](9);
|
|
91
|
+
_iterator2.e(_context.t0);
|
|
92
|
+
case 24:
|
|
93
|
+
_context.prev = 24;
|
|
94
|
+
_iterator2.f();
|
|
95
|
+
return _context.finish(24);
|
|
96
|
+
case 27:
|
|
97
|
+
return _context.abrupt("return", commits);
|
|
98
|
+
case 28:
|
|
99
|
+
case "end":
|
|
100
|
+
return _context.stop();
|
|
101
|
+
}
|
|
102
|
+
}, _callee, this, [[9, 21, 24, 27]]);
|
|
103
|
+
}));
|
|
104
|
+
function getCommits(_x, _x2, _x3) {
|
|
105
|
+
return _getCommits.apply(this, arguments);
|
|
106
|
+
}
|
|
107
|
+
return getCommits;
|
|
108
|
+
}()
|
|
109
|
+
}, {
|
|
110
|
+
key: "getCommitBranches",
|
|
111
|
+
value: function () {
|
|
112
|
+
var _getCommitBranches = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(commitHash, targetBranches) {
|
|
113
|
+
var result, allBranches;
|
|
114
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
115
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
116
|
+
case 0:
|
|
117
|
+
_context2.prev = 0;
|
|
118
|
+
_context2.next = 3;
|
|
119
|
+
return this.git.raw(['branch', '-r', '--contains', commitHash]);
|
|
120
|
+
case 3:
|
|
121
|
+
result = _context2.sent;
|
|
122
|
+
allBranches = result.split('\n').map(function (b) {
|
|
123
|
+
return b.trim();
|
|
124
|
+
}).filter(function (b) {
|
|
125
|
+
return b && !b.includes('HEAD');
|
|
126
|
+
});
|
|
127
|
+
if (!(targetBranches.length === 0)) {
|
|
128
|
+
_context2.next = 7;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
return _context2.abrupt("return", allBranches);
|
|
132
|
+
case 7:
|
|
133
|
+
return _context2.abrupt("return", allBranches.filter(function (branch) {
|
|
134
|
+
return targetBranches.some(function (target) {
|
|
135
|
+
return branch === target || branch.includes(target);
|
|
136
|
+
});
|
|
137
|
+
}));
|
|
138
|
+
case 10:
|
|
139
|
+
_context2.prev = 10;
|
|
140
|
+
_context2.t0 = _context2["catch"](0);
|
|
141
|
+
return _context2.abrupt("return", []);
|
|
142
|
+
case 13:
|
|
143
|
+
case "end":
|
|
144
|
+
return _context2.stop();
|
|
145
|
+
}
|
|
146
|
+
}, _callee2, this, [[0, 10]]);
|
|
147
|
+
}));
|
|
148
|
+
function getCommitBranches(_x4, _x5) {
|
|
149
|
+
return _getCommitBranches.apply(this, arguments);
|
|
150
|
+
}
|
|
151
|
+
return getCommitBranches;
|
|
152
|
+
}()
|
|
153
|
+
}, {
|
|
154
|
+
key: "analyzeCommit",
|
|
155
|
+
value: function () {
|
|
156
|
+
var _analyzeCommit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(commit) {
|
|
157
|
+
var show, lines, fileChanges, openspecProposals, hasCodeChanges, openspecDir, excludeExts, _iterator3, _step3, _loop, totalAdditions, totalDeletions;
|
|
158
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context4) {
|
|
159
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
160
|
+
case 0:
|
|
161
|
+
_context4.prev = 0;
|
|
162
|
+
_context4.next = 3;
|
|
163
|
+
return this.git.show(['--numstat', '--format=', commit.hash]);
|
|
164
|
+
case 3:
|
|
165
|
+
show = _context4.sent;
|
|
166
|
+
lines = show.split('\n').filter(function (line) {
|
|
167
|
+
return line.trim();
|
|
168
|
+
});
|
|
169
|
+
fileChanges = [];
|
|
170
|
+
openspecProposals = new Set();
|
|
171
|
+
hasCodeChanges = false;
|
|
172
|
+
openspecDir = this.config.openspecDir || 'openspec/';
|
|
173
|
+
excludeExts = this.config.excludeExtensions || [];
|
|
174
|
+
_iterator3 = _createForOfIteratorHelper(lines);
|
|
175
|
+
_context4.prev = 11;
|
|
176
|
+
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
177
|
+
var line, parts, _parts, addStr, delStr, pathParts, path, additions, deletions, proposalMatch, isExcluded, isInOpenspec;
|
|
178
|
+
return _regeneratorRuntime().wrap(function _loop$(_context3) {
|
|
179
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
180
|
+
case 0:
|
|
181
|
+
line = _step3.value;
|
|
182
|
+
parts = line.split(/\s+/);
|
|
183
|
+
if (!(parts.length < 3)) {
|
|
184
|
+
_context3.next = 4;
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
return _context3.abrupt("return", 1);
|
|
188
|
+
case 4:
|
|
189
|
+
_parts = _toArray(parts), addStr = _parts[0], delStr = _parts[1], pathParts = _parts.slice(2);
|
|
190
|
+
path = pathParts.join(' ');
|
|
191
|
+
additions = addStr === '-' ? 0 : parseInt(addStr, 10);
|
|
192
|
+
deletions = delStr === '-' ? 0 : parseInt(delStr, 10);
|
|
193
|
+
if (path.startsWith(openspecDir)) {
|
|
194
|
+
proposalMatch = path.match(new RegExp("^".concat(openspecDir, "changes/([^/]+)")));
|
|
195
|
+
if (proposalMatch) {
|
|
196
|
+
openspecProposals.add(proposalMatch[1]);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
isExcluded = excludeExts.some(function (ext) {
|
|
200
|
+
return path.endsWith(ext);
|
|
201
|
+
});
|
|
202
|
+
isInOpenspec = path.startsWith(openspecDir);
|
|
203
|
+
if (!isExcluded && !isInOpenspec) {
|
|
204
|
+
hasCodeChanges = true;
|
|
205
|
+
fileChanges.push({
|
|
206
|
+
path: path,
|
|
207
|
+
additions: additions,
|
|
208
|
+
deletions: deletions,
|
|
209
|
+
status: 'M'
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
case 12:
|
|
213
|
+
case "end":
|
|
214
|
+
return _context3.stop();
|
|
215
|
+
}
|
|
216
|
+
}, _loop);
|
|
217
|
+
});
|
|
218
|
+
_iterator3.s();
|
|
219
|
+
case 14:
|
|
220
|
+
if ((_step3 = _iterator3.n()).done) {
|
|
221
|
+
_context4.next = 20;
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
return _context4.delegateYield(_loop(), "t0", 16);
|
|
225
|
+
case 16:
|
|
226
|
+
if (!_context4.t0) {
|
|
227
|
+
_context4.next = 18;
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
return _context4.abrupt("continue", 18);
|
|
231
|
+
case 18:
|
|
232
|
+
_context4.next = 14;
|
|
233
|
+
break;
|
|
234
|
+
case 20:
|
|
235
|
+
_context4.next = 25;
|
|
236
|
+
break;
|
|
237
|
+
case 22:
|
|
238
|
+
_context4.prev = 22;
|
|
239
|
+
_context4.t1 = _context4["catch"](11);
|
|
240
|
+
_iterator3.e(_context4.t1);
|
|
241
|
+
case 25:
|
|
242
|
+
_context4.prev = 25;
|
|
243
|
+
_iterator3.f();
|
|
244
|
+
return _context4.finish(25);
|
|
245
|
+
case 28:
|
|
246
|
+
if (!(openspecProposals.size > 0 && hasCodeChanges)) {
|
|
247
|
+
_context4.next = 32;
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
totalAdditions = fileChanges.reduce(function (sum, f) {
|
|
251
|
+
return sum + f.additions;
|
|
252
|
+
}, 0);
|
|
253
|
+
totalDeletions = fileChanges.reduce(function (sum, f) {
|
|
254
|
+
return sum + f.deletions;
|
|
255
|
+
}, 0);
|
|
256
|
+
return _context4.abrupt("return", {
|
|
257
|
+
commit: commit,
|
|
258
|
+
openspecProposals: openspecProposals,
|
|
259
|
+
codeFiles: fileChanges,
|
|
260
|
+
totalAdditions: totalAdditions,
|
|
261
|
+
totalDeletions: totalDeletions,
|
|
262
|
+
netChanges: totalAdditions - totalDeletions
|
|
263
|
+
});
|
|
264
|
+
case 32:
|
|
265
|
+
return _context4.abrupt("return", null);
|
|
266
|
+
case 35:
|
|
267
|
+
_context4.prev = 35;
|
|
268
|
+
_context4.t2 = _context4["catch"](0);
|
|
269
|
+
console.error("Error analyzing commit ".concat(commit.hash, ":"), _context4.t2);
|
|
270
|
+
return _context4.abrupt("return", null);
|
|
271
|
+
case 39:
|
|
272
|
+
case "end":
|
|
273
|
+
return _context4.stop();
|
|
274
|
+
}
|
|
275
|
+
}, _callee3, this, [[0, 35], [11, 22, 25, 28]]);
|
|
276
|
+
}));
|
|
277
|
+
function analyzeCommit(_x6) {
|
|
278
|
+
return _analyzeCommit.apply(this, arguments);
|
|
279
|
+
}
|
|
280
|
+
return analyzeCommit;
|
|
281
|
+
}()
|
|
282
|
+
}, {
|
|
283
|
+
key: "getActiveAuthors",
|
|
284
|
+
value: function () {
|
|
285
|
+
var _getActiveAuthors = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
286
|
+
var weeks,
|
|
287
|
+
since,
|
|
288
|
+
log,
|
|
289
|
+
authors,
|
|
290
|
+
_iterator4,
|
|
291
|
+
_step4,
|
|
292
|
+
commit,
|
|
293
|
+
normalizedAuthor,
|
|
294
|
+
_args5 = arguments;
|
|
295
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context5) {
|
|
296
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
297
|
+
case 0:
|
|
298
|
+
weeks = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : 2;
|
|
299
|
+
since = new Date();
|
|
300
|
+
since.setDate(since.getDate() - weeks * 7);
|
|
301
|
+
_context5.next = 5;
|
|
302
|
+
return this.git.log({
|
|
303
|
+
'--since': since.toISOString(),
|
|
304
|
+
'--all': null
|
|
305
|
+
});
|
|
306
|
+
case 5:
|
|
307
|
+
log = _context5.sent;
|
|
308
|
+
authors = new Set();
|
|
309
|
+
_iterator4 = _createForOfIteratorHelper(log.all);
|
|
310
|
+
try {
|
|
311
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
312
|
+
commit = _step4.value;
|
|
313
|
+
normalizedAuthor = normalizeAuthor(commit.author_name, this.config.authorMapping);
|
|
314
|
+
authors.add(normalizedAuthor);
|
|
315
|
+
}
|
|
316
|
+
} catch (err) {
|
|
317
|
+
_iterator4.e(err);
|
|
318
|
+
} finally {
|
|
319
|
+
_iterator4.f();
|
|
320
|
+
}
|
|
321
|
+
return _context5.abrupt("return", authors);
|
|
322
|
+
case 10:
|
|
323
|
+
case "end":
|
|
324
|
+
return _context5.stop();
|
|
325
|
+
}
|
|
326
|
+
}, _callee4, this);
|
|
327
|
+
}));
|
|
328
|
+
function getActiveAuthors() {
|
|
329
|
+
return _getActiveAuthors.apply(this, arguments);
|
|
330
|
+
}
|
|
331
|
+
return getActiveAuthors;
|
|
332
|
+
}()
|
|
333
|
+
}]);
|
|
334
|
+
return GitAnalyzer;
|
|
335
|
+
}();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type Language = 'en' | 'zh-CN';
|
|
2
|
+
type TranslationKey = string;
|
|
3
|
+
export declare function setLanguage(lang: Language): void;
|
|
4
|
+
export declare function getLanguage(): Language;
|
|
5
|
+
export declare function t(key: TranslationKey, params?: Record<string, string | number>): string;
|
|
6
|
+
export declare function initI18n(lang?: string): void;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { join, dirname } from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
var __filename = fileURLToPath(import.meta.url);
|
|
5
|
+
var __dirname = dirname(__filename);
|
|
6
|
+
var currentLanguage = 'en';
|
|
7
|
+
var translations = {
|
|
8
|
+
'en': {},
|
|
9
|
+
'zh-CN': {}
|
|
10
|
+
};
|
|
11
|
+
function loadTranslations() {
|
|
12
|
+
try {
|
|
13
|
+
var enPath = join(__dirname, 'locales', 'en.json');
|
|
14
|
+
var zhPath = join(__dirname, 'locales', 'zh-CN.json');
|
|
15
|
+
translations['en'] = JSON.parse(readFileSync(enPath, 'utf-8'));
|
|
16
|
+
translations['zh-CN'] = JSON.parse(readFileSync(zhPath, 'utf-8'));
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error('Failed to load translations:', error);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function setLanguage(lang) {
|
|
22
|
+
currentLanguage = lang;
|
|
23
|
+
}
|
|
24
|
+
export function getLanguage() {
|
|
25
|
+
return currentLanguage;
|
|
26
|
+
}
|
|
27
|
+
export function t(key, params) {
|
|
28
|
+
if (Object.keys(translations[currentLanguage]).length === 0) {
|
|
29
|
+
loadTranslations();
|
|
30
|
+
}
|
|
31
|
+
var text = translations[currentLanguage][key] || translations['en'][key] || key;
|
|
32
|
+
if (params) {
|
|
33
|
+
Object.keys(params).forEach(function (paramKey) {
|
|
34
|
+
text = text.replace(new RegExp("{{".concat(paramKey, "}}"), 'g'), String(params[paramKey]));
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return text;
|
|
38
|
+
}
|
|
39
|
+
export function initI18n(lang) {
|
|
40
|
+
if (lang && (lang === 'en' || lang === 'zh-CN' || lang === 'zh')) {
|
|
41
|
+
setLanguage(lang === 'zh' ? 'zh-CN' : lang);
|
|
42
|
+
} else {
|
|
43
|
+
var envLang = process.env.LANG || process.env.LANGUAGE || '';
|
|
44
|
+
if (envLang.includes('zh') || envLang.includes('CN')) {
|
|
45
|
+
setLanguage('zh-CN');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
loadTranslations();
|
|
49
|
+
}
|