cornfield 0.13.1 → 0.13.2
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/package.json +1 -1
- package/server/agent-runs.js +42 -13
- package/server/triggers.js +6 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cornfield",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "popcorn245 (https://github.com/popcorn245)",
|
package/server/agent-runs.js
CHANGED
|
@@ -82,7 +82,7 @@ import { createRequest, findRunId, formatRunComment, runAuthors, runBlocksOf, ru
|
|
|
82
82
|
import { quietAfterMs } from '../core/config.js';
|
|
83
83
|
import { nodesForFile, parseMentions, resolveMentions } from '../core/mentions.js';
|
|
84
84
|
import { readTopology } from '../core/validate.js';
|
|
85
|
-
import { findPullProposal, listPullProposals, readPullProposal } from './proposal-pulls.js';
|
|
85
|
+
import { findPullProposal, listPullProposals, pullProposals, readPullProposal } from './proposal-pulls.js';
|
|
86
86
|
import { Refused, countAttempt, throttle } from './throttle.js';
|
|
87
87
|
|
|
88
88
|
/** Requests one person may make in a minute (a ceiling of its own; every other action is counted by `ATTEMPTS_PER_MINUTE` and `PER_MINUTE`) */
|
|
@@ -237,6 +237,8 @@ function requestNodes(request, known) {
|
|
|
237
237
|
* @property {{ auth: object, now?: () => number }} limits what server/throttle.js counts by
|
|
238
238
|
* @property {{ token: { id: number, label: string } } | null} [via] set when the request came through the API: the token it came with
|
|
239
239
|
* @property {() => string | null | Promise<string | null>} [stillAllowed] asked once more just before the cap is taken: null to go on, or why not
|
|
240
|
+
* @property {number} [landed] set only by the `spec.approved` trigger: the spec pull request the approval was on. If no open pull request holds the
|
|
241
|
+
* proposal because that one has since merged, the request is about the proposal as it is on the default branch (no `refs.pull`) and is posted there
|
|
240
242
|
* @property {{ event: string, ref: string }} [trigger] set only by an opt-in trigger (server/triggers.js): what caused this request. It is written into the
|
|
241
243
|
* request (`trigger: { event, by, ref }`, `by` being the maintainer asking) and the audit row, and the run's `via` is 'trigger'. A caller's body can never set it
|
|
242
244
|
*/
|
|
@@ -486,11 +488,16 @@ export function createRuns({ config, where, auth, hooks = null, now = Date.now,
|
|
|
486
488
|
else if (made.refs.proposal != null) {
|
|
487
489
|
const listed = await listPullProposals(forge, folder, { hooks: null });
|
|
488
490
|
entry = listed.entries.find((e) => e.slug === made.refs.proposal) ?? null;
|
|
489
|
-
if (
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
491
|
+
if (entry) {
|
|
492
|
+
number = entry.pull.number;
|
|
493
|
+
made = build(me.login, number);
|
|
494
|
+
runId = made.runId;
|
|
495
|
+
Object.assign(asked, { runId });
|
|
496
|
+
} else if (ctx.landed != null && (entry = await landedEntry(forge, ctx.landed, made.refs.proposal))) {
|
|
497
|
+
// A trigger's approval landed its spec pull request first (proposals.approveLands): the proposal is on the default branch, so
|
|
498
|
+
// the request names no pull request ("an approved proposal already on the default branch has none") and is posted on the merged one
|
|
499
|
+
number = ctx.landed;
|
|
500
|
+
} else throw new Refused(404, listed.problem ? `The open spec pull requests could not be read: ${listed.problem}` : `No open spec pull request holds the proposal ${made.refs.proposal}, so there is nowhere to post the request.`, 'not-found');
|
|
494
501
|
} else number = /** @type {number} */ (made.refs.issue);
|
|
495
502
|
if (made.refs.issue != null) {
|
|
496
503
|
try {
|
|
@@ -721,20 +728,42 @@ export function createRuns({ config, where, auth, hooks = null, now = Date.now,
|
|
|
721
728
|
return following;
|
|
722
729
|
}
|
|
723
730
|
|
|
731
|
+
/**
|
|
732
|
+
* The proposal `slug` as merged pull request `n` held it, or null: not merged, gone, or it never held that proposal. Read of the forge
|
|
733
|
+
* (its files at its head), not taken from the trigger's word, so a request is posted only on a pull request that landed the proposal.
|
|
734
|
+
* @param {import('./forge.js').Forge} forge
|
|
735
|
+
* @param {number} n
|
|
736
|
+
* @param {string} slug
|
|
737
|
+
*/
|
|
738
|
+
async function landedEntry(forge, n, slug) {
|
|
739
|
+
let pull;
|
|
740
|
+
try {
|
|
741
|
+
pull = await forge.pull(n);
|
|
742
|
+
} catch (err) {
|
|
743
|
+
if (err instanceof ForgeError && err.code === 'not-found') return null;
|
|
744
|
+
throw err;
|
|
745
|
+
}
|
|
746
|
+
if (pull.state !== 'merged') return null;
|
|
747
|
+
return (await pullProposals(forge, folder, pull)).find((e) => e.slug === slug) ?? null;
|
|
748
|
+
}
|
|
749
|
+
|
|
724
750
|
/**
|
|
725
751
|
* What a run is about, as references the map resolves (spec 0005 D9: "before the first push, the nodes come from what the request was
|
|
726
752
|
* about: the proposal, or the thread's mentions"): the `[[mentions]]` in the opening post of its thread, issue or spec PR, and for a
|
|
727
753
|
* proposal the ids of every node it touches (what it adds, changes and removes, the parents of what it adds, and the ends of the edges it
|
|
728
|
-
* adds, changes and removes). Asks the forge; throws what it throws. `entry`: the spec PR's listing when the caller has it already.
|
|
754
|
+
* adds, changes and removes). Asks the forge; throws what it throws. `entry`: the spec PR's listing when the caller has it already. A proposal
|
|
755
|
+
* with no `pull` (one a trigger asked about after it landed) is read from the merged pull request `target` the request was posted on.
|
|
729
756
|
* @returns {Promise<string[]>}
|
|
730
757
|
*/
|
|
731
|
-
async function subjectRefs(forge, refs, entry = null) {
|
|
758
|
+
async function subjectRefs(forge, refs, entry = null, target = null) {
|
|
732
759
|
const out = [];
|
|
733
760
|
const add = (r) => { if (typeof r === 'string' && r !== '' && !out.includes(r)) out.push(r); };
|
|
734
|
-
|
|
735
|
-
|
|
761
|
+
// A request about a proposal and a conversation is read as the conversation's when it names no spec pull request
|
|
762
|
+
const at = refs?.pull ?? entry?.pull.number ?? (refs?.thread == null && refs?.issue == null ? target : null);
|
|
763
|
+
if (refs?.proposal != null && at != null) {
|
|
764
|
+
const pull = await forge.pull(at);
|
|
736
765
|
parseMentions(pull.body ?? '').refs.forEach(add);
|
|
737
|
-
const found = entry ?? await findPullProposal(forge, folder, refs.proposal, refs.pull);
|
|
766
|
+
const found = entry ?? (refs.pull != null ? await findPullProposal(forge, folder, refs.proposal, refs.pull) : await landedEntry(forge, at, refs.proposal));
|
|
738
767
|
if (found) {
|
|
739
768
|
let proposal = null;
|
|
740
769
|
try { proposal = JSON.parse(await readPullProposal(forge, folder, found)); } catch (err) { if (!(err instanceof SyntaxError)) throw err; }
|
|
@@ -797,10 +826,10 @@ export function createRuns({ config, where, auth, hooks = null, now = Date.now,
|
|
|
797
826
|
if (mentions >= MAX_MENTION_READS) continue;
|
|
798
827
|
let refs = null;
|
|
799
828
|
try { refs = JSON.parse(row.request).refs; } catch { refs = null; }
|
|
800
|
-
if (!(refs?.proposal != null && refs.pull != null) && refs?.thread == null && refs?.issue == null) continue;
|
|
829
|
+
if (!(refs?.proposal != null && (refs.pull != null || row.target != null)) && refs?.thread == null && refs?.issue == null) continue;
|
|
801
830
|
mentions += 1;
|
|
802
831
|
try {
|
|
803
|
-
save.run(row.run_id, 'mentions', '', JSON.stringify(await subjectRefs(forge, refs)), iso(at));
|
|
832
|
+
save.run(row.run_id, 'mentions', '', JSON.stringify(await subjectRefs(forge, refs, null, row.target)), iso(at));
|
|
804
833
|
} catch (err) {
|
|
805
834
|
log(`what ${row.run_id} is about could not be read for its nodes: ${words(err)}`);
|
|
806
835
|
}
|
package/server/triggers.js
CHANGED
|
@@ -38,9 +38,10 @@
|
|
|
38
38
|
* over (finished, or quiet: what the cap counts). While one is open, the trigger is skipped with `run-open` (`trigger-skipped` and the
|
|
39
39
|
* hook), whatever its profile; the one-run-per-subject rule of the request path only clashes within a profile.
|
|
40
40
|
*
|
|
41
|
-
* **approveLands.** With `proposals.approveLands`, an approval may land the spec pull request before the trigger's request reads it
|
|
42
|
-
* request then finds no open proposal and the
|
|
43
|
-
*
|
|
41
|
+
* **approveLands.** With `proposals.approveLands`, an approval may land the spec pull request before the trigger's request reads it. The
|
|
42
|
+
* request then finds no open proposal and asks for the run on the landed one: `refs: { proposal }` with no `pull`, posted on the merged spec
|
|
43
|
+
* pull request, the cause unchanged (`pull:<n>`), once the forge says that pull request merged and its files held the proposal (else
|
|
44
|
+
* `not-found`). Either order works; the cap and the one-run-per-subject rule apply as always.
|
|
44
45
|
*
|
|
45
46
|
* **No live sign-in.** If the maintainer has no live session, the trigger does nothing else (cornfield holds no forge token of its own, and
|
|
46
47
|
* another maintainer's would put words in their name): an audit row (`trigger-skipped`), the hook event `trigger.skipped`
|
|
@@ -257,6 +258,8 @@ export function createTriggers({ config, auth, runs, hooks, now = Date.now }) {
|
|
|
257
258
|
await runs.request({
|
|
258
259
|
forge: () => forge, who: { login: cause.by, userId: String(userId) }, limits: { auth, now },
|
|
259
260
|
trigger: { event: cause.event, ref: cause.ref },
|
|
261
|
+
// An approval that landed its spec pull request first leaves the proposal on the default branch: the request goes on the merged one
|
|
262
|
+
...(event === 'spec.approved' ? { landed: cause.subject } : {}),
|
|
260
263
|
}, { body });
|
|
261
264
|
} catch (err) {
|
|
262
265
|
if (!(err instanceof Refused) && !(err instanceof ForgeError)) log(`a ${event} trigger failed: ${err instanceof Error ? err.stack || err.message : err}`);
|