@arcgis/codemod 6.0.0-next.6 → 6.0.0-next.7

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.
@@ -0,0 +1,158 @@
1
+ import u from "typescript";
2
+ import { findPath as v, asyncFindPath as y } from "@arcgis/node-toolkit/file";
3
+ import { path as d } from "@arcgis/node-toolkit/path";
4
+ import { retrievePackageJson as k, asyncRetrievePackageJson as x } from "@arcgis/node-toolkit/packageJson";
5
+ import { log as w } from "@arcgis/toolkit/log";
6
+ import { realpath as g, readFile as S } from "node:fs/promises";
7
+ import { f as D } from "./log.js";
8
+ import { b as P } from "./cli.js";
9
+ function L(e) {
10
+ return typeof e == "string" ? e : e.map((t) => t.kind === u.SyntaxKind.JSDocText ? t.text : J(t.getText())).join("");
11
+ }
12
+ function $(e) {
13
+ return e === void 0 ? void 0 : b(u.displayPartsToString([...e]));
14
+ }
15
+ function b(e) {
16
+ return e.replace(
17
+ /\{@link(?:code|plain)?\s+([\s\S]*?)\}/gu,
18
+ (t, n) => h(n)
19
+ );
20
+ }
21
+ function J(e) {
22
+ const t = /^\{@link(?:code|plain)?\s+([\s\S]*?)\}$/u.exec(e)?.[1];
23
+ return t === void 0 ? e : h(t);
24
+ }
25
+ function h(e) {
26
+ const t = e.trim().replace(/^(\S+)\s+([/:#!.])/u, "$1$2"), n = t.indexOf("|");
27
+ if (n !== -1)
28
+ return t.slice(n + 1).trim() || t.slice(0, n).trim();
29
+ const [i, ...s] = t.split(/\s+/u);
30
+ return s.join(" ") || i;
31
+ }
32
+ function R(e, t) {
33
+ const n = v("package.json", e);
34
+ return n === void 0 ? t : k(d.dirname(n)).name ?? t;
35
+ }
36
+ const m = {
37
+ excludedPackageNames: /* @__PURE__ */ new Set([
38
+ "@arcgis/charts-components-react",
39
+ "@arcgis/coding-components-react",
40
+ "@arcgis/components-build-utils",
41
+ "@arcgis/map-components-react",
42
+ "@arcgis/portal-components-react",
43
+ "@arcgis-test/lit-components-react"
44
+ ]),
45
+ excludedDefinitionPathFragments: ["test-package", "packages/docs/lumina-code-samples/", "packages/starter-packages/"],
46
+ ignoreDeprecatedApis: ["getReactWrapperOptions"],
47
+ ignoredDeprecationsByIncludes: ["React wrappers are not needed in React 19 or above"]
48
+ };
49
+ function U(e) {
50
+ return e !== void 0 && m.excludedPackageNames.has(e);
51
+ }
52
+ function A(e) {
53
+ return m.excludedDefinitionPathFragments.some(
54
+ (t) => e.includes(t)
55
+ );
56
+ }
57
+ function z(e, t) {
58
+ return m.ignoreDeprecatedApis.some((n) => n === e) || t != null && m.ignoredDeprecationsByIncludes.some((n) => t.includes(n));
59
+ }
60
+ function N(e, t, n) {
61
+ const i = JSON.parse(e), s = { definitions: [], components: /* @__PURE__ */ new Set() };
62
+ for (const o of i.modules)
63
+ for (const a of o.declarations ?? []) {
64
+ let r = function(p, f, c) {
65
+ c !== !0 && typeof c != "string" || s.definitions.push({
66
+ package: n,
67
+ module: o.path,
68
+ name: p,
69
+ kind: f,
70
+ memberOf: f === "element" ? void 0 : l,
71
+ provenance: "manifest",
72
+ reason: typeof c == "string" ? c : void 0,
73
+ sourceFileName: t,
74
+ line: 1,
75
+ column: 1
76
+ });
77
+ };
78
+ if (!("tagName" in a) || a.tagName === void 0)
79
+ continue;
80
+ const l = a.tagName;
81
+ s.components.add(l), r(l, "element", a.deprecated);
82
+ for (const [p, f] of [
83
+ ["cssProperties", "css-property"],
84
+ ["cssParts", "css-part"],
85
+ ["cssStates", "css-state"],
86
+ ["slots", "slot"],
87
+ ["attributes", "attribute"]
88
+ ])
89
+ for (const c of a[p] ?? [])
90
+ p === "slots" && c.name === "" || r(c.name, f, c.deprecated);
91
+ }
92
+ return s;
93
+ }
94
+ function _(e) {
95
+ const t = e.flatMap((o) => o.definitions), n = /* @__PURE__ */ new Map();
96
+ for (const o of e)
97
+ for (const a of o.components) {
98
+ const r = n.get(a) ?? [];
99
+ r.push(o), n.set(a, r);
100
+ }
101
+ const i = /* @__PURE__ */ new Map(), s = Map.groupBy(
102
+ t.filter(({ kind: o }) => o === "css-property"),
103
+ ({ name: o }) => o
104
+ );
105
+ for (const [o, a] of s)
106
+ new Set(a.map((r) => r.package)).size === 1 && i.set(o, a[0]);
107
+ return { hasDeprecatedApis: t.length > 0, components: n, cssVariables: i };
108
+ }
109
+ function K(e = "warn", t) {
110
+ const n = /* @__PURE__ */ new Map();
111
+ return async (i) => {
112
+ const s = await g(i);
113
+ let o = n.get(s);
114
+ return o === void 0 && (o = j(s).catch((a) => {
115
+ if (t?.(), e === "throw")
116
+ throw new Error(
117
+ `Unable to read component manifest for ${s}. Build the package before auditing definitions.`,
118
+ { cause: a }
119
+ );
120
+ w("warn", D(s), `Unable to read component manifest: ${String(a)}`);
121
+ }), n.set(s, o)), await o;
122
+ };
123
+ }
124
+ async function V(e, t, n) {
125
+ const i = /* @__PURE__ */ new Set([
126
+ ...Object.keys(e.contents.dependencies ?? {}),
127
+ ...Object.keys(e.contents.devDependencies ?? {}),
128
+ ...Object.keys(e.contents.peerDependencies ?? {}),
129
+ ...Object.keys(e.contents.optionalDependencies ?? {})
130
+ ]), s = await Promise.all(
131
+ [...i].filter((o) => o !== e.contents.name && (!n || P(o))).map(async (o) => {
132
+ const a = await y(
133
+ d.join("node_modules", o, "package.json"),
134
+ d.dirname(e.filePath)
135
+ );
136
+ return a === void 0 ? void 0 : await t(a);
137
+ })
138
+ );
139
+ return [...new Set(s.filter((o) => o !== void 0))];
140
+ }
141
+ async function j(e) {
142
+ const t = d.dirname(e), n = await x(t), i = typeof n.customElements == "string" ? n.customElements : n.customElements?.[0];
143
+ if (i === void 0)
144
+ return;
145
+ const s = await g(d.resolve(t, i));
146
+ return N(await S(s, "utf8"), s, n.name);
147
+ }
148
+ export {
149
+ z as a,
150
+ K as b,
151
+ _ as c,
152
+ L as d,
153
+ $ as e,
154
+ A as f,
155
+ R as g,
156
+ V as l,
157
+ U as s
158
+ };
@@ -1,70 +1,71 @@
1
- import { d as f } from "./cli.js";
2
- import { o as b, q as m, r as P, s as D, c as O, a as d, b as B } from "./classification.js";
3
- const h = `<!-- ${m} -->`, J = `<!-- ${m}`, w = 65536;
4
- function Q(e) {
5
- const n = k(e, e.findings);
6
- return `${n.summary.trim().replace(/^### /u, "## ")}
1
+ import { h as R, k as d, l as D, m as b, d as h } from "./cli.js";
2
+ import { g as v, i as B, b as $, d as K } from "./classification.js";
3
+ import { markdownTextLimit as k, splitMarkdown as O } from "@arcgis/node-toolkit/markdown";
4
+ const y = `<!-- ${d} -->`, X = `<!-- ${d}`;
5
+ function Y(e) {
6
+ const t = M(e, e.findings);
7
+ return `${t.summary.trim().replace(/^### /u, "## ")}
7
8
 
8
- ${n.details}`;
9
+ ${t.details}`;
9
10
  }
10
- function V(e) {
11
- const n = /* @__PURE__ */ new Map();
12
- for (const o of e.findings) {
13
- const r = $(o.codeowners), i = r.join(","), t = n.get(i) ?? [];
14
- t.push({ ...o, codeowners: r }), n.set(i, t);
11
+ function Z(e) {
12
+ const t = /* @__PURE__ */ new Map();
13
+ for (const n of e.findings) {
14
+ const s = f(n.codeowners), r = s.join(","), o = t.get(r) ?? [];
15
+ o.push({ ...n, codeowners: s }), t.set(r, o);
15
16
  }
16
- return [...n.entries()].map(([o, r]) => {
17
- const i = o === "" ? [] : o.split(","), t = K(e, r);
17
+ return [...t.entries()].map(([n, s]) => {
18
+ const r = n === "" ? [] : n.split(","), o = L(e, s);
18
19
  return {
19
20
  changes: [],
20
- title: b[e.kind],
21
- owners: i,
22
- assignees: i.filter((s) => /^@[^/@\s]+$/u.test(s)).map((s) => s.slice(1)),
23
- chunks: v(t, w, N(i))
21
+ title: R[e.auditKind],
22
+ owners: r,
23
+ assignees: r.filter((a) => /^@[^/@\s]+$/u.test(a)).map((a) => a.slice(1)),
24
+ chunks: _(o, k, G(r))
24
25
  };
25
- }).sort((o, r) => o.title.localeCompare(r.title));
26
+ }).sort((n, s) => n.title.localeCompare(s.title));
26
27
  }
27
- function K(e, n) {
28
- const o = $(n.flatMap((i) => i.codeowners)).filter(
29
- (i) => /^@[^/@\s]+\/[^@\s]+$/u.test(i)
30
- ), r = o.length === 0 ? "" : `
28
+ function L(e, t) {
29
+ const n = f(t.flatMap((r) => r.codeowners)).filter(
30
+ (r) => /^@[^/@\s]+\/[^@\s]+$/u.test(r)
31
+ ), s = n.length === 0 ? "" : `
31
32
 
32
- CODEOWNERS: ${o.join(", ")}`;
33
- return L(e, n, r);
33
+ CODEOWNERS: ${n.join(", ")}`;
34
+ return U(e, t, s);
34
35
  }
35
- function L(e, n, o) {
36
- const r = P[e.kind], i = k(e, n);
37
- return `${r}${o}${i.summary}
36
+ function U(e, t, n) {
37
+ const s = D[e.auditKind], r = M(e, t);
38
+ return `${s}${n}${r.summary}
38
39
 
39
- ${D}
40
+ ${b}
40
41
 
41
- ${i.details}`;
42
+ ${r.details}`;
42
43
  }
43
- function k(e, n) {
44
- return e.kind === "usages" ? U(e, n) : z(e, n);
44
+ function M(e, t) {
45
+ return e.auditKind === "usages" ? z(e, t) : E(e, t);
45
46
  }
46
- function U(e, n) {
47
- const o = y(n, "usages"), r = O(n, (s) => s), i = r.map(({ categoryName: s, count: c, packages: a }) => {
48
- const u = a.map(({ packageName: p, count: l }) => ` - \`${p}\`: ${l}`).join(`
47
+ function z(e, t) {
48
+ const n = x(t, "usages"), s = v(t, (a) => a), r = s.map(({ categoryName: a, count: c, packages: m }) => {
49
+ const u = m.map(({ displayName: p, count: i }) => ` - \`${p}\`: ${i}`).join(`
49
50
  `);
50
- return `- **${f[s].label}**: ${c}
51
+ return `- **${h[a].label}**: ${c}
51
52
  ${u}`;
52
53
  }).join(`
53
- `), t = r.map(({ categoryName: s, count: c, packages: a }) => {
54
- const u = a.map(({ packageName: j, count: A, apis: S }) => {
55
- const C = S.flatMap(
56
- ({ items: R }) => M(e, R, "usages", o)
54
+ `), o = s.map(({ categoryName: a, count: c, packages: m }) => {
55
+ const u = m.map(({ displayName: l, count: S, apis: A }) => {
56
+ const C = A.flatMap(
57
+ ({ items: P }) => I(e, P, "usages", n)
57
58
  );
58
- return `#### ${j} (${A})
59
+ return `#### ${l} (${S})
59
60
 
60
61
  ${C.join(`
61
62
  `)}`;
62
63
  }).join(`
63
64
 
64
- `), p = f[s], l = "description" in p ? `
65
+ `), p = h[a], i = "description" in p ? `
65
66
 
66
67
  ${p.description}` : "";
67
- return `### ${p.label} (${c})${l}
68
+ return `### ${p.label} (${c})${i}
68
69
 
69
70
  ${u}`;
70
71
  }).join(`
@@ -75,25 +76,28 @@ ${u}`;
75
76
 
76
77
  ### Deprecation summary
77
78
 
78
- ${i}`,
79
+ ${r}`,
79
80
  details: `## Deprecation details
80
81
 
81
- ${t}`
82
+ ${o}`
82
83
  };
83
84
  }
84
- function y(e, n) {
85
- const o = /* @__PURE__ */ new Map();
86
- for (const r of e) {
87
- const i = d(r), t = o.get(i) ?? /* @__PURE__ */ new Set();
88
- t.add(`${r.package}\0${I(n, r)}`), o.set(i, t);
85
+ function x(e, t) {
86
+ const n = /* @__PURE__ */ new Map();
87
+ for (const s of e) {
88
+ const r = $(s), o = n.get(r) ?? /* @__PURE__ */ new Set();
89
+ o.add(`${s.package}\0${j(t, s)}`), n.set(r, o);
89
90
  }
90
- return new Set([...o].filter(([, r]) => r.size > 1).map(([r]) => r));
91
- }
92
- function z(e, n) {
93
- const o = y(n, "definitions");
94
- return { summary: "", details: [...Map.groupBy(n, (t) => t.package).entries()].sort(([t], [s]) => t.localeCompare(s)).map(([t, s]) => {
95
- const c = M(e, s, "definitions", o);
96
- return `#### ${t}'s deprecations
91
+ return new Set([...n].filter(([, s]) => s.size > 1).map(([s]) => s));
92
+ }
93
+ function E(e, t) {
94
+ const n = x(t, "definitions");
95
+ return { summary: "", details: [...Map.groupBy(
96
+ t,
97
+ (o) => B(o.package, o.module ?? g("definitions", o))
98
+ ).entries()].sort(([o], [a]) => o.localeCompare(a)).map(([o, a]) => {
99
+ const c = I(e, a, "definitions", n);
100
+ return `#### ${o}'s deprecations
97
101
 
98
102
  ${c.join(`
99
103
  `)}`;
@@ -101,84 +105,84 @@ ${c.join(`
101
105
 
102
106
  `) };
103
107
  }
104
- function M(e, n, o, r) {
105
- const i = [...Map.groupBy(n, (t) => I(o, t))];
106
- return o === "definitions" && i.sort(([t], [s]) => t.localeCompare(s)), i.map(([, t]) => {
107
- const s = d(t[0]), c = x(o, t[0]), a = c !== void 0 && r.has(s) ? `${c} ${s}` : s, u = T(t);
108
- return o === "usages" && u.sort((p, l) => p.localeCompare(l)), E(e, a, u, t);
108
+ function I(e, t, n, s) {
109
+ const r = [...Map.groupBy(t, (o) => j(n, o))];
110
+ return n === "definitions" && r.sort(([o], [a]) => o.localeCompare(a)), r.map(([, o]) => {
111
+ const a = $(o[0]), c = g(n, o[0]), m = c !== void 0 && s.has(a) ? `${c} ${a}` : a, u = T(o);
112
+ return n === "usages" && u.sort((p, i) => p.localeCompare(i)), N(e, m, u, o, n);
109
113
  });
110
114
  }
111
- function E(e, n, o, r) {
112
- const i = o.length === 0 ? "" : ` - ${o.map(q).join(" ")}`, t = [
115
+ function N(e, t, n, s, r) {
116
+ const o = n.length === 0 ? "" : ` - ${n.map(q).join(" ")}`, a = [
113
117
  ...new Set(
114
- r.toSorted((a, u) => a.file.localeCompare(u.file) || a.line - u.line).map((a) => G(e.repository, e.ref, a.file, a.line))
118
+ s.filter((i) => r === "usages" || i.provenance !== "manifest").toSorted((i, l) => i.file.localeCompare(l.file) || i.line - l.line).map((i) => H(e.repository, e.ref, i.file, i.line))
115
119
  )
116
- ], s = t.length === 1 ? ` ${t[0]}` : t.map((a) => ` - ${a}`).join(`
117
- `), c = r[0].apiKind;
118
- return `- [ ] \`${n}\`${B(c)}${i}
119
- ${s}`;
120
+ ], c = a.length === 1 ? ` ${a[0]}` : a.map((i) => ` - ${i}`).join(`
121
+ `), m = s[0].kind, u = [
122
+ ...new Set(
123
+ s.filter(
124
+ (i) => r === "definitions" && i.provenance === "manifest" && i.kind === "css-property"
125
+ ).flatMap(({ memberOf: i }) => i === void 0 ? [] : [i])
126
+ )
127
+ ].sort(), p = u.length === 0 ? "" : ` (components: ${u.map((i) => `\`<${i}>\``).join(", ")})`;
128
+ return `- [ ] \`${t}\`${K(m)}${p}${o}${c === "" ? "" : `
129
+ ${c}`}`;
120
130
  }
121
131
  function T(e) {
122
132
  return [
123
133
  ...new Set(
124
- e.map(({ reason: n }) => n).filter((n) => n !== null && n !== "")
134
+ e.map(({ deprecated: t }) => t).filter((t) => typeof t == "string" && t !== "")
125
135
  )
126
136
  ];
127
137
  }
128
- function v(e, n = w, o = h) {
129
- const r = `${o}
130
- `, i = n - r.length;
131
- if (i < 1)
138
+ function _(e, t = k, n = y) {
139
+ const s = `${n}
140
+ `, r = t - s.length;
141
+ if (r < 1)
132
142
  throw new Error("Issue content limit is too small for the managed marker.");
133
- const t = [];
134
- let s = e;
135
- for (; s.length > i; ) {
136
- const c = s.lastIndexOf(`
137
- `, i), a = c > 0 ? c : i;
138
- t.push(r + s.slice(0, a)), s = s.slice(a + (c > 0 ? 1 : 0));
139
- }
140
- return t.push(r + s), t;
143
+ return O(e, r).map((o) => s + o);
141
144
  }
142
- function N(e) {
143
- return e.length === 0 ? h : `<!-- ${m} ${$(e).join(",")} -->`;
145
+ function G(e) {
146
+ return e.length === 0 ? y : `<!-- ${d} ${f(e).join(",")} -->`;
144
147
  }
145
- function $(e) {
146
- return [...new Set(e)].sort((n, o) => n.localeCompare(o));
148
+ function f(e) {
149
+ return [...new Set(e)].sort((t, n) => t.localeCompare(n));
147
150
  }
148
- function I(e, n) {
149
- return `${d(n)}\0${x(e, n) ?? ""}`;
151
+ function j(e, t) {
152
+ return `${$(t)}\0${g(e, t) ?? ""}`;
150
153
  }
151
- function x(e, n) {
152
- return e === "definitions" ? _(n.file) : n.module;
154
+ function g(e, t) {
155
+ return e === "definitions" && t.provenance !== "manifest" ? W(t.file) : t.module;
153
156
  }
154
- function _(e) {
155
- const n = "/src/", o = "/dist/", r = e.lastIndexOf(n), i = e.lastIndexOf(o), t = Math.max(r, i), s = i > r ? o : n;
156
- return (t === -1 ? e : e.slice(t + s.length)).replace(/\.(?:d\.)?(?:[cm]?ts|tsx)$/u, "");
157
+ function W(e) {
158
+ const t = "/src/", n = "/dist/", s = e.lastIndexOf(t), r = e.lastIndexOf(n), o = Math.max(s, r), a = r > s ? n : t;
159
+ return (o === -1 ? e : e.slice(o + a.length)).replace(/\.(?:d\.)?(?:[cm]?ts|tsx)$/u, "");
157
160
  }
158
161
  function q(e) {
159
- const n = [], o = (t) => `\0${n.push(t) - 1}\0`, i = e.replaceAll(`\r
162
+ const t = [], n = (o) => `\0${t.push(o) - 1}\0`, r = e.replaceAll(`\r
160
163
  `, `
161
164
  `).replaceAll("\r", `
162
165
  `).replace(
163
166
  /\[([^\]\n]+)\]\((https?:\/\/(?:[^()\s]|\([^()\s]*\))+?)\)/gu,
164
- (t, s, c) => o(`[${g(s)}](${c})`)
165
- ).replace(/https?:\/\/[^\s<>()]+/gu, (t) => {
166
- const s = /[.,;:!?]+$/u.exec(t)?.[0] ?? "";
167
- return `${o(t.slice(0, -s.length || void 0))}${s}`;
167
+ (o, a, c) => n(`[${w(a)}](${c})`)
168
+ ).replace(/https?:\/\/[^\s<>()]+/gu, (o) => {
169
+ const a = /[.,;:!?]+$/u.exec(o)?.[0] ?? "";
170
+ return `${n(o.slice(0, -a.length || void 0))}${a}`;
168
171
  });
169
- return g(i).replace(/\0(\d+)\0/gu, (t, s) => n[Number(s)]).replaceAll(`
172
+ return w(r).replace(/\0(\d+)\0/gu, (o, a) => t[Number(a)]).replaceAll(`
170
173
  `, `
171
174
  `);
172
175
  }
173
- function g(e) {
176
+ function w(e) {
174
177
  return e.replace(/^(\s*)(#{1,6})(?=\s)/gmu, "$1\\$2").replace(/#(?=\d)/gu, "# ");
175
178
  }
176
- function G(e, n, o, r) {
177
- const i = n.split("/").map(encodeURIComponent).join("/"), t = o.split("/").map(encodeURIComponent).join("/");
178
- return `https://${e}/blob/${i}/${t}#L${r}`;
179
+ function H(e, t, n, s) {
180
+ const r = t.split("/").map(encodeURIComponent).join("/"), o = n.split("/").map(encodeURIComponent).join("/");
181
+ return `https://${e}/blob/${r}/${o}#L${s}`;
179
182
  }
180
183
  export {
181
- V as c,
182
- Q as f,
183
- J as i
184
+ y as a,
185
+ Z as c,
186
+ Y as f,
187
+ X as i
184
188
  };
@@ -0,0 +1,124 @@
1
+ import { collectOutput as h } from "@arcgis/node-toolkit/shell";
2
+ import { j as c } from "./cli.js";
3
+ const p = /^( (?:- )?https:\/\/[^/\s]+\/[^/\s]+\/[^/\s]+\/blob\/)[a-f0-9]{40}(\/\S+#L\d+)$/gmu;
4
+ class $ {
5
+ constructor(s, t = !1) {
6
+ this.changes = [], this.#i = /* @__PURE__ */ new Map(), this.#n = -1;
7
+ const [e, i, n, ...o] = s.split("/");
8
+ if (e === void 0 || i === void 0 || n === void 0 || o.length > 0)
9
+ throw new Error(`Invalid repository: ${s}`);
10
+ this.#e = e, this.#s = `${i}/${n}`, this.dryRun = t;
11
+ }
12
+ #e;
13
+ #s;
14
+ #i;
15
+ #n;
16
+ async #t(s, t, e) {
17
+ if (process.env.VITEST !== void 0)
18
+ throw new Error("GitHub requests are disabled while running Vitest.");
19
+ const i = await h(
20
+ "gh",
21
+ ["api", "--hostname", this.#e, "--method", s, t, ...e === void 0 ? [] : ["--input", "-"]],
22
+ e === void 0 ? {} : { input: JSON.stringify(e) }
23
+ );
24
+ return i === "" ? void 0 : JSON.parse(i);
25
+ }
26
+ async listOpenIssues(s) {
27
+ const t = await h("gh", [
28
+ "api",
29
+ "--hostname",
30
+ this.#e,
31
+ "--method",
32
+ "GET",
33
+ "--paginate",
34
+ "--slurp",
35
+ "-f",
36
+ `q="${s}" in:title repo:${this.#s} is:issue is:open`,
37
+ "-f",
38
+ "per_page=100",
39
+ "/search/issues"
40
+ ]);
41
+ return JSON.parse(t).flatMap(({ items: e }) => e);
42
+ }
43
+ async createIssue(s, t, e, i) {
44
+ if (this.dryRun) {
45
+ const n = this.#n--;
46
+ return this.#i.set(n, s), this.changes.push(`CREATE issue: ${s}`), { number: n, title: s, body: t, assignees: e.map((o) => ({ login: o })) };
47
+ }
48
+ return await this.#t("POST", `/repos/${this.#s}/issues`, {
49
+ title: s,
50
+ body: t,
51
+ assignees: e,
52
+ labels: i,
53
+ type: c
54
+ });
55
+ }
56
+ async updateIssueBody(s, t) {
57
+ if (this.dryRun) {
58
+ this.changes.push(`UPDATE issue #${s} body`);
59
+ return;
60
+ }
61
+ await this.#t("PATCH", `/repos/${this.#s}/issues/${s}`, { body: t });
62
+ }
63
+ async closeIssue(s) {
64
+ if (this.dryRun) {
65
+ this.changes.push(`CLOSE issue #${s}`);
66
+ return;
67
+ }
68
+ await this.#t("PATCH", `/repos/${this.#s}/issues/${s}`, { state: "closed" });
69
+ }
70
+ async listComments(s) {
71
+ if (this.#i.has(s))
72
+ return [];
73
+ const t = await h("gh", [
74
+ "api",
75
+ "--hostname",
76
+ this.#e,
77
+ "--method",
78
+ "GET",
79
+ "--paginate",
80
+ "--slurp",
81
+ `/repos/${this.#s}/issues/${s}/comments?per_page=100`
82
+ ]);
83
+ return JSON.parse(t).flat();
84
+ }
85
+ async createComment(s, t) {
86
+ if (this.dryRun) {
87
+ const e = this.#i.get(s), i = e === void 0 ? `issue #${s}` : `new issue: ${e}`;
88
+ this.changes.push(`ADD comment to ${i}`);
89
+ return;
90
+ }
91
+ await this.#t("POST", `/repos/${this.#s}/issues/${s}/comments`, { body: t });
92
+ }
93
+ async updateComment(s, t) {
94
+ if (this.dryRun) {
95
+ this.changes.push(`UPDATE comment #${s}`);
96
+ return;
97
+ }
98
+ await this.#t("PATCH", `/repos/${this.#s}/issues/comments/${s}`, { body: t });
99
+ }
100
+ async deleteComment(s) {
101
+ if (this.dryRun) {
102
+ this.changes.push(`REMOVE comment #${s}`);
103
+ return;
104
+ }
105
+ await this.#t("DELETE", `/repos/${this.#s}/issues/comments/${s}`);
106
+ }
107
+ }
108
+ async function f(a, s, t, e) {
109
+ const i = (await a.listComments(s)).filter(({ body: n }) => e(n));
110
+ for (const [n, o] of t.entries()) {
111
+ const r = i[n];
112
+ r === void 0 ? await a.createComment(s, o) : u(r.body) !== u(o) && await a.updateComment(r.id, o);
113
+ }
114
+ for (const n of i.slice(t.length))
115
+ await a.deleteComment(n.id);
116
+ }
117
+ function u(a) {
118
+ return a?.replace(p, "$1<sha>$2");
119
+ }
120
+ export {
121
+ $ as G,
122
+ u as n,
123
+ f as s
124
+ };