@veda-hq/niyam 0.6.18 → 0.6.19

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 CHANGED
@@ -614,7 +614,14 @@ opening with `Needs you:` or `Proposal:`, on an issue, a pull request or a revie
614
614
  owner's `approved` label or `Decision:` comment takes the label off at once;
615
615
  on a pull request, where a label approves nothing (approvals are given on
616
616
  issues only), the owner answers with a `Decision:` comment, which takes it
617
- off at once, or a 👍 on the ask, which the hourly sweep counts. The sweep
617
+ off at once, or a 👍 on the ask, which the hourly sweep counts. The owner
618
+ may answer an ask on an issue while its own run is still going, before the
619
+ label is on: that run reads the owner's `approved` label, a `Decision:` that
620
+ no one but owners edited, a 👍 on the ask, or a batch answer on the
621
+ Approvals issue whose first line names the ask's issue (for a `Proposal:`,
622
+ the issue its first line names) that no one but owners edited, each newer
623
+ than the ask, before it labels the issue and again after, and leaves the
624
+ label off when one is there. The sweep
618
625
  reads an issue's or pull request's own comments, not review threads, so an
619
626
  ask in a review thread is answered with a `Decision:` reply there. Hourly
620
627
  (cron `41 * * * *`), on a run by hand, and at once when the owner posts a
