Skip to content

Commit 705724a

Browse files
committed
chore(commands): biome format and lint
1 parent f7b32dd commit 705724a

File tree

3 files changed

+92
-162
lines changed

3 files changed

+92
-162
lines changed

src/commands/report/committers.ts

Lines changed: 68 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
1-
import { Command, Flags } from "@oclif/core";
2-
import { makeTable } from "@oclif/table";
3-
import { spawnSync } from "node:child_process";
4-
import fs from "node:fs";
5-
import { filenamePrefix, GIT_OUTPUT_FORMAT } from "../../config/constants.ts";
1+
import { Command, Flags } from '@oclif/core';
2+
import { makeTable } from '@oclif/table';
3+
import { spawnSync } from 'node:child_process';
4+
import fs from 'node:fs';
5+
import { filenamePrefix, GIT_OUTPUT_FORMAT } from '../../config/constants.ts';
66
import {
7-
ASCI_COLOR_CODES_REGEX,
8-
filenamePrefix,
9-
GIT_OUTPUT_FORMAT,
10-
} from "../../config/constants.ts";
11-
import {
12-
type AuthorReportRow,
137
type AuthorReportTableRow,
148
type CommitEntry,
159
type CommittersReport,
1610
generateCommittersReport,
1711
generateMonthlyReport,
1812
type MonthlyReportRow,
19-
type MonthlyReportTableRow,
2013
parseGitLogOutput,
21-
} from "../../service/committers.svc.ts";
22-
import { getErrorMessage, isErrnoException } from "../../service/error.svc.ts";
14+
} from '../../service/committers.svc.ts';
15+
import { getErrorMessage, isErrnoException } from '../../service/error.svc.ts';
2316
import {
2417
DEFAULT_DATE_FORMAT,
2518
formatCommitDate,
@@ -28,120 +21,95 @@ import {
2821
getEndOfDay,
2922
parseDate,
3023
subtractMonths,
31-
} from "../../utils/date-parsers.ts";
24+
} from '../../utils/date-parsers.ts';
3225

