co-maintainer 0.7.8 → 0.7.9-beta.1

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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "co-maintainer",
3
- "version": "0.7.8",
3
+ "version": "0.7.9-beta.1",
4
4
  "description": "An imitator of yours, A PR review tool like co-maintainer.",
5
5
  "keywords": [
6
6
  "ai",
@@ -121,6 +121,7 @@ async function runReviewPr(options, cli) {
121
121
  catchesUp: true,
122
122
  extensions,
123
123
  intent: intent !== null,
124
+ showReferences: readConfig().repos?.[options.repo]?.reviewReferences === true,
124
125
  });
125
126
  }
126
127
  else {
@@ -13,7 +13,10 @@ export declare function escapeProperty(value: string): string;
13
13
  /** One workflow command per finding still standing, errors first. A finding
14
14
  * that was closed since the last review needs no annotation. The dropped
15
15
  * files warning takes one of the warning slots. */
16
- export declare function githubAnnotations(findings: HumanFinding[], coverage?: Coverage): string[];
16
+ export declare function githubAnnotations(findings: HumanFinding[], coverage?: Coverage,
17
+ /** Name each finding's rules, only when the repository turned references
18
+ * on, as the terminal output does. */
19
+ showReferences?: boolean): string[];
17
20
  export type GithubSummaryInput = {
18
21
  /** What was reviewed, for the line under the heading. */
19
22
  title: string;
@@ -30,6 +33,9 @@ export type GithubSummaryInput = {
30
33
  /** The extensions' results. Their findings join the table, and their
31
34
  * `markdown` follows the AI part. */
32
35
  extensions?: ExtensionReport;
36
+ /** Name each finding's rules in its annotation. On only when the
37
+ * repository turned references on. */
38
+ showReferences?: boolean;
33
39
  /** An intent file was given. The summary says so and never shows the text. */
34
40
  intent?: boolean;
35
41
  };
@@ -27,7 +27,17 @@ export function escapeData(value) {
27
27
  export function escapeProperty(value) {
28
28
  return escapeData(value).replace(/:/g, "%3A").replace(/,/g, "%2C");
29
29
  }
30
- function annotation(row) {
30
+ /** ` (rule R3)` or ` (rules R3, I1)`: the guide and instruction rules a
31
+ * finding rests on, so a CI annotation names them as the terminal does. */
32
+ function rulesNote(row) {
33
+ const ids = (row.references ?? []).flatMap((reference) => reference.kind === "rule" || reference.kind === "instruction"
34
+ ? [reference.id]
35
+ : []);
36
+ if (ids.length === 0)
37
+ return "";
38
+ return ` (${ids.length === 1 ? "rule" : "rules"} ${ids.join(", ")})`;
39
+ }
40
+ function annotation(row, showReferences = false) {
31
41
  const properties = [];
32
42
  if (row.path) {
33
43
  properties.push(`file=${escapeProperty(row.path)}`);
@@ -46,7 +56,8 @@ function annotation(row) {
46
56
  ? `${row.severity}: ${short}`
47
57
  : `${row.severity} finding`)}`);
48
58
  const level = row.blocking ? "error" : "warning";
49
- return `::${level} ${properties.join(",")}::${escapeData(row.body || row.title)}`;
59
+ const note = showReferences ? rulesNote(row) : "";
60
+ return `::${level} ${properties.join(",")}::${escapeData(`${row.body || row.title}${note}`)}`;
50
61
  }
51
62
  function active(findings) {
52
63
  return sortHumanFindings(findings).filter((row) => row.state !== "closed");
@@ -63,7 +74,10 @@ function droppedAnnotation(coverage) {
63
74
  /** One workflow command per finding still standing, errors first. A finding
64
75
  * that was closed since the last review needs no annotation. The dropped
65
76
  * files warning takes one of the warning slots. */
66
- export function githubAnnotations(findings, coverage) {
77
+ export function githubAnnotations(findings, coverage,
78
+ /** Name each finding's rules, only when the repository turned references
79
+ * on, as the terminal output does. */
80
+ showReferences = false) {
67
81
  const rows = active(findings);
68
82
  const errors = rows.filter((row) => row.blocking);
69
83
  const warnings = rows.filter((row) => !row.blocking);
@@ -72,7 +86,7 @@ export function githubAnnotations(findings, coverage) {
72
86
  ...errors.slice(0, MAX_ANNOTATIONS_PER_LEVEL),
73
87
  ...warnings.slice(0, MAX_ANNOTATIONS_PER_LEVEL - (dropped ? 1 : 0)),
74
88
  ];
75
- const lines = shown.map(annotation);
89
+ const lines = shown.map((row) => annotation(row, showReferences));
76
90
  if (dropped)
77
91
  lines.push(dropped);
78
92
  const left = rows.length - shown.length;
@@ -150,7 +164,7 @@ export function emitGithubOutput(input) {
150
164
  // Only an extension finding with a location is annotated. The job summary
151
165
  // lists the rest.
152
166
  const located = extensionHumanFindings(input.extensions).filter((row) => row.path);
153
- for (const line of githubAnnotations([...input.findings, ...located], input.coverage)) {
167
+ for (const line of githubAnnotations([...input.findings, ...located], input.coverage, input.showReferences)) {
154
168
  console.log(line);
155
169
  }
156
170
  appendStepSummary(githubSummary(input));
@@ -312,6 +312,7 @@ export async function runLocalReview(cli) {
312
312
  catchesUp: true,
313
313
  extensions,
314
314
  intent: Boolean(intentLoad.intent),
315
+ showReferences: readConfig().repos?.[options.repo]?.reviewReferences === true,
315
316
  });
316
317
  }
317
318
  else {
@@ -304,6 +304,7 @@ export async function runRemoteReview(cli) {
304
304
  catchesUp: true,
305
305
  extensions,
306
306
  intent: intent !== null,
307
+ showReferences: readConfig().repos?.[repo]?.reviewReferences === true,
307
308
  });
308
309
  }
309
310
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "co-maintainer",
3
- "version": "0.7.8",
3
+ "version": "0.7.9-beta.1",
4
4
  "description": "An imitator of yours, A PR review tool like co-maintainer.",
5
5
  "keywords": [
6
6
  "ai",