repometry 0.10.1 → 0.11.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 (147) hide show
  1. package/README.md +4 -2
  2. package/package.json +1 -1
  3. package/target/main/resources/config/process-plugins-v1.schema.json +22 -0
  4. package/target/main/resources/report/json/config-v1.schema.json +41 -0
  5. package/target/main/resources/report/json/file-metrics-v1.schema.json +23 -1
  6. package/target/main/resources/report/json/pull-review-v2.schema.json +100 -0
  7. package/target/main/ts/api/cache/root.d.ts +1 -1
  8. package/target/main/ts/api/cache/root.js +2 -2
  9. package/target/main/ts/api/gh/github.d.ts +0 -4
  10. package/target/main/ts/api/gh/github.js +3 -33
  11. package/target/main/ts/api/git/commit-metadata.d.ts +0 -1
  12. package/target/main/ts/api/git/commit-metadata.js +1 -10
  13. package/target/main/ts/api/import/cobertura.d.ts +2 -0
  14. package/target/main/ts/api/import/cobertura.js +160 -0
  15. package/target/main/ts/api/import/coverage-xml.d.ts +7 -0
  16. package/target/main/ts/api/import/coverage-xml.js +135 -0
  17. package/target/main/ts/api/import/lcov-files.d.ts +3 -1
  18. package/target/main/ts/api/import/lcov-files.js +23 -4
  19. package/target/main/ts/cli/arguments.js +2 -4
  20. package/target/main/ts/cli/config.d.ts +10 -6
  21. package/target/main/ts/cli/config.js +36 -6
  22. package/target/main/ts/cli/imports.d.ts +1 -0
  23. package/target/main/ts/cli/imports.js +6 -2
  24. package/target/main/ts/cli/main.js +47 -139
  25. package/target/main/ts/cli/range-inspection.d.ts +0 -3
  26. package/target/main/ts/cli/range-inspection.js +5 -17
  27. package/target/main/ts/cli/range-jobs.js +1 -3
  28. package/target/main/ts/cli/reporting.d.ts +2 -7
  29. package/target/main/ts/cli/reporting.js +23 -37
  30. package/target/main/ts/compose/analysis-report.d.ts +1 -1
  31. package/target/main/ts/compose/analysis-report.js +4 -5
  32. package/target/main/ts/compose/analysis-results.d.ts +1 -1
  33. package/target/main/ts/compose/analysis-results.js +4 -6
  34. package/target/main/ts/compose/analysis-steps.d.ts +23 -0
  35. package/target/main/ts/compose/analysis-steps.js +215 -0
  36. package/target/main/ts/compose/analyze-snapshot.d.ts +1 -1
  37. package/target/main/ts/compose/analyze-snapshot.js +8 -12
  38. package/target/main/ts/compose/built-ins.d.ts +3 -0
  39. package/target/main/ts/compose/built-ins.js +5 -0
  40. package/target/main/ts/compose/diff-coverage.d.ts +2 -4
  41. package/target/main/ts/compose/diff-coverage.js +15 -12
  42. package/target/main/ts/compose/history-cache.d.ts +1 -1
  43. package/target/main/ts/compose/inspect.d.ts +6 -9
  44. package/target/main/ts/compose/inspect.js +8 -9
  45. package/target/main/ts/compose/languages.d.ts +4 -1
  46. package/target/main/ts/compose/languages.js +9 -6
  47. package/target/main/ts/compose/native-language-plugins.d.ts +0 -1
  48. package/target/main/ts/compose/native-language-plugins.js +4 -11
  49. package/target/main/ts/compose/phases.d.ts +126 -0
  50. package/target/main/ts/compose/phases.js +154 -0
  51. package/target/main/ts/compose/plugin-list.d.ts +8 -2
  52. package/target/main/ts/compose/plugin-list.js +4 -13
  53. package/target/main/ts/compose/process-plugins.js +1 -1
  54. package/target/main/ts/compose/review.d.ts +2 -4
  55. package/target/main/ts/compose/review.js +10 -9
  56. package/target/main/ts/compose/sources.d.ts +1 -2
  57. package/target/main/ts/compose/sources.js +7 -7
  58. package/target/main/ts/core/engine/execute.d.ts +4 -1
  59. package/target/main/ts/core/engine/execute.js +1 -1
  60. package/target/main/ts/core/engine/manifest.d.ts +0 -1
  61. package/target/main/ts/core/engine/manifest.js +9 -13
  62. package/target/main/ts/core/engine/plugin.d.ts +1 -1
  63. package/target/main/ts/core/engine/report-products.js +3 -2
  64. package/target/main/ts/core/model/changes.d.ts +2 -0
  65. package/target/main/ts/core/model/changes.js +5 -1
  66. package/target/main/ts/core/model/clone-source.d.ts +2 -0
  67. package/target/main/ts/core/model/clone-source.js +4 -0
  68. package/target/main/ts/core/model/code-structure.d.ts +4 -1
  69. package/target/main/ts/core/model/code-structure.js +3 -1
  70. package/target/main/ts/core/model/coverage-input.d.ts +12 -0
  71. package/target/main/ts/core/model/coverage-input.js +11 -0
  72. package/target/main/ts/core/model/diff-coverage.d.ts +2 -0
  73. package/target/main/ts/core/model/diff-coverage.js +9 -1
  74. package/target/main/ts/core/model/language.d.ts +28 -0
  75. package/target/main/ts/core/model/language.js +25 -1
  76. package/target/main/ts/core/model/quality-summary.js +1 -1
  77. package/target/main/ts/core/model/report.d.ts +0 -2
  78. package/target/main/ts/core/model/report.js +0 -20
  79. package/target/main/ts/core/ports/tool-runner.d.ts +13 -0
  80. package/target/main/ts/core/usecases/inspect.d.ts +1 -2
  81. package/target/main/ts/core/usecases/review.js +11 -3
  82. package/target/main/ts/index.d.ts +6 -33
  83. package/target/main/ts/index.js +3 -18
  84. package/target/main/ts/plugin.d.ts +7 -3
  85. package/target/main/ts/plugin.js +3 -0
  86. package/target/main/ts/plugins/built-in.d.ts +6 -0
  87. package/target/main/ts/plugins/built-in.js +39 -0
  88. package/target/main/ts/plugins/coverage/coverage.d.ts +3 -24
  89. package/target/main/ts/plugins/coverage/coverage.js +8 -11
  90. package/target/main/ts/plugins/coverage/diff-coverage.d.ts +1 -5
  91. package/target/main/ts/plugins/coverage/diff-coverage.js +5 -14
  92. package/target/main/ts/plugins/duplication/duplication.d.ts +1 -3
  93. package/target/main/ts/plugins/duplication/duplication.js +2 -6
  94. package/target/main/ts/plugins/language-js/babel-provider.js +3 -2
  95. package/target/main/ts/plugins/language-js/structural-observations.js +1 -1
  96. package/target/main/ts/plugins/language-js/syntax.d.ts +2 -0
  97. package/target/main/ts/plugins/language-js/syntax.js +11 -0
  98. package/target/main/ts/plugins/maintainability/maintainability.d.ts +1 -8
  99. package/target/main/ts/plugins/maintainability/maintainability.js +4 -10
  100. package/target/main/ts/plugins/source/forges.js +1 -1
  101. package/target/main/ts/report/html/app/viewer-languages.d.ts +3 -1
  102. package/target/main/ts/report/html/app/viewer-languages.js +11 -1
  103. package/target/main/ts/report/html/app/viewer-metrics-view.js +1 -1
  104. package/target/main/ts/report/html/app/viewer-source-view.js +2 -2
  105. package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +7 -6
  106. package/target/main/ts/report/html/app/viewer-tokenizer.js +72 -71
  107. package/target/main/ts/report/html/site/export-site.d.ts +1 -5
  108. package/target/main/ts/report/html/site/export-site.js +2 -6
  109. package/target/main/ts/report/html/site/projects.d.ts +1 -3
  110. package/target/main/ts/report/html/site/projects.js +2 -4
  111. package/target/main/ts/report/json/projections/file-metrics.js +1 -1
  112. package/target/main/ts/report/json/projections/inspection-context.d.ts +1 -0
  113. package/target/main/ts/report/json/projections/inspection-context.js +19 -1
  114. package/target/main/ts/report/json/projections/inspection-details.js +7 -2
  115. package/target/main/ts/report/json/store/local-store.js +2 -0
  116. package/target/main/ts/report/json/store/replace-file.d.ts +1 -1
  117. package/target/main/ts/report/json/store/replace-file.js +24 -3
  118. package/target/main/ts/report/json/store/store-check.js +10 -1
  119. package/target/main/ts/report/json/validation/metabranch.d.ts +1 -1
  120. package/target/main/ts/report/json/validation/metabranch.js +6 -3
  121. package/target/main/ts/report/json/wire/file-metrics-model.d.ts +3 -1
  122. package/target/main/ts/report.d.ts +13 -1
  123. package/target/main/ts/report.js +7 -1
  124. package/target/main/ts/api/git/metabranch-worktree.d.ts +0 -1
  125. package/target/main/ts/api/git/metabranch-worktree.js +0 -35
  126. package/target/main/ts/api/worker/remote-executor.d.ts +0 -2
  127. package/target/main/ts/api/worker/remote-executor.js +0 -46
  128. package/target/main/ts/api/worker/worker-protocol.d.ts +0 -7
  129. package/target/main/ts/api/worker/worker-protocol.js +0 -127
  130. package/target/main/ts/api/worker/worker.d.ts +0 -5
  131. package/target/main/ts/api/worker/worker.js +0 -86
  132. package/target/main/ts/compose/analysis-files.d.ts +0 -15
  133. package/target/main/ts/compose/analysis-files.js +0 -129
  134. package/target/main/ts/compose/analysis-imports.d.ts +0 -7
  135. package/target/main/ts/compose/analysis-imports.js +0 -36
  136. package/target/main/ts/compose/analysis-repository.d.ts +0 -7
  137. package/target/main/ts/compose/analysis-repository.js +0 -99
  138. package/target/main/ts/compose/analysis-sources.d.ts +0 -48
  139. package/target/main/ts/compose/analysis-sources.js +0 -54
  140. package/target/main/ts/compose/prepare-metabranch.d.ts +0 -9
  141. package/target/main/ts/compose/prepare-metabranch.js +0 -17
  142. package/target/main/ts/compose/security-plugins.d.ts +0 -1
  143. package/target/main/ts/compose/security-plugins.js +0 -7
  144. package/target/main/ts/core/usecases/compare.d.ts +0 -6
  145. package/target/main/ts/core/usecases/compare.js +0 -189
  146. package/target/main/ts/report/json/store/components.d.ts +0 -2
  147. package/target/main/ts/report/json/store/components.js +0 -32
