@arcgis/codemod 6.0.0-next.4 → 6.0.0-next.41
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/chunks/aggregateUsages.js +351 -0
- package/dist/chunks/auditDefinitions.js +173 -0
- package/dist/chunks/auditUsages.js +1246 -0
- package/dist/chunks/classification.js +168 -126
- package/dist/chunks/cli.js +387 -231
- package/dist/chunks/codemod5.js +0 -1
- package/dist/chunks/codemod7.js +1214 -1232
- package/dist/chunks/componentAudit.js +272 -0
- package/dist/chunks/format.js +140 -112
- package/dist/chunks/legacyCompatibility.js +210 -0
- package/dist/chunks/log.js +21 -7
- package/dist/chunks/sync.js +148 -142
- package/dist/chunks/syncMarkdown.js +42 -0
- package/dist/chunks/useProjectInstance.js +27 -24
- package/package.json +10 -7
- package/dist/chunks/hardcodedBehavior.js +0 -63
- package/dist/chunks/index.js +0 -459
- package/dist/chunks/index2.js +0 -160
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { collectOutput as u } from "@arcgis/node-toolkit/shell";
|
|
2
|
+
import { m, h as l, k as p } from "./cli.js";
|
|
3
|
+
import { log as f } from "@arcgis/toolkit/log";
|
|
4
|
+
const g = /^( (?:- )?https:\/\/[^/\s]+\/[^/\s]+\/[^/\s]+\/blob\/)[a-f0-9]{40}(\/\S+#L\d+)$/gmu;
|
|
5
|
+
class v {
|
|
6
|
+
constructor(s, t = !1) {
|
|
7
|
+
this.changes = [], this.#i = /* @__PURE__ */ new Map(), this.#n = -1;
|
|
8
|
+
const [e, i, o, ...a] = s.split("/");
|
|
9
|
+
if (e === void 0 || i === void 0 || o === void 0 || a.length > 0)
|
|
10
|
+
throw new Error(`Invalid repository: ${s}`);
|
|
11
|
+
this.#e = e, this.#s = `${i}/${o}`, this.dryRun = t;
|
|
12
|
+
}
|
|
13
|
+
#e;
|
|
14
|
+
#s;
|
|
15
|
+
#i;
|
|
16
|
+
#n;
|
|
17
|
+
async #t(s, t, e) {
|
|
18
|
+
if (process.env.VITEST !== void 0)
|
|
19
|
+
throw new Error("GitHub requests are disabled while running Vitest.");
|
|
20
|
+
const i = await u(
|
|
21
|
+
"gh",
|
|
22
|
+
["api", "--hostname", this.#e, "--method", s, t, ...e === void 0 ? [] : ["--input", "-"]],
|
|
23
|
+
e === void 0 ? {} : { input: JSON.stringify(e) }
|
|
24
|
+
);
|
|
25
|
+
return i === "" ? void 0 : JSON.parse(i);
|
|
26
|
+
}
|
|
27
|
+
async listOpenIssues(s) {
|
|
28
|
+
const t = await u("gh", [
|
|
29
|
+
"api",
|
|
30
|
+
"--hostname",
|
|
31
|
+
this.#e,
|
|
32
|
+
"--method",
|
|
33
|
+
"GET",
|
|
34
|
+
"--paginate",
|
|
35
|
+
"--slurp",
|
|
36
|
+
"-f",
|
|
37
|
+
`q="${s}" in:body repo:${this.#s} is:issue is:open`,
|
|
38
|
+
"-f",
|
|
39
|
+
"per_page=100",
|
|
40
|
+
"/search/issues"
|
|
41
|
+
]), e = JSON.parse(t);
|
|
42
|
+
if (e.some(
|
|
43
|
+
({ incomplete_results: i, total_count: o }) => i || o > 1e3
|
|
44
|
+
))
|
|
45
|
+
throw new Error(`Incomplete issue search for ${s}; refusing to synchronize issues.`);
|
|
46
|
+
return e.flatMap(({ items: i }) => i);
|
|
47
|
+
}
|
|
48
|
+
async readLabelerConfig(s) {
|
|
49
|
+
const t = await this.#t(
|
|
50
|
+
"GET",
|
|
51
|
+
`/repos/${this.#s}/contents/.github?ref=${encodeURIComponent(s)}`
|
|
52
|
+
), e = t.find(({ name: o }) => o === "labeler.yml") ?? t.find(({ name: o }) => o === "labeler.yaml");
|
|
53
|
+
if (e === void 0)
|
|
54
|
+
return;
|
|
55
|
+
const { content: i } = await this.#t(
|
|
56
|
+
"GET",
|
|
57
|
+
`/repos/${this.#s}/contents/.github/${e.name}?ref=${encodeURIComponent(s)}`
|
|
58
|
+
);
|
|
59
|
+
return Buffer.from(i, "base64").toString("utf8");
|
|
60
|
+
}
|
|
61
|
+
async listLabels() {
|
|
62
|
+
const s = await u("gh", [
|
|
63
|
+
"api",
|
|
64
|
+
"--hostname",
|
|
65
|
+
this.#e,
|
|
66
|
+
"--method",
|
|
67
|
+
"GET",
|
|
68
|
+
"--paginate",
|
|
69
|
+
"--slurp",
|
|
70
|
+
`/repos/${this.#s}/labels?per_page=100`
|
|
71
|
+
]);
|
|
72
|
+
return JSON.parse(s).flat().map(({ name: t }) => t);
|
|
73
|
+
}
|
|
74
|
+
async addLabels(s, t) {
|
|
75
|
+
if (this.dryRun) {
|
|
76
|
+
this.changes.push(`ADD labels to issue #${s}: ${t.join(", ")}`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
await this.#t("POST", `/repos/${this.#s}/issues/${s}/labels`, { labels: t });
|
|
80
|
+
}
|
|
81
|
+
async createIssue(s, t, e, i) {
|
|
82
|
+
if (this.dryRun) {
|
|
83
|
+
const o = this.#n--;
|
|
84
|
+
return this.#i.set(o, s), this.changes.push(`CREATE issue: ${s}`), {
|
|
85
|
+
number: o,
|
|
86
|
+
title: s,
|
|
87
|
+
body: t,
|
|
88
|
+
assignees: e.map((a) => ({ login: a })),
|
|
89
|
+
labels: i.map((a) => ({ name: a }))
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return await this.#t("POST", `/repos/${this.#s}/issues`, {
|
|
93
|
+
title: s,
|
|
94
|
+
body: t,
|
|
95
|
+
assignees: e,
|
|
96
|
+
labels: i,
|
|
97
|
+
type: m
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
async updateIssueBody(s, t) {
|
|
101
|
+
if (this.dryRun) {
|
|
102
|
+
this.changes.push(`UPDATE issue #${s} body`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
await this.#t("PATCH", `/repos/${this.#s}/issues/${s}`, { body: t });
|
|
106
|
+
}
|
|
107
|
+
async closeIssue(s) {
|
|
108
|
+
if (this.dryRun) {
|
|
109
|
+
this.changes.push(`CLOSE issue #${s}`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
await this.#t("PATCH", `/repos/${this.#s}/issues/${s}`, { state: "closed" });
|
|
113
|
+
}
|
|
114
|
+
async listComments(s) {
|
|
115
|
+
if (this.#i.has(s))
|
|
116
|
+
return [];
|
|
117
|
+
const t = await u("gh", [
|
|
118
|
+
"api",
|
|
119
|
+
"--hostname",
|
|
120
|
+
this.#e,
|
|
121
|
+
"--method",
|
|
122
|
+
"GET",
|
|
123
|
+
"--paginate",
|
|
124
|
+
"--slurp",
|
|
125
|
+
`/repos/${this.#s}/issues/${s}/comments?per_page=100`
|
|
126
|
+
]);
|
|
127
|
+
return JSON.parse(t).flat();
|
|
128
|
+
}
|
|
129
|
+
async createComment(s, t) {
|
|
130
|
+
if (this.dryRun) {
|
|
131
|
+
const e = this.#i.get(s), i = e === void 0 ? `issue #${s}` : `new issue: ${e}`;
|
|
132
|
+
this.changes.push(`ADD comment to ${i}`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
await this.#t("POST", `/repos/${this.#s}/issues/${s}/comments`, { body: t });
|
|
136
|
+
}
|
|
137
|
+
async updateComment(s, t) {
|
|
138
|
+
if (this.dryRun) {
|
|
139
|
+
this.changes.push(`UPDATE comment #${s}`);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
await this.#t("PATCH", `/repos/${this.#s}/issues/comments/${s}`, { body: t });
|
|
143
|
+
}
|
|
144
|
+
async deleteComment(s) {
|
|
145
|
+
if (this.dryRun) {
|
|
146
|
+
this.changes.push(`REMOVE comment #${s}`);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
await this.#t("DELETE", `/repos/${this.#s}/issues/comments/${s}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async function E(n, s, t, e) {
|
|
153
|
+
const i = (await n.listComments(s)).filter(({ body: o }) => e(o));
|
|
154
|
+
for (const [o, a] of t.entries()) {
|
|
155
|
+
const r = i[o];
|
|
156
|
+
r === void 0 ? await n.createComment(s, a) : d(r.body) !== d(a) && await n.updateComment(r.id, a);
|
|
157
|
+
}
|
|
158
|
+
for (const o of i.slice(t.length))
|
|
159
|
+
await n.deleteComment(o.id);
|
|
160
|
+
}
|
|
161
|
+
function d(n) {
|
|
162
|
+
return n?.replace(g, "$1<sha>$2");
|
|
163
|
+
}
|
|
164
|
+
const c = "@arcgis/codemod", y = `<!-- ${c} -->`;
|
|
165
|
+
async function T(n) {
|
|
166
|
+
const s = await n.listOpenIssues(c);
|
|
167
|
+
for (const t of s) {
|
|
168
|
+
const e = h(t.body);
|
|
169
|
+
e !== void 0 && e.kind === void 0 && f(
|
|
170
|
+
"warn",
|
|
171
|
+
l,
|
|
172
|
+
`Cannot determine audit kind for legacy issue #${t.number}; leaving it unchanged.`
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
return s;
|
|
176
|
+
}
|
|
177
|
+
function h(n) {
|
|
178
|
+
const s = n?.split(`
|
|
179
|
+
`, 1)[0], t = s === void 0 ? null : /^<!-- (\S+)(?: (@[^\s,]+(?:,@[^\s,]+)*))? -->$/u.exec(s);
|
|
180
|
+
if (t?.[1] !== c)
|
|
181
|
+
return;
|
|
182
|
+
const e = n?.split(`
|
|
183
|
+
`, 2)[1], i = e === p.usages ? "usages" : e === p.definitions ? "definitions" : void 0, o = t[2] === void 0 ? [] : [...new Set(t[2].split(","))].sort((a, r) => a.localeCompare(r));
|
|
184
|
+
return { kind: i, owners: o };
|
|
185
|
+
}
|
|
186
|
+
function I(n, s) {
|
|
187
|
+
const t = h(n.body);
|
|
188
|
+
if (t !== void 0 && t.kind === void 0 && t.owners.join(",") === s.join(","))
|
|
189
|
+
throw new Error(
|
|
190
|
+
`Cannot determine audit kind for legacy issue #${n.number}. Restore its generated introduction before synchronizing.`
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
function S(n, s) {
|
|
194
|
+
const t = h(n);
|
|
195
|
+
return t !== void 0 && (t.owners.length === 0 || t.owners.join(",") === s.join(","));
|
|
196
|
+
}
|
|
197
|
+
function b(n) {
|
|
198
|
+
return n.split(`
|
|
199
|
+
`, 1)[0] === y;
|
|
200
|
+
}
|
|
201
|
+
export {
|
|
202
|
+
v as G,
|
|
203
|
+
I as a,
|
|
204
|
+
b,
|
|
205
|
+
S as i,
|
|
206
|
+
T as l,
|
|
207
|
+
d as n,
|
|
208
|
+
h as p,
|
|
209
|
+
E as s
|
|
210
|
+
};
|
package/dist/chunks/log.js
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
|
-
import { path as
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { path as o } from "@arcgis/node-toolkit/path";
|
|
2
|
+
import { log as a } from "@arcgis/toolkit/log";
|
|
3
|
+
function c(e) {
|
|
4
|
+
if (e)
|
|
5
|
+
return;
|
|
6
|
+
const r = "Review scan warnings above. This may indicate an unsupported pattern or a bug in @arcgis/codemod; report it to the WebGIS SDK team with a reproduction and log output. Stale deprecation issues won't be closed as results may be incomplete.";
|
|
7
|
+
if (a("error", "@arcgis/codemod", r), process.env.GITHUB_ACTIONS === "true") {
|
|
8
|
+
const t = r.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll(`
|
|
9
|
+
`, "%0A");
|
|
10
|
+
process.stderr.write(`::error::${t}
|
|
11
|
+
`);
|
|
12
|
+
}
|
|
13
|
+
process.exitCode = 1;
|
|
4
14
|
}
|
|
5
|
-
function
|
|
6
|
-
return e.
|
|
15
|
+
function p(e) {
|
|
16
|
+
return s(e.getFilePath());
|
|
17
|
+
}
|
|
18
|
+
function s(e) {
|
|
19
|
+
return o.relative(process.cwd(), e);
|
|
7
20
|
}
|
|
8
21
|
export {
|
|
9
|
-
|
|
10
|
-
|
|
22
|
+
p as a,
|
|
23
|
+
s as f,
|
|
24
|
+
c as r
|
|
11
25
|
};
|
package/dist/chunks/sync.js
CHANGED
|
@@ -1,164 +1,170 @@
|
|
|
1
|
-
import { readFile as
|
|
2
|
-
import { log as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
throw new Error("GitHub requests are disabled while running Vitest.");
|
|
21
|
-
const t = await h(
|
|
22
|
-
"gh",
|
|
23
|
-
["api", "--hostname", this.#e, "--method", s, e, ...i === void 0 ? [] : ["--input", "-"]],
|
|
24
|
-
i === void 0 ? {} : { input: JSON.stringify(i) }
|
|
25
|
-
);
|
|
26
|
-
return t === "" ? void 0 : JSON.parse(t);
|
|
27
|
-
}
|
|
28
|
-
async listOpenIssues(s) {
|
|
29
|
-
const e = await h("gh", [
|
|
30
|
-
"api",
|
|
31
|
-
"--hostname",
|
|
32
|
-
this.#e,
|
|
33
|
-
"--method",
|
|
34
|
-
"GET",
|
|
35
|
-
"--paginate",
|
|
36
|
-
"--slurp",
|
|
37
|
-
"-f",
|
|
38
|
-
`q="${s}" in:title repo:${this.#s} is:issue is:open`,
|
|
39
|
-
"-f",
|
|
40
|
-
"per_page=100",
|
|
41
|
-
"/search/issues"
|
|
42
|
-
]);
|
|
43
|
-
return JSON.parse(e).flatMap(({ items: i }) => i);
|
|
44
|
-
}
|
|
45
|
-
async createIssue(s, e, i, t) {
|
|
46
|
-
if (this.dryRun) {
|
|
47
|
-
const o = this.#n--;
|
|
48
|
-
return this.#i.set(o, s), this.changes.push(`CREATE issue: ${s}`), { number: o, title: s, body: e, assignees: i.map((a) => ({ login: a })) };
|
|
49
|
-
}
|
|
50
|
-
return await this.#t("POST", `/repos/${this.#s}/issues`, {
|
|
51
|
-
title: s,
|
|
52
|
-
body: e,
|
|
53
|
-
assignees: i,
|
|
54
|
-
labels: t,
|
|
55
|
-
type: $
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
async updateIssueBody(s, e) {
|
|
59
|
-
if (this.dryRun) {
|
|
60
|
-
this.changes.push(`UPDATE issue #${s} body`);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
await this.#t("PATCH", `/repos/${this.#s}/issues/${s}`, { body: e });
|
|
64
|
-
}
|
|
65
|
-
async listComments(s) {
|
|
66
|
-
if (this.#i.has(s))
|
|
67
|
-
return [];
|
|
68
|
-
const e = await h("gh", [
|
|
69
|
-
"api",
|
|
70
|
-
"--hostname",
|
|
71
|
-
this.#e,
|
|
72
|
-
"--method",
|
|
73
|
-
"GET",
|
|
74
|
-
"--paginate",
|
|
75
|
-
"--slurp",
|
|
76
|
-
`/repos/${this.#s}/issues/${s}/comments?per_page=100`
|
|
77
|
-
]);
|
|
78
|
-
return JSON.parse(e).flat();
|
|
79
|
-
}
|
|
80
|
-
async createComment(s, e) {
|
|
81
|
-
if (this.dryRun) {
|
|
82
|
-
const i = this.#i.get(s), t = i === void 0 ? `issue #${s}` : `new issue: ${i}`;
|
|
83
|
-
this.changes.push(`ADD comment to ${t}`);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
await this.#t("POST", `/repos/${this.#s}/issues/${s}/comments`, { body: e });
|
|
87
|
-
}
|
|
88
|
-
async updateComment(s, e) {
|
|
89
|
-
if (this.dryRun) {
|
|
90
|
-
this.changes.push(`UPDATE comment #${s}`);
|
|
91
|
-
return;
|
|
1
|
+
import { readFile as j } from "node:fs/promises";
|
|
2
|
+
import { log as l } from "@arcgis/toolkit/log";
|
|
3
|
+
import { r as M } from "./log.js";
|
|
4
|
+
import { n as x } from "./classification.js";
|
|
5
|
+
import { h as d } from "./cli.js";
|
|
6
|
+
import { c as O, a as N, p as C, b as v } from "./format.js";
|
|
7
|
+
import { G as R, l as T, n as I, s as z, p as B, a as D, i as G } from "./legacyCompatibility.js";
|
|
8
|
+
import P from "picomatch";
|
|
9
|
+
import { parse as U } from "yaml";
|
|
10
|
+
function q(s) {
|
|
11
|
+
const e = U(s);
|
|
12
|
+
if (typeof e != "object" || e === null || Array.isArray(e))
|
|
13
|
+
throw new Error("Expected a label-to-rule mapping in the labeler config.");
|
|
14
|
+
const r = [];
|
|
15
|
+
for (const [n, t] of Object.entries(e))
|
|
16
|
+
try {
|
|
17
|
+
r.push({ label: n, matches: S(t) });
|
|
18
|
+
} catch (o) {
|
|
19
|
+
l("warn", d, `Skipping labeler rule for ${n}: ${String(o)}`);
|
|
92
20
|
}
|
|
93
|
-
|
|
21
|
+
return (n) => r.filter(({ matches: t }) => n.some(t)).map(({ label: t }) => t);
|
|
22
|
+
}
|
|
23
|
+
function S(s, e = !1) {
|
|
24
|
+
if (typeof s == "string") {
|
|
25
|
+
const n = P(s, { dot: !0 });
|
|
26
|
+
return (t) => n(t);
|
|
94
27
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
28
|
+
if (Array.isArray(s))
|
|
29
|
+
return h(s, e);
|
|
30
|
+
if (typeof s != "object" || s === null || Object.keys(s).length === 0)
|
|
31
|
+
throw new Error("Expected a glob or a match object.");
|
|
32
|
+
const r = Object.entries(s).map(([n, t]) => {
|
|
33
|
+
switch (n) {
|
|
34
|
+
case "any":
|
|
35
|
+
return h(t, Array.isArray(t) && t.every((o) => typeof o == "string"));
|
|
36
|
+
case "all":
|
|
37
|
+
return h(t, !0);
|
|
38
|
+
case "changed-files":
|
|
39
|
+
return h(t, e);
|
|
40
|
+
case "any-glob-to-any-file":
|
|
41
|
+
return h(t, !1);
|
|
42
|
+
default:
|
|
43
|
+
throw new Error(`Unsupported labeler condition: ${n}.`);
|
|
99
44
|
}
|
|
100
|
-
|
|
45
|
+
});
|
|
46
|
+
return (n) => r.every((t) => t(n));
|
|
47
|
+
}
|
|
48
|
+
function h(s, e) {
|
|
49
|
+
const r = Array.isArray(s) ? s : [s];
|
|
50
|
+
if (r.length === 0)
|
|
51
|
+
throw new Error("Expected a nonempty rule list.");
|
|
52
|
+
const n = r.map((t) => S(t, e));
|
|
53
|
+
return (t) => e ? n.every((o) => o(t)) : n.some((o) => o(t));
|
|
54
|
+
}
|
|
55
|
+
async function oe(s, e, r = 0, n, t = {}) {
|
|
56
|
+
const { labels: o = [], closeResolved: c = !1 } = t, p = x(await j(s, "utf8")), g = c && H(p, r, n), m = new R(p.repository, e), y = await F(m, p.ref), b = W(O(p, y), r, n), a = await Y(b, m, o, g ? p.auditKind : void 0);
|
|
57
|
+
e && process.stdout.write(`${[J(b), ...a].filter(Boolean).join(`
|
|
58
|
+
`)}
|
|
59
|
+
`), c && M(g);
|
|
60
|
+
}
|
|
61
|
+
async function F(s, e) {
|
|
62
|
+
try {
|
|
63
|
+
const r = await s.readLabelerConfig(e);
|
|
64
|
+
return r === void 0 ? void 0 : q(r);
|
|
65
|
+
} catch (r) {
|
|
66
|
+
l("warn", d, `Skipping labeling based on .github/labeler.yml due to an error: ${String(r)}`);
|
|
67
|
+
return;
|
|
101
68
|
}
|
|
102
69
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
70
|
+
function H(s, e, r) {
|
|
71
|
+
if (e !== 0 || r !== void 0)
|
|
72
|
+
throw new Error("--close-resolved cannot be used with --offset or --limit.");
|
|
73
|
+
return s.complete !== !0 ? (l(
|
|
74
|
+
"warn",
|
|
75
|
+
d,
|
|
76
|
+
"Skipping --close-resolved: the report is not a complete, unfiltered repository-root audit. Issue creation and updates will continue."
|
|
77
|
+
), !1) : !0;
|
|
108
78
|
}
|
|
109
|
-
function
|
|
110
|
-
return
|
|
79
|
+
function W(s, e, r) {
|
|
80
|
+
return s.slice(e, r === void 0 ? void 0 : e + r);
|
|
111
81
|
}
|
|
112
|
-
async function
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
82
|
+
async function Y(s, e, r = [], n) {
|
|
83
|
+
await K(s, e, r);
|
|
84
|
+
const t = n ?? w(s[0]?.chunks[0] ?? null)?.kind, o = t === void 0 ? [] : [...await e.listOpenIssues(N[t]), ...await T(e)], c = [...new Map(o.map((a) => [a.number, a])).values()], p = n === void 0 ? [] : c.filter((a) => w(a.body)?.kind === n), g = s.map((a) => ({ plan: a, issues: Q(c, a) })), m = /* @__PURE__ */ new Set();
|
|
85
|
+
for (const a of g) {
|
|
86
|
+
const { plan: i } = a;
|
|
87
|
+
let f = a.issues[0];
|
|
88
|
+
f === void 0 ? (f = await e.createIssue(i.title, i.chunks[0], i.assignees, []), e.dryRun || l("info", d, `Created issue #${f.number}: ${i.title}`)) : I(f.body) !== I(i.chunks[0]) && (await e.updateIssueBody(f.number, i.chunks[0]), e.dryRun || l("info", d, `Updated issue #${f.number}: ${i.title}`));
|
|
89
|
+
const k = f.number, A = w(i.chunks[0]);
|
|
90
|
+
await z(e, k, i.chunks.slice(1), (u) => {
|
|
91
|
+
const $ = C(u);
|
|
92
|
+
return $?.kind === A?.kind && $?.owners.join(",") === i.owners.join(",") || G(u, i.owners);
|
|
93
|
+
});
|
|
94
|
+
const E = new Set(f.labels.map(({ name: u }) => u.toLowerCase())), L = i.labels.filter((u) => !E.has(u.toLowerCase()));
|
|
95
|
+
if (L.length > 0)
|
|
96
|
+
try {
|
|
97
|
+
await e.addLabels(k, L);
|
|
98
|
+
} catch (u) {
|
|
99
|
+
l("warn", d, `Unable to add labels to issue #${k}: ${String(u)}`);
|
|
100
|
+
}
|
|
101
|
+
m.add(k);
|
|
102
|
+
for (const u of a.issues)
|
|
103
|
+
m.add(u.number);
|
|
104
|
+
i.changes.push(...e.changes.splice(0));
|
|
120
105
|
}
|
|
106
|
+
const y = p.filter((a) => !m.has(a.number)), b = y.length === 0 ? void 0 : (await e.listLabels()).find((a) => a.toLowerCase() === "8-verified");
|
|
107
|
+
for (const a of y)
|
|
108
|
+
b !== void 0 && !a.labels.some(({ name: i }) => i.toLowerCase() === "8-verified") && await e.addLabels(a.number, [b]), await e.closeIssue(a.number), e.dryRun || l("info", d, `Closed stale issue #${a.number}: ${a.title}`);
|
|
109
|
+
return e.changes.splice(0);
|
|
121
110
|
}
|
|
122
|
-
function
|
|
123
|
-
return
|
|
124
|
-
(
|
|
111
|
+
function J(s) {
|
|
112
|
+
return s.map(
|
|
113
|
+
(e) => `ACTIONS: ${e.changes.length === 0 ? "No changes" : e.changes.join("; ")}
|
|
125
114
|
|
|
126
|
-
CODEOWNERS: ${
|
|
127
|
-
ASSIGNEES: ${
|
|
128
|
-
|
|
115
|
+
CODEOWNERS: ${e.owners.length === 0 ? "unowned" : e.owners.join(", ")}
|
|
116
|
+
ASSIGNEES: ${e.assignees.length === 0 ? "none" : e.assignees.join(", ")}
|
|
117
|
+
LABELS: ${e.labels.length === 0 ? "none" : e.labels.join(", ")}
|
|
118
|
+
TITLE: ${e.title}
|
|
129
119
|
|
|
130
|
-
${
|
|
131
|
-
${
|
|
120
|
+
${e.chunks.map((r, n) => `--- ${n === 0 ? "BODY" : "COMMENT"} (${n + 1}/${e.chunks.length}) ---
|
|
121
|
+
${r}`).join(`
|
|
132
122
|
|
|
133
123
|
`)}`
|
|
134
124
|
).join(`
|
|
135
125
|
|
|
136
126
|
`);
|
|
137
127
|
}
|
|
138
|
-
function
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
128
|
+
async function K(s, e, r) {
|
|
129
|
+
const n = new Set(s.flatMap((t) => [...r, ...t.labels]));
|
|
130
|
+
if (n.size !== 0)
|
|
131
|
+
try {
|
|
132
|
+
const t = new Map((await e.listLabels()).map((o) => [o.toLowerCase(), o]));
|
|
133
|
+
for (const o of n)
|
|
134
|
+
t.has(o.toLowerCase()) || l(
|
|
135
|
+
"warn",
|
|
136
|
+
d,
|
|
137
|
+
`.github/labeler.yml specifies a label that doesn't exist in the repository. Skipping: ${o}`
|
|
138
|
+
);
|
|
139
|
+
for (const o of s)
|
|
140
|
+
o.labels = [
|
|
141
|
+
...new Set([...r, ...o.labels].flatMap((c) => t.get(c.toLowerCase()) ?? []))
|
|
142
|
+
];
|
|
143
|
+
} catch (t) {
|
|
144
|
+
l("warn", d, `Skipping labels: unable to read repository labels: ${String(t)}`);
|
|
145
|
+
for (const o of s)
|
|
146
|
+
o.labels = [];
|
|
147
|
+
}
|
|
146
148
|
}
|
|
147
|
-
function
|
|
148
|
-
|
|
149
|
+
function Q(s, e) {
|
|
150
|
+
const r = w(e.chunks[0]);
|
|
151
|
+
if (r === void 0)
|
|
152
|
+
throw new Error("Expected an audit marker in issue plan.");
|
|
153
|
+
const n = v(r.owners, r.kind);
|
|
154
|
+
for (const o of s)
|
|
155
|
+
D(o, r.owners);
|
|
156
|
+
return s.filter((o) => {
|
|
157
|
+
const c = w(o.body);
|
|
158
|
+
return c !== void 0 && v(c.owners, c.kind) === n;
|
|
159
|
+
}).sort((o, c) => o.number - c.number);
|
|
149
160
|
}
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
const a = i[t];
|
|
154
|
-
a === void 0 ? await n.createComment(s, o) : u(a.body) !== u(o) && await n.updateComment(a.id, o);
|
|
155
|
-
}
|
|
156
|
-
for (const t of i.slice(e.length))
|
|
157
|
-
await n.deleteComment(t.id);
|
|
161
|
+
function w(s) {
|
|
162
|
+
const e = C(s) ?? B(s);
|
|
163
|
+
return e?.kind === void 0 ? void 0 : { kind: e.kind, owners: e.owners };
|
|
158
164
|
}
|
|
159
165
|
export {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
166
|
+
J as formatDryRun,
|
|
167
|
+
W as sliceIssuePlans,
|
|
168
|
+
oe as syncDeprecationIssues,
|
|
169
|
+
Y as synchronizeIssuePlans
|
|
164
170
|
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readFile as m } from "node:fs/promises";
|
|
2
|
+
import { markdownTextLimit as u, splitMarkdown as p } from "@arcgis/node-toolkit/markdown";
|
|
3
|
+
import { G as f, s as w, b as d } from "./legacyCompatibility.js";
|
|
4
|
+
const a = "<!-- arcgisCodemodSyncMarkdown -->";
|
|
5
|
+
async function M(e, t, n = !1) {
|
|
6
|
+
const { repository: s, issueNumber: c } = h(t), r = new f(s, n), o = l(await m(e, "utf8"));
|
|
7
|
+
await w(
|
|
8
|
+
r,
|
|
9
|
+
c,
|
|
10
|
+
o,
|
|
11
|
+
(i) => k(i) || d(i)
|
|
12
|
+
), n && process.stdout.write(
|
|
13
|
+
`${r.changes.length === 0 ? "No changes" : r.changes.join(`
|
|
14
|
+
`)}
|
|
15
|
+
|
|
16
|
+
${o.join(`
|
|
17
|
+
|
|
18
|
+
`)}
|
|
19
|
+
`
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
function h(e) {
|
|
23
|
+
const t = new URL(e), n = /^\/([^/]+)\/([^/]+)\/issues\/([1-9]\d*)\/?$/u.exec(t.pathname);
|
|
24
|
+
if (t.protocol !== "https:" || n === null || !Number.isSafeInteger(Number(n[3])))
|
|
25
|
+
throw new Error(`Expected an HTTPS GitHub issue URL: ${e}`);
|
|
26
|
+
return { repository: `${t.host}/${n[1]}/${n[2]}`, issueNumber: Number(n[3]) };
|
|
27
|
+
}
|
|
28
|
+
function l(e, t = u) {
|
|
29
|
+
const n = `${a}
|
|
30
|
+
|
|
31
|
+
`;
|
|
32
|
+
return p(e, t - n.length).map((s) => n + s);
|
|
33
|
+
}
|
|
34
|
+
function k(e) {
|
|
35
|
+
return e.split(`
|
|
36
|
+
`, 1)[0] === a;
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
l as createMarkdownComments,
|
|
40
|
+
k as isMarkdownComment,
|
|
41
|
+
M as syncMarkdown
|
|
42
|
+
};
|