3326
export default class Committers extends Command {
34-
static override description =
35-
"Generate report of committers to a git repository";
27+
static override description = 'Generate report of committers to a git repository';
3628
static enableJsonFlag = true;
3729
static override examples = [
38-
"<%= config.bin %> <%= command.id %>",
39-
"<%= config.bin %> <%= command.id %> --csv -s",
40-
"<%= config.bin %> <%= command.id %> --json",
41-
"<%= config.bin %> <%= command.id %> --csv",
30+
'<%= config.bin %> <%= command.id %>',
31+
'<%= config.bin %> <%= command.id %> --csv -s',
32+
'<%= config.bin %> <%= command.id %> --json',
33+
'<%= config.bin %> <%= command.id %> --csv',
4234
];
4335

4436
static override flags = {
4537
beforeDate: Flags.string({
46-
char: "s",
38+
char: 's',
4739
default: formatDate(new Date()),
4840
description: `End date (format: ${DEFAULT_DATE_FORMAT})`,
4941
}),
5042
afterDate: Flags.string({
51-
char: "e",
43+
char: 'e',
5244
default: formatDate(subtractMonths(new Date(), 12)),
5345
description: `Start date (format: ${DEFAULT_DATE_FORMAT})`,
5446
}),
5547
exclude: Flags.string({
56-
char: "x",
48+
char: 'x',
5749
description: 'Path Exclusions (eg -x="./src/bin" -x="./dist")',
5850
multiple: true,
5951
multipleNonGreedy: true,
6052
}),
6153
json: Flags.boolean({
62-
description: "Output to JSON format",
54+
description: 'Output to JSON format',
6355
default: false,
6456
}),
6557
directory: Flags.string({
66-
char: "d",
67-
description: "Directory to search",
58+
char: 'd',
59+
description: 'Directory to search',
6860
}),
6961
monthly: Flags.boolean({
70-
char: "m",
71-
description: "Break down by calendar month.",
62+
char: 'm',
63+
description: 'Break down by calendar month.',
7264
default: false,
7365
}),
7466
months: Flags.integer({
75-
char: "n",
76-
description:
77-
"The number of months of git history to review. Cannot be used along beforeDate and afterDate",
67+
char: 'n',
68+
description: 'The number of months of git history to review. Cannot be used along beforeDate and afterDate',
7869
default: 12,
79-
exclusive: ["beforeDate", "afterDate", "s", "e"],
70+
exclusive: ['beforeDate', 'afterDate', 's', 'e'],
8071
}),
8172
csv: Flags.boolean({
82-
char: "c",
83-
description: "Output in CSV format",
73+
char: 'c',
74+
description: 'Output in CSV format',
8475
default: false,
8576
}),
8677
save: Flags.boolean({
87-
char: "s",
78+
char: 's',
8879
description: `Save the committers report as ${filenamePrefix}.committers.<output>`,
8980
default: false,
9081
}),
9182
};
9283

9384
public async run(): Promise<CommittersReport | string> {
9485
const { flags } = await this.parse(Committers);
95-
const {
96-
afterDate,
97-
beforeDate,
98-
exclude,
99-
directory: cwd,
100-
monthly,
101-
months,
102-
csv,
103-
save,
104-
} = flags;
86+
const { afterDate, beforeDate, exclude, directory: cwd, monthly, months, csv, save } = flags;
10587
const isJson = this.jsonEnabled();
10688

107-
const reportFormat = isJson ? "json" : csv ? "csv" : "txt";
89+
const reportFormat = isJson ? 'json' : csv ? 'csv' : 'txt';
10890

109-
const afterDateStartOfDay = months
110-
? `${subtractMonths(new Date(), months)}`
111-
: `${parseDate(afterDate)}`;
112-
const beforeDateEndOfDay = formatISODate(
113-
getEndOfDay(parseDate(beforeDate)),
114-
);
91+
const afterDateStartOfDay = months ? `${subtractMonths(new Date(), months)}` : `${parseDate(afterDate)}`;
92+
const beforeDateEndOfDay = formatISODate(getEndOfDay(parseDate(beforeDate)));
11593

116-
const ignores =
117-
exclude && exclude.length > 0
118-
? `. "\!(${exclude.join("|")})"`
119-
: undefined;
94+
const ignores = exclude && exclude.length > 0 ? `. "!(${exclude.join('|')})"` : undefined;
12095

12196
try {
122-
const entries = this.fetchGitCommitData(
123-
afterDateStartOfDay,
124-
beforeDateEndOfDay,
125-
ignores,
126-
cwd,
127-
);
97+
const entries = this.fetchGitCommitData(afterDateStartOfDay, beforeDateEndOfDay, ignores, cwd);
12898

12999
if (entries.length === 0) {
130100
return `No commits found between ${afterDate} and ${beforeDate}`;
131101
}
132102

133-
this.log("\nFetched %d commit entries\n", entries.length);
103+
this.log('\nFetched %d commit entries\n', entries.length);
134104

135-
const reportData = monthly
136-
? generateMonthlyReport(entries)
137-
: generateCommittersReport(entries);
105+
const reportData = monthly ? generateMonthlyReport(entries) : generateCommittersReport(entries);
138106

139-
let finalReport = "";
107+
let finalReport = '';
140108
switch (reportFormat) {
141-
case "json":
109+
case 'json':
142110
finalReport = JSON.stringify(
143-
reportData.map((row, index) =>
144-
"month" in row
111+
reportData.map((row) =>
112+
'month' in row
145113
? {
146114
month: row.month,
147115
start: row.start,
@@ -158,28 +126,25 @@ export default class Committers extends Command {
158126
2,
159127
);
160128
break;
161-
case "csv":
129+
case 'csv':
162130
finalReport = reportData
163131
.map((row, index) =>
164-
"month" in row
132+
'month' in row
165133
? `${index},${row.month},${row.start},${row.end},${row.totalCommits}`
166-
: `${index},${row.author},${row.commits.length},${formatCommitDate(row.lastCommitOn).replace(",", "")}`,
134+
: `${index},${row.author},${row.commits.length},${formatCommitDate(row.lastCommitOn).replace(',', '')}`,
167135
)
168-
.join("\n")
136+
.join('\n')
169137
.replace(
170138
/^/,
171-
monthly
172-
? `(index),month,start,end,totalCommits\n`
173-
: `(index),Committer,Commits,Last Commit Date\n`,
139+
monthly ? `(index),month,start,end,totalCommits\n` : `(index),Committer,Commits,Last Commit Date\n`,
174140
);
175141
break;
176-
case "txt":
177142
default:
178143
if (monthly) {
179144
finalReport = makeTable({
180-
title: "Monthly Report",
145+
title: 'Monthly Report',
181146
data: reportData
182-
.filter((row) => "month" in row)
147+
.filter((row) => 'month' in row)
183148
.map((row: MonthlyReportRow, index) => ({
184149
index,
185150
month: row.month,
@@ -194,9 +159,9 @@ export default class Committers extends Command {
194159
});
195160
} else {
196161
finalReport = makeTable({
197-
title: "Committers Report",
162+
title: 'Committers Report',
198163
data: reportData
199-
.filter((row) => "author" in row)
164+
.filter((row) => 'author' in row)
200165
.map(
201166
(row, index): AuthorReportTableRow => ({
202167
index,
@@ -207,20 +172,20 @@ export default class Committers extends Command {
207172
),
208173
columns: [
209174
{
210-
key: "index",
211-
name: "(index)",
175+
key: 'index',
176+
name: '(index)',
212177
},
213178
{
214-
key: "author",
215-
name: "Committer",
179+
key: 'author',
180+
name: 'Committer',
216181
},
217182
{
218-
key: "commits",
219-
name: "Commits",
183+
key: 'commits',
184+
name: 'Commits',
220185
},
221186
{
222-
key: "lastCommitOn",
223-
name: "Last Commit Date",
187+
key: 'lastCommitOn',
188+
name: 'Last Commit Date',
224189
},
225190
],
226191
headerOptions: {
@@ -234,18 +199,12 @@ export default class Committers extends Command {
234199

235200
if (save) {
236201
try {
237-
fs.writeFileSync(
238-
`${filenamePrefix}.${monthly ? "monthly" : "committers"}.${reportFormat}`,
239-
finalReport,
240-
{
241-
encoding: "utf-8",
242-
},
243-
);
202+
fs.writeFileSync(`${filenamePrefix}.${monthly ? 'monthly' : 'committers'}.${reportFormat}`, finalReport, {
203+
encoding: 'utf-8',
204+
});
244205
this.log(`Report written to ${reportFormat.toUpperCase()}`);
245206
} catch (err) {
246-
this.error(
247-
`Failed to save ${reportFormat.toUpperCase()} report: ${getErrorMessage(err)}`,
248-
);
207+
this.error(`Failed to save ${reportFormat.toUpperCase()} report: ${getErrorMessage(err)}`);
249208
}
250209
}
251210

@@ -270,36 +229,32 @@ export default class Committers extends Command {
270229
cwd?: string,
271230
): CommitEntry[] {
272231
const logParameters = [
273-
"log",
232+
'log',
274233
// "--all", // Include committers on all branches in the repo
275234
// "--date=format:%Y-%m", // Format date as YYYY-MM
276235
`--since="${sinceDate}"`,
277236
`--until="${beforeDateEndOfDay}"`,
278237
`--format=${GIT_OUTPUT_FORMAT}`,
279-
...(cwd ? ["--", cwd] : []),
280-
...(ignores ? ["--", ignores] : []),
238+
...(cwd ? ['--', cwd] : []),
239+
...(ignores ? ['--', ignores] : []),
281240
];
282241

283-
const logProcess = spawnSync("git", logParameters, {
284-
encoding: "utf-8",
242+
const logProcess = spawnSync('git', logParameters, {
243+
encoding: 'utf-8',
285244
});
286245

287246
if (logProcess.error) {
288247
if (isErrnoException(logProcess.error)) {
289-
if (logProcess.error.code === "ENOENT") {
290-
this.error(
291-
"Git command not found. Please ensure git is installed and available in your PATH.",
292-
);
248+
if (logProcess.error.code === 'ENOENT') {
249+
this.error('Git command not found. Please ensure git is installed and available in your PATH.');
293250
}
294251
this.error(`Git command failed: ${getErrorMessage(logProcess.error)}`);
295252
}
296253
this.error(`Git command failed: ${getErrorMessage(logProcess.error)}`);
297254
}
298255

299256
if (logProcess.status !== 0) {
300-
this.error(
301-
`Git command failed with status ${logProcess.status}: ${logProcess.stderr}`,
302-
);
257+
this.error(`Git command failed with status ${logProcess.status}: ${logProcess.stderr}`);
303258
}
304259

305260
if (!logProcess.stdout) {

0 commit comments

Comments
 (0)