@arcgis/codemod 6.0.0-next.2 → 6.0.0-next.20

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,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
+ };