@veda-hq/niyam 0.7.17 → 0.7.18
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/README.md +12 -1
- package/dist/design.js +10 -7
- package/dist/issue-types.js +1 -1
- package/dist/keep-going.js +4 -4
- package/dist/work.js +184 -77
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -660,6 +660,17 @@ issue's, and the Approvals issue's. The agent passes that link on, never a
|
|
|
660
660
|
bare number (#557). Guard's refusal for a pull request that names no slice
|
|
661
661
|
has no issue to link yet: it says to add the `Slice:` line first.
|
|
662
662
|
|
|
663
|
+
**A slice in another repository.** A repository whose work is planned in
|
|
664
|
+
another one names that repository's slice as `Slice: owner/name#N` or by its
|
|
665
|
+
address, `Slice: https://github.com/owner/name/issues/N`, and its States as
|
|
666
|
+
`State: owner/name#N`; a bare `#N` is always this repository's. The slice is
|
|
667
|
+
read there by the same rules, judged by this repository's owners, with that
|
|
668
|
+
repository's own Approvals issue. It counts only where the token reads that
|
|
669
|
+
repository. A workflow's own token reads no private repository but its own,
|
|
670
|
+
so the pull request check refuses a slice in another private repository,
|
|
671
|
+
saying so. The pre-push hook, on the agent's token, can pass it. Slice done
|
|
672
|
+
leaves it to its own repository.
|
|
673
|
+
|
|
663
674
|
**One comment answers a batch.** Settings that name the repository's standing
|
|
664
675
|
Approvals issue (`"approvals": N`) let the owner answer many asks at once:
|
|
665
676
|
an owner's comment there whose first line opens `Decision: approve`, then
|
|
@@ -1791,7 +1802,7 @@ commit. `upgrade` asks with no token; `onboard` asks with the agent's. Install t
|
|
|
1791
1802
|
once; nothing is built on install:
|
|
1792
1803
|
|
|
1793
1804
|
```bash
|
|
1794
|
-
pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.7.
|
|
1805
|
+
pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.7.18/veda-hq-niyam-0.7.18.tgz
|
|
1795
1806
|
```
|
|
1796
1807
|
|
|
1797
1808
|
The package puts one command on `PATH`, `niyam`. Since P-57 a release
|
package/dist/design.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { API, SETTINGS_PATH, anyLogin, loadSettings } from './agent.js';
|
|
2
|
-
import { slicesNamed } from './work.js';
|
|
2
|
+
import { refName, slicesNamed } from './work.js';
|
|
3
3
|
import { FIGMA_FILE_KEY, PERSONAL_REPO, isOn, isPersonal, notAdoptedLine, offLine, renamedLines } from './features.js';
|
|
4
4
|
const FIGMA = 'https://api.figma.com/v1';
|
|
5
5
|
/** A Figma link to one node: the file's key and the node's id. */
|
|
@@ -148,13 +148,16 @@ export async function prDesign(sys, io) {
|
|
|
148
148
|
const event = JSON.parse(sys.read(eventPath));
|
|
149
149
|
const pull = event.pull_request;
|
|
150
150
|
const { agents } = loadSettings(sys, sys.cwd);
|
|
151
|
-
const [
|
|
152
|
-
if (!pull || !anyLogin(agents, pull.user.login) ||
|
|
151
|
+
const [ref] = slicesNamed(pull?.body ?? '', slug);
|
|
152
|
+
if (!pull || !anyLogin(agents, pull.user.login) || ref === undefined) {
|
|
153
153
|
io.out('pr-design: not an agent pull request naming a slice; nothing to check');
|
|
154
154
|
return 0;
|
|
155
155
|
}
|
|
156
|
+
// A slice in another repository is read there.
|
|
157
|
+
const { number: slice } = ref;
|
|
158
|
+
const label = refName(ref, slug);
|
|
156
159
|
// Every state of the slice, 100 a page: GitHub's most.
|
|
157
|
-
const [owner, name] =
|
|
160
|
+
const [owner, name] = ref.repo.split('/');
|
|
158
161
|
const states = [];
|
|
159
162
|
for (let after = null;;) {
|
|
160
163
|
const { status, json } = await sys.http(`${API}/graphql`, {
|
|
@@ -168,13 +171,13 @@ export async function prDesign(sys, io) {
|
|
|
168
171
|
const issue = json?.data?.repository?.issue;
|
|
169
172
|
const page = issue?.subIssues;
|
|
170
173
|
if (status !== 200 || !page)
|
|
171
|
-
throw new Error(`cannot read the states of
|
|
174
|
+
throw new Error(`cannot read the states of ${label} (HTTP ${status})`);
|
|
172
175
|
// The work item's kind, read with the first page: only Experience work is designed in Figma.
|
|
173
176
|
const parent = issue.parent;
|
|
174
177
|
if (after === null && parent?.issueType?.name === 'Work item') {
|
|
175
178
|
const kind = workItemKind(parent.body);
|
|
176
179
|
if (kind && kind.toLowerCase() !== DESIGNED_KIND.toLowerCase()) {
|
|
177
|
-
io.out(`✓ pr-design:
|
|
180
|
+
io.out(`✓ pr-design: ${label} builds ${kind} work item #${parent.number}; frames are for ${DESIGNED_KIND} work`);
|
|
178
181
|
return 0;
|
|
179
182
|
}
|
|
180
183
|
}
|
|
@@ -202,6 +205,6 @@ export async function prDesign(sys, io) {
|
|
|
202
205
|
io.err('pr-design: refused by the design check');
|
|
203
206
|
return 1;
|
|
204
207
|
}
|
|
205
|
-
io.out(`✓ pr-design: ${checked} state${checked === 1 ? '' : 's'} of
|
|
208
|
+
io.out(`✓ pr-design: ${checked} state${checked === 1 ? '' : 's'} of ${label}, each a frame built from the design library`);
|
|
206
209
|
return 0;
|
|
207
210
|
}
|
package/dist/issue-types.js
CHANGED
|
@@ -118,7 +118,7 @@ async function untyped(sys, token, repo) {
|
|
|
118
118
|
* standing record the owner answers batches on, never closed, which no work
|
|
119
119
|
* model type fits.
|
|
120
120
|
*/
|
|
121
|
-
async function approvalsOf(sys, token, repo) {
|
|
121
|
+
export async function approvalsOf(sys, token, repo) {
|
|
122
122
|
const { status, json } = await sys.http(`${API}/repos/${repo}/contents/${SETTINGS_PATH}`, { token });
|
|
123
123
|
if (status === 404)
|
|
124
124
|
return undefined;
|
package/dist/keep-going.js
CHANGED
|
@@ -2,7 +2,7 @@ import { basename, dirname } from 'node:path';
|
|
|
2
2
|
import { anyLogin, githubSlug, isNoToken, loadSettings, SETTINGS_PATH } from './agent.js';
|
|
3
3
|
import { agentEnv } from './as-agent.js';
|
|
4
4
|
import { GITHUB_API } from './host.js';
|
|
5
|
-
import { deleteBranchCommand, pullUrl, sessionToken, slicesNamed } from './work.js';
|
|
5
|
+
import { deleteBranchCommand, pullUrl, sameIssue, sessionToken, slicesNamed } from './work.js';
|
|
6
6
|
/**
|
|
7
7
|
* Claude Code's Stop hook: a session whose branch has commits the default
|
|
8
8
|
* branch lacks keeps going until its pull request merges (docs/decisions.md,
|
|
@@ -291,7 +291,7 @@ async function readPrAt(sys, { slug, token }, branch, head) {
|
|
|
291
291
|
}
|
|
292
292
|
/**
|
|
293
293
|
* The agents' pull requests for the slices this branch's own commits name
|
|
294
|
-
* (`Slice
|
|
294
|
+
* (`Slice:` trailers, here or in another repository), closed without merging, from this repository,
|
|
295
295
|
* whose branch is still on origin and builds no open pull request: a
|
|
296
296
|
* superseded one, whose branch the agent deletes itself (#557). The most
|
|
297
297
|
* recently updated hundred closed pull requests are read, each page and
|
|
@@ -299,7 +299,7 @@ async function readPrAt(sys, { slug, token }, branch, head) {
|
|
|
299
299
|
* none, so the hook fails open.
|
|
300
300
|
*/
|
|
301
301
|
export async function leftBranches(sys, root, settings, branch, { slug, token }) {
|
|
302
|
-
const slices = slicesNamed(out(sys, root, 'git', ['log', '--format=%B', `origin/${settings.base}..HEAD`]) ?? '');
|
|
302
|
+
const slices = slicesNamed(out(sys, root, 'git', ['log', '--format=%B', `origin/${settings.base}..HEAD`]) ?? '', slug);
|
|
303
303
|
if (slices.length === 0)
|
|
304
304
|
return [];
|
|
305
305
|
let agents;
|
|
@@ -325,7 +325,7 @@ export async function leftBranches(sys, root, settings, branch, { slug, token })
|
|
|
325
325
|
return [];
|
|
326
326
|
if (!anyLogin(agents, typeof pull.user?.login === 'string' ? pull.user.login : undefined))
|
|
327
327
|
return [];
|
|
328
|
-
if (!slicesNamed(typeof pull.body === 'string' ? pull.body : '').some((slice) => slices.
|
|
328
|
+
if (!slicesNamed(typeof pull.body === 'string' ? pull.body : '', slug).some((slice) => slices.some((mine) => sameIssue(mine, slice))))
|
|
329
329
|
return [];
|
|
330
330
|
return [{ number: pull.number, url: pullUrl(slug, pull.number, pull.html_url), ref }];
|
|
331
331
|
});
|
package/dist/work.js
CHANGED
|
@@ -8,21 +8,50 @@ import { boardStarted } from './board.js';
|
|
|
8
8
|
import { gate } from './handoff.js';
|
|
9
9
|
import { ownersAlone, whyNotCounted } from './edits.js';
|
|
10
10
|
import { batchAnswers } from './approvals.js';
|
|
11
|
+
import { approvalsOf } from './issue-types.js';
|
|
11
12
|
import { PAGE_LINK, askProblem } from './asks.js';
|
|
13
|
+
/**
|
|
14
|
+
* How a line names an issue: `#N` in the repository it is in, or another
|
|
15
|
+
* repository's issue as `owner/name#N` or by its full address.
|
|
16
|
+
*/
|
|
17
|
+
const REPO_NAMED = '[A-Za-z0-9-]+/[A-Za-z0-9._-]+';
|
|
18
|
+
const ISSUE_NAMED = `(?:#(\\d+)|(${REPO_NAMED})#(\\d+)|https://${GITHUB_HOST_RE}/(${REPO_NAMED})/issues/(\\d+))`;
|
|
12
19
|
/** How a pull request or a commit names the slice it builds. */
|
|
13
|
-
const SLICE_LINE = new RegExp(`^Slice:\\s
|
|
20
|
+
const SLICE_LINE = new RegExp(`^Slice:\\s*${ISSUE_NAMED}\\s*$`, 'gim');
|
|
14
21
|
/** How a pull request names a State of its slice that it delivers. */
|
|
15
|
-
const STATE_LINE = new RegExp(`^State:\\s
|
|
16
|
-
/**
|
|
17
|
-
const
|
|
18
|
-
/**
|
|
19
|
-
export
|
|
20
|
-
|
|
22
|
+
const STATE_LINE = new RegExp(`^State:\\s*${ISSUE_NAMED}\\s*$`, 'gim');
|
|
23
|
+
/** Whether `a` and `b` name one repository: GitHub reads owner and name in any case. */
|
|
24
|
+
const sameRepo = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
25
|
+
/** Whether `a` and `b` are one issue. */
|
|
26
|
+
export const sameIssue = (a, b) => a.number === b.number && sameRepo(a.repo, b.repo);
|
|
27
|
+
/** How a message names `ref` from repository `here`: `#N` there, `owner/name#N` anywhere else. */
|
|
28
|
+
export function refName(ref, here) {
|
|
29
|
+
return sameRepo(ref.repo, here) ? `#${ref.number}` : `${ref.repo}#${ref.number}`;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The issues `line` names in `text`, read from repository `here`, in order,
|
|
33
|
+
* without repeats: a line naming `here` by name is one of its own issues.
|
|
34
|
+
*/
|
|
35
|
+
function named(line, text, here) {
|
|
36
|
+
const refs = [];
|
|
37
|
+
for (const match of text.matchAll(line)) {
|
|
38
|
+
const repo = match[2] ?? match[4];
|
|
39
|
+
const ref = { repo: repo === undefined || sameRepo(repo, here) ? here : repo, number: Number(match[1] ?? match[3] ?? match[5]) };
|
|
40
|
+
if (!refs.some((one) => sameIssue(one, ref)))
|
|
41
|
+
refs.push(ref);
|
|
42
|
+
}
|
|
43
|
+
return refs;
|
|
21
44
|
}
|
|
22
|
-
/** The
|
|
23
|
-
export function
|
|
24
|
-
return named(
|
|
45
|
+
/** The slices `text` names, read from repository `here`, in order, without repeats. */
|
|
46
|
+
export function slicesNamed(text, here) {
|
|
47
|
+
return named(SLICE_LINE, text, here);
|
|
25
48
|
}
|
|
49
|
+
/** The States `text` names with a line `State: #N`, read from repository `here`, in order, without repeats. */
|
|
50
|
+
export function statesNamed(text, here) {
|
|
51
|
+
return named(STATE_LINE, text, here);
|
|
52
|
+
}
|
|
53
|
+
/** How an error names `slice`. */
|
|
54
|
+
const tagOf = (slice) => (typeof slice === 'number' ? `#${slice}` : slice);
|
|
26
55
|
/**
|
|
27
56
|
* Reads `url` from GitHub's REST API for slice `slice`'s work rules: its
|
|
28
57
|
* JSON, or undefined on 404 when `missing` allows it. The work rules read
|
|
@@ -35,9 +64,14 @@ async function rest(sys, token, slice, url, missing = false) {
|
|
|
35
64
|
return undefined;
|
|
36
65
|
if (status !== 200) {
|
|
37
66
|
const why = json?.message ?? `HTTP ${status}`;
|
|
38
|
-
// A client workflow from before the work rules grants no issues: read.
|
|
39
|
-
|
|
40
|
-
|
|
67
|
+
// A client workflow from before the work rules grants no issues: read. Another repository's slice is read with
|
|
68
|
+
// whatever the token reaches there, which onboard does not set.
|
|
69
|
+
const hint = /not accessible/i.test(why)
|
|
70
|
+
? typeof slice === 'number'
|
|
71
|
+
? '; the client workflow needs issues: read, so run niyam onboard to update it'
|
|
72
|
+
: `; this token cannot read ${slice.replace(/#\d+$/, '')}`
|
|
73
|
+
: '';
|
|
74
|
+
throw new Error(`cannot read ${tagOf(slice)}: ${why} (${url.replace(API, '')})${hint}`);
|
|
41
75
|
}
|
|
42
76
|
return json;
|
|
43
77
|
}
|
|
@@ -49,7 +83,7 @@ async function every(sys, token, slice, url, missing = false) {
|
|
|
49
83
|
if (json === undefined)
|
|
50
84
|
return items;
|
|
51
85
|
if (!Array.isArray(json))
|
|
52
|
-
throw new Error(`cannot read
|
|
86
|
+
throw new Error(`cannot read ${tagOf(slice)}: GitHub did not answer a list (${url.replace(API, '')})`);
|
|
53
87
|
items.push(...json);
|
|
54
88
|
if (json.length < 100)
|
|
55
89
|
return items;
|
|
@@ -114,7 +148,7 @@ async function readIssue(sys, token, slug, number) {
|
|
|
114
148
|
* Read from the parent endpoint, not the issue's `parent_issue_url`: on a
|
|
115
149
|
* private repository a workflow's GITHUB_TOKEN gets that field back as null.
|
|
116
150
|
*/
|
|
117
|
-
async function parentOf(sys, token, issue) {
|
|
151
|
+
async function parentOf(sys, token, issue, nameOf = (number) => `#${number}`) {
|
|
118
152
|
const { status, json } = await sys.http(`${issue.url}/parent`, { token });
|
|
119
153
|
if (status === 200)
|
|
120
154
|
return { parent: json };
|
|
@@ -122,40 +156,85 @@ async function parentOf(sys, token, issue) {
|
|
|
122
156
|
// An issue with no parent reads as 404 "No parent issue found"; any other failure is a read that failed, not a missing parent.
|
|
123
157
|
if (status === 404 && message && /no parent/i.test(message))
|
|
124
158
|
return {};
|
|
125
|
-
return { problem: `could not read
|
|
159
|
+
return { problem: `could not read ${nameOf(issue.number)}'s parent (HTTP ${status}${message ? `: ${message}` : ''})` };
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Issue `ref` from another repository than `here`, or the problem that
|
|
163
|
+
* refuses it: one the token cannot read there (GitHub answers 404 or 403
|
|
164
|
+
* for a private repository it does not reach) or a pull request.
|
|
165
|
+
*/
|
|
166
|
+
async function foreignIssue(sys, token, here, ref) {
|
|
167
|
+
const name = refName(ref, here);
|
|
168
|
+
const url = `${API}/repos/${ref.repo}/issues/${ref.number}`;
|
|
169
|
+
const { status, json } = await sys.http(url, { token });
|
|
170
|
+
const message = json?.message;
|
|
171
|
+
if (status === 404 || status === 403 || status === 401) {
|
|
172
|
+
return {
|
|
173
|
+
problem: `${name} cannot be read with this token (HTTP ${status}${message ? `: ${message}` : ''}): a slice in another repository counts only where the token reads that repository, and a workflow's GITHUB_TOKEN reads no private repository but ${here}`,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
if (status !== 200)
|
|
177
|
+
throw new Error(`cannot read ${name}: ${message ?? `HTTP ${status}`} (${url.replace(API, '')})`);
|
|
178
|
+
const issue = json;
|
|
179
|
+
return issue.pull_request ? { problem: `${name} is a pull request, not an issue` } : { issue };
|
|
126
180
|
}
|
|
127
181
|
/**
|
|
128
|
-
* Reads slice `
|
|
182
|
+
* Reads slice `ref` against the work rules' approvals: the problems that
|
|
129
183
|
* stop it outright (not a Slice under a Work item an owner approved), else
|
|
130
|
-
* the decisions it owes an owner and whether each was given.
|
|
184
|
+
* the decisions it owes an owner and whether each was given. The slice may
|
|
185
|
+
* be in another repository than `here`, the one being pushed or checked:
|
|
186
|
+
* it is then read there, by the owners and agents `here`'s settings name,
|
|
187
|
+
* and the Approvals issue is the one that repository's settings name.
|
|
131
188
|
*/
|
|
132
|
-
async function readSlice(sys, token,
|
|
133
|
-
const
|
|
189
|
+
async function readSlice(sys, token, here, ref, settings) {
|
|
190
|
+
const { owners, agents } = settings;
|
|
191
|
+
const { repo: slug, number: slice } = ref;
|
|
192
|
+
const foreign = !sameRepo(slug, here);
|
|
193
|
+
const nameOf = (number) => refName({ repo: slug, number }, here);
|
|
194
|
+
// How errors name the slice: a number here, `owner/name#N` from another repository.
|
|
195
|
+
const tag = foreign ? nameOf(slice) : slice;
|
|
196
|
+
let issue;
|
|
197
|
+
if (foreign) {
|
|
198
|
+
const read = await foreignIssue(sys, token, here, ref);
|
|
199
|
+
if (read.problem)
|
|
200
|
+
return { problems: [read.problem], owed: [] };
|
|
201
|
+
issue = read.issue;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
issue = await readIssue(sys, token, slug, slice);
|
|
205
|
+
}
|
|
134
206
|
if (!issue)
|
|
135
207
|
return { problems: [`#${slice} is not an issue in ${slug}`], owed: [] };
|
|
136
208
|
if (issue.type?.name !== 'Slice')
|
|
137
|
-
return { problems: [
|
|
138
|
-
const { parent, problem } = await parentOf(sys, token, issue);
|
|
209
|
+
return { problems: [`${nameOf(slice)} is not a Slice (its type is ${issue.type?.name ?? 'none'})`], owed: [] };
|
|
210
|
+
const { parent, problem } = await parentOf(sys, token, issue, nameOf);
|
|
139
211
|
if (problem)
|
|
140
212
|
return { problems: [problem], owed: [] };
|
|
141
213
|
if (parent?.type?.name !== 'Work item')
|
|
142
|
-
return { problems: [
|
|
143
|
-
|
|
214
|
+
return { problems: [`${nameOf(slice)} is not a sub-issue of a Work item`], owed: [] };
|
|
215
|
+
// Another repository's batch answers are on its own Approvals issue.
|
|
216
|
+
const approvals = foreign
|
|
217
|
+
? await approvalsOf(sys, token, slug).catch(() => {
|
|
218
|
+
// fail-open: settings there that cannot be read name no Approvals issue, which only takes a way to pass away.
|
|
219
|
+
return undefined;
|
|
220
|
+
})
|
|
221
|
+
: settings.approvals;
|
|
222
|
+
const events = await every(sys, token, tag, `${parent.url}/timeline`);
|
|
144
223
|
const approval = events
|
|
145
224
|
.filter((event) => (event.event === 'labeled' || event.event === 'unlabeled') && event.label.name === 'approved')
|
|
146
225
|
.at(-1);
|
|
147
226
|
if (approval?.event !== 'labeled') {
|
|
148
|
-
return { problems: [`work item
|
|
227
|
+
return { problems: [`work item ${nameOf(parent.number)}, ${issueUrl(slug, parent.number)}, is not approved: ${either(owners)} adds the approved label before any slice starts`], owed: [] };
|
|
149
228
|
}
|
|
150
229
|
if (!anyLogin(owners, approval.actor?.login)) {
|
|
151
|
-
return { problems: [`work item
|
|
230
|
+
return { problems: [`work item ${nameOf(parent.number)}, ${issueUrl(slug, parent.number)}, was labeled approved by ${approval.actor?.login ?? 'someone unknown'}, not ${either(owners)}`], owed: [] };
|
|
152
231
|
}
|
|
153
232
|
const approvedAt = approval.created_at;
|
|
154
233
|
const parentComments = events.filter((event) => event.event === 'commented');
|
|
155
234
|
// Every comment on the slice, so a proposal or decision that later discussion pushed back still counts.
|
|
156
|
-
const comments = await every(sys, token,
|
|
235
|
+
const comments = await every(sys, token, tag, `${issue.url}/comments`);
|
|
157
236
|
// Every state, however many: one past the first page can be a dropped one.
|
|
158
|
-
const states = await every(sys, token,
|
|
237
|
+
const states = await every(sys, token, tag, `${issue.url}/sub_issues`);
|
|
159
238
|
// The Approvals issue's comments, read once a check and only when a decision owed may need them; an
|
|
160
239
|
// Approvals issue GitHub cannot find answers nothing. Only an owner's comment whose first line approves
|
|
161
240
|
// `number`, made after `since`, counts there.
|
|
@@ -163,7 +242,7 @@ async function readSlice(sys, token, slug, slice, { owners, agents, approvals })
|
|
|
163
242
|
const batchFor = async (number, since) => {
|
|
164
243
|
if (approvals === undefined)
|
|
165
244
|
return [];
|
|
166
|
-
batch ??= await every(sys, token,
|
|
245
|
+
batch ??= await every(sys, token, tag, `${API}/repos/${slug}/issues/${approvals}/comments`, true);
|
|
167
246
|
return batchAnswers(batch, owners, number, since);
|
|
168
247
|
};
|
|
169
248
|
const owed = [];
|
|
@@ -173,7 +252,7 @@ async function readSlice(sys, token, slug, slice, { owners, agents, approvals })
|
|
|
173
252
|
.filter((event) => event.event === 'parent_issue_added')
|
|
174
253
|
.map((event) => event.created_at);
|
|
175
254
|
const mine = [
|
|
176
|
-
...(await joined(
|
|
255
|
+
...(await joined(tag, issue.url)),
|
|
177
256
|
...events.flatMap((event) => (event.event === 'sub_issue_added' && event.sub_issue?.number === slice ? [event.created_at] : [])),
|
|
178
257
|
];
|
|
179
258
|
// An addition after approval that names no issue may be this slice's. It is put down to another sub-issue of the
|
|
@@ -181,10 +260,10 @@ async function readSlice(sys, token, slug, slice, { owners, agents, approvals })
|
|
|
181
260
|
// slice's, so it owes the owner's say rather than passing.
|
|
182
261
|
let hidden = events.flatMap((event) => event.event === 'sub_issue_added' && !event.sub_issue && event.created_at > approvedAt && !mine.includes(event.created_at) ? [event.created_at] : []);
|
|
183
262
|
if (hidden.length > 0) {
|
|
184
|
-
for (const sibling of await every(sys, token,
|
|
263
|
+
for (const sibling of await every(sys, token, tag, `${parent.url}/sub_issues`)) {
|
|
185
264
|
if (sibling.number === slice || hidden.length === 0)
|
|
186
265
|
continue;
|
|
187
|
-
const theirs = await joined(
|
|
266
|
+
const theirs = await joined(tag, sibling.url);
|
|
188
267
|
hidden = hidden.filter((at) => !theirs.includes(at));
|
|
189
268
|
}
|
|
190
269
|
}
|
|
@@ -213,7 +292,7 @@ async function readSlice(sys, token, slug, slice, { owners, agents, approvals })
|
|
|
213
292
|
// unedited decision on the slice settles it.
|
|
214
293
|
const decisions = onSlice.some((one) => !editedAt(one))
|
|
215
294
|
? onSlice
|
|
216
|
-
: [...onSlice, ...decisionsIn(await every(sys, token,
|
|
295
|
+
: [...onSlice, ...decisionsIn(await every(sys, token, tag, `${state.url}/comments`), owners), ...(await batchFor(state.number, state.closed_at))];
|
|
217
296
|
owed.push({
|
|
218
297
|
kind: 'dropped',
|
|
219
298
|
number: state.number,
|
|
@@ -226,11 +305,11 @@ async function readSlice(sys, token, slug, slice, { owners, agents, approvals })
|
|
|
226
305
|
// Reactions are read only for the proposals that could still settle something; a deleted proposal has none.
|
|
227
306
|
const reactions = new Map();
|
|
228
307
|
for (const proposal of owed.filter((one) => !one.settled).flatMap((one) => one.proposals)) {
|
|
229
|
-
reactions.set(proposal.id, await every(sys, token,
|
|
308
|
+
reactions.set(proposal.id, await every(sys, token, tag, `${API}/repos/${slug}/issues/comments/${proposal.id}/reactions?content=%2B1`, true));
|
|
230
309
|
}
|
|
231
310
|
for (const one of owed)
|
|
232
311
|
one.settled ||= thumbsUp(one.proposals, reactions, owners, one.since);
|
|
233
|
-
return { problems: [], parent: parent.number, owed, closed: issue.state === 'closed', states };
|
|
312
|
+
return { problems: [], parent: parent.number, owed, closed: issue.state === 'closed', states, ...(approvals === undefined ? {} : { approvals }) };
|
|
234
313
|
}
|
|
235
314
|
/**
|
|
236
315
|
* What is wrong with the States a pull request for slice `slice` names with
|
|
@@ -238,33 +317,43 @@ async function readSlice(sys, token, slug, slice, { owners, agents, approvals })
|
|
|
238
317
|
* under the slice, and a pull request for a slice closed already, a fix,
|
|
239
318
|
* must name the open State it is filed as.
|
|
240
319
|
*/
|
|
241
|
-
function stateProblems(slice, closed, states, names) {
|
|
242
|
-
const
|
|
320
|
+
function stateProblems(slice, here, closed, states, names) {
|
|
321
|
+
const name = refName(slice, here);
|
|
322
|
+
// A State is a sub-issue of the slice, so it is in the slice's repository.
|
|
323
|
+
const ours = (ref) => sameRepo(ref.repo, slice.repo);
|
|
324
|
+
const problems = names.flatMap((ref) => ours(ref) && states.some((state) => state.number === ref.number && state.type?.name === 'State')
|
|
243
325
|
? []
|
|
244
|
-
: [
|
|
245
|
-
const open = states.some((state) => names.
|
|
326
|
+
: [`${refName(ref, here)} is not a State under slice ${name}; a "State: #N" line names a State sub-issue of the slice the pull request builds`]);
|
|
327
|
+
const open = states.some((state) => names.some((ref) => ours(ref) && ref.number === state.number) && state.type?.name === 'State' && state.state !== 'closed');
|
|
246
328
|
if (closed && !open) {
|
|
247
|
-
problems.push(
|
|
329
|
+
problems.push(`${name} is closed, so this pull request is a fix: file it as a State under ${name} and name it with a line "State: ${sameRepo(slice.repo, here) ? '#N' : `${slice.repo}#N`}"`);
|
|
248
330
|
}
|
|
249
331
|
return problems;
|
|
250
332
|
}
|
|
251
|
-
/**
|
|
252
|
-
|
|
333
|
+
/**
|
|
334
|
+
* Why `owed` stops slice `slice`, and how the owner settles it; a slice in
|
|
335
|
+
* another repository than `here` is settled there, on its Approvals issue
|
|
336
|
+
* `approvals`.
|
|
337
|
+
*/
|
|
338
|
+
function owedProblem(one, slice, here, parent, approvals, { owners, agents }) {
|
|
253
339
|
const owner = either(owners);
|
|
254
340
|
// The agent proposes as itself; with several, any of them.
|
|
255
341
|
const agent = either(agents);
|
|
256
|
-
const
|
|
342
|
+
const at = (number) => (number === undefined ? '#undefined' : refName({ repo: slice.repo, number }, here));
|
|
343
|
+
const s = at(slice.number);
|
|
344
|
+
const where = sameRepo(slice.repo, here) ? '' : ` in a clone of ${slice.repo}`;
|
|
345
|
+
const ask = `${one.note ? ` (${one.note})` : ''}${one.proposals.length > 0 ? '' : `; ${agent} proposes it${where} with: ${proposeCommand(one.number)}`}`;
|
|
257
346
|
// Each place the owner acts, by its full address, so an agent passes on a link, never a bare number.
|
|
258
|
-
const issue = (number) => issueUrl(
|
|
347
|
+
const issue = (number) => issueUrl(slice.repo, number);
|
|
259
348
|
// The comment the owner reacts to, where there is one; else the slice, where the proposal is to be posted.
|
|
260
349
|
const on = one.proposals.length > 0
|
|
261
350
|
? `${agent}'s proposal${one.kind === 'added' ? '' : ' for it'}, ${newest(one.proposals).html_url}`
|
|
262
|
-
: `${agent}'s proposal${one.kind === 'added' ? '' : ' for it'} on
|
|
351
|
+
: `${agent}'s proposal${one.kind === 'added' ? '' : ' for it'} on ${s}, ${issue(slice.number)}`;
|
|
263
352
|
// Where the settings name an Approvals issue, one comment there answers this among a batch.
|
|
264
|
-
const batch = approvals === undefined ? '' : `, or ${owner} comments on
|
|
353
|
+
const batch = approvals === undefined ? '' : `, or ${owner} comments on ${at(approvals)}, the Approvals issue, ${issue(approvals)}, with a first line "Decision: approve #${one.number}"`;
|
|
265
354
|
return one.kind === 'added'
|
|
266
|
-
?
|
|
267
|
-
: `state
|
|
355
|
+
? `${s} was added to work item ${at(parent)}, ${issue(parent)}, after its approval; ${owner} reacts 👍 on ${on}, or adds a "Decision:" comment naming #${slice.number} on ${issue(slice.number)}, or ${s} links ${owner}'s request for it on ${at(parent)}${batch}${ask}`
|
|
356
|
+
: `state ${at(one.number)}, ${issue(one.number)}, was closed as not planned after approval; ${owner} reacts 👍 on ${on}, or adds a "Decision:" comment to it${batch}${ask}`;
|
|
268
357
|
}
|
|
269
358
|
/** Issue `number`'s own address on GitHub, where the owner acts on it. */
|
|
270
359
|
export function issueUrl(slug, number) {
|
|
@@ -290,7 +379,7 @@ export function deleteBranchCommand(ref) {
|
|
|
290
379
|
*/
|
|
291
380
|
function secondPull(slug, slice, pull, here) {
|
|
292
381
|
const remedy = here ? `close it and delete its branch: ${deleteBranchCommand(pull.head.ref)}` : 'close it';
|
|
293
|
-
return
|
|
382
|
+
return `${refName(slice, slug)} already has pull request #${pull.number}, ${pullUrl(slug, pull.number, pull.html_url)}; one slice, one pull request. If #${pull.number} is superseded, ${remedy}`;
|
|
294
383
|
}
|
|
295
384
|
/**
|
|
296
385
|
* The work rules for building one slice, as problems; none means it may be
|
|
@@ -301,13 +390,15 @@ function secondPull(slug, slice, pull, here) {
|
|
|
301
390
|
* request, whose States are in `mine.states`, each is a State under the slice
|
|
302
391
|
* and a closed slice's names an open one.
|
|
303
392
|
*/
|
|
304
|
-
export async function sliceProblems(sys, token, slug,
|
|
393
|
+
export async function sliceProblems(sys, token, slug, which, accounts, mine) {
|
|
394
|
+
// A slice in this repository may be given by its number alone.
|
|
395
|
+
const slice = typeof which === 'number' ? { repo: slug, number: which } : which;
|
|
305
396
|
const read = await readSlice(sys, token, slug, slice, accounts);
|
|
306
397
|
if (read.problems.length > 0)
|
|
307
398
|
return read.problems;
|
|
308
|
-
const problems = read.owed.filter((one) => !one.settled).map((one) => owedProblem(
|
|
399
|
+
const problems = read.owed.filter((one) => !one.settled).map((one) => owedProblem(one, slice, slug, read.parent, read.approvals, accounts));
|
|
309
400
|
if (mine.states)
|
|
310
|
-
problems.push(...stateProblems(slice, read.closed ?? false, read.states ?? [], mine.states));
|
|
401
|
+
problems.push(...stateProblems(slice, slug, read.closed ?? false, read.states ?? [], mine.states));
|
|
311
402
|
// The pull request being checked: by number, or by its branch in this repository (not a fork's of the same name).
|
|
312
403
|
for (let page = 1;; page++) {
|
|
313
404
|
const pulls = await sys.http(`${API}/repos/${slug}/pulls?state=open&per_page=100&page=${page}`, { token });
|
|
@@ -317,7 +408,7 @@ export async function sliceProblems(sys, token, slug, slice, accounts, mine) {
|
|
|
317
408
|
const here = pull.head.repo?.full_name.toLowerCase() === slug.toLowerCase();
|
|
318
409
|
if (pull.number === mine.pull || (pull.head.ref === mine.branch && here))
|
|
319
410
|
continue;
|
|
320
|
-
if (slicesNamed(pull.body ?? '').
|
|
411
|
+
if (slicesNamed(pull.body ?? '', slug).some((one) => sameIssue(one, slice)))
|
|
321
412
|
problems.push(secondPull(slug, slice, pull, here));
|
|
322
413
|
}
|
|
323
414
|
if (pulls.json.length < 100)
|
|
@@ -389,18 +480,18 @@ export async function prWorkRules(sys, io) {
|
|
|
389
480
|
return 0;
|
|
390
481
|
}
|
|
391
482
|
}
|
|
392
|
-
const slices = slicesNamed(pull.body ?? '');
|
|
483
|
+
const slices = slicesNamed(pull.body ?? '', slug);
|
|
393
484
|
if (slices.length !== 1) {
|
|
394
485
|
return report(io, 'pr-work-rules', [
|
|
395
486
|
slices.length === 0
|
|
396
487
|
? `#${pull.number} names no slice; add a line "Slice: #N" to its description`
|
|
397
|
-
: `#${pull.number} names ${slices.length} slices (${slices.map((
|
|
488
|
+
: `#${pull.number} names ${slices.length} slices (${slices.map((one) => refName(one, slug)).join(', ')}); an agent pull request builds exactly one`,
|
|
398
489
|
]);
|
|
399
490
|
}
|
|
400
491
|
const [slice] = slices;
|
|
401
|
-
const problems = await sliceProblems(sys, token, slug, slice, accounts, { pull: pull.number, states: statesNamed(pull.body ?? '') });
|
|
492
|
+
const problems = await sliceProblems(sys, token, slug, slice, accounts, { pull: pull.number, states: statesNamed(pull.body ?? '', slug) });
|
|
402
493
|
if (problems.length === 0)
|
|
403
|
-
io.out(`✓ pr-work-rules: #${pull.number} builds slice
|
|
494
|
+
io.out(`✓ pr-work-rules: #${pull.number} builds slice ${refName(slice, slug)}, which may be built`);
|
|
404
495
|
return report(io, 'pr-work-rules', problems);
|
|
405
496
|
}
|
|
406
497
|
const ZERO = /^0+$/;
|
|
@@ -528,14 +619,14 @@ export async function prePush(sys, io, refLines, url) {
|
|
|
528
619
|
if (!log.trim())
|
|
529
620
|
continue;
|
|
530
621
|
// Asked of GitHub only when the push would be refused: what its merges brought from the default branch.
|
|
531
|
-
if (branch && slicesNamed(log).length !== 1) {
|
|
622
|
+
if (branch && slicesNamed(log, slug).length !== 1) {
|
|
532
623
|
const merged = await mergedFromDefault(sys, root, slug, token, branch, rangeOf(base));
|
|
533
624
|
if (merged.length > 0) {
|
|
534
625
|
base = [...base, ...merged];
|
|
535
626
|
log = gitLog(sys, root, ['--format=%B', ...rangeOf(base)]);
|
|
536
627
|
}
|
|
537
628
|
}
|
|
538
|
-
if (slicesNamed(log).length === 0) {
|
|
629
|
+
if (slicesNamed(log, slug).length === 0) {
|
|
539
630
|
log = (base.length > 0 ? gitLog(sys, root, ['--format=%B', local, '--not', ...base]) : branchBeyondMerges(sys, root, rangeOf(base))) ?? log;
|
|
540
631
|
}
|
|
541
632
|
messages += `${log}\n`;
|
|
@@ -543,13 +634,13 @@ export async function prePush(sys, io, refLines, url) {
|
|
|
543
634
|
}
|
|
544
635
|
if (branches.length === 0)
|
|
545
636
|
return 0;
|
|
546
|
-
const slices = slicesNamed(messages);
|
|
637
|
+
const slices = slicesNamed(messages, slug);
|
|
547
638
|
const where = branches.join(', ');
|
|
548
639
|
if (slices.length !== 1) {
|
|
549
640
|
return report(io, 'pre-push', [
|
|
550
641
|
slices.length === 0
|
|
551
642
|
? `the commits for ${where} name no slice; add a trailer "Slice: #N" to a commit message`
|
|
552
|
-
: `the commits for ${where} name ${slices.length} slices (${slices.map((
|
|
643
|
+
: `the commits for ${where} name ${slices.length} slices (${slices.map((one) => refName(one, slug)).join(', ')}); one push builds one slice`,
|
|
553
644
|
]);
|
|
554
645
|
}
|
|
555
646
|
if (branches.length > 1)
|
|
@@ -571,16 +662,17 @@ const CLOUD_PROXY_REFUSAL = /sessions are bound to their configured repositories
|
|
|
571
662
|
* shared workflow's Slice started job moves the slice when its pull request
|
|
572
663
|
* opens.
|
|
573
664
|
*/
|
|
574
|
-
async function moveBoard(sys, io, token,
|
|
665
|
+
async function moveBoard(sys, io, token, here, ref) {
|
|
666
|
+
const slice = refName(ref, here);
|
|
575
667
|
try {
|
|
576
|
-
for (const line of await boardStarted(sys, token,
|
|
668
|
+
for (const line of await boardStarted(sys, token, ref.repo, ref.number))
|
|
577
669
|
io.err(line);
|
|
578
670
|
}
|
|
579
671
|
catch (error) {
|
|
580
672
|
const message = error.message;
|
|
581
673
|
io.err(CLOUD_PROXY_REFUSAL.test(message)
|
|
582
|
-
? `- board: this cloud session cannot reach the board; niyam's workflow moves
|
|
583
|
-
: `! board: could not read where
|
|
674
|
+
? `- board: this cloud session cannot reach the board; niyam's workflow moves ${slice} when its pull request opens`
|
|
675
|
+
: `! board: could not read where ${slice} and its work item are on the board, so nothing moved (${message}); the push goes on`);
|
|
584
676
|
}
|
|
585
677
|
}
|
|
586
678
|
/** Throws for a write to an issue that GitHub refused, saying how to fix a workflow that grants no issues: write. */
|
|
@@ -656,12 +748,23 @@ export async function prMerged(sys, io) {
|
|
|
656
748
|
io.out(`pr-merged: #${pull.number} merged into ${pull.base.ref}, not ${branch}; its slices stay open until their work reaches ${branch}`);
|
|
657
749
|
return 0;
|
|
658
750
|
}
|
|
659
|
-
const slices = slicesNamed(pull.body ?? '');
|
|
751
|
+
const slices = slicesNamed(pull.body ?? '', slug);
|
|
660
752
|
if (slices.length === 0)
|
|
661
753
|
io.out(`pr-merged: #${pull.number} names no slice; nothing to close`);
|
|
754
|
+
// A slice or State in another repository is closed there, by whoever builds the rest of it: this workflow's
|
|
755
|
+
// GITHUB_TOKEN writes only here, and never touches this repository's issue of the same number.
|
|
756
|
+
const elsewhere = (ref) => {
|
|
757
|
+
if (sameRepo(ref.repo, slug))
|
|
758
|
+
return false;
|
|
759
|
+
io.out(`- ${refName(ref, slug)} is in another repository; left as it is`);
|
|
760
|
+
return true;
|
|
761
|
+
};
|
|
662
762
|
// The slices named that are Slices: a State is closed only under one of them.
|
|
663
763
|
const built = [];
|
|
664
|
-
for (const
|
|
764
|
+
for (const ref of slices) {
|
|
765
|
+
if (elsewhere(ref))
|
|
766
|
+
continue;
|
|
767
|
+
const slice = ref.number;
|
|
665
768
|
const issue = await readIssue(sys, token, slug, slice);
|
|
666
769
|
if (issue?.type?.name !== 'Slice') {
|
|
667
770
|
io.out(`- #${slice} is not a Slice in ${slug}; left as it is`);
|
|
@@ -671,7 +774,10 @@ export async function prMerged(sys, io) {
|
|
|
671
774
|
// GitHub closes a slice itself when the pull request also says "Closes #N"; the slice still gets its comment, once.
|
|
672
775
|
await closeBuilt(sys, io, token, issue, pull);
|
|
673
776
|
}
|
|
674
|
-
for (const
|
|
777
|
+
for (const ref of statesNamed(pull.body ?? '', slug)) {
|
|
778
|
+
if (elsewhere(ref))
|
|
779
|
+
continue;
|
|
780
|
+
const { number } = ref;
|
|
675
781
|
const issue = await readIssue(sys, token, slug, number);
|
|
676
782
|
if (issue?.type?.name !== 'State') {
|
|
677
783
|
io.out(`- #${number} is not a State in ${slug}; left as it is`);
|
|
@@ -730,31 +836,32 @@ export async function prStarted(sys, io) {
|
|
|
730
836
|
io.out(offLine('pr-started', 'work-rules', PERSONAL_REPO));
|
|
731
837
|
return 0;
|
|
732
838
|
}
|
|
733
|
-
const slices = slicesNamed(pull.body ?? '');
|
|
839
|
+
const slices = slicesNamed(pull.body ?? '', slug);
|
|
734
840
|
if (slices.length !== 1) {
|
|
735
841
|
io.out(`pr-started: #${pull.number} names ${slices.length === 0 ? 'no slice' : `${slices.length} slices`}; nothing moves on the board`);
|
|
736
842
|
return 0;
|
|
737
843
|
}
|
|
738
|
-
const [
|
|
844
|
+
const [ref] = slices;
|
|
845
|
+
const slice = refName(ref, slug);
|
|
739
846
|
if (!board) {
|
|
740
|
-
io.out(`pr-started: no board app token here (the NIYAM_BOARD_APP_ID and NIYAM_BOARD_APP_KEY secrets are not passed, or GitHub would not make the token), so
|
|
847
|
+
io.out(`pr-started: no board app token here (the NIYAM_BOARD_APP_ID and NIYAM_BOARD_APP_KEY secrets are not passed, or GitHub would not make the token), so ${slice} moves on the board only from a desktop push`);
|
|
741
848
|
return 0;
|
|
742
849
|
}
|
|
743
850
|
try {
|
|
744
|
-
const problems = await sliceProblems(sys, token, slug,
|
|
851
|
+
const problems = await sliceProblems(sys, token, slug, ref, loadSettings(sys, sys.cwd), { pull: pull.number, states: statesNamed(pull.body ?? '', slug) });
|
|
745
852
|
if (problems.length > 0) {
|
|
746
|
-
io.out(`pr-started:
|
|
853
|
+
io.out(`pr-started: ${slice} may not be built yet (Work rules says why), so nothing moves on the board`);
|
|
747
854
|
return 0;
|
|
748
855
|
}
|
|
749
|
-
const moved = await boardStarted(sys, board,
|
|
856
|
+
const moved = await boardStarted(sys, board, ref.repo, ref.number);
|
|
750
857
|
for (const line of moved)
|
|
751
858
|
io.out(line);
|
|
752
859
|
if (moved.length === 0)
|
|
753
|
-
io.out(`pr-started:
|
|
860
|
+
io.out(`pr-started: ${slice} and its work item are where they belong on the board already`);
|
|
754
861
|
}
|
|
755
862
|
catch (error) {
|
|
756
863
|
// fail-open: the board never fails a pull request; Work rules judges the slice, and the line says what GitHub refused.
|
|
757
|
-
io.out(`! board: nothing moved for
|
|
864
|
+
io.out(`! board: nothing moved for ${slice} (${error.message}); the pull request's checks go on`);
|
|
758
865
|
}
|
|
759
866
|
return 0;
|
|
760
867
|
}
|
|
@@ -875,7 +982,7 @@ async function proposeOne(sys, io, token, slug, accounts, number, page) {
|
|
|
875
982
|
return { code: report(io, 'propose', [problem]), waiting: [] };
|
|
876
983
|
const state = parent?.type?.name === 'Slice';
|
|
877
984
|
const slice = state ? parent.number : number;
|
|
878
|
-
const read = await readSlice(sys, token, slug, slice, accounts);
|
|
985
|
+
const read = await readSlice(sys, token, slug, { repo: slug, number: slice }, accounts);
|
|
879
986
|
if (read.problems.length > 0)
|
|
880
987
|
return { code: report(io, 'propose', read.problems), waiting: [] };
|
|
881
988
|
const owner = either(accounts.owners);
|