@@ -1291,7 +1298,10 @@ niyam owner-step required-checks <owner/repo> <ruleset id or name> [--check <nam
1291
1298
  when it reported `success` on the head commit of the last pull request
1292
1299
  merged into the default branch, from one app alone, and requires it from
1293
1300
  that app. That shows pull requests run it and it passes. One that never
1294
- ran there, did not pass, or that two apps reported is a `✗`. A check a
1301
+ ran there, did not pass, or that two apps reported is a `✗`. A
1302
+ `cancelled` run counts for nothing when a run from the same app started
1303
+ after it and passed, as a workflow with `cancel-in-progress` leaves
1304
+ one when a pull request is edited or pushed again. A check a
1295
1305
  workflow runs only for some paths can pass there and then never report
1296
1306
  on a pull request that skips them, holding it: name only checks that run
1297
1307
  on every pull request.
@@ -1333,7 +1343,11 @@ A release is the merge of its version bump: a push to `main` whose
1333
1343
  `package.json` version has no tag `vX.Y.Z` yet (P-61). The Release workflow
1334
1344
  then runs `pnpm check`, makes that annotated tag (`niyam X.Y.Z`) on the
1335
1345
  merged commit itself, and publishes the GitHub release, attaching the CLI
1336
- package it built and tested. Agents push no release tags. From 0.6.16 the same
1346
+ package it built and tested. Agents push no release tags. The tag is made as
1347
+ niyam's own GitHub App, the one bypass of the `v*` tag ruleset's rule against
1348
+ creating a tag, so no one else, and no other workflow, can make one (P-64);
1349
+ the app's client id and private key are the `npm` environment's
1350
+ `RELEASE_APP_CLIENT_ID` and `RELEASE_APP_PRIVATE_KEY`. From 0.6.16 the same
1337
1351
  package is on npm as `@veda-hq/niyam`, with provenance, for a repository that
1338
1352
  pins it as an exact version; it publishes from the `npm` environment, which
1339
1353
  only `main` may deploy to. A tag on any other commit is not a release:
@@ -1343,7 +1357,7 @@ tag and the commit. Install the attached package on each machine with pnpm,
1343
1357
  once; nothing is built on install:
1344
1358
 
1345
1359
  ```bash
1346
- pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.6.18/veda-hq-niyam-0.6.18.tgz
1360
+ pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.6.19/veda-hq-niyam-0.6.19.tgz
1347
1361
  ```
1348
1362
 
1349
1363
  The package puts one command on `PATH`, `niyam`. Since P-57 a release
@@ -1450,6 +1464,13 @@ ruleset requires, or `Guard`. It fails closed: a truncated file list, or any
1450
1464
  read GitHub does not answer, refuses. Each refusal names the file and how to
1451
1465
  pass. A slice edit does not run Guard again: edit or push the pull request.
1452
1466
 
1467
+ Guard cannot judge a change to its own rules, so `.github/CODEOWNERS` names
1468
+ `@AlokBansal8` for the guard's files alone: `.github/workflows/guard.yml`,
1469
+ `scripts/guard.mjs`, `scripts/guard.test.mjs` and `.github/CODEOWNERS`
1470
+ itself. With "Require review from Code Owners" on in the `main` ruleset, a
1471
+ pull request that changes one of them waits for his approval. Every other
1472
+ pull request, including one under `.github/` that Guard passed, does not.
1473
+
1453
1474
  ## License
1454
1475
 
1455
1476
  MIT
package/dist/asks.js CHANGED
@@ -354,6 +354,35 @@ async function answered(sys, token, slug, number, { owners, agents, approvals },
354
354
  const waiting = owed.filter((one) => !how.has(one));
355
355
  return waiting.length > 0 ? { waiting } : { answer: [...new Set(how.values())].join(' and ') };
356
356
  }
357
+ /**
358
+ * How the owner has answered issue `number` since the ask `ask`, the ask's
359
+ * own run reading it, or undefined: their `approved` label, a `Decision:`
360
+ * comment no one but owners edited, a 👍 on the ask, or a batch answer on
361
+ * the Approvals issue whose first line names `ask.names` (the issue a
362
+ * proposal's first line names, as the sweep reads it) that no one but owners
363
+ * edited, each newer than the ask. The owner's approval and batch answer run
364
+ * their own jobs, which take off only a label already on, so an ask whose run
365
+ * labels the issue after that answer reads it here (#355, #357).
366
+ */
367
+ async function answeredSince(sys, token, slug, number, ask, { owners, approvals }) {
368
+ const owner = (login) => anyLogin(owners, login);
369
+ const events = await every(sys, token, `${API}/repos/${slug}/issues/${number}/events`);
370
+ const approved = events.some((one) => one.event === 'labeled' && one.label?.name === 'approved' && owner(one.actor?.login ?? undefined) && (one.created_at ?? '') > ask.created_at);
371
+ if (approved)
372
+ return 'their approved label';
373
+ const comments = await every(sys, token, `${API}/repos/${slug}/issues/${number}/comments?since=${encodeURIComponent(ask.created_at)}`);
374
+ const decisions = comments.filter((comment) => comment.created_at > ask.created_at && owner(comment.user?.login ?? undefined) && opensDecision(comment.body ?? ''));
375
+ if (decisions.length > 0 && (await ownersAlone(sys, token, decisions, owners)).kept.length > 0)
376
+ return 'a Decision: comment';
377
+ const reactions = await every(sys, token, `${API}/repos/${slug}/issues/comments/${ask.id}/reactions?content=%2B1`);
378
+ if (reactions.some((reaction) => owner(reaction.user?.login ?? undefined) && reaction.created_at > ask.created_at))
379
+ return 'a 👍 on the ask';
380
+ // The Approvals issue is read last, only when the issue itself has no answer, and none where GitHub cannot find it.
381
+ if (approvals === undefined)
382
+ return undefined;
383
+ const answers = batchAnswers(await every(sys, token, `${API}/repos/${slug}/issues/${approvals}/comments?since=${encodeURIComponent(ask.created_at)}`, true), owners, ask.names, ask.created_at);
384
+ return answers.length > 0 && (await ownersAlone(sys, token, answers, owners)).kept.length > 0 ? `a "Decision: approve" on #${approvals}, the Approvals issue` : undefined;
385
+ }
357
386
  /** The asks still waiting, as the sweep names them. */
358
387
  function waitingOn(waiting) {
359
388
  return waiting.map(({ kind, number }) => (kind === 'Proposal' ? `the proposal for #${number}` : 'the Needs you: ask')).join(', ');
@@ -431,10 +460,27 @@ export async function needsOwner(sys, io) {
431
460
  if ((name === 'issue_comment' || name === 'pull_request_review_comment') && issue !== undefined) {
432
461
  const author = event.comment?.user?.login ?? undefined;
433
462
  const body = event.comment?.body ?? '';
434
- if (event.action === 'created' && anyLogin(settings.agents, author) && opensAsk(body)) {
463
+ const kind = opensAsk(body);
464
+ if (event.action === 'created' && anyLogin(settings.agents, author) && kind) {
465
+ // The owner may answer while this run is still going: read their answer before labelling, and again after,
466
+ // since their approval's run takes off only a label its event shows. An issue's comment alone is read, by its id and time.
467
+ const { id, created_at } = event.comment ?? {};
468
+ const names = kind === 'Proposal' ? (firstIssue(body.split(/\r?\n/, 1)[0]) ?? issue) : issue;
469
+ const ask = !labelled && name === 'issue_comment' && id !== undefined && created_at ? { id, created_at, names } : undefined;
470
+ const before = ask ? await answeredSince(sys, token, slug, issue, ask, settings) : undefined;
471
+ if (before) {
472
+ io.out(`needs-owner: #${issue} asks the owner (${kind}:), and the owner already answered with ${before}; not labelled ${NEEDS_OWNER}`);
473
+ return 0;
474
+ }
435
475
  if (!labelled)
436
476
  await addLabel(sys, token, slug, issue);
437
- io.out(`needs-owner: #${issue} asks the owner (${opensAsk(body)}:); labelled ${NEEDS_OWNER}`);
477
+ const after = ask ? await answeredSince(sys, token, slug, issue, ask, settings) : undefined;
478
+ if (after) {
479
+ await removeLabel(sys, token, slug, issue);
480
+ io.out(`needs-owner: #${issue} asks the owner (${kind}:), and the owner answered with ${after} as it was labelled; ${NEEDS_OWNER} taken off`);
481
+ return 0;
482
+ }
483
+ io.out(`needs-owner: #${issue} asks the owner (${kind}:); labelled ${NEEDS_OWNER}`);
438
484
  return 0;
439
485
  }
440
486
  // The owner's batch answer on the Approvals issue names a proposal's own issue, such as a dropped State, not
@@ -322,12 +322,24 @@ function workflowJobs(gh, repo) {
322
322
  }
323
323
  /** How many recently updated pull requests are searched for the last one merged. */
324
324
  const RECENT_PULLS = 30;
325
+ /**
326
+ * `runs` without the cancelled ones a later run replaced: a `cancelled`
327
+ * run is left out when a run from the same app started after it and
328
+ * concluded `success`. A workflow with `cancel-in-progress` cancels the
329
+ * run an edit or a push replaced, in another check suite, so both are
330
+ * latest runs of the name (#358). A cancelled run nothing replaced stays.
331
+ */
332
+ function superseded(runs) {
333
+ const at = (one) => (typeof one.started_at === 'string' ? one.started_at : '');
334
+ return runs.filter((one) => one.conclusion !== 'cancelled' || !runs.some((other) => other.conclusion === 'success' && other.app?.id === one.app?.id && at(other) > at(one) && at(one) !== ''));
335
+ }
325
336
  /**
326
337
  * Whether each named check reported `success` on the head commit of the
327
338
  * last pull request merged into the default branch, and from which app.
328
339
  * A check that does is one pull requests run, so a ruleset requiring it
329
340
  * holds none; one that does not might never report on a pull request. Two
330
341
  * apps reporting the same name is refused: the ruleset requires one app's.
342
+ * A cancelled run a later success replaced does not count (`superseded`).
331
343
  */
332
344
  function passedOnPull(gh, repo, names) {
333
345
  const found = new Map();
@@ -352,7 +364,7 @@ function passedOnPull(gh, repo, names) {
352
364
  continue;
353
365
  }
354
366
  const runs = (answer.json?.check_runs ?? []);
355
- const named = runs.filter((one) => one.name === name);
367
+ const named = superseded(runs.filter((one) => one.name === name));
356
368
  // Every latest run of that name passed, all from one app.
357
369
  const apps = [...new Set(named.map((one) => one.app?.id))];
358
370
  const app = apps[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veda-hq/niyam",
3
- "version": "0.6.18",
3
+ "version": "0.6.19",
4
4
  "description": "Work rules for repos that track work in GitHub Issues: setup, agent identity, push and PR checks.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -31,7 +31,7 @@
31
31
  "typescript": "7.0.2"
32
32
  },
33
33
  "dependencies": {
34
- "@clack/prompts": "1.8.1",
34
+ "@clack/prompts": "1.9.0",
35
35
  "libsodium-wrappers": "0.8.4",
36
36
  "yaml": "2.9.1"
37
37
  },