repometry 0.1.0 → 0.2.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.
Files changed (118) hide show
  1. package/README.md +3 -2
  2. package/package.json +5 -4
  3. package/target/main/resources/report/json/config-v1.schema.json +0 -1
  4. package/target/main/resources/report/json/report-v2.schema.json +14 -0
  5. package/target/main/resources/viewer/index.html +10 -20
  6. package/target/main/resources/viewer/styles.css +3 -29
  7. package/target/main/ts/api/gh/github.js +1 -0
  8. package/target/main/ts/api/git/blob-batch.js +1 -0
  9. package/target/main/ts/api/git/changes.js +1 -0
  10. package/target/main/ts/api/git/commit-metadata.js +5 -6
  11. package/target/main/ts/api/git/git-churn.js +1 -0
  12. package/target/main/ts/api/git/git-reader.js +1 -0
  13. package/target/main/ts/api/git/git.js +1 -0
  14. package/target/main/ts/api/git/inspection-source.js +1 -0
  15. package/target/main/ts/api/git/local-sources.js +1 -0
  16. package/target/main/ts/api/git/local.js +1 -0
  17. package/target/main/ts/api/git/metabranch-worktree.js +1 -0
  18. package/target/main/ts/api/git/source-cache.js +1 -0
  19. package/target/main/ts/api/import/finding-import.js +1 -0
  20. package/target/main/ts/api/import/lcov-files.js +1 -0
  21. package/target/main/ts/api/import/profile-file.js +1 -0
  22. package/target/main/ts/api/worker/remote-executor.js +1 -0
  23. package/target/main/ts/api/worker/worker-protocol.js +1 -0
  24. package/target/main/ts/api/worker/worker.js +1 -0
  25. package/target/main/ts/cli/arguments.js +1 -0
  26. package/target/main/ts/cli/config.d.ts +0 -1
  27. package/target/main/ts/cli/config.js +3 -5
  28. package/target/main/ts/cli/imports.js +1 -0
  29. package/target/main/ts/cli/main.js +3 -2
  30. package/target/main/ts/cli/reporting.js +9 -13
  31. package/target/main/ts/cli/revisions.js +1 -0
  32. package/target/main/ts/cli/store.js +1 -0
  33. package/target/main/ts/compose/analyze-snapshot.js +1 -0
  34. package/target/main/ts/compose/attach-churn.js +13 -0
  35. package/target/main/ts/compose/diff-coverage.js +1 -0
  36. package/target/main/ts/compose/inspect.js +1 -0
  37. package/target/main/ts/compose/plugin-list.js +1 -0
  38. package/target/main/ts/compose/prepare-metabranch.js +1 -0
  39. package/target/main/ts/compose/review.js +1 -0
  40. package/target/main/ts/compose/sources.js +1 -0
  41. package/target/main/ts/core/engine/execute.js +1 -0
  42. package/target/main/ts/core/engine/manifest.js +1 -0
  43. package/target/main/ts/core/engine/plan.js +1 -0
  44. package/target/main/ts/core/engine/report-products.js +1 -0
  45. package/target/main/ts/core/model/changes.js +1 -0
  46. package/target/main/ts/core/model/clone-source.js +1 -0
  47. package/target/main/ts/core/model/code-structure.js +1 -0
  48. package/target/main/ts/core/model/finding-ignore.js +1 -0
  49. package/target/main/ts/core/model/measurement.d.ts +6 -0
  50. package/target/main/ts/core/model/measurement.js +6 -0
  51. package/target/main/ts/core/model/report.d.ts +8 -0
  52. package/target/main/ts/core/model/scanner-import.js +1 -0
  53. package/target/main/ts/core/model/snapshot.js +1 -0
  54. package/target/main/ts/core/ports/report.js +1 -0
  55. package/target/main/ts/core/ports/source-provider.js +1 -0
  56. package/target/main/ts/core/profile/exclusions.js +1 -0
  57. package/target/main/ts/core/profile/maintainability.js +1 -0
  58. package/target/main/ts/core/profile/profile.js +1 -0
  59. package/target/main/ts/core/usecases/compare.js +1 -0
  60. package/target/main/ts/core/usecases/diff-coverage-policy.js +1 -0
  61. package/target/main/ts/core/usecases/diff-coverage.js +1 -0
  62. package/target/main/ts/core/usecases/inspect.js +1 -0
  63. package/target/main/ts/core/usecases/review.js +1 -0
  64. package/target/main/ts/index.js +1 -0
  65. package/target/main/ts/plugin.js +1 -0
  66. package/target/main/ts/plugins/coverage/coverage.d.ts +2 -0
  67. package/target/main/ts/plugins/coverage/coverage.js +83 -4
  68. package/target/main/ts/plugins/coverage/diff-coverage.js +1 -0
  69. package/target/main/ts/plugins/duplication/duplication.js +1 -0
  70. package/target/main/ts/plugins/language-js/babel-provider.js +1 -0
  71. package/target/main/ts/plugins/language-js/clone-candidates.js +1 -0
  72. package/target/main/ts/plugins/language-js/code-lines.js +1 -0
  73. package/target/main/ts/plugins/language-js/function-facts.js +1 -0
  74. package/target/main/ts/plugins/language-js/structural-observations.js +1 -0
  75. package/target/main/ts/plugins/maintainability/maintainability.js +1 -0
  76. package/target/main/ts/plugins/maintainability/structural-smells.js +1 -0
  77. package/target/main/ts/plugins/source/forges.js +1 -0
  78. package/target/main/ts/plugins/structure/structure.js +1 -0
  79. package/target/main/ts/report/html/app/viewer-commits.d.ts +1 -1
  80. package/target/main/ts/report/html/app/viewer-commits.js +1 -1
  81. package/target/main/ts/report/html/app/viewer-data.d.ts +1 -1
  82. package/target/main/ts/report/html/app/viewer-data.js +4 -4
  83. package/target/main/ts/report/html/app/viewer-files.js +25 -8
  84. package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +3 -1
  85. package/target/main/ts/report/html/app/viewer-metric-registry.js +24 -6
  86. package/target/main/ts/report/html/app/viewer-profile.js +3 -3
  87. package/target/main/ts/report/html/app/viewer-trends.d.ts +0 -1
  88. package/target/main/ts/report/html/app/viewer-trends.js +16 -6
  89. package/target/main/ts/report/html/app/viewer.js +48 -107
  90. package/target/main/ts/report/html/site/badges.js +1 -0
  91. package/target/main/ts/report/html/site/export-site.d.ts +2 -1
  92. package/target/main/ts/report/html/site/export-site.js +17 -24
  93. package/target/main/ts/report/html/site/exported-server.js +1 -0
  94. package/target/main/ts/report/html/site/local-server.js +1 -0
  95. package/target/main/ts/report/html/site/projects.js +1 -0
  96. package/target/main/ts/report/html/site/server.js +1 -0
  97. package/target/main/ts/report/html/site/source-route.js +1 -0
  98. package/target/main/ts/report/json/projections/commit-summary.d.ts +1 -0
  99. package/target/main/ts/report/json/projections/commit-summary.js +7 -1
  100. package/target/main/ts/report/json/projections/components.js +1 -0
  101. package/target/main/ts/report/json/projections/file-metrics.js +1 -0
  102. package/target/main/ts/report/json/projections/inspection-context.js +1 -0
  103. package/target/main/ts/report/json/projections/inspection-details.js +1 -0
  104. package/target/main/ts/report/json/projections/metric-values.js +1 -0
  105. package/target/main/ts/report/json/projections/public-history.js +1 -0
  106. package/target/main/ts/report/json/store/components.js +1 -0
  107. package/target/main/ts/report/json/store/local-store.js +1 -0
  108. package/target/main/ts/report/json/store/pull-review-store.js +1 -0
  109. package/target/main/ts/report/json/validation/metabranch.js +1 -0
  110. package/target/main/ts/report/json/validation/report.js +1 -0
  111. package/target/main/ts/report/json/validation/summary-validation.js +1 -0
  112. package/target/main/ts/report.js +1 -0
  113. package/target/main/ts/api/gh/github-pr-comment.d.ts +0 -4
  114. package/target/main/ts/api/gh/github-pr-comment.js +0 -107
  115. package/target/main/ts/cli/github-pr-comment.d.ts +0 -1
  116. package/target/main/ts/cli/github-pr-comment.js +0 -12
  117. package/target/main/ts/report/html/app/viewer-access.d.ts +0 -19
  118. package/target/main/ts/report/html/app/viewer-access.js +0 -25
