repometry 0.8.1 → 0.10.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 (53) hide show
  1. package/README.md +2 -1
  2. package/package.json +1 -1
  3. package/target/main/resources/languages/go/parser.go +25 -5
  4. package/target/main/resources/languages/python/parser.py +12 -1
  5. package/target/main/resources/report/json/config-v1.schema.json +0 -1
  6. package/target/main/resources/report/json/report-v2.schema.json +12 -0
  7. package/target/main/ts/api/gh/github.d.ts +3 -1
  8. package/target/main/ts/api/gh/github.js +39 -54
  9. package/target/main/ts/api/git/changes.d.ts +6 -1
  10. package/target/main/ts/api/git/changes.js +19 -10
  11. package/target/main/ts/api/git/git-churn.js +38 -37
  12. package/target/main/ts/api/git/line-changes.d.ts +6 -0
  13. package/target/main/ts/api/git/line-changes.js +57 -0
  14. package/target/main/ts/cli/config.d.ts +2 -1
  15. package/target/main/ts/cli/config.js +12 -5
  16. package/target/main/ts/cli/main.js +33 -38
  17. package/target/main/ts/compose/review.d.ts +24 -13
  18. package/target/main/ts/compose/review.js +46 -32
  19. package/target/main/ts/core/model/changes.d.ts +29 -0
  20. package/target/main/ts/core/model/code-structure.d.ts +2 -0
  21. package/target/main/ts/core/model/code-structure.js +8 -2
  22. package/target/main/ts/core/model/finding.d.ts +6 -0
  23. package/target/main/ts/core/model/finding.js +23 -8
  24. package/target/main/ts/core/model/pull-review.d.ts +52 -30
  25. package/target/main/ts/core/model/pull-review.js +4 -1
  26. package/target/main/ts/core/usecases/review-effect.d.ts +18 -0
  27. package/target/main/ts/core/usecases/review-effect.js +37 -0
  28. package/target/main/ts/core/usecases/review-match.d.ts +14 -0
  29. package/target/main/ts/core/usecases/review-match.js +72 -0
  30. package/target/main/ts/core/usecases/review-position.d.ts +14 -0
  31. package/target/main/ts/core/usecases/review-position.js +53 -0
  32. package/target/main/ts/core/usecases/review-scope.d.ts +21 -0
  33. package/target/main/ts/core/usecases/review-scope.js +41 -0
  34. package/target/main/ts/core/usecases/review.d.ts +32 -21
  35. package/target/main/ts/core/usecases/review.js +89 -114
  36. package/target/main/ts/index.d.ts +4 -3
  37. package/target/main/ts/index.js +1 -1
  38. package/target/main/ts/plugins/duplication/duplication.js +1 -1
  39. package/target/main/ts/plugins/language-js/babel-provider.js +4 -2
  40. package/target/main/ts/plugins/language-js/function-facts.d.ts +3 -3
  41. package/target/main/ts/plugins/language-js/function-facts.js +3 -15
  42. package/target/main/ts/plugins/language-js/qualified-names.d.ts +11 -0
  43. package/target/main/ts/plugins/language-js/qualified-names.js +63 -0
  44. package/target/main/ts/plugins/language-js/structural-observations.d.ts +2 -1
  45. package/target/main/ts/plugins/language-js/structural-observations.js +18 -14
  46. package/target/main/ts/plugins/maintainability/structural-smells.js +3 -2
  47. package/target/main/ts/report/html/app/viewer-chart-bars.js +9 -5
  48. package/target/main/ts/report/json/store/pull-review-store.d.ts +0 -1
  49. package/target/main/ts/report/json/store/pull-review-store.js +2 -20
  50. package/target/main/ts/report/json/wire/pull-review-model.d.ts +49 -2
  51. package/target/main/ts/report/json/wire/pull-review-model.js +2 -0
  52. package/target/main/ts/report/markdown/pull-review.d.ts +5 -0
  53. package/target/main/ts/report/markdown/pull-review.js +132 -0
