@code-pushup/utils 0.25.6 → 0.26.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/index.js CHANGED
@@ -312,23 +312,42 @@ function getDuplicateSlugCategories(categories) {
312
312
  return hasDuplicateStrings(categories.map(({ slug }) => slug));
313
313
  }
314
314
 
315
+ // packages/models/src/lib/commit.ts
316
+ import { z as z6 } from "zod";
317
+ var commitSchema = z6.object(
318
+ {
319
+ hash: z6.string({ description: "Commit SHA (full)" }).regex(
320
+ /^[\da-f]{40}$/,
321
+ "Commit SHA should be a 40-character hexadecimal string"
322
+ ),
323
+ message: z6.string({ description: "Commit message" }),
324
+ date: z6.coerce.date({
325
+ description: "Date and time when commit was authored"
326
+ }),
327
+ author: z6.string({
328
+ description: "Commit author name"
329
+ }).trim()
330
+ },
331
+ { description: "Git commit" }
332
+ );
333
+
315
334
  // packages/models/src/lib/core-config.ts
316
- import { z as z11 } from "zod";
335
+ import { z as z12 } from "zod";
317
336
 
318
337
  // packages/models/src/lib/persist-config.ts
319
- import { z as z6 } from "zod";
320
- var formatSchema = z6.enum(["json", "md"]);
321
- var persistConfigSchema = z6.object({
338
+ import { z as z7 } from "zod";
339
+ var formatSchema = z7.enum(["json", "md"]);
340
+ var persistConfigSchema = z7.object({
322
341
  outputDir: filePathSchema.describe("Artifacts folder").optional(),
323
342
  filename: fileNameSchema.describe("Artifacts file name (without extension)").optional(),
324
- format: z6.array(formatSchema).optional()
343
+ format: z7.array(formatSchema).optional()
325
344
  });
326
345
 
327
346
  // packages/models/src/lib/plugin-config.ts
328
- import { z as z9 } from "zod";
347
+ import { z as z10 } from "zod";
329
348
 
330
349
  // packages/models/src/lib/group.ts
331
- import { z as z7 } from "zod";
350
+ import { z as z8 } from "zod";
332
351
  var groupRefSchema = weightedRefSchema(
333
352
  "Weighted reference to a group",
334
353
  "Reference slug to a group within this plugin (e.g. 'max-lines')"
@@ -345,7 +364,7 @@ var groupSchema = scorableSchema(
345
364
  getDuplicateRefsInGroups,
346
365
  duplicateRefsInGroupsErrorMsg
347
366
  ).merge(groupMetaSchema);
348
- var groupsSchema = z7.array(groupSchema, {
367
+ var groupsSchema = z8.array(groupSchema, {
349
368
  description: "List of groups"
350
369
  }).optional().refine(
351
370
  (groups) => !getDuplicateSlugsInGroups(groups),
@@ -373,14 +392,14 @@ function getDuplicateSlugsInGroups(groups) {
373
392
  }
374
393
 
375
394
  // packages/models/src/lib/runner-config.ts
376
- import { z as z8 } from "zod";
377
- var outputTransformSchema = z8.function().args(z8.unknown()).returns(z8.union([auditOutputsSchema, z8.promise(auditOutputsSchema)]));
378
- var runnerConfigSchema = z8.object(
395
+ import { z as z9 } from "zod";
396
+ var outputTransformSchema = z9.function().args(z9.unknown()).returns(z9.union([auditOutputsSchema, z9.promise(auditOutputsSchema)]));
397
+ var runnerConfigSchema = z9.object(
379
398
  {
380
- command: z8.string({
399
+ command: z9.string({
381
400
  description: "Shell command to execute"
382
401
  }),
383
- args: z8.array(z8.string({ description: "Command arguments" })).optional(),
402
+ args: z9.array(z9.string({ description: "Command arguments" })).optional(),
384
403
  outputFile: filePathSchema.describe("Output path"),
385
404
  outputTransform: outputTransformSchema.optional()
386
405
  },
@@ -388,8 +407,8 @@ var runnerConfigSchema = z8.object(
388
407
  description: "How to execute runner"
389
408
  }
390
409
  );
391
- var onProgressSchema = z8.function().args(z8.unknown()).returns(z8.void());
392
- var runnerFunctionSchema = z8.function().args(onProgressSchema.optional()).returns(z8.union([auditOutputsSchema, z8.promise(auditOutputsSchema)]));
410
+ var onProgressSchema = z9.function().args(z9.unknown()).returns(z9.void());
411
+ var runnerFunctionSchema = z9.function().args(onProgressSchema.optional()).returns(z9.union([auditOutputsSchema, z9.promise(auditOutputsSchema)]));
393
412
 
394
413
  // packages/models/src/lib/plugin-config.ts
395
414
  var pluginMetaSchema = packageVersionSchema().merge(
@@ -400,13 +419,13 @@ var pluginMetaSchema = packageVersionSchema().merge(
400
419
  description: "Plugin metadata"
401
420
  })
402
421
  ).merge(
403
- z9.object({
422
+ z10.object({
404
423
  slug: slugSchema.describe("Unique plugin slug within core config"),
405
424
  icon: materialIconSchema
406
425
  })
407
426
  );
408
- var pluginDataSchema = z9.object({
409
- runner: z9.union([runnerConfigSchema, runnerFunctionSchema]),
427
+ var pluginDataSchema = z10.object({
428
+ runner: z10.union([runnerConfigSchema, runnerFunctionSchema]),
410
429
  audits: pluginAuditsSchema,
411
430
  groups: groupsSchema
412
431
  });
@@ -432,22 +451,22 @@ function getMissingRefsFromGroups(pluginCfg) {
432
451
  }
433
452
 
434
453
  // packages/models/src/lib/upload-config.ts
435
- import { z as z10 } from "zod";
436
- var uploadConfigSchema = z10.object({
454
+ import { z as z11 } from "zod";
455
+ var uploadConfigSchema = z11.object({
437
456
  server: urlSchema.describe("URL of deployed portal API"),
438
- apiKey: z10.string({
457
+ apiKey: z11.string({
439
458
  description: "API key with write access to portal (use `process.env` for security)"
440
459
  }),
441
460
  organization: slugSchema.describe(
442
461
  "Organization slug from Code PushUp portal"
443
462
  ),
444
463
  project: slugSchema.describe("Project slug from Code PushUp portal"),
445
- timeout: z10.number({ description: "Request timeout in minutes (default is 5)" }).positive().int().optional()
464
+ timeout: z11.number({ description: "Request timeout in minutes (default is 5)" }).positive().int().optional()
446
465
  });
447
466
 
448
467
  // packages/models/src/lib/core-config.ts
449
- var unrefinedCoreConfigSchema = z11.object({
450
- plugins: z11.array(pluginConfigSchema, {
468
+ var unrefinedCoreConfigSchema = z12.object({
469
+ plugins: z12.array(pluginConfigSchema, {
451
470
  description: "List of plugins to be used (official, community-provided, or custom)"
452
471
  }).min(1),
453
472
  /** portal configuration for persisting results */
@@ -470,7 +489,7 @@ function refineCoreConfig(schema) {
470
489
  }
471
490
 
472
491
  // packages/models/src/lib/report.ts
473
- import { z as z12 } from "zod";
492
+ import { z as z13 } from "zod";
474
493
  var auditReportSchema = auditSchema.merge(auditOutputSchema);
475
494
  var pluginReportSchema = pluginMetaSchema.merge(
476
495
  executionMetaSchema({
@@ -478,9 +497,9 @@ var pluginReportSchema = pluginMetaSchema.merge(
478
497
  descriptionDuration: "Duration of the plugin run in ms"
479
498
  })
480
499
  ).merge(
481
- z12.object({
482
- audits: z12.array(auditReportSchema).min(1),
483
- groups: z12.array(groupSchema).optional()
500
+ z13.object({
501
+ audits: z13.array(auditReportSchema).min(1),
502
+ groups: z13.array(groupSchema).optional()
484
503
  })
485
504
  ).refine(
486
505
  (pluginReport) => !getMissingRefsFromGroups2(pluginReport.audits, pluginReport.groups ?? []),
@@ -514,10 +533,11 @@ var reportSchema = packageVersionSchema({
514
533
  descriptionDuration: "Duration of the collect run in ms"
515
534
  })
516
535
  ).merge(
517
- z12.object(
536
+ z13.object(
518
537
  {
519
- categories: z12.array(categoryConfigSchema),
520
- plugins: z12.array(pluginReportSchema).min(1)
538
+ categories: z13.array(categoryConfigSchema),
539
+ plugins: z13.array(pluginReportSchema).min(1),
540
+ commit: commitSchema.describe("Git commit for which report was collected").nullable()
521
541
  },
522
542
  { description: "Collect output data" }
523
543
  )
@@ -1115,9 +1135,12 @@ function toOrdinal(value) {
1115
1135
  async function getLatestCommit(git = simpleGit()) {
1116
1136
  const log = await git.log({
1117
1137
  maxCount: 1,
1118
- format: { hash: "%H", message: "%s", author: "%an", date: "%ad" }
1138
+ format: { hash: "%H", message: "%s", author: "%an", date: "%aI" }
1119
1139
  });
1120
- return log.latest;
1140
+ if (!log.latest) {
1141
+ return null;
1142
+ }
1143
+ return commitSchema.parse(log.latest);
1121
1144
  }
1122
1145
  function getGitRoot(git = simpleGit()) {
1123
1146
  return git.revparse("--show-toplevel");
@@ -1131,18 +1154,6 @@ async function toGitPath(path, git = simpleGit()) {
1131
1154
  const gitRoot = await getGitRoot(git);
1132
1155
  return formatGitPath(path, gitRoot);
1133
1156
  }
1134
- function validateCommitData(commitData, options = {}) {
1135
- if (!commitData) {
1136
- const msg = "no commit data available";
1137
- if (options.throwError) {
1138
- throw new Error(msg);
1139
- } else {
1140
- console.warn(msg);
1141
- return false;
1142
- }
1143
- }
1144
- return true;
1145
- }
1146
1157
 
1147
1158
  // packages/utils/src/lib/group-by-status.ts
1148
1159
  function groupByStatus(results) {
@@ -1290,7 +1301,7 @@ function tableHtml(data) {
1290
1301
  }
1291
1302
 
1292
1303
  // packages/utils/src/lib/reports/generate-md-report.ts
1293
- function generateMdReport(report, commitData) {
1304
+ function generateMdReport(report) {
1294
1305
  const printCategories = report.categories.length > 0;
1295
1306
  return (
1296
1307
  // header section
@@ -1299,7 +1310,7 @@ function generateMdReport(report, commitData) {
1299
1310
  (printCategories ? reportToOverviewSection(report) + NEW_LINE + NEW_LINE : "") + // categories section
1300
1311
  (printCategories ? reportToCategoriesSection(report) + NEW_LINE + NEW_LINE : "") + // audits section
1301
1312
  reportToAuditsSection(report) + NEW_LINE + NEW_LINE + // about section
1302
- reportToAboutSection(report, commitData) + NEW_LINE + NEW_LINE + // footer section
1313
+ reportToAboutSection(report) + NEW_LINE + NEW_LINE + // footer section
1303
1314
  `${FOOTER_PREFIX} ${link2(README_LINK, "Code PushUp")}`
1304
1315
  );
1305
1316
  }
@@ -1423,10 +1434,10 @@ function reportToDetailsSection(audit) {
1423
1434
  const detailsTable = `<h4>Issues</h4>${tableHtml(detailsTableData)}`;
1424
1435
  return details(detailsTitle, detailsTable);
1425
1436
  }
1426
- function reportToAboutSection(report, commitData) {
1437
+ function reportToAboutSection(report) {
1427
1438
  const date = formatDate(/* @__PURE__ */ new Date());
1428
- const { duration, version, plugins, categories } = report;
1429
- const commitInfo = commitData ? `${commitData.message} (${commitData.hash.slice(0, 7)})` : "N/A";
1439
+ const { duration, version, commit, plugins, categories } = report;
1440
+ const commitInfo = commit ? `${commit.message} (${commit.hash.slice(0, 7)})` : "N/A";
1430
1441
  const reportMetaTable = [
1431
1442
  reportMetaTableHeaders,
1432
1443
  [
@@ -1766,6 +1777,5 @@ export {
1766
1777
  truncateIssueMessage,
1767
1778
  truncateText,
1768
1779
  truncateTitle,
1769
- validateCommitData,
1770
1780
  verboseUtils
1771
1781
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/utils",
3
- "version": "0.25.6",
3
+ "version": "0.26.0",
4
4
  "dependencies": {
5
5
  "@code-pushup/models": "*",
6
6
  "bundle-require": "^4.0.1",
package/src/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { ProcessConfig, ProcessError, ProcessObserver, ProcessResult, executePro
3
3
  export { CrawlFileSystemOptions, FileResult, MultipleFileResults, crawlFileSystem, directoryExists, ensureDirectoryExists, fileExists, findLineNumberInText, importEsmModule, logMultipleFileResults, pluginWorkDir, readJsonFile, readTextFile, removeDirectoryIfExists, } from './lib/file-system';
4
4
  export { filterItemRefsBy } from './lib/filter';
5
5
  export { formatBytes, formatDuration, pluralize, pluralizeToken, slugify, truncateDescription, truncateIssueMessage, truncateText, truncateTitle, } from './lib/formatting';
6
- export { formatGitPath, getGitRoot, getLatestCommit, toGitPath, validateCommitData, } from './lib/git';
6
+ export { formatGitPath, getGitRoot, getLatestCommit, toGitPath, } from './lib/git';
7
7
  export { groupByStatus } from './lib/group-by-status';
8
8
  export { isPromiseFulfilledResult, isPromiseRejectedResult, } from './lib/guards';
9
9
  export { logMultipleResults } from './lib/log-results';
package/src/lib/git.d.ts CHANGED
@@ -1,21 +1,8 @@
1
- export type CommitData = {
2
- hash: string;
3
- message: string;
4
- author: string;
5
- date: string;
6
- };
7
- export declare function getLatestCommit(git?: import("simple-git").SimpleGit): Promise<({
8
- hash: string;
9
- message: string;
10
- author: string;
11
- date: string;
12
- } & import("simple-git").ListLogLine) | null>;
1
+ import { Commit } from '@code-pushup/models';
2
+ export declare function getLatestCommit(git?: import("simple-git").SimpleGit): Promise<Commit | null>;
13
3
  export declare function getGitRoot(git?: import("simple-git").SimpleGit): Promise<string>;
14
4
  export declare function formatGitPath(path: string, gitRoot: string): string;
15
5
  export declare function toGitPath(path: string, git?: import("simple-git").SimpleGit): Promise<string>;
16
- export declare function validateCommitData(commitData: CommitData | null, options?: {
17
- throwError?: true;
18
- }): commitData is CommitData;
19
6
  export declare function guardAgainstLocalChanges(git?: import("simple-git").SimpleGit): Promise<void>;
20
7
  export declare function getCurrentBranchOrTag(git?: import("simple-git").SimpleGit): Promise<string>;
21
8
  export declare function safeCheckout(branchOrHash: string, options?: {
@@ -1,3 +1,2 @@
1
- import { CommitData } from '../git';
2
1
  import { ScoredReport } from './types';
3
- export declare function generateMdReport(report: ScoredReport, commitData: CommitData | null): string;
2
+ export declare function generateMdReport(report: ScoredReport): string;