@kana-ai/edgar-ext-github 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +469 -2
- package/agents/dismiss/agent.toml +4 -0
- package/agents/dismiss/instructions.md +25 -0
- package/dist/src/api/app.d.ts +16 -0
- package/dist/src/api/app.js +32 -0
- package/dist/src/api/client.d.ts +26 -0
- package/dist/src/api/client.js +103 -0
- package/dist/src/api/failures.d.ts +8 -0
- package/dist/src/api/failures.js +31 -0
- package/dist/src/feed/alerts.d.ts +26 -0
- package/dist/src/feed/alerts.js +117 -0
- package/dist/src/feed/cards.d.ts +32 -0
- package/dist/src/feed/cards.js +164 -0
- package/dist/src/feed/service.d.ts +28 -0
- package/dist/src/feed/service.js +163 -0
- package/dist/src/index.d.ts +490 -0
- package/dist/src/index.js +62 -0
- package/dist/src/schemas/config.d.ts +57 -0
- package/dist/src/schemas/config.js +89 -0
- package/dist/src/schemas/github.d.ts +417 -0
- package/dist/src/schemas/github.js +216 -0
- package/dist/src/schemas/tools.d.ts +620 -0
- package/dist/src/schemas/tools.js +501 -0
- package/dist/src/tools/alerts.d.ts +45 -0
- package/dist/src/tools/alerts.js +100 -0
- package/dist/src/tools/branch.d.ts +9 -0
- package/dist/src/tools/branch.js +48 -0
- package/dist/src/tools/checks.d.ts +118 -0
- package/dist/src/tools/checks.js +223 -0
- package/dist/src/tools/discussion.d.ts +41 -0
- package/dist/src/tools/discussion.js +66 -0
- package/dist/src/tools/pull-request.d.ts +195 -0
- package/dist/src/tools/pull-request.js +537 -0
- package/dist/src/tools/repository.d.ts +53 -0
- package/dist/src/tools/repository.js +134 -0
- package/dist/src/tools/screenshot.d.ts +21 -0
- package/dist/src/tools/screenshot.js +99 -0
- package/dist/src/tracker/assignee.d.ts +15 -0
- package/dist/src/tracker/assignee.js +65 -0
- package/dist/src/tracker/cards.d.ts +41 -0
- package/dist/src/tracker/cards.js +361 -0
- package/dist/src/tracker/comments.d.ts +9 -0
- package/dist/src/tracker/comments.js +68 -0
- package/dist/src/tracker/description.d.ts +19 -0
- package/dist/src/tracker/description.js +55 -0
- package/dist/src/tracker/hand-back.d.ts +8 -0
- package/dist/src/tracker/hand-back.js +60 -0
- package/dist/src/tracker/port.d.ts +2 -0
- package/dist/src/tracker/port.js +42 -0
- package/dist/src/tracker/states.d.ts +77 -0
- package/dist/src/tracker/states.js +189 -0
- package/dist/src/tracker/tools.d.ts +143 -0
- package/dist/src/tracker/tools.js +131 -0
- package/dist/src/tracker/transitions.d.ts +12 -0
- package/dist/src/tracker/transitions.js +101 -0
- package/edgar-extension.json +507 -0
- package/package.json +43 -3
- package/schemas/assign.in.json +15 -0
- package/schemas/assign.out.json +14 -0
- package/schemas/attach_screenshot.in.json +44 -0
- package/schemas/attach_screenshot.out.json +31 -0
- package/schemas/batch_cards.in.json +27 -0
- package/schemas/batch_cards.out.json +37 -0
- package/schemas/branch_protection.in.json +15 -0
- package/schemas/branch_protection.out.json +67 -0
- package/schemas/ci_run.in.json +12 -0
- package/schemas/ci_run.out.json +109 -0
- package/schemas/close.in.json +14 -0
- package/schemas/close.out.json +10 -0
- package/schemas/close_pull_request.in.json +21 -0
- package/schemas/close_pull_request.out.json +14 -0
- package/schemas/comment.in.json +19 -0
- package/schemas/comment.out.json +10 -0
- package/schemas/config.json +202 -0
- package/schemas/count_sighting.in.json +17 -0
- package/schemas/count_sighting.out.json +10 -0
- package/schemas/create_card.in.json +108 -0
- package/schemas/create_card.out.json +13 -0
- package/schemas/dependabot_alerts.in.json +49 -0
- package/schemas/dependabot_alerts.out.json +75 -0
- package/schemas/dismiss_dependabot_alert.in.json +26 -0
- package/schemas/dismiss_dependabot_alert.out.json +27 -0
- package/schemas/find_assignee.in.json +15 -0
- package/schemas/find_assignee.out.json +10 -0
- package/schemas/find_cards.in.json +18 -0
- package/schemas/find_cards.out.json +33 -0
- package/schemas/find_dependabot_dismissal.in.json +12 -0
- package/schemas/find_dependabot_dismissal.out.json +27 -0
- package/schemas/find_description.in.json +15 -0
- package/schemas/find_description.out.json +10 -0
- package/schemas/find_pull_request.in.json +25 -0
- package/schemas/find_pull_request.out.json +14 -0
- package/schemas/hand_back.in.json +11 -0
- package/schemas/hand_back.out.json +18 -0
- package/schemas/linked_pull_requests.in.json +15 -0
- package/schemas/linked_pull_requests.out.json +44 -0
- package/schemas/list_pull_requests.in.json +26 -0
- package/schemas/list_pull_requests.out.json +42 -0
- package/schemas/merge_pull_request.in.json +22 -0
- package/schemas/merge_pull_request.out.json +16 -0
- package/schemas/move.in.json +15 -0
- package/schemas/move.out.json +10 -0
- package/schemas/note_pull_request.in.json +15 -0
- package/schemas/note_pull_request.out.json +10 -0
- package/schemas/open_pull_request.in.json +113 -0
- package/schemas/open_pull_request.out.json +15 -0
- package/schemas/pull_request_checks.in.json +11 -0
- package/schemas/pull_request_checks.out.json +72 -0
- package/schemas/pull_request_discussion.in.json +11 -0
- package/schemas/pull_request_discussion.out.json +107 -0
- package/schemas/pull_request_state.in.json +11 -0
- package/schemas/pull_request_state.out.json +52 -0
- package/schemas/push_branch.in.json +21 -0
- package/schemas/push_branch.out.json +13 -0
- package/schemas/release_follow_ups.in.json +15 -0
- package/schemas/release_follow_ups.out.json +13 -0
- package/schemas/reopen_dependabot_alert.in.json +33 -0
- package/schemas/reopen_dependabot_alert.out.json +22 -0
- package/schemas/restore_assignee.in.json +20 -0
- package/schemas/restore_assignee.out.json +10 -0
- package/schemas/restore_description.in.json +20 -0
- package/schemas/restore_description.out.json +10 -0
- package/schemas/update_description.in.json +15 -0
- package/schemas/update_description.out.json +14 -0
- package/schemas/update_pull_request.in.json +81 -0
- package/schemas/update_pull_request.out.json +10 -0
- package/schemas/wait_for_checks.in.json +11 -0
- package/schemas/wait_for_checks.out.json +72 -0
- package/schemas/wait_for_merge.in.json +11 -0
- package/schemas/wait_for_merge.out.json +17 -0
- package/schemas/wait_for_passed_checks.in.json +11 -0
- package/schemas/wait_for_passed_checks.out.json +72 -0
- package/schemas/wait_for_review.in.json +11 -0
- package/schemas/wait_for_review.out.json +52 -0
- package/workflows/resume.toml +17 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { blockLine, done, err, oneAtATime, ok, permanentFailure, readBlock, sighted, withBlock, } from "@kana-ai/edgar-sdk";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { github, githubCounted } from "#api/client";
|
|
4
|
+
import { foundIssues, issue, issueBy } from "#schemas/github";
|
|
5
|
+
import { assigneeOf, cardId, ensureLabels, isHeld, inScope, isPull, isState, issueOf, marker, openStates, reposOf, settingsOf, stateOf, toCard, } from "#tracker/states";
|
|
6
|
+
/** The issues of one page; GitHub's largest page is 100, and 50 keeps an answer small. */
|
|
7
|
+
const PAGE = 50;
|
|
8
|
+
/** The repository index and GitHub page of a `list_cards` cursor, `0:1` for none. */
|
|
9
|
+
function pageOf(cursor) {
|
|
10
|
+
if (cursor === null)
|
|
11
|
+
return ok({ index: 0, page: 1 });
|
|
12
|
+
const parts = /^(\d+):([1-9]\d*)$/.exec(cursor);
|
|
13
|
+
return parts?.[1] === undefined || parts[2] === undefined
|
|
14
|
+
? err(permanentFailure("invalid", "github: list_cards got a cursor it did not give", {
|
|
15
|
+
cause: cursor,
|
|
16
|
+
}))
|
|
17
|
+
: ok({ index: Number(parts[1]), page: Number(parts[2]) });
|
|
18
|
+
}
|
|
19
|
+
/** One page of the open issues of the table's repositories that are in scope and in the engine states `columns`, a repository after the other, with the cursor of the next page and the requests left. Pull requests are left out. A name that is not an engine state is `invalid`. A closed issue is never listed: the engine reads a card that a listing no longer has, and `card` answers `done` or `cancelled`. */
|
|
20
|
+
export async function listCards(ctx, input) {
|
|
21
|
+
const settings = settingsOf(ctx);
|
|
22
|
+
if (!settings.ok)
|
|
23
|
+
return settings.error;
|
|
24
|
+
const unknown = input.columns.filter((column) => !isState(column));
|
|
25
|
+
if (unknown.length > 0) {
|
|
26
|
+
return permanentFailure("invalid", "github: list_cards takes engine states", {
|
|
27
|
+
cause: unknown.join(", "),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const at = pageOf(input.cursor);
|
|
31
|
+
if (!at.ok)
|
|
32
|
+
return at.error;
|
|
33
|
+
const repos = reposOf(settings.value);
|
|
34
|
+
const repo = repos[at.value.index];
|
|
35
|
+
if (repo === undefined)
|
|
36
|
+
return done({ cards: [], next: null, budget_remaining: 0 });
|
|
37
|
+
const assignee = await assigneeOf(ctx, settings.value);
|
|
38
|
+
if (!assignee.ok)
|
|
39
|
+
return assignee.error;
|
|
40
|
+
const query = new URLSearchParams({
|
|
41
|
+
state: "open",
|
|
42
|
+
sort: "created",
|
|
43
|
+
direction: "asc",
|
|
44
|
+
per_page: String(PAGE),
|
|
45
|
+
page: String(at.value.page),
|
|
46
|
+
});
|
|
47
|
+
const labels = settings.value.tracker.labels ?? [];
|
|
48
|
+
if (labels.length > 0)
|
|
49
|
+
query.set("labels", labels.join(","));
|
|
50
|
+
const listed = await githubCounted(ctx, "GET", `/repos/${repo.repo}/issues?${query.toString()}`, z.array(issue));
|
|
51
|
+
if (!listed.ok)
|
|
52
|
+
return listed.error;
|
|
53
|
+
const cards = listed.value.value.flatMap((found) => {
|
|
54
|
+
if (isPull(found) || !inScope(settings.value, found, assignee.value))
|
|
55
|
+
return [];
|
|
56
|
+
const card = toCard(settings.value, repo, found, false);
|
|
57
|
+
return card.ok && input.columns.includes(card.value.column) ? [card.value] : [];
|
|
58
|
+
});
|
|
59
|
+
const full = listed.value.value.length === PAGE;
|
|
60
|
+
const last = at.value.index + 1 >= repos.length;
|
|
61
|
+
const next = full
|
|
62
|
+
? `${String(at.value.index)}:${String(at.value.page + 1)}`
|
|
63
|
+
: last
|
|
64
|
+
? null
|
|
65
|
+
: `${String(at.value.index + 1)}:1`;
|
|
66
|
+
return done({ cards, next, budget_remaining: listed.value.remaining });
|
|
67
|
+
}
|
|
68
|
+
/** The card `id`; a missing or deleted issue, a pull request and a key the table does not name are `not_found`, and a bad block `invalid`. An open issue out of the table's scope is `not_found` too, so the engine reads it as a card that left; a closed issue reads as `done` or `cancelled`. */
|
|
69
|
+
export async function readCard(ctx, id) {
|
|
70
|
+
const settings = settingsOf(ctx);
|
|
71
|
+
if (!settings.ok)
|
|
72
|
+
return settings.error;
|
|
73
|
+
const target = issueOf(settings.value, id);
|
|
74
|
+
if (!target.ok)
|
|
75
|
+
return target.error;
|
|
76
|
+
const read = await github(ctx, "GET", target.value.path, issue);
|
|
77
|
+
if (!read.ok)
|
|
78
|
+
return read.error;
|
|
79
|
+
if (isPull(read.value)) {
|
|
80
|
+
return permanentFailure("not_found", `github: ${id} is a pull request`);
|
|
81
|
+
}
|
|
82
|
+
const assignee = await assigneeOf(ctx, settings.value);
|
|
83
|
+
if (!assignee.ok)
|
|
84
|
+
return assignee.error;
|
|
85
|
+
if (!isHeld(settings.value, read.value, assignee.value)) {
|
|
86
|
+
return permanentFailure("not_found", `github: card ${id} is out of the scope of [extensions.github.tracker]`);
|
|
87
|
+
}
|
|
88
|
+
const card = toCard(settings.value, target.value.repo, read.value, true);
|
|
89
|
+
return card.ok ? done(card.value) : card.error;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Raises `occurrences` and `last_seen` in the block of the issue at `path` for one more sighting at `at`, read again just before, because the search and the issue list can answer an older body; an issue with no readable block, or a retried sighting, is not written.
|
|
93
|
+
* With `fingerprint`, an issue that is closed, a pull request, or no longer holds it is not written and answers `false`.
|
|
94
|
+
* The read and the write of one issue run one at a time in this process, so a `create_card` sighting and a `count_sighting` call cannot both count from one body. The key names the issue, not a fingerprint, so a call inside a fingerprint's turn never waits on itself.
|
|
95
|
+
* A count refused for good is logged and dropped, because the card was found and a count never costs the stage its card.
|
|
96
|
+
*/
|
|
97
|
+
async function countSighting(ctx, path, at, fingerprint) {
|
|
98
|
+
return await oneAtATime(`github:issue:${path}`, async () => {
|
|
99
|
+
const fresh = await github(ctx, "GET", path, issue);
|
|
100
|
+
if (!fresh.ok)
|
|
101
|
+
return fresh;
|
|
102
|
+
if (fingerprint !== undefined && !holds(fresh.value, fingerprint))
|
|
103
|
+
return ok(false);
|
|
104
|
+
const body = fresh.value.body ?? "";
|
|
105
|
+
const block = readBlock(body);
|
|
106
|
+
if (!block.ok || block.value === null)
|
|
107
|
+
return ok(true);
|
|
108
|
+
const next = sighted(block.value, at);
|
|
109
|
+
if (next === null)
|
|
110
|
+
return ok(true);
|
|
111
|
+
const written = await github(ctx, "PATCH", path, issue, { body: withBlock(body, next) });
|
|
112
|
+
if (written.ok || written.error.outcome === "temporary_failure") {
|
|
113
|
+
return written.ok ? ok(true) : written;
|
|
114
|
+
}
|
|
115
|
+
ctx.log(`sighting not counted on ${path}: ${written.error.message}`);
|
|
116
|
+
return ok(true);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/** True when `found` is an open issue, not a pull request, whose block holds `fingerprint`. */
|
|
120
|
+
function holds(found, fingerprint) {
|
|
121
|
+
const block = readBlock(found.body ?? "");
|
|
122
|
+
return (found.state === "open" && !isPull(found) && block.ok && block.value?.fingerprint === fingerprint);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The issue each fingerprint was filed into or found in by this process, with the operation that did it, read back before the search, because the search and the issue list can miss an issue filed a second ago.
|
|
126
|
+
* shortcut: one process only, and gone on restart, after which the search has caught up; upgrade when filings of one fingerprint span processes.
|
|
127
|
+
*/
|
|
128
|
+
const filings = new Map();
|
|
129
|
+
/** Forgets every remembered filing, for a test that starts cold. */
|
|
130
|
+
export function forgetFilings() {
|
|
131
|
+
filings.clear();
|
|
132
|
+
}
|
|
133
|
+
/** The holder as the answer of `create_card`, after one more sighting at the spec's `last_seen`, or now; the holder is remembered for its fingerprint. */
|
|
134
|
+
async function sightOn(ctx, spec, held) {
|
|
135
|
+
if (spec.block.fingerprint !== undefined) {
|
|
136
|
+
filings.set(spec.block.fingerprint, { ...held, operation: ctx.operation_id });
|
|
137
|
+
}
|
|
138
|
+
const at = spec.block.last_seen ?? new Date().toISOString();
|
|
139
|
+
const counted = await countSighting(ctx, held.path, at);
|
|
140
|
+
return counted.ok ? done({ id: held.id, url: held.url }) : counted.error;
|
|
141
|
+
}
|
|
142
|
+
/** The repository a new card goes to: the one whose service the block names, else the first. */
|
|
143
|
+
function homeOf(settings, spec) {
|
|
144
|
+
const repos = reposOf(settings);
|
|
145
|
+
return repos.find((repo) => repo.service === spec.block.service) ?? repos[0];
|
|
146
|
+
}
|
|
147
|
+
/** At most `max` open issues of the table's repositories that GitHub's search matches with `words`, the best match first; issues of other repositories are left out. */
|
|
148
|
+
export async function searchOpen(ctx, settings, words, max) {
|
|
149
|
+
const repos = reposOf(settings);
|
|
150
|
+
const scope = repos.map((repo) => `repo:${repo.repo}`).join(" ");
|
|
151
|
+
const q = `${words} is:issue is:open ${scope}`;
|
|
152
|
+
const found = await github(ctx, "GET", `/search/issues?${new URLSearchParams({ q, per_page: String(max) }).toString()}`, foundIssues);
|
|
153
|
+
if (!found.ok)
|
|
154
|
+
return found;
|
|
155
|
+
return ok(found.value.items.flatMap((item) => {
|
|
156
|
+
const repo = repos.find((known) => item.repository_url.endsWith(`/repos/${known.repo}`));
|
|
157
|
+
return repo === undefined ? [] : [{ repo, item }];
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
/** The words that find the block line of `key` in a body: GitHub's search drops the quotes and the `=`. */
|
|
161
|
+
function lineWords(key, value) {
|
|
162
|
+
return `"${blockLine(key, value).replaceAll('"', "")}" in:body`;
|
|
163
|
+
}
|
|
164
|
+
/** The open issue of the table's repositories whose block holds `fingerprint`; GitHub's search matches words, so the block is read to be sure. */
|
|
165
|
+
async function holderOf(ctx, settings, fingerprint) {
|
|
166
|
+
const found = await searchOpen(ctx, settings, lineWords("fingerprint", fingerprint), 5);
|
|
167
|
+
if (!found.ok)
|
|
168
|
+
return found;
|
|
169
|
+
const held = found.value.find(({ item }) => {
|
|
170
|
+
const block = readBlock(item.body ?? "");
|
|
171
|
+
return block.ok && block.value?.fingerprint === fingerprint;
|
|
172
|
+
});
|
|
173
|
+
return ok(held === undefined
|
|
174
|
+
? undefined
|
|
175
|
+
: {
|
|
176
|
+
id: cardId(held.repo, held.item.number),
|
|
177
|
+
url: held.item.html_url,
|
|
178
|
+
path: `/repos/${held.repo.repo}/issues/${String(held.item.number)}`,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/** Files an issue inside the table's scope, or returns the open issue that already holds the block's fingerprint, counting one more sighting on it. The issue goes to the repository of the block's service, else the first; it gets `title_prefix`, `labels` and the label of `spec.column`, and with `assignee_only`, `assignee`. A retry finds the issue its first call filed by the hidden marker of the operation among the newest 10 issues of the repository. Those 10 issues are also read for an open holder of the fingerprint that the search does not index yet, and calls with one fingerprint run one at a time in this process, so the second finds the issue the first filed. */
|
|
182
|
+
export async function createCard(ctx, spec) {
|
|
183
|
+
const fingerprint = spec.block.fingerprint;
|
|
184
|
+
if (fingerprint === undefined)
|
|
185
|
+
return await fileCard(ctx, spec);
|
|
186
|
+
return await oneAtATime(`github:${fingerprint}`, () => fileCard(ctx, spec));
|
|
187
|
+
}
|
|
188
|
+
/** One `create_card` call: the issue this process remembers for the fingerprint, the holder search, the newest issues, then the new issue. A retry of the operation that filed or counted on the remembered issue answers it again. */
|
|
189
|
+
async function fileCard(ctx, spec) {
|
|
190
|
+
const settings = settingsOf(ctx);
|
|
191
|
+
if (!settings.ok)
|
|
192
|
+
return settings.error;
|
|
193
|
+
const home = homeOf(settings.value, spec);
|
|
194
|
+
if (home === undefined)
|
|
195
|
+
return permanentFailure("invalid", "github: no repository in repos");
|
|
196
|
+
const fingerprint = spec.block.fingerprint;
|
|
197
|
+
if (fingerprint !== undefined) {
|
|
198
|
+
const known = filings.get(fingerprint);
|
|
199
|
+
if (known?.operation === ctx.operation_id)
|
|
200
|
+
return done({ id: known.id, url: known.url });
|
|
201
|
+
if (known !== undefined) {
|
|
202
|
+
const at = spec.block.last_seen ?? new Date().toISOString();
|
|
203
|
+
const counted = await countSighting(ctx, known.path, at, fingerprint);
|
|
204
|
+
if (!counted.ok && counted.error.outcome === "temporary_failure")
|
|
205
|
+
return counted.error;
|
|
206
|
+
if (counted.ok && counted.value) {
|
|
207
|
+
filings.set(fingerprint, { ...known, operation: ctx.operation_id });
|
|
208
|
+
return done({ id: known.id, url: known.url });
|
|
209
|
+
}
|
|
210
|
+
filings.delete(fingerprint);
|
|
211
|
+
}
|
|
212
|
+
const held = await holderOf(ctx, settings.value, fingerprint);
|
|
213
|
+
if (!held.ok)
|
|
214
|
+
return held.error;
|
|
215
|
+
if (held.value !== undefined)
|
|
216
|
+
return await sightOn(ctx, spec, held.value);
|
|
217
|
+
}
|
|
218
|
+
const mark = marker(ctx.operation_id);
|
|
219
|
+
const recent = new URLSearchParams({
|
|
220
|
+
state: "all",
|
|
221
|
+
sort: "created",
|
|
222
|
+
direction: "desc",
|
|
223
|
+
per_page: "10",
|
|
224
|
+
});
|
|
225
|
+
const earlier = await github(ctx, "GET", `/repos/${home.repo}/issues?${recent.toString()}`, z.array(issue));
|
|
226
|
+
if (!earlier.ok)
|
|
227
|
+
return earlier.error;
|
|
228
|
+
const filed = earlier.value.find((found) => (found.body ?? "").includes(mark));
|
|
229
|
+
if (filed !== undefined)
|
|
230
|
+
return done({ id: cardId(home, filed.number), url: filed.html_url });
|
|
231
|
+
const twin = earlier.value.find((found) => fingerprint !== undefined && holds(found, fingerprint));
|
|
232
|
+
if (twin !== undefined) {
|
|
233
|
+
return await sightOn(ctx, spec, {
|
|
234
|
+
id: cardId(home, twin.number),
|
|
235
|
+
url: twin.html_url,
|
|
236
|
+
path: `/repos/${home.repo}/issues/${String(twin.number)}`,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
const assignee = await assigneeOf(ctx, settings.value);
|
|
240
|
+
if (!assignee.ok)
|
|
241
|
+
return assignee.error;
|
|
242
|
+
const state = openStates.find((open) => open === spec.column);
|
|
243
|
+
const column = state === undefined ? undefined : settings.value.columns[state];
|
|
244
|
+
const labels = [
|
|
245
|
+
...new Set([
|
|
246
|
+
...(spec.labels ?? []),
|
|
247
|
+
...(settings.value.tracker.labels ?? []),
|
|
248
|
+
...(column === undefined ? [] : [column]),
|
|
249
|
+
]),
|
|
250
|
+
];
|
|
251
|
+
const made = await ensureLabels(ctx, home, labels);
|
|
252
|
+
if (!made.ok)
|
|
253
|
+
return made.error;
|
|
254
|
+
const prefix = settings.value.tracker.title_prefix ?? "";
|
|
255
|
+
const created = await github(ctx, "POST", `/repos/${home.repo}/issues`, issue, {
|
|
256
|
+
title: spec.title.startsWith(prefix) ? spec.title : `${prefix} ${spec.title}`,
|
|
257
|
+
body: withBlock(`${spec.description.trimEnd()}\n\n${mark}`, spec.block),
|
|
258
|
+
...(labels.length === 0 ? {} : { labels }),
|
|
259
|
+
...(assignee.value === undefined ? {} : { assignees: [assignee.value] }),
|
|
260
|
+
});
|
|
261
|
+
if (!created.ok)
|
|
262
|
+
return created.error;
|
|
263
|
+
const holder = {
|
|
264
|
+
id: cardId(home, created.value.number),
|
|
265
|
+
url: created.value.html_url,
|
|
266
|
+
path: `/repos/${home.repo}/issues/${String(created.value.number)}`,
|
|
267
|
+
};
|
|
268
|
+
if (fingerprint !== undefined) {
|
|
269
|
+
filings.set(fingerprint, { ...holder, operation: ctx.operation_id });
|
|
270
|
+
}
|
|
271
|
+
return done({ id: holder.id, url: holder.url });
|
|
272
|
+
}
|
|
273
|
+
/** Counts one more sighting, at `seen` or now, of the fault that the card `card` holds, for a fault that a run found again without filing a card. */
|
|
274
|
+
export async function countSightingOn(ctx, card, seen) {
|
|
275
|
+
const settings = settingsOf(ctx);
|
|
276
|
+
if (!settings.ok)
|
|
277
|
+
return settings.error;
|
|
278
|
+
const target = issueOf(settings.value, card);
|
|
279
|
+
if (!target.ok)
|
|
280
|
+
return target.error;
|
|
281
|
+
const counted = await countSighting(ctx, target.value.path, seen ?? new Date().toISOString());
|
|
282
|
+
return counted.ok ? done({ id: card }) : counted.error;
|
|
283
|
+
}
|
|
284
|
+
/** At most 10 open issues of the table's repositories and scope that GitHub's search matches with the first 200 characters of `text`, without quotes or colons, the best match first. With `except`, that card and each issue made after it are left out, so two cards never point at each other; a missing `except` is `not_found`. */
|
|
285
|
+
export async function findCards(ctx, text, except) {
|
|
286
|
+
const settings = settingsOf(ctx);
|
|
287
|
+
if (!settings.ok)
|
|
288
|
+
return settings.error;
|
|
289
|
+
let before = "";
|
|
290
|
+
if (except !== undefined) {
|
|
291
|
+
const target = issueOf(settings.value, except);
|
|
292
|
+
if (!target.ok)
|
|
293
|
+
return target.error;
|
|
294
|
+
const read = await github(ctx, "GET", target.value.path, issueBy);
|
|
295
|
+
if (!read.ok)
|
|
296
|
+
return read.error;
|
|
297
|
+
before = ` created:<${read.value.created_at}`;
|
|
298
|
+
}
|
|
299
|
+
const assignee = await assigneeOf(ctx, settings.value);
|
|
300
|
+
if (!assignee.ok)
|
|
301
|
+
return assignee.error;
|
|
302
|
+
const words = text
|
|
303
|
+
.replaceAll(/[":\s]+/g, " ")
|
|
304
|
+
.trim()
|
|
305
|
+
.slice(0, 200);
|
|
306
|
+
const found = await searchOpen(ctx, settings.value, `${words}${before}`, 10);
|
|
307
|
+
if (!found.ok)
|
|
308
|
+
return found.error;
|
|
309
|
+
return done({
|
|
310
|
+
cards: found.value
|
|
311
|
+
.filter(({ item }) => inScope(settings.value, item, assignee.value))
|
|
312
|
+
.map(({ repo, item }) => ({
|
|
313
|
+
id: cardId(repo, item.number),
|
|
314
|
+
title: item.title,
|
|
315
|
+
url: item.html_url,
|
|
316
|
+
state: stateOf(settings.value, item),
|
|
317
|
+
created_at: item.created_at,
|
|
318
|
+
})),
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
/** At most 20 open issues of the table's repositories and scope whose block names `batch` in `decided.batch`, with `except` left out. With `ids`, only those, and the ids not found as `skipped`. An issue whose block does not read is left out. */
|
|
322
|
+
export async function batchCards(ctx, batch, except, ids) {
|
|
323
|
+
const settings = settingsOf(ctx);
|
|
324
|
+
if (!settings.ok)
|
|
325
|
+
return settings.error;
|
|
326
|
+
const assignee = await assigneeOf(ctx, settings.value);
|
|
327
|
+
if (!assignee.ok)
|
|
328
|
+
return assignee.error;
|
|
329
|
+
const found = await searchOpen(ctx, settings.value, lineWords("batch", batch), 21);
|
|
330
|
+
if (!found.ok)
|
|
331
|
+
return found.error;
|
|
332
|
+
const cards = found.value.flatMap(({ repo, item }) => {
|
|
333
|
+
const description = item.body ?? "";
|
|
334
|
+
const block = readBlock(description);
|
|
335
|
+
const id = cardId(repo, item.number);
|
|
336
|
+
const same = block.ok && block.value?.decided?.["batch"] === batch;
|
|
337
|
+
return same && id !== except && inScope(settings.value, item, assignee.value)
|
|
338
|
+
? [{ id, title: item.title, url: item.html_url, description }]
|
|
339
|
+
: [];
|
|
340
|
+
});
|
|
341
|
+
if (ids === undefined)
|
|
342
|
+
return done({ cards: cards.slice(0, 20) });
|
|
343
|
+
const wanted = new Set(ids);
|
|
344
|
+
const kept = cards.filter((card) => wanted.has(card.id)).slice(0, 20);
|
|
345
|
+
const keptIds = new Set(kept.map((card) => card.id));
|
|
346
|
+
const skipped = [...wanted].filter((id) => !keptIds.has(id));
|
|
347
|
+
return done(skipped.length === 0 ? { cards: kept } : { cards: kept, skipped });
|
|
348
|
+
}
|
|
349
|
+
/** The open issues in `intake` whose block waits for `card`, from the search API, read to be sure. */
|
|
350
|
+
export async function waitingOn(ctx, settings, card) {
|
|
351
|
+
const found = await searchOpen(ctx, settings, lineWords("waits_for", card), 50);
|
|
352
|
+
if (!found.ok)
|
|
353
|
+
return found;
|
|
354
|
+
return ok(found.value.flatMap(({ repo, item }) => {
|
|
355
|
+
const block = readBlock(item.body ?? "");
|
|
356
|
+
const intake = stateOf(settings, item) === "intake";
|
|
357
|
+
return block.ok && block.value?.waits_for === card && intake
|
|
358
|
+
? [cardId(repo, item.number)]
|
|
359
|
+
: [];
|
|
360
|
+
}));
|
|
361
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Comment } from "@kana-ai/edgar-contracts/rpc";
|
|
2
|
+
import { type Outcome } from "@kana-ai/edgar-sdk";
|
|
3
|
+
import { type GithubCtx } from "#tracker/states";
|
|
4
|
+
/** Posts a comment with the hidden marker of the operation; a repeat finds the first comment on the issue's last page instead of posting twice. */
|
|
5
|
+
export declare function postComment(ctx: GithubCtx, card: string, text: string): Promise<Outcome<{
|
|
6
|
+
id: string;
|
|
7
|
+
}>>;
|
|
8
|
+
/** The first 100 comments of card `id` made after `since`, oldest first, without EDGAR's hidden marker, each flagged when it mentions EDGAR's login. */
|
|
9
|
+
export declare function listComments(ctx: GithubCtx, id: string, since: string | null): Promise<Outcome<Comment[]>>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { done } from "@kana-ai/edgar-sdk";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { github } from "#api/client";
|
|
4
|
+
import { cardComment, issue } from "#schemas/github";
|
|
5
|
+
import { issueOf, marker, ownLogin, settingsOf } from "#tracker/states";
|
|
6
|
+
/** The most comments one page answers. */
|
|
7
|
+
const PAGE = 100;
|
|
8
|
+
/** The hidden marker a comment of EDGAR ends with, which a reader never needs. */
|
|
9
|
+
const trailer = /\n\n<!-- edgar:op [0-9a-f]{16} -->$/;
|
|
10
|
+
/** Posts a comment with the hidden marker of the operation; a repeat finds the first comment on the issue's last page instead of posting twice. */
|
|
11
|
+
export async function postComment(ctx, card, text) {
|
|
12
|
+
const settings = settingsOf(ctx);
|
|
13
|
+
if (!settings.ok)
|
|
14
|
+
return settings.error;
|
|
15
|
+
const target = issueOf(settings.value, card);
|
|
16
|
+
if (!target.ok)
|
|
17
|
+
return target.error;
|
|
18
|
+
const read = await github(ctx, "GET", target.value.path, issue.pick({ number: true }).extend({ comments: z.number().int() }));
|
|
19
|
+
if (!read.ok)
|
|
20
|
+
return read.error;
|
|
21
|
+
const mark = marker(ctx.operation_id);
|
|
22
|
+
if (read.value.comments > 0) {
|
|
23
|
+
const last = Math.ceil(read.value.comments / PAGE);
|
|
24
|
+
const page = await github(ctx, "GET", `${target.value.path}/comments?per_page=${String(PAGE)}&page=${String(last)}`, z.array(cardComment));
|
|
25
|
+
if (!page.ok)
|
|
26
|
+
return page.error;
|
|
27
|
+
const earlier = page.value.find((said) => (said.body ?? "").endsWith(mark));
|
|
28
|
+
if (earlier !== undefined)
|
|
29
|
+
return done({ id: String(earlier.id) });
|
|
30
|
+
}
|
|
31
|
+
const made = await github(ctx, "POST", `${target.value.path}/comments`, cardComment, {
|
|
32
|
+
body: `${text}\n\n${mark}`,
|
|
33
|
+
});
|
|
34
|
+
return made.ok ? done({ id: String(made.value.id) }) : made.error;
|
|
35
|
+
}
|
|
36
|
+
/** The first 100 comments of card `id` made after `since`, oldest first, without EDGAR's hidden marker, each flagged when it mentions EDGAR's login. */
|
|
37
|
+
export async function listComments(ctx, id, since) {
|
|
38
|
+
const settings = settingsOf(ctx);
|
|
39
|
+
if (!settings.ok)
|
|
40
|
+
return settings.error;
|
|
41
|
+
const target = issueOf(settings.value, id);
|
|
42
|
+
if (!target.ok)
|
|
43
|
+
return target.error;
|
|
44
|
+
const me = await ownLogin(ctx, settings.value);
|
|
45
|
+
if (!me.ok)
|
|
46
|
+
return me.error;
|
|
47
|
+
const query = new URLSearchParams({ per_page: String(PAGE) });
|
|
48
|
+
if (since !== null)
|
|
49
|
+
query.set("since", since);
|
|
50
|
+
const read = await github(ctx, "GET", `${target.value.path}/comments?${query.toString()}`, z.array(cardComment));
|
|
51
|
+
if (!read.ok)
|
|
52
|
+
return read.error;
|
|
53
|
+
const after = since === null ? 0 : Date.parse(since);
|
|
54
|
+
const mention = new RegExp(`@${me.value.replace(/[[\]]/g, "\\$&")}(?![\\w-])`, "i");
|
|
55
|
+
return done(read.value
|
|
56
|
+
.filter((said) => Date.parse(said.created_at) > after)
|
|
57
|
+
.map((said) => {
|
|
58
|
+
const text = (said.body ?? "").replace(trailer, "");
|
|
59
|
+
return {
|
|
60
|
+
id: String(said.id),
|
|
61
|
+
author: said.user?.login ?? "",
|
|
62
|
+
text,
|
|
63
|
+
at: said.created_at,
|
|
64
|
+
mentioned: mention.test(text),
|
|
65
|
+
};
|
|
66
|
+
})
|
|
67
|
+
.sort((a, b) => a.at.localeCompare(b.at)));
|
|
68
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Outcome } from "@kana-ai/edgar-sdk";
|
|
2
|
+
import { type GithubCtx } from "#tracker/states";
|
|
3
|
+
/** Replaces a card's body, keeping its block, and answers the body it replaced. A body that already reads so is not written again and gets no `previous`: this call cannot know what a lost earlier call replaced, so its undo writes nothing. */
|
|
4
|
+
export declare function updateDescription(ctx: GithubCtx, card: string, text: string): Promise<Outcome<{
|
|
5
|
+
id: string;
|
|
6
|
+
previous?: string;
|
|
7
|
+
}>>;
|
|
8
|
+
/**
|
|
9
|
+
* Writes `previous` back as the card's body, as it was before `update_description`, with the card's current block, so a count made since stays. With no `previous` the undone call wrote nothing, so this writes nothing.
|
|
10
|
+
*
|
|
11
|
+
* shortcut: a retried `update_description` whose first answer was lost has no `previous` either, so its undo leaves the new text; keep the replaced text in the first call's own record when a card must get it back.
|
|
12
|
+
*/
|
|
13
|
+
export declare function restoreDescription(ctx: GithubCtx, card: string, previous: string | undefined): Promise<Outcome<{
|
|
14
|
+
id: string;
|
|
15
|
+
}>>;
|
|
16
|
+
/** `done` when the card's body already is what `update_description` writes for `text`, else `skipped`: the lookup of a call that did not end. */
|
|
17
|
+
export declare function findDescription(ctx: GithubCtx, card: string, text: string): Promise<Outcome<{
|
|
18
|
+
id: string;
|
|
19
|
+
}>>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { done, err, ok, readBlock, skipped, withBlock, } from "@kana-ai/edgar-sdk";
|
|
2
|
+
import { github } from "#api/client";
|
|
3
|
+
import { issue } from "#schemas/github";
|
|
4
|
+
import { issueOf, settingsOf } from "#tracker/states";
|
|
5
|
+
/** The issue behind a card, and the body a replace with `text` writes: `text`, with the card's `edgar:v0` block kept, so the fingerprint and `waits_for` survive. */
|
|
6
|
+
async function planned(ctx, card, text) {
|
|
7
|
+
const settings = settingsOf(ctx);
|
|
8
|
+
if (!settings.ok)
|
|
9
|
+
return err(settings.error);
|
|
10
|
+
const target = issueOf(settings.value, card);
|
|
11
|
+
if (!target.ok)
|
|
12
|
+
return err(target.error);
|
|
13
|
+
const read = await github(ctx, "GET", target.value.path, issue);
|
|
14
|
+
if (!read.ok)
|
|
15
|
+
return err(read.error);
|
|
16
|
+
const current = read.value.body ?? "";
|
|
17
|
+
const block = readBlock(current);
|
|
18
|
+
const next = block.ok && block.value !== null ? withBlock(text, block.value) : text;
|
|
19
|
+
return ok({ path: target.value.path, current, next });
|
|
20
|
+
}
|
|
21
|
+
/** Replaces a card's body, keeping its block, and answers the body it replaced. A body that already reads so is not written again and gets no `previous`: this call cannot know what a lost earlier call replaced, so its undo writes nothing. */
|
|
22
|
+
export async function updateDescription(ctx, card, text) {
|
|
23
|
+
const plan = await planned(ctx, card, text);
|
|
24
|
+
if (!plan.ok)
|
|
25
|
+
return plan.error;
|
|
26
|
+
const { path, current, next } = plan.value;
|
|
27
|
+
if (current === next)
|
|
28
|
+
return done({ id: card });
|
|
29
|
+
const written = await github(ctx, "PATCH", path, issue, { body: next });
|
|
30
|
+
return written.ok ? done({ id: card, previous: current }) : written.error;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Writes `previous` back as the card's body, as it was before `update_description`, with the card's current block, so a count made since stays. With no `previous` the undone call wrote nothing, so this writes nothing.
|
|
34
|
+
*
|
|
35
|
+
* shortcut: a retried `update_description` whose first answer was lost has no `previous` either, so its undo leaves the new text; keep the replaced text in the first call's own record when a card must get it back.
|
|
36
|
+
*/
|
|
37
|
+
export async function restoreDescription(ctx, card, previous) {
|
|
38
|
+
if (previous === undefined)
|
|
39
|
+
return done({ id: card });
|
|
40
|
+
const plan = await planned(ctx, card, previous);
|
|
41
|
+
if (!plan.ok)
|
|
42
|
+
return plan.error;
|
|
43
|
+
const { path, current, next } = plan.value;
|
|
44
|
+
if (current === next)
|
|
45
|
+
return done({ id: card });
|
|
46
|
+
const written = await github(ctx, "PATCH", path, issue, { body: next });
|
|
47
|
+
return written.ok ? done({ id: card }) : written.error;
|
|
48
|
+
}
|
|
49
|
+
/** `done` when the card's body already is what `update_description` writes for `text`, else `skipped`: the lookup of a call that did not end. */
|
|
50
|
+
export async function findDescription(ctx, card, text) {
|
|
51
|
+
const plan = await planned(ctx, card, text);
|
|
52
|
+
if (!plan.ok)
|
|
53
|
+
return plan.error;
|
|
54
|
+
return plan.value.current === plan.value.next ? done({ id: card }) : skipped();
|
|
55
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Outcome } from "@kana-ai/edgar-sdk";
|
|
2
|
+
import { type GithubCtx } from "#tracker/states";
|
|
3
|
+
/** Gives the card to the person who asked for the work: the newest person who assigned it to EDGAR, else its writer, never EDGAR's login, an App or a bot. Adds edgar:waiting with the label endpoint, so a label a person sets meanwhile stays, and so with `assignee_only` the card and the person's reply stay in scope. A card that nobody can be given, such as a feeder's card, is `skipped`. */
|
|
4
|
+
export declare function handBack(ctx: GithubCtx, card: string): Promise<Outcome<{
|
|
5
|
+
id: string;
|
|
6
|
+
to: string;
|
|
7
|
+
previous: string;
|
|
8
|
+
}>>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { done, skipped } from "@kana-ai/edgar-sdk";
|
|
2
|
+
import { github } from "#api/client";
|
|
3
|
+
import { issueBy, issueEvent } from "#schemas/github";
|
|
4
|
+
import { WAITING, assigneeOf, ensureLabels, issueOf, labelNames, ownLogin, relabel, settingsOf, } from "#tracker/states";
|
|
5
|
+
/** Gives the card to the person who asked for the work: the newest person who assigned it to EDGAR, else its writer, never EDGAR's login, an App or a bot. Adds edgar:waiting with the label endpoint, so a label a person sets meanwhile stays, and so with `assignee_only` the card and the person's reply stay in scope. A card that nobody can be given, such as a feeder's card, is `skipped`. */
|
|
6
|
+
export async function handBack(ctx, card) {
|
|
7
|
+
const settings = settingsOf(ctx);
|
|
8
|
+
if (!settings.ok)
|
|
9
|
+
return settings.error;
|
|
10
|
+
const target = issueOf(settings.value, card);
|
|
11
|
+
if (!target.ok)
|
|
12
|
+
return target.error;
|
|
13
|
+
const read = await github(ctx, "GET", target.value.path, issueBy);
|
|
14
|
+
if (!read.ok)
|
|
15
|
+
return read.error;
|
|
16
|
+
const events = await github(ctx, "GET", `${target.value.path}/events?per_page=100`, issueEvent.array());
|
|
17
|
+
if (!events.ok)
|
|
18
|
+
return events.error;
|
|
19
|
+
const me = await ownLogin(ctx, settings.value);
|
|
20
|
+
if (!me.ok)
|
|
21
|
+
return me.error;
|
|
22
|
+
const assignee = await assigneeOf(ctx, settings.value);
|
|
23
|
+
if (!assignee.ok)
|
|
24
|
+
return assignee.error;
|
|
25
|
+
const own = new Set([me.value, assignee.value ?? me.value]);
|
|
26
|
+
const human = (who) => who !== null &&
|
|
27
|
+
who !== undefined &&
|
|
28
|
+
who.type !== "Bot" &&
|
|
29
|
+
!who.login.endsWith("[bot]") &&
|
|
30
|
+
!own.has(who.login);
|
|
31
|
+
const handOver = events.value
|
|
32
|
+
.filter((entry) => entry.event === "assigned" && own.has(entry.assignee?.login ?? ""))
|
|
33
|
+
.toSorted((a, b) => b.created_at.localeCompare(a.created_at))
|
|
34
|
+
.map((entry) => entry.actor)
|
|
35
|
+
.find(human);
|
|
36
|
+
const to = handOver ?? (human(read.value.user) ? read.value.user : undefined);
|
|
37
|
+
if (to === undefined)
|
|
38
|
+
return skipped();
|
|
39
|
+
const assignees = read.value.assignees ?? [];
|
|
40
|
+
const previous = assignees[0]?.login ?? "";
|
|
41
|
+
const names = labelNames(read.value);
|
|
42
|
+
const labelled = names.includes(WAITING);
|
|
43
|
+
const answer = { id: card, to: to.login, previous };
|
|
44
|
+
if (assignees.length === 1 && previous === to.login && labelled)
|
|
45
|
+
return done(answer);
|
|
46
|
+
if (assignees.length !== 1 || previous !== to.login) {
|
|
47
|
+
const assigned = await github(ctx, "PATCH", target.value.path, issueBy, {
|
|
48
|
+
assignees: [to.login],
|
|
49
|
+
});
|
|
50
|
+
if (!assigned.ok)
|
|
51
|
+
return assigned.error;
|
|
52
|
+
}
|
|
53
|
+
if (labelled)
|
|
54
|
+
return done(answer);
|
|
55
|
+
const made = await ensureLabels(ctx, target.value.repo, [WAITING]);
|
|
56
|
+
if (!made.ok)
|
|
57
|
+
return made.error;
|
|
58
|
+
const added = await relabel(ctx, target.value.path, [WAITING], []);
|
|
59
|
+
return added.ok ? done(answer) : added.error;
|
|
60
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** The tracker port over GitHub Issues, across each repository of `[extensions.github.tracker] repos`. With no `columns` and `tracker` tables, each method answers `invalid`. GitHub keeps no attachments apart from the body, so `attachments` answers none. */
|
|
2
|
+
export declare const tracker: import("@kana-ai/edgar-sdk").Tracker;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { defineTracker, done } from "@kana-ai/edgar-sdk";
|
|
2
|
+
import { apiAccess } from "#api/client";
|
|
3
|
+
import { createCard, listCards, readCard } from "#tracker/cards";
|
|
4
|
+
import { listComments, postComment } from "#tracker/comments";
|
|
5
|
+
import { ownLogin, personOf, settingsOf } from "#tracker/states";
|
|
6
|
+
import { setLabels, transition } from "#tracker/transitions";
|
|
7
|
+
function asNull(outcome) {
|
|
8
|
+
return outcome.outcome === "done" ? done(null) : outcome;
|
|
9
|
+
}
|
|
10
|
+
function asCreated(outcome) {
|
|
11
|
+
return outcome.outcome === "done" ? done({ id: outcome.output.id }) : outcome;
|
|
12
|
+
}
|
|
13
|
+
/** The tracker port over GitHub Issues, across each repository of `[extensions.github.tracker] repos`. With no `columns` and `tracker` tables, each method answers `invalid`. GitHub keeps no attachments apart from the body, so `attachments` answers none. */
|
|
14
|
+
export const tracker = defineTracker({
|
|
15
|
+
...apiAccess,
|
|
16
|
+
list_cards: async (input, ctx) => await listCards(ctx, input),
|
|
17
|
+
card: async ({ id }, ctx) => await readCard(ctx, id),
|
|
18
|
+
comments: async ({ id, since }, ctx) => await listComments(ctx, id, since),
|
|
19
|
+
attachments: (_input, ctx) => {
|
|
20
|
+
const settings = settingsOf(ctx);
|
|
21
|
+
return Promise.resolve(settings.ok ? done([]) : settings.error);
|
|
22
|
+
},
|
|
23
|
+
comment: async ({ card, text }, ctx) => asCreated(await postComment(ctx, card, text)),
|
|
24
|
+
move: async ({ card, column }, ctx) => asNull(await transition(ctx, card, column)),
|
|
25
|
+
set_labels: async ({ card, labels }, ctx) => await setLabels(ctx, card, labels),
|
|
26
|
+
create_card: async ({ spec }, ctx) => asCreated(await createCard(ctx, spec)),
|
|
27
|
+
close: async ({ card }, ctx) => asNull(await transition(ctx, card, "done", true)),
|
|
28
|
+
whoami: async (_input, ctx) => {
|
|
29
|
+
const settings = settingsOf(ctx);
|
|
30
|
+
if (!settings.ok)
|
|
31
|
+
return settings.error;
|
|
32
|
+
const me = await ownLogin(ctx, settings.value);
|
|
33
|
+
return me.ok ? done({ actor: me.value }) : me.error;
|
|
34
|
+
},
|
|
35
|
+
person: async ({ actor }, ctx) => {
|
|
36
|
+
const settings = settingsOf(ctx);
|
|
37
|
+
if (!settings.ok)
|
|
38
|
+
return settings.error;
|
|
39
|
+
const found = await personOf(ctx, actor);
|
|
40
|
+
return found.ok ? done(found.value) : found.error;
|
|
41
|
+
},
|
|
42
|
+
});
|