@@ -1,10 +1,10 @@
1
- import { isClass, isFunction, isIdentifier, isVariableDeclarator } from '@babel/types';
2
- import { children, functionName } from './function-facts.js';
1
+ import { isClass, isFunction } from '@babel/types';
2
+ import { children } from './function-facts.js';
3
3
  const complexityBlocks = new Set([
4
4
  'IfStatement', 'ConditionalExpression', 'ForStatement', 'ForInStatement', 'ForOfStatement',
5
5
  'WhileStatement', 'DoWhileStatement', 'CatchClause', 'SwitchStatement',
6
6
  ]);
7
- export function structuralObservations(ast) {
7
+ export function structuralObservations(ast, names) {
8
8
  const observations = [];
9
9
  const cognitiveFunctions = [];
10
10
  let cognitive = 0;
@@ -20,21 +20,23 @@ export function structuralObservations(ast) {
20
20
  if (isClass(node))
21
21
  classes++;
22
22
  if (isFunction(node) && node.body) {
23
- const own = { cognitive: 0, returns: 0, maxNesting: 0 };
23
+ const naming = names.get(node);
24
+ const own = { cognitive: 0, returns: 0, maxNesting: 0, anchor: naming?.anchor };
24
25
  visit(node.body, own, 0, node);
25
26
  for (const parameter of node.params)
26
27
  visit(parameter, own, 0, node);
27
- const name = isVariableDeclarator(parent) && isIdentifier(parent.id) ? parent.id.name : functionName(node);
28
+ const name = naming?.name;
28
29
  const start = node.loc?.start;
29
30
  cognitiveFunctions.push({ line: start?.line,
30
31
  column: start === undefined ? undefined : start.column + 1, name, value: own.cognitive });
31
32
  const label = name ?? '(anonymous)';
32
33
  cognitive += own.cognitive;
33
- observe('function-parameters', node.params.length, `${label} · Parameters`, node);
34
- observe('return-statements', own.returns, `${label} · Return statements`, node);
35
- observe('function-complexity', own.cognitive, `${label} · Cognitive complexity`, node);
36
- if (own.nestedRange !== undefined)
37
- observe('nested-control-flow', own.maxNesting, `${label} · Control-flow depth`, own.nestedRange);
34
+ observe('function-parameters', node.params.length, `${label} · Parameters`, node, own.anchor);
35
+ observe('return-statements', own.returns, `${label} · Return statements`, node, own.anchor);
36
+ observe('function-complexity', own.cognitive, `${label} · Cognitive complexity`, node, own.anchor);
37
+ if (own.nestedRange !== undefined) {
38
+ observe('nested-control-flow', own.maxNesting, `${label} · Control-flow depth`, own.nestedRange, own.anchor);
39
+ }
38
40
  return;
39
41
  }
40
42
  if (node.type === 'ReturnStatement')
@@ -44,8 +46,9 @@ export function structuralObservations(ast) {
44
46
  if (node.type === 'LogicalExpression') {
45
47
  if (parent?.type !== 'LogicalExpression' || parent.operator !== node.operator)
46
48
  frame.cognitive++;
47
- if (parent?.type !== 'LogicalExpression')
48
- observe('boolean-logic', countLogicalOperators(node), 'Logical operators in one expression', node);
49
+ if (parent?.type !== 'LogicalExpression') {
50
+ observe('boolean-logic', countLogicalOperators(node), 'Logical operators in one expression', node, frame.anchor);
51
+ }
49
52
  }
50
53
  const block = complexityBlocks.has(node.type);
51
54
  const chained = node.type === 'IfStatement' && parent?.type === 'IfStatement' && parent.alternate === node;
@@ -69,8 +72,9 @@ export function structuralObservations(ast) {
69
72
  visit(child, frame, depth + Number(block || node.type === 'TryStatement'), node);
70
73
  }
71
74
  }
72
- function observe(rule, value, label, location) {
73
- observations.push({ rule, value, label, line: location?.loc?.start.line, endLine: location?.loc?.end.line });
75
+ function observe(rule, value, label, location, anchor) {
76
+ observations.push({ rule, value, label, line: location?.loc?.start.line, endLine: location?.loc?.end.line,
77
+ ...(anchor === undefined ? {} : { anchor }) });
74
78
  }
75
79
  }
76
80
  function countLogicalOperators(node) {
@@ -3,13 +3,14 @@ export function structuralSmells(path, observations) {
3
3
  const findings = [];
4
4
  const functionLimit = structuralRules['function-complexity'].limit;
5
5
  const functionExcess = observations.reduce((total, { rule, value }) => total + (rule === 'function-complexity' ? Math.max(0, value - functionLimit) : 0), 0);
6
- for (const { rule, value, label, line, endLine } of observations) {
6
+ for (const { rule, value, label, line, endLine, anchor } of observations) {
7
7
  const { limit, minutesPerExcess } = structuralRules[rule];
8
8
  if (value <= limit)
9
9
  continue;
10
10
  const chargedExcess = rule === 'file-complexity' ? Math.max(0, value - limit - functionExcess) : value - limit;
11
11
  findings.push({ tool: 'repometry', rule, category: 'structure', level: 'medium', path,
12
- message: `${label} ${value} (limit ${limit})`, line, endLine, effortMinutes: chargedExcess * minutesPerExcess });
12
+ message: `${label} ${value} (limit ${limit})`, line, endLine, effortMinutes: chargedExcess * minutesPerExcess,
13
+ value, limit, anchor: anchor ?? '(file)' });
13
14
  }
14
15
  return findings;
15
16
  }
@@ -2,6 +2,11 @@ import { markBoundaries, measuredValues, pointLink } from './viewer-chart-points
2
2
  import { yAxis } from './viewer-chart-scale.js';
3
3
  import { centredText, line, setAttributes, svgNode } from './viewer-chart-svg.js';
4
4
  import { placeX } from './viewer-chart-x.js';
5
+ /** One width for every bar, set by the two closest inspections: only a bar's height says how much changed. */
6
+ function barWidth(xs) {
7
+ const gaps = xs.slice(1).map((at, index) => at - xs[index]);
8
+ return Math.max(2, Math.min(28, gaps.length ? Math.min(...gaps) * .62 : 28));
9
+ }
5
10
  /** The room beside a bar: the distance to the nearer neighbour. */
6
11
  function room(x, count, index) {
7
12
  const before = index > 0 ? x(index) - x(index - 1) : Infinity;
@@ -9,7 +14,7 @@ function room(x, count, index) {
9
14
  return Math.min(before, after);
10
15
  }
11
16
  /** A bar from zero to the value, labelled where the label fits or the commit is the selected one. */
12
- function bar({ points, x, y, format, upIsWorse }, index, width, space) {
17
+ function bar({ points, x, y, format, upIsWorse, width }, index, space) {
13
18
  const point = points[index];
14
19
  const value = point.value;
15
20
  const worse = upIsWorse ? value > 0 : value < 0;
@@ -22,16 +27,15 @@ function bar({ points, x, y, format, upIsWorse }, index, width, space) {
22
27
  }
23
28
  /** A point's marks: its bar, a flat mark for no change, or a tick on the zero line where nothing was measured. */
24
29
  function barMarks(context, index) {
25
- const { points, x, y } = context;
30
+ const { points, x, y, width } = context;
26
31
  const value = points[index].value;
27
32
  const space = room(x, points.length, index);
28
- const width = Math.max(2, Math.min(28, Number.isFinite(space) ? space * .62 : 28));
29
33
  const cx = x(index);
30
34
  if (value === null)
31
35
  return [line('tc-missing-mark', { x1: cx, x2: cx, y1: y(0) - 3.5, y2: y(0) + 3.5 })];
32
36
  if (value === 0)
33
37
  return [line('tc-zero-mark', { x1: cx - width / 2, x2: cx + width / 2, y1: y(0), y2: y(0) })];
34
- return bar(context, index, width, space);
38
+ return bar(context, index, space);
35
39
  }
36
40
  export function barChart(svg, layout, points, options) {
37
41
  svg.classList.add('tc-bars');
@@ -43,7 +47,7 @@ export function barChart(svg, layout, points, options) {
43
47
  layout.ys = points.map(point => point.value === null ? null : y(point.value));
44
48
  // In a long history the zero line already says "no change" and "not measured"; only bars that moved are drawn.
45
49
  const dense = layout.xs.some((at, index) => index > 0 && at - layout.xs[index - 1] < 7);
46
- const context = { ...options, points, x, y };
50
+ const context = { ...options, points, x, y, width: barWidth(layout.xs) };
47
51
  for (const [index, point] of points.entries()) {
48
52
  const link = pointLink(point, index);
49
53
  const quiet = !point.current && !point.value;
@@ -1,3 +1,2 @@
1
1
  import type { PullReview } from '../wire/pull-review-model.js';
2
- export declare function savePullReview(output: string, review: PullReview): Promise<void>;
3
2
  export declare function listPullReviews(output: string): Promise<readonly PullReview[]>;
@@ -1,5 +1,4 @@
1
- import { randomUUID } from 'node:crypto';
2
- import { lstat, mkdir, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises';
1
+ import { lstat, readFile, readdir } from 'node:fs/promises';
3
2
  import { join } from 'node:path';
4
3
  import { Ajv2020 } from 'ajv/dist/2020.js';
5
4
  import metricCatalog from '../../../../resources/report/json/metric-catalog-v1.schema.json' with { type: 'json' };
@@ -8,25 +7,8 @@ import diffCoverage from '../../../../resources/report/json/diff-coverage-v1.sch
8
7
  import currentInspection from '../../../../resources/report/json/report-v2.schema.json' with { type: 'json' };
9
8
  import schema from '../../../../resources/report/json/pull-review-v1.schema.json' with { type: 'json' };
10
9
  const ajv = new Ajv2020({ schemas: [metricCatalog, currentInspection, comparison, diffCoverage] });
10
+ /** Reviews saved before 0.9 stay readable for the viewer; review no longer saves them. */
11
11
  const validate = ajv.compile(schema);
12
- export async function savePullReview(output, review) {
13
- if (!validate(review))
14
- throw new Error(`Invalid pull request review: ${ajv.errorsText(validate.errors)}`);
15
- if (review.number === null)
16
- throw new Error('Saving a pull request review requires its number');
17
- const directory = join(output, 'reviews');
18
- await mkdir(directory, { recursive: true, mode: 0o700 });
19
- if (!(await lstat(directory)).isDirectory())
20
- throw new Error('Expected a directory for PR reviews');
21
- const temporary = join(directory, `.review-${randomUUID()}.tmp`);
22
- try {
23
- await writeFile(temporary, `${JSON.stringify(review, null, 2)}\n`, { flag: 'wx', mode: 0o600 });
24
- await rename(temporary, join(directory, `${review.number}.json`));
25
- }
26
- finally {
27
- await rm(temporary, { force: true });
28
- }
29
- }
30
12
  export async function listPullReviews(output) {
31
13
  const directory = join(output, 'reviews');
32
14
  try {
@@ -1,7 +1,54 @@
1
- import type { PullReview } from '../../../core/model/pull-review.js';
2
- export type { PullReview } from '../../../core/model/pull-review.js';
1
+ import type { DiffCoverage } from '../../../core/model/diff-coverage.js';
2
+ import type { InspectionComparison } from '../../../core/model/comparison.js';
3
+ import type { Finding } from '../../../core/model/finding.js';
4
+ /** Reviews saved before 0.9 under `reviews/<number>.json`; the viewer lists them. */
5
+ export declare const storedPullReviewSchema = "urn:repometry:schema:pull-review:1";
6
+ type LineCoverage = InspectionComparison['metrics']['lineCoverage'];
7
+ type GateStatus = 'passed' | 'failed' | 'not-applicable' | 'indeterminate';
8
+ export interface PullReview {
9
+ readonly schema: typeof storedPullReviewSchema;
10
+ readonly number: number | null;
11
+ readonly generatedAt: string;
12
+ readonly base: string;
13
+ readonly mergeBase: string;
14
+ readonly head: string;
15
+ readonly coverage: {
16
+ readonly base: LineCoverage['baseline'] | null;
17
+ readonly head: LineCoverage['current'] | null;
18
+ readonly delta: number | null;
19
+ readonly reason: LineCoverage['reason'] | 'reports-unavailable' | 'head-coverage-changed';
20
+ readonly gate: {
21
+ readonly status: GateStatus;
22
+ readonly maxDrop: number;
23
+ } | null;
24
+ };
25
+ readonly diff: Pick<DiffCoverage, 'covered' | 'total' | 'percent' | 'files' | 'gaps'> & {
26
+ readonly status: DiffCoverage['status'] | 'unavailable';
27
+ readonly excludedPaths: readonly string[] | null;
28
+ readonly coverageInputDigest: string | null;
29
+ readonly uncovered: readonly {
30
+ readonly path: string;
31
+ readonly lines: readonly number[];
32
+ }[];
33
+ readonly gate: {
34
+ readonly status: GateStatus;
35
+ readonly minimumPercent: number;
36
+ readonly minimumLines: number;
37
+ } | null;
38
+ };
39
+ readonly findings: {
40
+ readonly added: readonly Finding[] | null;
41
+ readonly qualityCount: number | null;
42
+ readonly reason: 'reports-unavailable' | 'findings-unavailable' | 'partial-inspection' | 'analysis-changed' | null;
43
+ readonly gate: {
44
+ readonly status: GateStatus;
45
+ readonly maximum: number;
46
+ } | null;
47
+ };
48
+ }
3
49
  export declare const pullReviewsSchema = "urn:repometry:schema:pull-reviews:1";
4
50
  export interface PullReviews {
5
51
  readonly schema: typeof pullReviewsSchema;
6
52
  readonly reviews: readonly PullReview[];
7
53
  }
54
+ export {};
@@ -1 +1,3 @@
1
+ /** Reviews saved before 0.9 under `reviews/<number>.json`; the viewer lists them. */
2
+ export const storedPullReviewSchema = 'urn:repometry:schema:pull-review:1';
1
3
  export const pullReviewsSchema = 'urn:repometry:schema:pull-reviews:1';
@@ -0,0 +1,5 @@
1
+ import type { PullReview } from '../../core/model/pull-review.js';
2
+ /** The first line of every review comment, which finds the comment to update. */
3
+ export declare const reviewMarker = "<!-- repometry-review -->";
4
+ /** The review as Markdown: the run summary and the pull request comment carry the same text. */
5
+ export declare function pullReviewMarkdown(review: PullReview): string;
@@ -0,0 +1,132 @@
1
+ import { annotationLimit } from '../../core/model/pull-review.js';
2
+ /** The first line of every review comment, which finds the comment to update. */
3
+ export const reviewMarker = '<!-- repometry-review -->';
4
+ const maxLength = 60_000;
5
+ const assets = 'https://raw.githubusercontent.com/idleware/repometry/master/.github/assets';
6
+ const groups = [
7
+ { effect: 'new', title: 'New', folded: false }, { effect: 'worsened', title: 'Worsened', folded: false },
8
+ { effect: 'improved', title: 'Improved', folded: true }, { effect: 'touched', title: 'Touched', folded: true },
9
+ ];
10
+ const verdicts = { passed: 'Passed', failed: 'Failed', unmeasured: 'Not measured' };
11
+ /** The review as Markdown: the run summary and the pull request comment carry the same text. */
12
+ export function pullReviewMarkdown(review) {
13
+ const head = [reviewMarker, `## ${review.verdict === 'unmeasured' ? '' : `${flag(review.verdict)} `}repometry`, '', headline(review), '',
14
+ ...facts(review).map(line => `- ${line}`), ''];
15
+ const annotated = review.issues.filter(issue => issue.effect === 'new' || issue.effect === 'worsened').length;
16
+ const ranges = review.coverage.uncovered.length;
17
+ const tail = [...annotated > annotationLimit ? [`Annotated on the diff: ${annotationLimit} of ${annotated}.`, ''] : [],
18
+ ...ranges > annotationLimit ? [`Annotated on the diff: ${annotationLimit} of ${ranges} uncovered ranges.`, ''] : []];
19
+ const { lines, cut } = issueTables(review, maxLength - [...head, ...tail].join('\n').length - 200);
20
+ return [...head, ...lines, ...tail, ...cut ? [`${cut} more issues not shown.`, ''] : []].join('\n');
21
+ }
22
+ /**
23
+ * One table per group, then the uncovered changed lines, with as many rows as the budget allows. Rows keep their order
24
+ * of importance: once one doesn't fit, every later row is counted as cut.
25
+ */
26
+ function issueTables(review, budget) {
27
+ const tables = [...groups.map(({ effect, title, folded }) => ({ title, folded, heads: ['File', 'Issue'],
28
+ rows: review.issues.filter(issue => issue.effect === effect).map(issue => `| ${place(issue.finding)} | ${describe(issue)} |`) })),
29
+ { title: 'Changed lines without coverage', folded: true, heads: ['Changed lines'],
30
+ rows: review.coverage.uncovered.map(({ path, first, last }) => `| ${location({ path, line: first, endLine: last })} |`) }];
31
+ const lines = [];
32
+ let left = budget;
33
+ let cut = 0;
34
+ for (const table of tables) {
35
+ const rendered = cut ? { lines: [], length: 0, cut: table.rows.length } : fitTable(table, left);
36
+ lines.push(...rendered.lines);
37
+ left -= rendered.length;
38
+ cut += rendered.cut;
39
+ }
40
+ return { lines, cut };
41
+ }
42
+ function fitTable({ title, folded, heads, rows }, budget) {
43
+ const header = [...folded ? [`<details><summary>${title} (${rows.length})</summary>`, ''] : [`### ${title}`, ''],
44
+ `| ${heads.join(' | ')} |`, `| ${heads.map(() => '---').join(' | ')} |`];
45
+ const closing = folded ? ['', '</details>', ''] : [''];
46
+ const kept = [];
47
+ let length = [...header, ...closing].join('\n').length + 1;
48
+ for (const row of rows) {
49
+ if (length + row.length + 1 > budget)
50
+ break;
51
+ length += row.length + 1;
52
+ kept.push(row);
53
+ }
54
+ const cut = rows.length - kept.length;
55
+ return kept.length ? { lines: [...header, ...kept, ...closing], length, cut } : { lines: [], length: 0, cut };
56
+ }
57
+ /**
58
+ * The verdict flag that, with the name, forms the logo. Comments load it from master, so these paths must never change.
59
+ * It is cropped to its ink: at 17 px it stands on the heading's baseline at cap height.
60
+ */
61
+ function flag(verdict) {
62
+ const asset = (theme) => `${assets}/flag-${verdict}-${theme}.svg`;
63
+ return `<picture><source media="(prefers-color-scheme: dark)" srcset="${asset('dark')}">`
64
+ + `<img src="${asset('light')}" alt="" width="17" height="17"></picture>`;
65
+ }
66
+ function headline({ verdict, issues, base, mergeBase, head, changedFiles }) {
67
+ const counts = groups.map(({ effect }) => [effect, issues.filter(issue => issue.effect === effect).length])
68
+ .filter(([, count]) => count > 0).map(([effect, count]) => `${count} ${effect}`);
69
+ const what = changedFiles === 0 ? `no changes since \`${base}\``
70
+ : `${counts.length ? counts.join(' · ') : 'no issues'} on the lines changed since \`${base}\``;
71
+ return `**${verdicts[verdict]}** · ${what} (\`${mergeBase.slice(0, 7)}\` → \`${head.slice(0, 7)}\`)`;
72
+ }
73
+ function facts({ coverage, debt, unmeasured, notes }) {
74
+ const lines = [coverageLine(coverage)];
75
+ if (debt.added || debt.removed)
76
+ lines.push(`Debt: +${debt.added} min added, −${debt.removed} min removed`);
77
+ lines.push(...few(unmeasured).map(reason => `Not measured: ${typeof reason === 'string' ? reason : reasonText(reason)}`));
78
+ const unmapped = coverage.unmapped.map(({ path }) => code(path));
79
+ if (unmapped.length) {
80
+ const named = unmapped.length > 3 ? `${unmapped.slice(0, 3).join(', ')} and ${unmapped.length - 3} more` : unmapped.join(', ');
81
+ lines.push(`Coverage has no record for ${unmapped.length} changed ${unmapped.length === 1 ? 'file' : 'files'}: ${named}`);
82
+ }
83
+ lines.push(...few(notes).map(reason => `Note: ${typeof reason === 'string' ? reason : reasonText(reason)}`));
84
+ return lines;
85
+ }
86
+ /** The first reasons, and a count of the rest. */
87
+ function few(reasons, shown = 5) {
88
+ return reasons.length > shown ? [...reasons.slice(0, shown), `${reasons.length - shown} more`] : [...reasons];
89
+ }
90
+ function coverageLine({ imported, covered, total, percent, gate }) {
91
+ if (!imported)
92
+ return 'Coverage not imported';
93
+ const measured = percent === null ? 'no measured lines' : `${percent.toFixed(2)}% (${covered} of ${total} lines)`;
94
+ if (gate === null)
95
+ return `Changed-line coverage: ${measured}`;
96
+ const status = gate.status === 'not-applicable' ? `applies from ${gate.minimumLines} measured lines` : gate.status;
97
+ return `Changed-line coverage: ${measured}, minimum ${gate.minimumPercent}%, ${status}`;
98
+ }
99
+ function reasonText({ operation, path, message }) {
100
+ return [operation, path === undefined ? undefined : `on ${code(path)}`].filter(Boolean).join(' ') + (operation || path ? ': ' : '')
101
+ + cell(message);
102
+ }
103
+ function describe({ effect, finding, before, fixed, context }) {
104
+ const parts = [clip(cell(finding.message))];
105
+ if (fixed)
106
+ parts.push('fixed');
107
+ else if ((effect === 'worsened' || effect === 'improved') && before !== null)
108
+ parts.push(`was ${before}`);
109
+ if (context.length)
110
+ parts.push(`same code as ${context.map(location).join(', ')}`);
111
+ return parts.join(', ');
112
+ }
113
+ function place({ path, line, endLine }) {
114
+ if (path === undefined)
115
+ return '—';
116
+ return line === undefined ? code(path) : location({ path, line, endLine: endLine ?? line });
117
+ }
118
+ function location({ path, line, endLine }) {
119
+ return code(`${path}:${line}${endLine > line ? `–${endLine}` : ''}`);
120
+ }
121
+ function code(value) {
122
+ return `<code>${cell(value)}</code>`;
123
+ }
124
+ /** A long message is shortened, so one issue can't push the others out of the comment. */
125
+ function clip(value, length = 500) {
126
+ return value.length > length ? `${value.slice(0, length - 1)}…` : value;
127
+ }
128
+ function cell(value) {
129
+ return value.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('|', '&#124;')
130
+ .replace(/[\r\n]+/g, ' ');
131
+ }
132
+ //# sourceMappingURL=pull-review.js.map