@@ -1,107 +0,0 @@
1
- import { isRecord } from '../../core/engine/plugin.js';
2
- const marker = '<!-- repometry-coverage:v1 -->';
3
- const sha = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/;
4
- const repositoryName = /^[a-z0-9_.-]+\/[a-z0-9_.-]+$/i;
5
- export async function publishPullCoverageComment(env, request = fetch) {
6
- const { GITHUB_EVENT_NAME, GITHUB_REPOSITORY: repository, GITHUB_API_URL, REPOMETRY_COMMENT_TOKEN: token, REPOMETRY_PR_REPOSITORY, REPOMETRY_PR_NUMBER, REPOMETRY_PR_HEAD, REPOMETRY_PR_BASE, REPOMETRY_REVIEW_HEAD, REPOMETRY_REVIEW_BASE } = env;
7
- if (GITHUB_EVENT_NAME !== 'pull_request' || !repository || REPOMETRY_PR_REPOSITORY !== repository
8
- || REPOMETRY_REVIEW_HEAD !== REPOMETRY_PR_HEAD || REPOMETRY_REVIEW_BASE !== REPOMETRY_PR_BASE)
9
- return 'skipped';
10
- if (!repositoryName.test(repository) || repository.split('/').some(part => part === '.' || part === '..')
11
- || !sha.test(REPOMETRY_PR_HEAD ?? '') || !sha.test(REPOMETRY_PR_BASE ?? ''))
12
- return 'skipped';
13
- const number = count(REPOMETRY_PR_NUMBER);
14
- if (!number)
15
- return 'skipped';
16
- const body = coverageComment(env);
17
- if (body === null)
18
- return 'skipped';
19
- if (!GITHUB_API_URL || !token)
20
- throw new Error('Repometry PR comments require the GitHub Actions token and API URL');
21
- const api = new URL(GITHUB_API_URL);
22
- if (api.protocol !== 'https:' || api.username || api.password || api.search || api.hash)
23
- throw new Error('Invalid GitHub API URL');
24
- api.pathname = api.pathname.replace(/\/+$/, '') + '/';
25
- const prefix = `repos/${repository}`;
26
- const signal = AbortSignal.timeout(20_000);
27
- async function call(path, method = 'GET', content) {
28
- const response = await request(new URL(path, api), {
29
- method, signal, redirect: 'error',
30
- headers: { Accept: 'application/vnd.github+json', Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
31
- body: content === undefined ? undefined : JSON.stringify({ body: content }),
32
- });
33
- if (!response.ok)
34
- throw new Error(`GitHub PR comment request returned HTTP ${response.status}`);
35
- return response;
36
- }
37
- const pull = await (await call(`${prefix}/pulls/${number}`)).json();
38
- if (!isRecord(pull) || pull.state !== 'open' || !matchesRef(pull.head, REPOMETRY_PR_HEAD, repository)
39
- || !matchesRef(pull.base, REPOMETRY_PR_BASE, repository))
40
- return 'skipped';
41
- const comments = `${prefix}/issues/${number}/comments`;
42
- for (let page = 1; page <= 100; page++) {
43
- const result = await (await call(`${comments}?per_page=100&page=${page}`)).json();
44
- if (!Array.isArray(result))
45
- throw new Error('Invalid GitHub PR comments response');
46
- const owned = result.find(isOwnedComment);
47
- if (owned) {
48
- if (owned.body === body)
49
- return 'unchanged';
50
- await call(`${prefix}/issues/comments/${owned.id}`, 'PATCH', body);
51
- return 'updated';
52
- }
53
- if (result.length < 100) {
54
- await call(comments, 'POST', body);
55
- return 'created';
56
- }
57
- }
58
- throw new Error('Could not check all GitHub PR comments for the Repometry marker');
59
- }
60
- function matchesRef(ref, id, repository) {
61
- return isRecord(ref) && ref.sha === id && isRecord(ref.repo) && ref.repo.full_name === repository;
62
- }
63
- function isOwnedComment(value) {
64
- return isRecord(value) && typeof value.id === 'number' && Number.isSafeInteger(value.id) && value.id > 0
65
- && typeof value.body === 'string' && value.body.startsWith(marker + '\n')
66
- && isRecord(value.user) && value.user.login === 'github-actions[bot]' && value.user.type === 'Bot';
67
- }
68
- function coverageComment(env) {
69
- const total = decimal(env.REPOMETRY_TOTAL_PERCENT, 0, 100);
70
- const delta = decimal(env.REPOMETRY_TOTAL_DELTA, -100, 100);
71
- const diff = decimal(env.REPOMETRY_DIFF_PERCENT, 0, 100);
72
- const covered = count(env.REPOMETRY_DIFF_COVERED);
73
- const measured = count(env.REPOMETRY_DIFF_TOTAL);
74
- const status = env.REPOMETRY_DIFF_STATUS;
75
- if (total === null && diff === null && status !== 'partial' && status !== 'not-applicable')
76
- return null;
77
- const totalText = total === null ? 'Unavailable' : `${total.toFixed(2)}%`
78
- + (delta === null ? '' : ` (${delta > 0 ? '+' : ''}${delta.toFixed(2)} pp from base)`);
79
- const counts = covered !== null && measured !== null && covered <= measured && measured > 0 ? ` · ${covered}/${measured} measured lines` : '';
80
- const diffText = diff === null ? status === 'not-applicable' ? 'No measured changed lines' : 'Unavailable' : `${diff.toFixed(2)}%${counts}`;
81
- return [marker, '### Repometry coverage', '',
82
- '| Coverage | Result | Gate |', '| --- | --- | --- |',
83
- `| Total | ${totalText} | ${gate(env.REPOMETRY_TOTAL_GATE)} |`,
84
- `| Changed lines | ${diffText}${status === 'partial' ? ' · Partial' : ''} | ${gate(env.REPOMETRY_DIFF_GATE)} |`, '',
85
- ].join('\n');
86
- }
87
- function decimal(value, lower, upper) {
88
- if (!value || !/^-?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i.test(value))
89
- return null;
90
- const number = Number(value);
91
- return Number.isFinite(number) && number >= lower && number <= upper ? number : null;
92
- }
93
- function count(value) {
94
- if (!value || !/^\d+$/.test(value))
95
- return null;
96
- const number = Number(value);
97
- return Number.isSafeInteger(number) ? number : null;
98
- }
99
- function gate(value) {
100
- switch (value) {
101
- case 'passed': return 'Passed';
102
- case 'failed': return 'Failed';
103
- case 'not-applicable': return 'Skipped';
104
- case 'indeterminate': return 'Incomplete';
105
- default: return '—';
106
- }
107
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,12 +0,0 @@
1
- import { pathToFileURL } from 'node:url';
2
- import { publishPullCoverageComment } from '../api/gh/github-pr-comment.js';
3
- if (process.argv[1] && pathToFileURL(process.argv[1]).href === import.meta.url) {
4
- try {
5
- const outcome = await publishPullCoverageComment(process.env);
6
- process.stdout.write(`Repometry PR coverage comment: ${outcome}\n`);
7
- }
8
- catch (error) {
9
- process.stderr.write(`repometry: ${error instanceof Error ? error.message : 'PR coverage comment failed'}\n`);
10
- process.exitCode = 1;
11
- }
12
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * What a report can show follows what its export carries, never the host it is served from: the export writes its
3
- * mode into the page, and a public export has no per-file data.
4
- */
5
- /** Pages a public report keeps in the navigation as unavailable, so the reader sees what the full report holds. */
6
- export declare const unavailableTabs: readonly ['issues', 'hotspots', 'metrics', 'settings'];
7
- /** The export's own mode: `local` from `repometry view`, `private` with details, anything else is public. */
8
- export declare function isDetailed(mode: string | undefined): boolean;
9
- /** Whether a page draws its own content, or shows the public report notice in its place. */
10
- export declare function pageAccess(page: string, detailed: boolean): 'open' | 'notice';
11
- /** The one notice a public report gives, in parts so the command can be set as code and copied. */
12
- export declare const publicNotice: {
13
- readonly lead: 'Public report:';
14
- readonly text: 'history and totals only. To see files, findings and source, run';
15
- readonly command: 'npx repometry view';
16
- readonly tail: 'in the repository.';
17
- /** The same message for the Overview's side panel, which sets the command on a line of its own. */
18
- readonly panel: 'History and totals only. To see files, findings and source, run this in the repository:';
19
- };
@@ -1,25 +0,0 @@
1
- /**
2
- * What a report can show follows what its export carries, never the host it is served from: the export writes its
3
- * mode into the page, and a public export has no per-file data.
4
- */
5
- /** Pages every report can draw from the summary alone. */
6
- const summaryPages = new Set(['overview', 'trends']);
7
- /** Pages a public report keeps in the navigation as unavailable, so the reader sees what the full report holds. */
8
- export const unavailableTabs = ['issues', 'hotspots', 'metrics', 'settings'];
9
- /** The export's own mode: `local` from `repometry view`, `private` with details, anything else is public. */
10
- export function isDetailed(mode) {
11
- return mode === 'local' || mode === 'private';
12
- }
13
- /** Whether a page draws its own content, or shows the public report notice in its place. */
14
- export function pageAccess(page, detailed) {
15
- return detailed || summaryPages.has(page) ? 'open' : 'notice';
16
- }
17
- /** The one notice a public report gives, in parts so the command can be set as code and copied. */
18
- export const publicNotice = {
19
- lead: 'Public report:',
20
- text: 'history and totals only. To see files, findings and source, run',
21
- command: 'npx repometry view',
22
- tail: 'in the repository.',
23
- /** The same message for the Overview's side panel, which sets the command on a line of its own. */
24
- panel: 'History and totals only. To see files, findings and source, run this in the repository:',
25
- };