@webship.co/workspace-plane 0.0.0-stage → 1.0.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.
- package/LICENSE +15 -0
- package/README.md +210 -2
- package/ai/agents/plane-issue-worker.md +92 -0
- package/ai/agents/plane-site-builder.md +108 -0
- package/ai/agents/plane-tester.md +121 -0
- package/ai/commands/plane-test.md +66 -0
- package/ai/prompts/plane-build-and-test.md +28 -0
- package/ai/prompts/plane-issue-to-branch.md +24 -0
- package/ai/skills/plane-scenarios/SKILL.md +77 -0
- package/ai/skills/plane-scenarios/examples/issue.feature +12 -0
- package/ai/skills/plane-scenarios/examples/roles.feature +14 -0
- package/ai/skills/plane-scenarios/examples/session.feature +14 -0
- package/commands/cmd-plane-project.sh +30 -0
- package/commands/cmd-tools-plane-cli.sh +23 -0
- package/config/plugin.plane.settings.yml +30 -0
- package/config/settings.labels.yml +57 -0
- package/dist/src/index.d.ts +34 -0
- package/dist/src/index.js +62 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/tracker.d.ts +70 -0
- package/dist/src/lib/tracker.js +706 -0
- package/dist/src/lib/tracker.js.map +1 -0
- package/features/plane.feature +53 -0
- package/package.json +116 -4
- package/scripts/args/arg-plane-cli.sh +28 -0
- package/scripts/args/arg-plane.sh +35 -0
- package/scripts/docker-compose.plane.yaml +84 -0
- package/scripts/functions/fun-plane.sh +596 -0
- package/scripts/plane-site.py +340 -0
- package/scripts/plane-start.sh +18 -0
- package/testing/site.feature +34 -0
|
@@ -0,0 +1,706 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Plane, as a provider of the tracker family (@webship.co/workspace-tracker): the work items of a project of a Plane
|
|
4
|
+
* workspace (the Community Edition), over its public REST API (/api/v1) with an API key (the X-API-Key header), in a
|
|
5
|
+
* header file, never on a command line.
|
|
6
|
+
*
|
|
7
|
+
* A scope is a workspace's slug and a project's identifier ("webship/WEB"); an item is the identifier and its number
|
|
8
|
+
* ("WEB-1"), as Plane shows it.
|
|
9
|
+
*
|
|
10
|
+
* Reads: the open work items (their state is not of the completed or cancelled group), mine, assigned to someone, the
|
|
11
|
+
* current cycle's, and a search in the title; one work item with its comments. The Community Edition answers no filter
|
|
12
|
+
* on its lists (it refuses the pql and filters parameters), so the provider reads a project's work items in pages of
|
|
13
|
+
* 100, newest change first, and keeps the ones the view asks for: at most five pages, the newest 500 changes.
|
|
14
|
+
*
|
|
15
|
+
* Plane allows 60 calls a minute for a key. The provider reads lists in pages, keeps the project, its members, states
|
|
16
|
+
* and labels for five minutes, and never makes a call per item of a list. When Plane answers 429, nothing more is sent
|
|
17
|
+
* until the time its Retry-After gives has passed, and the message says how long that is.
|
|
18
|
+
*
|
|
19
|
+
* Each author's standing is their role in the project: an Admin and a Member are inside; a Guest (who sees only the
|
|
20
|
+
* work items it created) and someone with no membership are outside, so the base keeps their items analyze-only unless
|
|
21
|
+
* a person confirms by name. The last editor is the actor of the newest change of the title or the description, else
|
|
22
|
+
* the creator: what Plane's own screen shows as "Last edited by". Plane's editor rewrites the description of an item it
|
|
23
|
+
* opens for the first time, without an activity, so `updated_by` is not read.
|
|
24
|
+
*
|
|
25
|
+
* Writes, which the base offers only with writes on, each after a person's click: a comment, a state, labels, an
|
|
26
|
+
* assignee, and a new work item. The base writes Markdown; Plane keeps HTML, so the provider turns it into the HTML
|
|
27
|
+
* Plane's editor reads, with every character of the text escaped. The Community Edition has no worklog, which the
|
|
28
|
+
* capabilities say, so the dashboard offers no "Log work". Plane is not a forge: the pull request of the work is opened
|
|
29
|
+
* from the project's forge menu. A Plane API key is `plane_api_` and 32 hex digits; the base refuses that shape in
|
|
30
|
+
* whatever is about to be posted.
|
|
31
|
+
*/
|
|
32
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
33
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
34
|
+
};
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.isOpen = exports.KEY_RE = exports.ITEM_RE = void 0;
|
|
37
|
+
exports.roleAssociation = roleAssociation;
|
|
38
|
+
exports.stateClassOf = stateClassOf;
|
|
39
|
+
exports.nameOf = nameOf;
|
|
40
|
+
exports.itemOf = itemOf;
|
|
41
|
+
exports.currentCycle = currentCycle;
|
|
42
|
+
exports.textOf = textOf;
|
|
43
|
+
exports.htmlOf = htmlOf;
|
|
44
|
+
exports.headersOf = headersOf;
|
|
45
|
+
exports.saidOf = saidOf;
|
|
46
|
+
exports.planeTracker = planeTracker;
|
|
47
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
48
|
+
const fs_1 = __importDefault(require("fs"));
|
|
49
|
+
const os_1 = __importDefault(require("os"));
|
|
50
|
+
const path_1 = __importDefault(require("path"));
|
|
51
|
+
/** A workspace's slug: the part of its address after the host. */
|
|
52
|
+
const SLUG_RE = /^[A-Za-z0-9][A-Za-z0-9_-]{0,47}$/;
|
|
53
|
+
/** A project's identifier, as Plane writes it in front of its work items' numbers. */
|
|
54
|
+
const IDENT_RE = /^[A-Z0-9]{1,12}$/;
|
|
55
|
+
/** A work item: its project's identifier and its number. */
|
|
56
|
+
exports.ITEM_RE = /^([A-Z0-9]{1,12})-([1-9][0-9]{0,8})$/;
|
|
57
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
58
|
+
/** What a Plane API key looks like. */
|
|
59
|
+
exports.KEY_RE = /plane_api_[0-9a-f]{32}/;
|
|
60
|
+
/** How long the project, its members, states and labels are kept before they are asked again. */
|
|
61
|
+
const KEEP_MS = 5 * 60 * 1000;
|
|
62
|
+
/** The pages of 100 a list reads at most. */
|
|
63
|
+
const MAX_PAGES = 5;
|
|
64
|
+
const EXPAND = 'expand=state%2Cassignees%2Clabels';
|
|
65
|
+
const configured = (v) => { const s = String(v == null ? '' : v).trim(); return s && s !== 'CHANGE_ME' ? s : ''; };
|
|
66
|
+
/** A role in the project (Plane's numbers), as the base reads an author's standing. */
|
|
67
|
+
function roleAssociation(role) {
|
|
68
|
+
const r = Number(role);
|
|
69
|
+
if (r === 20)
|
|
70
|
+
return 'owner'; // Admin
|
|
71
|
+
if (r === 15)
|
|
72
|
+
return 'member'; // Member
|
|
73
|
+
if (r === 5)
|
|
74
|
+
return 'contributor'; // Guest
|
|
75
|
+
return 'outside';
|
|
76
|
+
}
|
|
77
|
+
/** How a state reads: the completed and cancelled groups are done, started is work going on, the rest is open. */
|
|
78
|
+
function stateClassOf(state) {
|
|
79
|
+
const g = String((state && state.group) || '');
|
|
80
|
+
if (g === 'completed' || g === 'cancelled')
|
|
81
|
+
return 'done';
|
|
82
|
+
if (g === 'started')
|
|
83
|
+
return 'doing';
|
|
84
|
+
return g ? 'open' : undefined;
|
|
85
|
+
}
|
|
86
|
+
/** A work item still to be done: its state is not of the completed or cancelled group. */
|
|
87
|
+
const isOpen = (i) => stateClassOf(i && i.state) !== 'done';
|
|
88
|
+
exports.isOpen = isOpen;
|
|
89
|
+
/** The name Plane shows for an account: its display name, else its whole name, else its address. */
|
|
90
|
+
function nameOf(u) {
|
|
91
|
+
if (!u || typeof u !== 'object')
|
|
92
|
+
return 'unknown';
|
|
93
|
+
return String(u.display_name || [u.first_name, u.last_name].filter(Boolean).join(' ') || u.email || 'unknown');
|
|
94
|
+
}
|
|
95
|
+
const idOf = (u) => String((u && typeof u === 'object' ? u.id : u) || '');
|
|
96
|
+
/** A work item of the API, as the base reads an item. */
|
|
97
|
+
function itemOf(i, base, slug, ident, iteration = '') {
|
|
98
|
+
const id = `${ident}-${i.sequence_id}`;
|
|
99
|
+
return {
|
|
100
|
+
id,
|
|
101
|
+
title: String(i.name || ''),
|
|
102
|
+
url: `${base}/${slug}/browse/${id}/`,
|
|
103
|
+
state: String((i.state && i.state.name) || ''),
|
|
104
|
+
stateClass: stateClassOf(i.state),
|
|
105
|
+
assignees: (Array.isArray(i.assignees) ? i.assignees : []).filter((a) => a && typeof a === 'object').map(nameOf),
|
|
106
|
+
labels: (Array.isArray(i.labels) ? i.labels : []).filter((l) => l && typeof l === 'object' && l.name).map((l) => String(l.name)),
|
|
107
|
+
...(iteration ? { iteration } : {}),
|
|
108
|
+
updated: i.updated_at || undefined,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/** The cycle a "current cycle" view means: of the ones running today, the one that ends first. */
|
|
112
|
+
function currentCycle(list) {
|
|
113
|
+
const running = (Array.isArray(list) ? list : []).filter((c) => c && UUID_RE.test(String(c.id || '')));
|
|
114
|
+
running.sort((a, b) => String(a.end_date || '').localeCompare(String(b.end_date || '')));
|
|
115
|
+
return running.length ? { id: String(running[0].id), name: String(running[0].name || '') } : null;
|
|
116
|
+
}
|
|
117
|
+
const ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ', '#39': "'" };
|
|
118
|
+
function decode(s) {
|
|
119
|
+
return s.replace(/&(#x[0-9a-f]{1,6}|#[0-9]{1,7}|[a-z]{2,8}|#39);/gi, (all, e) => {
|
|
120
|
+
if (/^#/.test(e) && e !== '#39') {
|
|
121
|
+
const n = /^#x/i.test(e) ? parseInt(e.slice(2), 16) : parseInt(e.slice(1), 10);
|
|
122
|
+
// A control character (but a tab or a new line) stays as it is written.
|
|
123
|
+
return (n >= 0x20 || n === 9 || n === 10) && n <= 0x10ffff ? String.fromCodePoint(n) : all;
|
|
124
|
+
}
|
|
125
|
+
return ENTITIES[e.toLowerCase()] ?? all;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
const tagsOut = (s) => s.replace(/<[^>]*>/g, '');
|
|
129
|
+
/**
|
|
130
|
+
* Plane's HTML (its editor's), as the text a snapshot keeps: blocks on their own lines, list items as "- ", a task as
|
|
131
|
+
* "- [ ]" or "- [x]", a quote as "> ", code as Markdown code, a link with its address, a mention by the name `names`
|
|
132
|
+
* gives its account. An HTML comment stays as it is written: what a page does not show is still read, as data.
|
|
133
|
+
*/
|
|
134
|
+
function textOf(html, names = new Map()) {
|
|
135
|
+
const kept = [];
|
|
136
|
+
const hold = (text) => { kept.push(text); return `\u0000${kept.length - 1}\u0000`; };
|
|
137
|
+
let s = String(html || '').replace(/[\u0000-\u0002]/g, '');
|
|
138
|
+
s = s.replace(/<!--[\s\S]*?-->/g, (c) => hold(c));
|
|
139
|
+
s = s.replace(/<pre\b[^>]*>([\s\S]*?)<\/pre>/gi, (_, c) => `\n${hold(`\`\`\`\n${decode(tagsOut(c)).replace(/\n+$/, '')}\n\`\`\``)}\n`);
|
|
140
|
+
s = s.replace(/<code\b[^>]*>([\s\S]*?)<\/code>/gi, (_, c) => hold(`\`${decode(tagsOut(c))}\``));
|
|
141
|
+
s = s.replace(/<mention-component\b([^>]*)>(?:[\s\S]*?<\/mention-component>)?/gi, (_, attrs) => {
|
|
142
|
+
const who = (attrs.match(/entity_identifier="([^"]*)"/i) || [])[1] || '';
|
|
143
|
+
return hold(`@${names.get(who) || 'someone'}`);
|
|
144
|
+
});
|
|
145
|
+
s = s.replace(/<a\b[^>]*href="([^"]*)"[^>]*>([\s\S]*?)<\/a>/gi, (_, href, label) => {
|
|
146
|
+
const text = decode(tagsOut(label)).trim();
|
|
147
|
+
const url = decode(href);
|
|
148
|
+
return hold(text && text !== url ? `${text} (${url})` : url);
|
|
149
|
+
});
|
|
150
|
+
s = s.replace(/<img\b[^>]*>|<image-component\b[^>]*>(?:<\/image-component>)?/gi, (img) => {
|
|
151
|
+
const alt = (img.match(/\balt="([^"]*)"/i) || [])[1] || '';
|
|
152
|
+
return hold(alt ? `[image: ${decode(alt)}]` : '[image]');
|
|
153
|
+
});
|
|
154
|
+
// A quote's lines get "> " in front, one for each quote they are in.
|
|
155
|
+
s = s.replace(/<blockquote\b[^>]*>/gi, '\n\u0001\n').replace(/<\/blockquote>/gi, '\n\u0002\n');
|
|
156
|
+
// A list item's own wrappers (a task's checkbox, a paragraph) are not lines of their own.
|
|
157
|
+
s = s.replace(/(<li\b[^>]*>)(?:\s*<label\b[^>]*>[\s\S]*?<\/label>)?(?:\s*<(?:div|p)\b[^>]*>)*/gi, '$1');
|
|
158
|
+
s = s.replace(/(?:<\/(?:p|div)>\s*)+(<\/li>)/gi, '$1');
|
|
159
|
+
s = s.replace(/<li\b[^>]*data-checked="(true|false)"[^>]*>/gi, (_, c) => `\n- [${c === 'true' ? 'x' : ' '}] `);
|
|
160
|
+
s = s.replace(/<li\b[^>]*>/gi, '\n- ');
|
|
161
|
+
s = s.replace(/<h([1-6])\b[^>]*>/gi, (_, n) => `\n\n${'#'.repeat(Number(n))} `);
|
|
162
|
+
s = s.replace(/<br\s*\/?>/gi, '\n');
|
|
163
|
+
s = s.replace(/<\/(p|div|h[1-6]|ul|ol|table|tr)>/gi, '\n\n');
|
|
164
|
+
s = s.replace(/<(p|div|ul|ol|table|tr)\b[^>]*>/gi, '\n');
|
|
165
|
+
s = s.replace(/<\/(td|th)>/gi, ' | ');
|
|
166
|
+
s = decode(tagsOut(s));
|
|
167
|
+
// Held text may hold more held text (code in a link): put it back until none is left.
|
|
168
|
+
for (let n = 0; n < 4 && /\u0000\d+\u0000/.test(s); n++)
|
|
169
|
+
s = s.replace(/\u0000(\d+)\u0000/g, (_, k) => kept[Number(k)] ?? '');
|
|
170
|
+
let depth = 0;
|
|
171
|
+
const lines = [];
|
|
172
|
+
for (const line of s.split('\n')) {
|
|
173
|
+
const l = line.replace(/[ \t]+$/, '');
|
|
174
|
+
if (l.trim() === '\u0001') {
|
|
175
|
+
depth += 1;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (l.trim() === '\u0002') {
|
|
179
|
+
depth = Math.max(0, depth - 1);
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
lines.push(depth && l.trim() ? `${'> '.repeat(depth)}${l.trim()}` : l);
|
|
183
|
+
}
|
|
184
|
+
return lines.join('\n').replace(/\n(?:[ \t]*\n){2,}/g, '\n\n').trim();
|
|
185
|
+
}
|
|
186
|
+
const esc = (s) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
187
|
+
/** Bold and a word in underscores, in text already escaped. */
|
|
188
|
+
const emphasis = (s) => s
|
|
189
|
+
.replace(/\*\*([^*\n]+?)\*\*/g, '<strong>$1</strong>')
|
|
190
|
+
.replace(/(^|[\s(])_([^_\n]+?)_(?=$|[\s).,;:!?])/g, '$1<em>$2</em>');
|
|
191
|
+
/** One line of Markdown text: code spans, links ([text](https://…) and bare addresses), bold and emphasis. */
|
|
192
|
+
function inline(text) {
|
|
193
|
+
const out = [];
|
|
194
|
+
const code = /(`+)([^`][\s\S]*?)\1(?!`)/g;
|
|
195
|
+
let at = 0;
|
|
196
|
+
let m;
|
|
197
|
+
const rich = (s) => {
|
|
198
|
+
const parts = [];
|
|
199
|
+
const link = /\[([^\]\n]{1,300})\]\((https?:\/\/[^\s)]{1,2000})\)|(https?:\/\/[^\s<>()]*[^\s<>().,;:!?'"])/g;
|
|
200
|
+
let from = 0;
|
|
201
|
+
let l;
|
|
202
|
+
while ((l = link.exec(s))) {
|
|
203
|
+
parts.push(emphasis(esc(s.slice(from, l.index))));
|
|
204
|
+
const href = l[2] || l[3];
|
|
205
|
+
parts.push(`<a href="${esc(href)}">${l[1] ? emphasis(esc(l[1])) : esc(href)}</a>`);
|
|
206
|
+
from = l.index + l[0].length;
|
|
207
|
+
}
|
|
208
|
+
parts.push(emphasis(esc(s.slice(from))));
|
|
209
|
+
return parts.join('');
|
|
210
|
+
};
|
|
211
|
+
while ((m = code.exec(text))) {
|
|
212
|
+
out.push(rich(text.slice(at, m.index)));
|
|
213
|
+
out.push(`<code>${esc(m[2])}</code>`);
|
|
214
|
+
at = m.index + m[0].length;
|
|
215
|
+
}
|
|
216
|
+
out.push(rich(text.slice(at)));
|
|
217
|
+
return out.join('');
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Markdown, as the HTML Plane's editor reads: paragraphs, headings, lists and task lists, quotes, code blocks, code,
|
|
221
|
+
* links, bold and emphasis. Every character of the text is escaped, so nothing in it becomes markup; an HTML comment
|
|
222
|
+
* (a placeholder in a template) is left out, as a Markdown page does not show it.
|
|
223
|
+
*/
|
|
224
|
+
function htmlOf(markdown) {
|
|
225
|
+
const lines = String(markdown || '').replace(/\r\n?/g, '\n').replace(/<!--[\s\S]*?-->/g, '').split('\n');
|
|
226
|
+
const out = [];
|
|
227
|
+
let para = [];
|
|
228
|
+
let quote = [];
|
|
229
|
+
let list = null;
|
|
230
|
+
const flushPara = () => { if (para.length)
|
|
231
|
+
out.push(`<p>${para.map(inline).join('<br>')}</p>`); para = []; };
|
|
232
|
+
const flushQuote = () => { if (quote.length)
|
|
233
|
+
out.push(`<blockquote><p>${quote.map(inline).join('<br>')}</p></blockquote>`); quote = []; };
|
|
234
|
+
const flushList = () => {
|
|
235
|
+
if (!list)
|
|
236
|
+
return;
|
|
237
|
+
if (list.kind === 'task')
|
|
238
|
+
out.push(`<ul data-type="taskList">${list.items.join('')}</ul>`);
|
|
239
|
+
else
|
|
240
|
+
out.push(`<${list.kind}>${list.items.join('')}</${list.kind}>`);
|
|
241
|
+
list = null;
|
|
242
|
+
};
|
|
243
|
+
const flush = () => { flushPara(); flushQuote(); flushList(); };
|
|
244
|
+
for (let n = 0; n < lines.length; n++) {
|
|
245
|
+
const line = lines[n];
|
|
246
|
+
const fence = line.match(/^\s*(`{3,}|~{3,})/);
|
|
247
|
+
if (fence) {
|
|
248
|
+
flush();
|
|
249
|
+
const body = [];
|
|
250
|
+
const close = new RegExp(`^\\s*${fence[1][0] === '`' ? '`' : '~'}{${fence[1].length},}\\s*$`);
|
|
251
|
+
for (n += 1; n < lines.length && !close.test(lines[n]); n++)
|
|
252
|
+
body.push(lines[n]);
|
|
253
|
+
out.push(`<pre><code>${esc(body.join('\n'))}</code></pre>`);
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
if (!line.trim()) {
|
|
257
|
+
flush();
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
const heading = line.match(/^\s{0,3}(#{1,6})\s+(.*?)\s*#*\s*$/);
|
|
261
|
+
if (heading) {
|
|
262
|
+
flush();
|
|
263
|
+
out.push(`<h${heading[1].length}>${inline(heading[2])}</h${heading[1].length}>`);
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (/^\s{0,3}([-*_])(\s*\1){2,}\s*$/.test(line)) {
|
|
267
|
+
flush();
|
|
268
|
+
out.push('<hr>');
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
const q = line.match(/^\s{0,3}>\s?(.*)$/);
|
|
272
|
+
if (q) {
|
|
273
|
+
flushPara();
|
|
274
|
+
flushList();
|
|
275
|
+
quote.push(q[1]);
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
const task = line.match(/^\s*[-*+]\s+\[([ xX])\]\s+(.*)$/);
|
|
279
|
+
const bullet = line.match(/^\s*[-*+]\s+(.*)$/);
|
|
280
|
+
const numbered = line.match(/^\s*\d{1,9}[.)]\s+(.*)$/);
|
|
281
|
+
if (task || bullet || numbered) {
|
|
282
|
+
flushPara();
|
|
283
|
+
flushQuote();
|
|
284
|
+
const kind = task ? 'task' : bullet ? 'ul' : 'ol';
|
|
285
|
+
if (!list || list.kind !== kind) {
|
|
286
|
+
flushList();
|
|
287
|
+
list = { kind, items: [] };
|
|
288
|
+
}
|
|
289
|
+
const current = list;
|
|
290
|
+
if (task)
|
|
291
|
+
current.items.push(`<li data-type="taskItem" data-checked="${task[1] === ' ' ? 'false' : 'true'}"><p>${inline(task[2])}</p></li>`);
|
|
292
|
+
else
|
|
293
|
+
current.items.push(`<li><p>${inline((bullet || numbered)[1])}</p></li>`);
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
flushQuote();
|
|
297
|
+
flushList();
|
|
298
|
+
para.push(line.trim());
|
|
299
|
+
}
|
|
300
|
+
flush();
|
|
301
|
+
return out.join('') || '<p></p>';
|
|
302
|
+
}
|
|
303
|
+
/** The headers of the last answer in a curl header dump (a redirect writes more than one), by lower-case name. */
|
|
304
|
+
function headersOf(dump) {
|
|
305
|
+
const blocks = String(dump || '').replace(/\r/g, '').split(/\n\n+/).filter((b) => /^HTTP\//.test(b.trim()));
|
|
306
|
+
const last = blocks.length ? blocks[blocks.length - 1] : '';
|
|
307
|
+
const out = {};
|
|
308
|
+
for (const line of last.split('\n').slice(1)) {
|
|
309
|
+
const at = line.indexOf(':');
|
|
310
|
+
if (at > 0)
|
|
311
|
+
out[line.slice(0, at).trim().toLowerCase()] = line.slice(at + 1).trim();
|
|
312
|
+
}
|
|
313
|
+
return out;
|
|
314
|
+
}
|
|
315
|
+
/** What an answer of Plane says went wrong, in one line: its error, its detail, or the first field it refused. */
|
|
316
|
+
function saidOf(data) {
|
|
317
|
+
if (!data || typeof data !== 'object')
|
|
318
|
+
return '';
|
|
319
|
+
for (const k of ['error', 'detail', 'error_message'])
|
|
320
|
+
if (typeof data[k] === 'string' && data[k])
|
|
321
|
+
return data[k];
|
|
322
|
+
const words = [];
|
|
323
|
+
const walk = (v, key) => {
|
|
324
|
+
if (words.length >= 3)
|
|
325
|
+
return;
|
|
326
|
+
if (typeof v === 'string')
|
|
327
|
+
words.push(key && key !== 'non_field_errors' && !/^\d+$/.test(key) ? `${key}: ${v}` : v);
|
|
328
|
+
else if (Array.isArray(v))
|
|
329
|
+
v.forEach((x) => walk(x, key));
|
|
330
|
+
else if (v && typeof v === 'object')
|
|
331
|
+
for (const [k, x] of Object.entries(v))
|
|
332
|
+
walk(x, /^\d+$/.test(k) ? key : k);
|
|
333
|
+
};
|
|
334
|
+
walk(data, '');
|
|
335
|
+
return words.join('; ');
|
|
336
|
+
}
|
|
337
|
+
function planeTracker(api) {
|
|
338
|
+
const lib = api.lib;
|
|
339
|
+
const settings = () => api.settings.read() || {};
|
|
340
|
+
const base = () => configured(settings().url).replace(/\/+$/, '');
|
|
341
|
+
const token = () => configured(settings().token);
|
|
342
|
+
// Who is asking: the site and its key, so that what is kept, and a wait Plane asked for, follow a change of either.
|
|
343
|
+
const asker = () => crypto_1.default.createHash('sha1').update(`${base()}\n${token()}`).digest('hex').slice(0, 12);
|
|
344
|
+
// Plane's answer to a key that used its calls: nothing is sent for that key before this time.
|
|
345
|
+
const blocked = new Map();
|
|
346
|
+
const blockedFor = () => (blocked.get(asker()) || 0) - Date.now();
|
|
347
|
+
const limitWords = (ms) => {
|
|
348
|
+
const s = Math.max(1, Math.ceil(ms / 1000));
|
|
349
|
+
return `Plane's limit of API calls a minute for this key is used up (60 by default): try again in ${s} second${s === 1 ? '' : 's'}. Nothing was sent.`;
|
|
350
|
+
};
|
|
351
|
+
/** One call of the REST API: the key and the body in files only this user reads, removed after. */
|
|
352
|
+
async function call(method, p, body) {
|
|
353
|
+
const wait = blockedFor();
|
|
354
|
+
if (wait > 0)
|
|
355
|
+
throw new Error(limitWords(wait));
|
|
356
|
+
const dir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'ws-plane-'));
|
|
357
|
+
try {
|
|
358
|
+
const h = path_1.default.join(dir, 'headers');
|
|
359
|
+
fs_1.default.writeFileSync(h, `X-API-Key: ${token()}\nAccept: application/json\n`, { mode: 0o600 });
|
|
360
|
+
const answered = path_1.default.join(dir, 'answer-headers');
|
|
361
|
+
const args = ['-sS', '-m', '30', '-X', method, '-w', '\n%{http_code}', '-H', `@${h}`, '-D', answered];
|
|
362
|
+
if (body !== undefined) {
|
|
363
|
+
const b = path_1.default.join(dir, 'body.json');
|
|
364
|
+
fs_1.default.writeFileSync(b, JSON.stringify(body), { mode: 0o600 });
|
|
365
|
+
args.push('-H', 'Content-Type: application/json', '--data-binary', `@${b}`);
|
|
366
|
+
}
|
|
367
|
+
args.push(`${base()}/api/v1${p}`);
|
|
368
|
+
const r = await lib.run('curl', args, process.env.HOME || '/', { timeoutMs: 40 * 1000, env: process.env });
|
|
369
|
+
const out = String(r.stdout || '');
|
|
370
|
+
const at = out.lastIndexOf('\n');
|
|
371
|
+
const status = Number(out.slice(at + 1)) || 0;
|
|
372
|
+
if (!status)
|
|
373
|
+
throw new Error(lib.cliError(String(r.stderr || 'curl did not answer')));
|
|
374
|
+
let data = null;
|
|
375
|
+
try {
|
|
376
|
+
data = JSON.parse(at >= 0 ? out.slice(0, at) : out);
|
|
377
|
+
}
|
|
378
|
+
catch (_) {
|
|
379
|
+
data = null;
|
|
380
|
+
}
|
|
381
|
+
if (status === 429) {
|
|
382
|
+
let after = NaN;
|
|
383
|
+
try {
|
|
384
|
+
after = Number(headersOf(fs_1.default.readFileSync(answered, 'utf8'))['retry-after']);
|
|
385
|
+
}
|
|
386
|
+
catch (_) {
|
|
387
|
+
after = NaN;
|
|
388
|
+
}
|
|
389
|
+
const ms = (Number.isFinite(after) && after > 0 ? Math.min(after, 3600) : 60) * 1000;
|
|
390
|
+
blocked.set(asker(), Date.now() + ms);
|
|
391
|
+
throw new Error(limitWords(ms));
|
|
392
|
+
}
|
|
393
|
+
return { status, data };
|
|
394
|
+
}
|
|
395
|
+
finally {
|
|
396
|
+
fs_1.default.rmSync(dir, { recursive: true, force: true });
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const why = (r) => { const said = saidOf(r.data); return `Plane answered ${r.status}${said ? `: ${said.slice(0, 200)}` : ''}`; };
|
|
400
|
+
async function get(p) {
|
|
401
|
+
const r = await call('GET', p);
|
|
402
|
+
if (r.status < 200 || r.status >= 300)
|
|
403
|
+
throw new Error(why(r));
|
|
404
|
+
return r.data;
|
|
405
|
+
}
|
|
406
|
+
async function write(method, p, body, url) {
|
|
407
|
+
try {
|
|
408
|
+
const r = await call(method, p, body);
|
|
409
|
+
return r.status >= 200 && r.status < 300 ? { ok: true, error: '', url, data: r.data } : { ok: false, error: why(r) };
|
|
410
|
+
}
|
|
411
|
+
catch (e) {
|
|
412
|
+
return { ok: false, error: String(e.message || e) };
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
/** The rows of a list, a page of 100 at a time, the ones `keep` takes, until `limit` of them or five pages. */
|
|
416
|
+
async function pages(p, keep, limit) {
|
|
417
|
+
const found = [];
|
|
418
|
+
let cursor = '';
|
|
419
|
+
for (let n = 0; n < MAX_PAGES && found.length < limit; n++) {
|
|
420
|
+
const d = await get(`${p}${p.includes('?') ? '&' : '?'}per_page=100${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ''}`);
|
|
421
|
+
const rows = Array.isArray(d) ? d : (d && Array.isArray(d.results) ? d.results : []);
|
|
422
|
+
for (const row of rows)
|
|
423
|
+
if (found.length < limit && keep(row))
|
|
424
|
+
found.push(row);
|
|
425
|
+
if (Array.isArray(d) || !d || !d.next_page_results || !d.next_cursor)
|
|
426
|
+
break;
|
|
427
|
+
cursor = String(d.next_cursor);
|
|
428
|
+
}
|
|
429
|
+
return found;
|
|
430
|
+
}
|
|
431
|
+
// What is kept for five minutes: a project's id, its members, states and labels, and the key's own account.
|
|
432
|
+
const kept = new Map();
|
|
433
|
+
async function keep(what, make) {
|
|
434
|
+
const key = `${asker()}:${what}`;
|
|
435
|
+
const hit = kept.get(key);
|
|
436
|
+
if (hit && Date.now() - hit.at < KEEP_MS)
|
|
437
|
+
return hit.value;
|
|
438
|
+
const value = await make();
|
|
439
|
+
kept.set(key, { at: Date.now(), value });
|
|
440
|
+
return value;
|
|
441
|
+
}
|
|
442
|
+
const partsOf = (scope) => { const [slug, ident] = scope.id.split('/'); return { slug, ident }; };
|
|
443
|
+
async function projectOf(scope) {
|
|
444
|
+
const { slug, ident } = partsOf(scope);
|
|
445
|
+
return keep(`project:${scope.id}`, async () => {
|
|
446
|
+
const found = await pages(`/workspaces/${slug}/projects/`, (x) => x && x.identifier === ident, 1);
|
|
447
|
+
if (!found.length)
|
|
448
|
+
throw new Error(`no project ${ident} in the Plane workspace ${slug} that this key can see`);
|
|
449
|
+
return { id: String(found[0].id), name: String(found[0].name || ident), path: `/workspaces/${slug}/projects/${found[0].id}` };
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
async function membersOf(scope) {
|
|
453
|
+
try {
|
|
454
|
+
const project = await projectOf(scope);
|
|
455
|
+
return await keep(`members:${scope.id}`, async () => {
|
|
456
|
+
const rows = await pages(`${project.path}/project-members-lite/`, () => true, 1000);
|
|
457
|
+
return new Map(rows.filter((m) => m && m.id).map((m) => [String(m.id), {
|
|
458
|
+
name: nameOf(m), display: String(m.display_name || ''), email: String(m.email || ''), first: String(m.first_name || ''),
|
|
459
|
+
full: [m.first_name, m.last_name].filter(Boolean).join(' '), role: Number(m.role), active: m.is_active !== false,
|
|
460
|
+
}]));
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
catch (e) {
|
|
464
|
+
if (blockedFor() > 0)
|
|
465
|
+
throw e;
|
|
466
|
+
return null;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
async function personOf(scope, who) {
|
|
470
|
+
const uid = idOf(who);
|
|
471
|
+
const members = await membersOf(scope);
|
|
472
|
+
const m = members && uid ? members.get(uid) : undefined;
|
|
473
|
+
const name = who && typeof who === 'object' ? nameOf(who) : m ? m.name : 'unknown';
|
|
474
|
+
if (!uid || !members)
|
|
475
|
+
return { name, association: 'unknown' };
|
|
476
|
+
return { name, association: m && m.active ? roleAssociation(m.role) : 'outside' };
|
|
477
|
+
}
|
|
478
|
+
const me = () => keep('me', async () => { const u = await get('/users/me/'); return { id: String(u.id || ''), name: nameOf(u) }; });
|
|
479
|
+
/**
|
|
480
|
+
* Someone of the project by what the person typed: "me", the display name Plane shows ("member"), the address, the
|
|
481
|
+
* whole name or its first word. Their id. Work items go to an Admin or a Member: Plane refuses a Guest as assignee.
|
|
482
|
+
*/
|
|
483
|
+
async function memberBy(scope, who, toAssign) {
|
|
484
|
+
const w = who.trim().toLowerCase();
|
|
485
|
+
if (w === 'me')
|
|
486
|
+
return (await me()).id;
|
|
487
|
+
const list = [...((await membersOf(scope)) || new Map()).entries()].filter(([, m]) => m.active);
|
|
488
|
+
const found = list.find(([id]) => id === w)
|
|
489
|
+
|| list.find(([, m]) => m.display.toLowerCase() === w)
|
|
490
|
+
|| list.find(([, m]) => m.email.toLowerCase() === w)
|
|
491
|
+
|| list.find(([, m]) => m.full.toLowerCase() === w)
|
|
492
|
+
|| list.find(([, m]) => m.first.toLowerCase() === w);
|
|
493
|
+
if (!found)
|
|
494
|
+
throw new Error(`${who} is no member of the project`);
|
|
495
|
+
if (toAssign && found[1].role < 15)
|
|
496
|
+
throw new Error(`${who} is a Guest of the project: Plane gives work items to its Admins and Members only`);
|
|
497
|
+
return found[0];
|
|
498
|
+
}
|
|
499
|
+
const statesOf = async (scope) => {
|
|
500
|
+
const project = await projectOf(scope);
|
|
501
|
+
return keep(`states:${scope.id}`, async () => (await pages(`${project.path}/states/`, (s) => s && s.id && !s.is_triage, 1000))
|
|
502
|
+
.map((s) => ({ id: String(s.id), name: String(s.name || ''), group: String(s.group || '') })));
|
|
503
|
+
};
|
|
504
|
+
const labelsOf = async (scope) => {
|
|
505
|
+
const project = await projectOf(scope);
|
|
506
|
+
return keep(`labels:${scope.id}`, async () => new Map((await pages(`${project.path}/labels/`, (l) => l && l.id && l.name, 1000))
|
|
507
|
+
.map((l) => [String(l.name).toLowerCase(), String(l.id)])));
|
|
508
|
+
};
|
|
509
|
+
/** The work item behind an id of the scope (its project checked), as the API gives it. */
|
|
510
|
+
async function itemIn(scope, id, expand = '') {
|
|
511
|
+
const { slug, ident } = partsOf(scope);
|
|
512
|
+
const m = exports.ITEM_RE.exec(id);
|
|
513
|
+
if (!m)
|
|
514
|
+
throw new Error(`not a work item: ${id}`);
|
|
515
|
+
if (m[1] !== ident)
|
|
516
|
+
throw new Error(`${id} is not a work item of ${scope.id}`);
|
|
517
|
+
const project = await projectOf(scope);
|
|
518
|
+
const i = await get(`/workspaces/${slug}/work-items/${id}/${expand ? `?${expand}` : ''}`);
|
|
519
|
+
if (!i || String(i.project) !== project.id || !UUID_RE.test(String(i.id || '')))
|
|
520
|
+
throw new Error(`${id} is not a work item of ${scope.id}`);
|
|
521
|
+
return i;
|
|
522
|
+
}
|
|
523
|
+
const itemUrl = (scope, id) => `${base()}/${partsOf(scope).slug}/browse/${id}/`;
|
|
524
|
+
const failed = (e) => ({ ok: false, error: String(e.message || e) });
|
|
525
|
+
return {
|
|
526
|
+
id: api.name,
|
|
527
|
+
title: 'Plane',
|
|
528
|
+
label: 'PLANE',
|
|
529
|
+
noun: { one: 'work item', many: 'work items' },
|
|
530
|
+
capabilities: {
|
|
531
|
+
views: ['open', 'mine', 'assigned', 'iteration', 'query'],
|
|
532
|
+
iterationWord: 'cycle',
|
|
533
|
+
comment: true, worklog: false, transition: true, labels: true, assign: true, create: true,
|
|
534
|
+
request: 'none',
|
|
535
|
+
},
|
|
536
|
+
idPattern: exports.ITEM_RE,
|
|
537
|
+
tokenVariables: ['PLANE_API_KEY', 'PLANE_TOKEN'],
|
|
538
|
+
secret: () => token(),
|
|
539
|
+
tokenShapes: [['a Plane API key', exports.KEY_RE]],
|
|
540
|
+
ready: () => (!base() ? `no Plane address in ${api.settings.file} (url)` : !token() ? `no API key in ${api.settings.file} (token)` : ''),
|
|
541
|
+
// A workspace project has no Plane project of its own: it remembers one, or the default is used.
|
|
542
|
+
scopeOf: () => null,
|
|
543
|
+
parseScope: (text) => {
|
|
544
|
+
const t = String(text || '').trim();
|
|
545
|
+
const [slug, ident, more] = t.split('/');
|
|
546
|
+
return more === undefined && SLUG_RE.test(slug || '') && IDENT_RE.test(ident || '') && base()
|
|
547
|
+
? { id: `${slug}/${ident}`, name: `${slug}/${ident}`, web: `${base()}/${slug}/projects/` }
|
|
548
|
+
: null;
|
|
549
|
+
},
|
|
550
|
+
urlOf: (scope, id) => itemUrl(scope, id),
|
|
551
|
+
account: async () => { try {
|
|
552
|
+
return (await me()).name;
|
|
553
|
+
}
|
|
554
|
+
catch (_) {
|
|
555
|
+
return '';
|
|
556
|
+
} },
|
|
557
|
+
// The projects of the workspaces the settings name (the default scope and the list).
|
|
558
|
+
scopes: async () => {
|
|
559
|
+
const s = settings();
|
|
560
|
+
const named = [configured(s.default_scope), ...(Array.isArray(s.scopes) ? s.scopes.map(configured) : [])];
|
|
561
|
+
const slugs = [...new Set(named.map((x) => x.split('/')[0]).filter((x) => SLUG_RE.test(x)))];
|
|
562
|
+
const all = [];
|
|
563
|
+
for (const slug of slugs) {
|
|
564
|
+
const rows = await pages(`/workspaces/${slug}/projects/`, (x) => x && IDENT_RE.test(String(x.identifier || '')), 500);
|
|
565
|
+
for (const x of rows)
|
|
566
|
+
all.push({ id: `${slug}/${x.identifier}`, name: String(x.name || x.identifier), web: `${base()}/${slug}/projects/${x.id}/issues/` });
|
|
567
|
+
}
|
|
568
|
+
return all;
|
|
569
|
+
},
|
|
570
|
+
list: async (scope, q) => {
|
|
571
|
+
const { slug, ident } = partsOf(scope);
|
|
572
|
+
const project = await projectOf(scope);
|
|
573
|
+
const limit = Math.max(1, Math.min(q.limit, 100));
|
|
574
|
+
let source = `${project.path}/work-items/?${EXPAND}&order_by=-updated_at`;
|
|
575
|
+
let take = (i) => (0, exports.isOpen)(i);
|
|
576
|
+
let iteration = '';
|
|
577
|
+
const assignedTo = (i, uid) => (Array.isArray(i.assignees) ? i.assignees : []).some((a) => idOf(a) === uid);
|
|
578
|
+
if (q.view === 'mine') {
|
|
579
|
+
const mine = (await me()).id;
|
|
580
|
+
take = (i) => (0, exports.isOpen)(i) && assignedTo(i, mine);
|
|
581
|
+
}
|
|
582
|
+
if (q.view === 'assigned') {
|
|
583
|
+
if (!q.who)
|
|
584
|
+
return [];
|
|
585
|
+
const uid = await memberBy(scope, q.who, false);
|
|
586
|
+
take = (i) => (0, exports.isOpen)(i) && assignedTo(i, uid);
|
|
587
|
+
}
|
|
588
|
+
if (q.view === 'iteration') {
|
|
589
|
+
const cycle = currentCycle(await get(`${project.path}/cycles/?cycle_view=current`));
|
|
590
|
+
if (!cycle)
|
|
591
|
+
return [];
|
|
592
|
+
source = `${project.path}/cycles/${cycle.id}/cycle-issues/?${EXPAND}&order_by=-updated_at`;
|
|
593
|
+
iteration = `cycle ${cycle.name}`;
|
|
594
|
+
}
|
|
595
|
+
if (q.view === 'query') {
|
|
596
|
+
const words = String(q.text || '').trim().toLowerCase();
|
|
597
|
+
take = (i) => (0, exports.isOpen)(i) && String(i.name || '').toLowerCase().includes(words);
|
|
598
|
+
}
|
|
599
|
+
return (await pages(source, take, limit)).map((i) => itemOf(i, base(), slug, ident, iteration));
|
|
600
|
+
},
|
|
601
|
+
get: async (scope, id) => {
|
|
602
|
+
const { slug, ident } = partsOf(scope);
|
|
603
|
+
const project = await projectOf(scope);
|
|
604
|
+
const i = await itemIn(scope, id, `${EXPAND}%2Ccreated_by`);
|
|
605
|
+
const at = `${project.path}/work-items/${i.id}`;
|
|
606
|
+
const members = await membersOf(scope);
|
|
607
|
+
const names = new Map([...(members || new Map()).entries()].map(([uid, m]) => [uid, m.name]));
|
|
608
|
+
const author = await personOf(scope, i.created_by);
|
|
609
|
+
// The last editor: the actor of the newest change of the title or the description, when not the creator.
|
|
610
|
+
const edits = await pages(`${at}/activities/?expand=actor&order_by=-created_at`, (a) => a && a.verb === 'updated' && (a.field === 'name' || a.field === 'description'), 1);
|
|
611
|
+
let lastEditor;
|
|
612
|
+
if (edits.length && edits[0].actor && idOf(edits[0].actor) !== idOf(i.created_by))
|
|
613
|
+
lastEditor = await personOf(scope, edits[0].actor);
|
|
614
|
+
const comments = [];
|
|
615
|
+
for (const c of await pages(`${at}/comments/?expand=actor`, (x) => x && !x.deleted_at, 500)) {
|
|
616
|
+
const body = textOf(String(c.comment_html || ''), names);
|
|
617
|
+
if (body)
|
|
618
|
+
comments.push({ author: await personOf(scope, c.actor), body, at: String(c.created_at || '') });
|
|
619
|
+
}
|
|
620
|
+
const full = { ...itemOf(i, base(), slug, ident), body: textOf(String(i.description_html || ''), names), author, ...(lastEditor ? { lastEditor } : {}), comments };
|
|
621
|
+
return full;
|
|
622
|
+
},
|
|
623
|
+
comment: async (scope, id, markdown) => {
|
|
624
|
+
try {
|
|
625
|
+
const i = await itemIn(scope, id);
|
|
626
|
+
const project = await projectOf(scope);
|
|
627
|
+
const r = await write('POST', `${project.path}/work-items/${i.id}/comments/`, { comment_html: htmlOf(markdown) }, itemUrl(scope, id));
|
|
628
|
+
const cid = r.ok && r.data && r.data.id ? String(r.data.id) : '';
|
|
629
|
+
return r.ok ? { ok: true, error: '', url: `${itemUrl(scope, id)}${cid ? `#comment-${cid}` : ''}`, ...(cid ? { id: cid } : {}) } : r;
|
|
630
|
+
}
|
|
631
|
+
catch (e) {
|
|
632
|
+
return failed(e);
|
|
633
|
+
}
|
|
634
|
+
},
|
|
635
|
+
transitions: async (scope, id) => {
|
|
636
|
+
const i = await itemIn(scope, id);
|
|
637
|
+
const now = idOf(i.state);
|
|
638
|
+
return (await statesOf(scope)).filter((s) => s.id !== now).map((s) => ({ id: s.id, name: s.name }));
|
|
639
|
+
},
|
|
640
|
+
transition: async (scope, id, to) => {
|
|
641
|
+
if (!UUID_RE.test(to))
|
|
642
|
+
return { ok: false, error: `not a state: ${to}` };
|
|
643
|
+
try {
|
|
644
|
+
if (!(await statesOf(scope)).some((s) => s.id === to))
|
|
645
|
+
return { ok: false, error: `not a state of ${scope.id}: ${to}` };
|
|
646
|
+
const i = await itemIn(scope, id);
|
|
647
|
+
const project = await projectOf(scope);
|
|
648
|
+
return await write('PATCH', `${project.path}/work-items/${i.id}/`, { state: to }, itemUrl(scope, id));
|
|
649
|
+
}
|
|
650
|
+
catch (e) {
|
|
651
|
+
return failed(e);
|
|
652
|
+
}
|
|
653
|
+
},
|
|
654
|
+
labels: async (scope, id, add, remove) => {
|
|
655
|
+
try {
|
|
656
|
+
const all = await labelsOf(scope);
|
|
657
|
+
const missing = add.filter((n) => !all.has(n.trim().toLowerCase()));
|
|
658
|
+
if (missing.length)
|
|
659
|
+
return { ok: false, error: `no label ${missing.map((n) => `"${n}"`).join(', ')} in ${scope.id}: Plane's labels belong to the project, so add it there first` };
|
|
660
|
+
const i = await itemIn(scope, id);
|
|
661
|
+
const ids = new Set((Array.isArray(i.labels) ? i.labels : []).map(idOf));
|
|
662
|
+
for (const n of add)
|
|
663
|
+
ids.add(all.get(n.trim().toLowerCase()));
|
|
664
|
+
for (const n of remove) {
|
|
665
|
+
const lid = all.get(n.trim().toLowerCase());
|
|
666
|
+
if (lid)
|
|
667
|
+
ids.delete(lid);
|
|
668
|
+
}
|
|
669
|
+
const project = await projectOf(scope);
|
|
670
|
+
return await write('PATCH', `${project.path}/work-items/${i.id}/`, { labels: [...ids] }, itemUrl(scope, id));
|
|
671
|
+
}
|
|
672
|
+
catch (e) {
|
|
673
|
+
return failed(e);
|
|
674
|
+
}
|
|
675
|
+
},
|
|
676
|
+
assign: async (scope, id, whom) => {
|
|
677
|
+
try {
|
|
678
|
+
const uid = await memberBy(scope, whom, true);
|
|
679
|
+
const i = await itemIn(scope, id);
|
|
680
|
+
const project = await projectOf(scope);
|
|
681
|
+
return await write('PATCH', `${project.path}/work-items/${i.id}/`, { assignees: [uid] }, itemUrl(scope, id));
|
|
682
|
+
}
|
|
683
|
+
catch (e) {
|
|
684
|
+
return failed(e);
|
|
685
|
+
}
|
|
686
|
+
},
|
|
687
|
+
create: async (scope, item) => {
|
|
688
|
+
try {
|
|
689
|
+
const { ident } = partsOf(scope);
|
|
690
|
+
const project = await projectOf(scope);
|
|
691
|
+
const r = await write('POST', `${project.path}/work-items/`, { name: item.title, description_html: htmlOf(item.body) }, '');
|
|
692
|
+
const seq = r.ok && r.data ? Number(r.data.sequence_id) : 0;
|
|
693
|
+
if (!r.ok)
|
|
694
|
+
return r;
|
|
695
|
+
if (!seq)
|
|
696
|
+
return { ok: false, error: 'Plane made the work item but did not say its number' };
|
|
697
|
+
const nid = `${ident}-${seq}`;
|
|
698
|
+
return { ok: true, error: '', id: nid, url: itemUrl(scope, nid) };
|
|
699
|
+
}
|
|
700
|
+
catch (e) {
|
|
701
|
+
return failed(e);
|
|
702
|
+
}
|
|
703
|
+
},
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
//# sourceMappingURL=tracker.js.map
|