package/README.md CHANGED
@@ -40,11 +40,13 @@ Run these commands in your repository. Without an install, start each with `npx`
40
40
  | --- | --- |
41
41
  | `repometry analyze` | Analyze HEAD and save its inspection under `.repometry/`. |
42
42
  | `repometry analyze HEAD~50..HEAD --skip-saved` | Build history for the last 50 commits, oldest first, skipping saved inspections. A long range uses every core; `--concurrency N` sets a limit. |
43
- | `repometry analyze --import lcov=coverage/lcov.info --import sarif=results.sarif` | Import coverage and scanner results. Repeat `--import` for each file. |
43
+ | `repometry analyze --import lcov=coverage/lcov.info --import sarif=results.sarif` | Import coverage and scanner results. Repeat `--import` for each file. [Commands and settings](docs/cli.md#analysis-settings) lists the formats, such as `cobertura` for `coverage.xml`. |
44
44
  | `repometry view` | Open the report locally on a free port. Use `--port 3030` to choose a port. |
45
- | `repometry report html` | Export a static report to `.repometry/report/html`. Use `-o DIR` for another folder. |
45
+ | `repometry report html` | Export a static report to `.repometry/report/html`. Use `repometry report html=DIR` for another folder. |
46
46
  | `repometry review origin/main --import lcov=coverage/lcov.info` | Report the issues a change adds or worsens on the lines it changes, and their coverage. |
47
47
  | `repometry store check --repair --from git:origin/repometry` | Check saved inspections. `--repair` restores missing data from a copy. |
48
+ | `repometry history` | List saved inspections. `show REVISION` prints one report. See [Reading inspections](docs/store.md#reading-inspections). |
49
+ | `repometry projects DIR` | Build an index page for a folder of exported reports. See [Projects index](docs/cli.md#projects-index). |
48
50
  | `repometry plugins` | List supported formats. |
49
51
  | `repometry help analyze` | Get help for a command. |
50
52
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repometry",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "Track repository metrics without SaaS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -58,6 +58,7 @@
58
58
  "color": { "type": "string", "pattern": "^#[0-9A-Fa-f]{6}$" },
59
59
  "extensions": { "$ref": "#/$defs/extensions" },
60
60
  "globs": { "$ref": "#/$defs/globs" },
61
+ "syntax": { "$ref": "#/$defs/syntax" },
61
62
  "measures": {
62
63
  "type": "array",
63
64
  "uniqueItems": true,
@@ -70,6 +71,27 @@
70
71
  }
71
72
  },
72
73
  "$defs": {
74
+ "syntax": {
75
+ "type": "object",
76
+ "additionalProperties": false,
77
+ "properties": {
78
+ "lineComments": { "type": "array", "items": { "$ref": "#/$defs/syntax/$defs/marker" } },
79
+ "blockComments": { "type": "array", "items": { "type": "array", "minItems": 2, "maxItems": 2,
80
+ "items": { "$ref": "#/$defs/syntax/$defs/marker" } } },
81
+ "strings": { "type": "array", "items": {
82
+ "type": "object", "required": ["quote"], "additionalProperties": false,
83
+ "properties": { "quote": { "$ref": "#/$defs/syntax/$defs/marker" },
84
+ "multiline": { "type": "boolean" }, "raw": { "type": "boolean" } }
85
+ } },
86
+ "stringPrefixes": { "type": "array", "items": { "$ref": "#/$defs/syntax/$defs/word" } },
87
+ "keywords": { "type": "array", "maxItems": 512, "items": { "$ref": "#/$defs/syntax/$defs/word" } },
88
+ "regexAfter": { "type": "array", "items": { "$ref": "#/$defs/syntax/$defs/word" } }
89
+ },
90
+ "$defs": {
91
+ "marker": { "type": "string", "minLength": 1, "maxLength": 8, "pattern": "^\\S+$" },
92
+ "word": { "type": "string", "pattern": "^[A-Za-z_$][\\w$]*$" }
93
+ }
94
+ },
73
95
  "id": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" },
74
96
  "text": { "type": "string", "pattern": "\\S" },
75
97
  "positiveInteger": { "type": "integer", "minimum": 1, "maximum": 9007199254740991 },
@@ -23,6 +23,25 @@
23
23
  "reports": { "$ref": "#/$defs/strings" },
24
24
  "sources": { "type": "string", "minLength": 1 },
25
25
  "branch": { "type": "string", "minLength": 1 },
26
+ "components": {
27
+ "type": "array",
28
+ "items": {
29
+ "type": "object",
30
+ "required": ["name", "pathGlobs"],
31
+ "properties": {
32
+ "name": { "type": "string", "maxLength": 100, "pattern": "\\S" },
33
+ "pathGlobs": {
34
+ "type": "array",
35
+ "minItems": 1,
36
+ "items": {
37
+ "type": "string",
38
+ "pattern": "^(?![A-Za-z]:)(?:(?!\\.{1,2}(?:/|$))[^/\\\\\\u0000]+/)*(?!\\.{1,2}$)[^/\\\\\\u0000]+$"
39
+ }
40
+ },
41
+ "description": { "type": "string" }
42
+ }
43
+ }
44
+ },
26
45
  "minCoverage": { "type": "number", "minimum": 0, "maximum": 100 },
27
46
  "minLines": { "type": "integer", "minimum": 0 },
28
47
  "maxNewIssues": { "type": "integer", "minimum": 0 },
@@ -91,6 +110,7 @@
91
110
  "color": { "type": "string", "pattern": "^#[0-9A-Fa-f]{6}$" },
92
111
  "extensions": { "$ref": "#/$defs/extensions" },
93
112
  "globs": { "$ref": "#/$defs/globs" },
113
+ "syntax": { "$ref": "#/$defs/syntax" },
94
114
  "measures": {
95
115
  "type": "array",
96
116
  "uniqueItems": true,
@@ -103,6 +123,27 @@
103
123
  }
104
124
  },
105
125
  "$defs": {
126
+ "syntax": {
127
+ "type": "object",
128
+ "additionalProperties": false,
129
+ "properties": {
130
+ "lineComments": { "type": "array", "items": { "$ref": "#/$defs/syntax/$defs/marker" } },
131
+ "blockComments": { "type": "array", "items": { "type": "array", "minItems": 2, "maxItems": 2,
132
+ "items": { "$ref": "#/$defs/syntax/$defs/marker" } } },
133
+ "strings": { "type": "array", "items": {
134
+ "type": "object", "required": ["quote"], "additionalProperties": false,
135
+ "properties": { "quote": { "$ref": "#/$defs/syntax/$defs/marker" },
136
+ "multiline": { "type": "boolean" }, "raw": { "type": "boolean" } }
137
+ } },
138
+ "stringPrefixes": { "type": "array", "items": { "$ref": "#/$defs/syntax/$defs/word" } },
139
+ "keywords": { "type": "array", "maxItems": 512, "items": { "$ref": "#/$defs/syntax/$defs/word" } },
140
+ "regexAfter": { "type": "array", "items": { "$ref": "#/$defs/syntax/$defs/word" } }
141
+ },
142
+ "$defs": {
143
+ "marker": { "type": "string", "minLength": 1, "maxLength": 8, "pattern": "^\\S+$" },
144
+ "word": { "type": "string", "pattern": "^[A-Za-z_$][\\w$]*$" }
145
+ }
146
+ },
106
147
  "id": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" },
107
148
  "text": { "type": "string", "pattern": "\\S" },
108
149
  "positiveInteger": { "type": "integer", "minimum": 1, "maximum": 9007199254740991 },
@@ -16,7 +16,8 @@
16
16
  "items": {
17
17
  "type": "object",
18
18
  "required": ["id", "analysed"],
19
- "properties": { "id": { "type": "string" }, "label": { "type": "string" }, "color": { "type": "string", "pattern": "^#[a-fA-F0-9]{6}$" }, "analysed": { "type": "boolean" } },
19
+ "properties": { "id": { "type": "string" }, "label": { "type": "string" }, "color": { "type": "string", "pattern": "^#[a-fA-F0-9]{6}$" }, "analysed": { "type": "boolean" },
20
+ "syntax": { "$ref": "#/$defs/syntax" } },
20
21
  "additionalProperties": false
21
22
  }
22
23
  },
@@ -50,6 +51,27 @@
50
51
  },
51
52
  "additionalProperties": false,
52
53
  "$defs": {
54
+ "syntax": {
55
+ "type": "object",
56
+ "additionalProperties": false,
57
+ "properties": {
58
+ "lineComments": { "type": "array", "items": { "$ref": "#/$defs/syntax/$defs/marker" } },
59
+ "blockComments": { "type": "array", "items": { "type": "array", "minItems": 2, "maxItems": 2,
60
+ "items": { "$ref": "#/$defs/syntax/$defs/marker" } } },
61
+ "strings": { "type": "array", "items": {
62
+ "type": "object", "required": ["quote"], "additionalProperties": false,
63
+ "properties": { "quote": { "$ref": "#/$defs/syntax/$defs/marker" },
64
+ "multiline": { "type": "boolean" }, "raw": { "type": "boolean" } }
65
+ } },
66
+ "stringPrefixes": { "type": "array", "items": { "$ref": "#/$defs/syntax/$defs/word" } },
67
+ "keywords": { "type": "array", "maxItems": 512, "items": { "$ref": "#/$defs/syntax/$defs/word" } },
68
+ "regexAfter": { "type": "array", "items": { "$ref": "#/$defs/syntax/$defs/word" } }
69
+ },
70
+ "$defs": {
71
+ "marker": { "type": "string", "minLength": 1, "maxLength": 8, "pattern": "^\\S+$" },
72
+ "word": { "type": "string", "pattern": "^[A-Za-z_$][\\w$]*$" }
73
+ }
74
+ },
53
75
  "count": { "$ref": "urn:repometry:schema:report:2#/$defs/count" },
54
76
  "optionalCount": { "anyOf": [{ "$ref": "#/$defs/count" }, { "type": "null" }] },
55
77
  "observations": {
@@ -0,0 +1,100 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "urn:repometry:schema:pull-review:2",
4
+ "type": "object",
5
+ "required": ["schema", "number", "generatedAt", "base", "mergeBase", "head", "changedFiles", "verdict", "issues", "debt", "coverage", "issueGate", "unmeasured", "notes"],
6
+ "properties": {
7
+ "schema": { "const": "urn:repometry:schema:pull-review:2" },
8
+ "number": { "type": ["integer", "null"], "minimum": 1, "maximum": 9007199254740991 },
9
+ "generatedAt": { "type": "string" },
10
+ "base": { "type": "string", "minLength": 1 },
11
+ "mergeBase": { "$ref": "urn:repometry:schema:diff-coverage:1#/$defs/sha" },
12
+ "head": { "$ref": "urn:repometry:schema:diff-coverage:1#/$defs/sha" },
13
+ "changedFiles": { "$ref": "urn:repometry:schema:report:2#/$defs/count" },
14
+ "verdict": { "enum": ["passed", "failed", "unmeasured"] },
15
+ "issues": { "type": "array", "items": { "$ref": "#/$defs/issue" } },
16
+ "debt": {
17
+ "type": "object",
18
+ "required": ["added", "removed"],
19
+ "properties": {
20
+ "added": { "$ref": "urn:repometry:schema:report:2#/$defs/count" },
21
+ "removed": { "$ref": "urn:repometry:schema:report:2#/$defs/count" }
22
+ },
23
+ "additionalProperties": false
24
+ },
25
+ "coverage": { "$ref": "#/$defs/coverage" },
26
+ "issueGate": {
27
+ "type": "object",
28
+ "required": ["maximum", "count", "status"],
29
+ "properties": {
30
+ "maximum": { "$ref": "urn:repometry:schema:report:2#/$defs/count" },
31
+ "count": { "$ref": "urn:repometry:schema:report:2#/$defs/count" },
32
+ "status": { "enum": ["passed", "failed"] }
33
+ },
34
+ "additionalProperties": false
35
+ },
36
+ "unmeasured": { "type": "array", "items": { "$ref": "#/$defs/reason" } },
37
+ "notes": { "type": "array", "items": { "$ref": "#/$defs/reason" } }
38
+ },
39
+ "additionalProperties": false,
40
+ "$defs": {
41
+ "issue": {
42
+ "type": "object",
43
+ "required": ["effect", "finding", "before", "fixed", "context", "debtMinutes"],
44
+ "properties": {
45
+ "effect": { "enum": ["new", "worsened", "improved", "touched"] },
46
+ "finding": { "$ref": "urn:repometry:schema:report:2#/$defs/finding" },
47
+ "before": { "type": ["number", "null"], "minimum": 0 },
48
+ "fixed": { "type": "boolean" },
49
+ "context": { "$ref": "urn:repometry:schema:report:2#/$defs/finding/properties/related" },
50
+ "debtMinutes": { "type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991 }
51
+ },
52
+ "additionalProperties": false
53
+ },
54
+ "coverage": {
55
+ "type": "object",
56
+ "required": ["imported", "covered", "total", "percent", "uncovered", "unmapped", "gate"],
57
+ "properties": {
58
+ "imported": { "type": "boolean" },
59
+ "covered": { "$ref": "urn:repometry:schema:report:2#/$defs/count" },
60
+ "total": { "$ref": "urn:repometry:schema:report:2#/$defs/count" },
61
+ "percent": { "$ref": "urn:repometry:schema:diff-coverage:1#/properties/percent" },
62
+ "uncovered": {
63
+ "type": "array",
64
+ "items": {
65
+ "type": "object",
66
+ "required": ["path", "first", "last"],
67
+ "properties": {
68
+ "path": { "type": "string", "minLength": 1 },
69
+ "first": { "type": "integer", "minimum": 1 },
70
+ "last": { "type": "integer", "minimum": 1 }
71
+ },
72
+ "additionalProperties": false
73
+ }
74
+ },
75
+ "unmapped": { "$ref": "urn:repometry:schema:diff-coverage:1#/properties/gaps" },
76
+ "gate": {
77
+ "type": ["object", "null"],
78
+ "required": ["minimumPercent", "minimumLines", "status"],
79
+ "properties": {
80
+ "minimumPercent": { "$ref": "urn:repometry:schema:diff-coverage:1#/$defs/percent" },
81
+ "minimumLines": { "$ref": "urn:repometry:schema:report:2#/$defs/count" },
82
+ "status": { "enum": ["passed", "failed", "not-applicable"] }
83
+ },
84
+ "additionalProperties": false
85
+ }
86
+ },
87
+ "additionalProperties": false
88
+ },
89
+ "reason": {
90
+ "type": "object",
91
+ "required": ["message"],
92
+ "properties": {
93
+ "message": { "type": "string" },
94
+ "path": { "type": "string" },
95
+ "operation": { "type": "string" }
96
+ },
97
+ "additionalProperties": false
98
+ }
99
+ }
100
+ }
@@ -1,3 +1,3 @@
1
1
  export declare function cacheRoot(env?: NodeJS.ProcessEnv, system?: NodeJS.Platform, home?: string): string;
2
2
  export declare const goParserCacheDirectory = "go-parsers-v1";
3
- export declare function clearCaches(root: string, sourcesOnly: boolean): Promise<readonly string[]>;
3
+ export declare function clearCaches(root: string): Promise<readonly string[]>;
@@ -13,8 +13,8 @@ export function cacheRoot(env = process.env, system = process.platform, home = h
13
13
  return join(home, '.cache', 'repometry');
14
14
  }
15
15
  export const goParserCacheDirectory = 'go-parsers-v1';
16
- export async function clearCaches(root, sourcesOnly) {
17
- const directories = sourcesOnly ? ['sources'] : ['sources', goParserCacheDirectory];
16
+ export async function clearCaches(root) {
17
+ const directories = ['sources', goParserCacheDirectory];
18
18
  await Promise.all(directories.map(directory => rm(join(root, directory), { recursive: true, force: true })));
19
19
  return directories;
20
20
  }
@@ -1,8 +1,4 @@
1
- import type { DiffCoverageReport } from '../../core/usecases/diff-coverage.js';
2
1
  import type { PullReview } from '../../core/model/pull-review.js';
3
- import type { Report } from '../../core/model/report.js';
4
- export declare function writeGitHubResult(report: Report): Promise<void>;
5
- export declare function writeGitHubDiffCoverage(report: DiffCoverageReport): Promise<void>;
6
2
  /** The number of the pull request whose event started this GitHub Actions run, if any. */
7
3
  export declare function gitHubPullRequest(): Promise<number | undefined>;
8
4
  export declare function writeGitHubReview(review: PullReview, markdown: string, repository: string): Promise<void>;
@@ -2,28 +2,6 @@ import { appendFile, readFile, realpath } from 'node:fs/promises';
2
2
  import { isAbsolute, relative, resolve, sep } from 'node:path';
3
3
  import { isRecord } from '../../core/engine/plugin.js';
4
4
  import { annotationLimit } from '../../core/model/pull-review.js';
5
- export async function writeGitHubResult(report) {
6
- const { output, summary } = githubFiles();
7
- await appendFile(output, `subject=${report.subject.id}\nstatus=${report.status}\n`);
8
- await appendFile(summary, [
9
- '## Repometry', '',
10
- `**${report.status}** · \`${report.subject.id}\``, '',
11
- `Parsed ${report.scope.parsed} of ${report.scope.files} files.`,
12
- `Measurements: ${report.measurements.length}. Diagnostics: ${report.diagnostics.length}.`, '', '',
13
- ].join('\n'));
14
- }
15
- export async function writeGitHubDiffCoverage(report) {
16
- const { output, summary } = githubFiles();
17
- const decision = report.decision?.status ?? '';
18
- await appendFile(output, `status=${report.status}\npercent=${report.percent ?? ''}\ndecision=${decision}\n`);
19
- const observed = report.percent === null ? '—' : `${report.percent.toFixed(2)}%`;
20
- const policy = report.decision === null ? [] : [`Minimum ${report.decision.minimumPercent}% · **${report.decision.status}**`];
21
- await appendFile(summary, ['## Repometry diff coverage', '',
22
- `**${report.status}** · \`${report.base}\` → \`${report.head}\``, '',
23
- `Observed coverage ${observed} (${report.covered}/${report.total} reported lines). Gaps: ${report.gaps.length}.`,
24
- ...policy, '', '',
25
- ].join('\n'));
26
- }
27
5
  /** The number of the pull request whose event started this GitHub Actions run, if any. */
28
6
  export async function gitHubPullRequest() {
29
7
  const path = process.env.GITHUB_EVENT_PATH;
@@ -35,10 +13,9 @@ export async function gitHubPullRequest() {
35
13
  return typeof number === 'number' && Number.isSafeInteger(number) && number > 0 ? number : undefined;
36
14
  }
37
15
  export async function writeGitHubReview(review, markdown, repository) {
38
- const { output, summary } = githubFiles();
39
- const count = (effect) => review.issues.filter(issue => issue.effect === effect).length;
40
- await appendFile(output, [`verdict=${review.verdict}`, ...['new', 'worsened', 'improved', 'touched'].map(effect => `${effect}=${count(effect)}`),
41
- `changed-coverage=${review.coverage.percent ?? ''}`, ''].join('\n'));
16
+ const summary = process.env.GITHUB_STEP_SUMMARY;
17
+ if (!summary)
18
+ throw new Error('GitHub reporting requires GITHUB_STEP_SUMMARY');
42
19
  await appendFile(summary, markdown);
43
20
  const annotate = await annotator(repository);
44
21
  review.issues.filter(issue => issue.effect === 'new' || issue.effect === 'worsened').slice(0, annotationLimit)
@@ -67,11 +44,4 @@ function data(value) {
67
44
  function property(value) {
68
45
  return data(value).replaceAll(':', '%3A').replaceAll(',', '%2C');
69
46
  }
70
- function githubFiles() {
71
- const output = process.env.GITHUB_OUTPUT;
72
- const summary = process.env.GITHUB_STEP_SUMMARY;
73
- if (!output || !summary)
74
- throw new Error('GitHub reporting requires GITHUB_OUTPUT and GITHUB_STEP_SUMMARY');
75
- return { output, summary };
76
- }
77
47
  //# sourceMappingURL=github.js.map
@@ -1,3 +1,2 @@
1
1
  import type { ReadCommitMetadata } from '../../report/json/projections/commit-summary.js';
2
2
  export declare function commitMetadataReader(repository: string): ReadCommitMetadata;
3
- export declare function resolveGitBranch(repository: string, name: string): Promise<string>;
@@ -1,4 +1,4 @@
1
- import { gitText, resolveGitCommit } from './git.js';
1
+ import { gitText } from './git.js';
2
2
  export function commitMetadataReader(repository) {
3
3
  return async (revisions) => {
4
4
  const result = new Map();
@@ -43,13 +43,4 @@ async function tagsByCommit(repository) {
43
43
  }
44
44
  return result;
45
45
  }
46
- export async function resolveGitBranch(repository, name) {
47
- await gitText(repository, ['check-ref-format', `refs/heads/${name}`]);
48
- try {
49
- return await resolveGitCommit(repository, `refs/heads/${name}`);
50
- }
51
- catch {
52
- return resolveGitCommit(repository, `refs/remotes/origin/${name}`);
53
- }
54
- }
55
46
  //# sourceMappingURL=commit-metadata.js.map
@@ -0,0 +1,2 @@
1
+ import type { CoverageSource } from './go-cover.js';
2
+ export declare function coberturaToLcov(text: string, input: string, source: CoverageSource): string;
@@ -0,0 +1,160 @@
1
+ import { posix, win32 } from 'node:path';
2
+ import { comparePaths } from '../../core/model/snapshot.js';
3
+ import { readCoverageXml } from './coverage-xml.js';
4
+ export function coberturaToLcov(text, input, source) {
5
+ const invalid = (line, reason) => { throw new Error('Invalid Cobertura report ' + input + ' at line ' + line + ': ' + reason); };
6
+ const { classes, sources } = parse(text, invalid);
7
+ const resolve = coveragePaths(source, sources);
8
+ const files = new Map();
9
+ for (const item of classes) {
10
+ const path = resolve(item.filename);
11
+ if (/[\r\n\0]/.test(path))
12
+ invalid(item.xmlLine, 'filename contains a line break or NUL');
13
+ const file = files.get(path) ?? { lines: new Map(), methods: [] };
14
+ files.set(path, file);
15
+ for (const line of item.lines.values())
16
+ mergeLine(file, line);
17
+ for (const method of item.methods)
18
+ file.methods.push(method);
19
+ }
20
+ return render(files);
21
+ }
22
+ const [sourcesPath, classesPath] = ['coverage/sources', 'coverage/packages/package/classes'];
23
+ const methodsPath = classesPath + '/class/methods';
24
+ const maxBranches = 2 ** 24; // Each branch becomes an entry of one Map, which holds at most 2^24.
25
+ function parse(input, invalid) {
26
+ const classes = [];
27
+ let branches = 0;
28
+ const sources = [];
29
+ let current;
30
+ let method;
31
+ let sourceText;
32
+ readCoverageXml(input, invalid, {
33
+ open(name, attributes, parents, line) {
34
+ const path = parents.join('/');
35
+ if (name === 'source' && path === sourcesPath)
36
+ sourceText = [];
37
+ if (name === 'class' && path === classesPath) {
38
+ const filename = attributes.get('filename');
39
+ if (!filename?.trim())
40
+ return invalid(line, '<class> has no filename');
41
+ current = { filename, name: attributes.get('name') ?? '', lines: new Map(), methods: [], xmlLine: line };
42
+ classes.push(current);
43
+ }
44
+ if (!current)
45
+ return;
46
+ if (name === 'method' && path === methodsPath) {
47
+ const key = current.name + '.' + (attributes.get('name') ?? '') + (attributes.get('signature') ?? '');
48
+ if (/[\r\n\0]/.test(key))
49
+ invalid(line, 'method name contains a line break or NUL');
50
+ method = { key };
51
+ current.methods.push(method);
52
+ }
53
+ if (name !== 'line')
54
+ return;
55
+ if (path === classesPath + '/class/lines') {
56
+ const entry = readLine(attributes, line, invalid, true);
57
+ branches += entry.branches?.total ?? 0;
58
+ if (branches > maxBranches)
59
+ invalid(line, 'too many branches');
60
+ mergeLine(current, entry);
61
+ }
62
+ if (method && path === methodsPath + '/method/lines') {
63
+ const entry = readLine(attributes, line, invalid, false);
64
+ if (!method.first || entry.number < method.first.number)
65
+ method.first = entry;
66
+ }
67
+ },
68
+ close(name, parents) {
69
+ const path = parents.join('/');
70
+ if (name === 'source' && path === sourcesPath && sourceText) {
71
+ const value = sourceText.join('').trim();
72
+ if (value)
73
+ sources.push(value);
74
+ sourceText = undefined;
75
+ }
76
+ if (name === 'class' && path === classesPath)
77
+ current = undefined;
78
+ if (name === 'method' && path === methodsPath)
79
+ method = undefined;
80
+ },
81
+ text(value, parents) {
82
+ if (sourceText && parents.join('/') === sourcesPath + '/source')
83
+ sourceText.push(value);
84
+ },
85
+ });
86
+ return { classes, sources };
87
+ }
88
+ function readLine(attributes, xmlLine, invalid, classLine) {
89
+ const rawLine = attributes.get('number') ?? '';
90
+ const rawHits = attributes.get('hits') ?? '';
91
+ const number = Number(rawLine);
92
+ const hits = Number(rawHits);
93
+ if (!/^\d+$/.test(rawLine) || !Number.isSafeInteger(number) || number === 0)
94
+ invalid(xmlLine, 'line number must be a positive integer');
95
+ if (!/^\d+$/.test(rawHits))
96
+ invalid(xmlLine, 'hits must be a non-negative integer');
97
+ if (!Number.isSafeInteger(hits))
98
+ invalid(xmlLine, 'hit count exceeds the supported integer range');
99
+ return { number, hits, branches: classLine ? readBranches(attributes.get('condition-coverage'), xmlLine, invalid) : undefined };
100
+ }
101
+ function readBranches(value, xmlLine, invalid) {
102
+ const match = value === undefined ? null : /^\d+(?:\.\d+)?%\s*\((\d+)\/(\d+)\)$/.exec(value);
103
+ if (!match)
104
+ return undefined;
105
+ const covered = Number(match[1]);
106
+ const total = Number(match[2]);
107
+ if (!Number.isSafeInteger(total) || !Number.isSafeInteger(covered) || total === 0 || covered > total) {
108
+ invalid(xmlLine, 'invalid condition-coverage ' + JSON.stringify(value));
109
+ }
110
+ return { covered, total };
111
+ }
112
+ function mergeLine(file, line) {
113
+ const previous = file.lines.get(line.number);
114
+ const before = previous?.branches;
115
+ const next = line.branches;
116
+ const branches = next && (!before || next.total > before.total || (next.total === before.total && next.covered > before.covered))
117
+ ? next : before;
118
+ file.lines.set(line.number, { number: line.number, hits: Math.max(line.hits, previous?.hits ?? 0), branches });
119
+ }
120
+ function coveragePaths({ root, snapshot }, sources) {
121
+ const platform = win32.isAbsolute(root) && !posix.isAbsolute(root) ? win32 : posix;
122
+ const slash = (path) => platform === win32 ? path.replaceAll('\\', '/') : path;
123
+ const known = new Set([...snapshot.files.map(file => file.path), ...(snapshot.generatedExcluded ?? []),
124
+ ...(snapshot.inventory?.map(file => file.path) ?? [])]);
125
+ const normalize = (path) => slash(platform.isAbsolute(path) ? platform.relative(root, path) || '.' : platform.normalize(path));
126
+ const paths = new Map();
127
+ return (filename) => {
128
+ const prior = paths.get(filename);
129
+ if (prior !== undefined)
130
+ return prior;
131
+ const candidates = platform.isAbsolute(filename) ? [normalize(filename)]
132
+ : [...sources.map(source => normalize(platform.join(source, filename))), normalize(filename)];
133
+ const matches = [...new Set(candidates)].filter(path => known.has(path));
134
+ if (matches.length > 1)
135
+ throw new Error('Ambiguous Cobertura source ' + JSON.stringify(filename) + ': ' + matches.sort(comparePaths).join(', '));
136
+ const selected = matches[0] ?? candidates.at(-1); // An unknown relative filename stays relative to the root.
137
+ paths.set(filename, selected);
138
+ return selected;
139
+ };
140
+ }
141
+ function render(files) {
142
+ const output = [];
143
+ for (const [path, { lines, methods }] of [...files].sort(([left], [right]) => comparePaths(left, right))) {
144
+ output.push('SF:' + path);
145
+ for (const { key, first } of methods)
146
+ if (first)
147
+ output.push('FN:' + first.number + ',' + key, 'FNDA:' + first.hits + ',' + key);
148
+ for (const { number, hits, branches } of [...lines.values()].sort((a, b) => a.number - b.number)) {
149
+ output.push('DA:' + number + ',' + hits);
150
+ if (!branches)
151
+ continue;
152
+ const prefix = 'BRDA:' + number + ',0,';
153
+ for (let index = 0; index < branches.total; index++)
154
+ output.push(prefix + index + ',' + Number(index < branches.covered));
155
+ }
156
+ output.push('end_of_record');
157
+ }
158
+ return output.join('\n');
159
+ }
160
+ //# sourceMappingURL=cobertura.js.map
@@ -0,0 +1,7 @@
1
+ interface XmlVisitor {
2
+ open(name: string, attributes: ReadonlyMap<string, string>, parents: readonly string[], line: number): void;
3
+ close(name: string, parents: readonly string[]): void;
4
+ text(value: string, parents: readonly string[]): void;
5
+ }
6
+ export declare function readCoverageXml(input: string, invalid: (line: number, reason: string) => never, visitor: XmlVisitor): void;
7
+ export {};