@defrex/autobuild 1.5.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/SPEC.md +192 -24
- package/docs/agent-runtimes.md +1 -1
- package/docs/answering-blocked-builds.md +7 -4
- package/docs/architecture.md +100 -32
- package/docs/configuration-overview.md +10 -0
- package/docs/configuration.md +340 -10
- package/docs/dispatcher.md +2 -2
- package/docs/forges.md +1 -0
- package/docs/glossary.md +1 -1
- package/docs/operating.md +1 -1
- package/docs/operator-api.md +33 -10
- package/docs/operator-surfaces.md +6 -3
- package/docs/plugin-authoring.md +48 -6
- package/docs/remote-store-protocol.md +33 -10
- package/docs/restacking.md +16 -7
- package/docs/ticket-sources.md +34 -6
- package/docs/tickets.md +7 -1
- package/docs/troubleshooting.md +1 -1
- package/docs/workspaces.md +1 -1
- package/package.json +3 -3
- package/packages/core/src/cli/attention.ts +3 -0
- package/packages/core/src/cli/binary-direct.ts +1 -0
- package/packages/core/src/cli/dashboard/model.ts +14 -4
- package/packages/core/src/cli/dashboard/poll.ts +14 -0
- package/packages/core/src/cli/dashboard/render.ts +3 -0
- package/packages/core/src/cli/dispatch-frontend.ts +10 -14
- package/packages/core/src/cli/dispatch-preflight.ts +5 -1
- package/packages/core/src/cli/dispatch-repository-feed.ts +145 -109
- package/packages/core/src/cli/dispatch-tickets.ts +47 -0
- package/packages/core/src/cli/dispatch-upgrade-controller.ts +3 -0
- package/packages/core/src/cli/dispatch.ts +377 -101
- package/packages/core/src/cli/help.ts +15 -6
- package/packages/core/src/cli/init-validation.ts +14 -1
- package/packages/core/src/cli/repo-lease.ts +225 -0
- package/packages/core/src/cli/repository-status.ts +40 -3
- package/packages/core/src/cli/status.ts +21 -13
- package/packages/core/src/cli/ticket.ts +22 -4
- package/packages/core/src/cli/wait.ts +4 -1
- package/packages/core/src/cli/watch.ts +17 -4
- package/packages/core/src/config/live.ts +4 -0
- package/packages/core/src/config/profiles.ts +96 -0
- package/packages/core/src/config/ready-assignee.ts +43 -11
- package/packages/core/src/config/roles.ts +33 -10
- package/packages/core/src/config/schema.ts +204 -26
- package/packages/core/src/events/catalog.ts +2 -0
- package/packages/core/src/events/compatibility.ts +3 -1
- package/packages/core/src/events/forge-degradation-policy.ts +16 -2
- package/packages/core/src/events/payloads.ts +23 -0
- package/packages/core/src/events/policy.ts +3 -0
- package/packages/core/src/events/repository.ts +19 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +267 -352
- package/packages/core/src/kernel/build-creation.ts +29 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +134 -30
- package/packages/core/src/kernel/engine.ts +13 -6
- package/packages/core/src/kernel/forge-health.ts +47 -0
- package/packages/core/src/kernel/generators/build-log.ts +9 -0
- package/packages/core/src/kernel/guarded-forge.ts +76 -18
- package/packages/core/src/kernel/incremental-fixtures.ts +1 -0
- package/packages/core/src/kernel/janitor-failure.ts +85 -5
- package/packages/core/src/kernel/leaf-restack-state.ts +4 -2
- package/packages/core/src/kernel/log-index.ts +1 -1
- package/packages/core/src/kernel/node-landing.ts +2 -1
- package/packages/core/src/kernel/node-parent.ts +2 -0
- package/packages/core/src/kernel/read-facts.ts +9 -1
- package/packages/core/src/kernel/reducer-registry.ts +6 -1
- package/packages/core/src/kernel/reducer.ts +75 -4
- package/packages/core/src/kernel/ticket-preparation.ts +15 -8
- package/packages/core/src/operator/protocol.ts +10 -0
- package/packages/core/src/operator/query.ts +16 -13
- package/packages/core/src/operator/registry.ts +25 -5
- package/packages/core/src/operator/sandbox-host.ts +3 -0
- package/packages/core/src/operator/tickets.ts +15 -3
- package/packages/core/src/plugin-sdk/index.ts +4 -0
- package/packages/core/src/ports/forge/create.ts +6 -0
- package/packages/core/src/ports/forge/github-transport.ts +40 -3
- package/packages/core/src/ports/forge/github.ts +12 -1
- package/packages/core/src/ports/forge/workspace-ancestry.ts +60 -0
- package/packages/core/src/ports/forge-failure.ts +31 -2
- package/packages/core/src/ports/runner/routing.ts +66 -5
- package/packages/core/src/ports/tickets/assignees.ts +54 -0
- package/packages/core/src/ports/tickets/contract.ts +164 -4
- package/packages/core/src/ports/tickets/create.ts +35 -7
- package/packages/core/src/ports/tickets/github-fake.ts +18 -2
- package/packages/core/src/ports/tickets/github.ts +247 -29
- package/packages/core/src/ports/tickets/hosted-index.ts +1 -0
- package/packages/core/src/ports/tickets/operations.ts +6 -1
- package/packages/core/src/ports/tickets/tree.ts +12 -2
- package/packages/core/src/ports/tickets/update.ts +6 -2
- package/packages/core/src/ports/types.ts +37 -3
- package/packages/core/src/ports/workspace/commit-preservation.ts +28 -12
- package/packages/core/src/ports/workspace/git-worktree.ts +3 -1
- package/packages/core/src/ports/workspace/harvest-execution.ts +4 -2
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +12 -0
- package/packages/core/src/processes/build-child.ts +28 -7
- package/packages/core/src/processes/build-execution-state.ts +4 -1
- package/packages/core/src/processes/build-runner.ts +17 -2
- package/packages/core/src/processes/dispatcher.ts +329 -59
- package/packages/core/src/processes/execution-no-progress.ts +2 -0
- package/packages/core/src/processes/harvest-child.ts +8 -2
- package/packages/core/src/processes/harvest-execution-state.ts +104 -0
- package/packages/core/src/processes/harvest-runner.ts +251 -17
- package/packages/core/src/processes/repo-view.ts +2 -0
- package/packages/core/src/scenarios/harness.ts +160 -36
- package/packages/core/src/store/reduced-reads.ts +10 -0
- package/packages/core/src/store/reducer-value-shapes.json +3339 -2898
- package/packages/core/src/store/remote/client.ts +21 -8
- package/packages/core/src/store/remote/index.ts +4 -0
- package/packages/core/src/store/remote/protocol.ts +7 -0
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.6.0.json +27173 -0
- package/packages/core/src/store/remote/released-reducer-values/1.7.0.json +27366 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +4 -0
- package/packages/core/src/store/repo-state-events.ts +1 -0
- package/packages/core/src/store/types.ts +11 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +84 -58
- package/packages/core/src/testing/index.ts +2 -0
- package/packages/core/src/testing/reduced-read-budget.ts +411 -11
- package/skills/guide/SKILL.md +166 -35
- package/skills/guide/references/operator-api.md +33 -10
- package/skills/guide/references/plugin-authoring.md +48 -6
- package/skills/guide/references/remote-store-protocol.md +33 -10
- package/skills/guide/references/restacking.md +16 -7
- package/skills/operate/SKILL.md +79 -14
- package/skills/tickets/SKILL.md +22 -4
- package/templates/hosted-service/package.json +2 -2
|
@@ -2,7 +2,7 @@ import { compatibleTicketSource } from './tree'
|
|
|
2
2
|
import { configuredStore } from '../../cli/configured-store'
|
|
3
3
|
import { projectToken } from '../../cli/project-credentials'
|
|
4
4
|
import { resolveRepoOrigin } from '../../cli/repo-state'
|
|
5
|
-
import { spawnExec } from '../workspace/git-worktree'
|
|
5
|
+
import { spawnExec, type Exec } from '../workspace/git-worktree'
|
|
6
6
|
/**
|
|
7
7
|
* TicketSource factory (SPEC §3.2, §13): construct the builtin or plugin source
|
|
8
8
|
* named by [tickets]. Plugin credentials, like LINEAR_API_KEY, come only from
|
|
@@ -20,15 +20,20 @@ import { GitHubTicketSource } from './github'
|
|
|
20
20
|
import { FileGitHubValidatorStore } from './github-validators'
|
|
21
21
|
import {
|
|
22
22
|
createGitHubFetchTransport,
|
|
23
|
+
githubCredentialRequirement,
|
|
23
24
|
githubTokenSource,
|
|
24
25
|
resolveGitHubToken,
|
|
26
|
+
type GitHubRequest,
|
|
25
27
|
} from '../forge/github-transport'
|
|
26
28
|
import { parseRepoCoordinates } from '../forge/github'
|
|
27
29
|
import { normalizeGitRemoteUrl } from '../../kernel/origin'
|
|
28
30
|
import { HostedTicketSource, hostedTicketPolicy } from './remote'
|
|
29
31
|
import { ticketLifecycle } from './lifecycle'
|
|
30
32
|
import { normalizeServiceURL } from '../../connection'
|
|
31
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
assertCreateAssigneeSupported,
|
|
35
|
+
assertReadyAssigneeSupported,
|
|
36
|
+
} from '../../config/ready-assignee'
|
|
32
37
|
|
|
33
38
|
function reason(error: unknown): string {
|
|
34
39
|
return error instanceof Error ? error.message : String(error)
|
|
@@ -37,13 +42,28 @@ function reason(error: unknown): string {
|
|
|
37
42
|
async function rawTicketSource(
|
|
38
43
|
config: TicketsConfig,
|
|
39
44
|
env: Record<string, string | undefined>,
|
|
40
|
-
/**
|
|
45
|
+
/** Filesystem location of the repository: the checkout, or origin-mode
|
|
46
|
+
* dispatch's scratch root. Never a repository identity URL. A relative
|
|
47
|
+
* [tickets].dir is relative to it, not this process's cwd. */
|
|
41
48
|
targetRepo: string,
|
|
42
49
|
/** Selected local state root. Remote stores pass the repo-local default. */
|
|
43
50
|
localStateRoot?: string,
|
|
44
51
|
/** Registry loaded from this repository's configured plugins. */
|
|
45
52
|
plugins: PluginRegistry = createPluginRegistry(),
|
|
53
|
+
options: {
|
|
54
|
+
/** Already-resolved repository origin for a caller with no checkout
|
|
55
|
+
* (origin-mode dispatch). Used instead of resolving targetRepo's origin. */
|
|
56
|
+
repository?: string
|
|
57
|
+
/** Exec seam for the origin lookup; defaults to spawnExec. */
|
|
58
|
+
exec?: Exec
|
|
59
|
+
/** GitHub API seam for the github source; defaults to the fetch transport. */
|
|
60
|
+
transport?: GitHubRequest
|
|
61
|
+
/** Process label: the github source's default transport refuses requests
|
|
62
|
+
* without a credential. Absent, `AB_GITHUB_REQUIRE_CREDENTIAL` decides. */
|
|
63
|
+
requireCredential?: string
|
|
64
|
+
} = {},
|
|
46
65
|
): Promise<TicketSource> {
|
|
66
|
+
const exec = options.exec ?? spawnExec
|
|
47
67
|
if (config.source === 'hosted') {
|
|
48
68
|
const buildUrl = env.AB_STORE?.trim() || configuredStore(targetRepo)
|
|
49
69
|
const rawUrl = config.url ?? buildUrl
|
|
@@ -72,7 +92,7 @@ async function rawTicketSource(
|
|
|
72
92
|
? env.AB_TICKET_TOKEN
|
|
73
93
|
: projectToken(
|
|
74
94
|
rawUrl,
|
|
75
|
-
(await resolveRepoOrigin(targetRepo,
|
|
95
|
+
options.repository ?? (await resolveRepoOrigin(targetRepo, exec)) ?? targetRepo,
|
|
76
96
|
config.url &&
|
|
77
97
|
(!buildUrl ||
|
|
78
98
|
!/^https?:/.test(buildUrl) ||
|
|
@@ -130,7 +150,8 @@ async function rawTicketSource(
|
|
|
130
150
|
}
|
|
131
151
|
|
|
132
152
|
if (config.source === 'github') {
|
|
133
|
-
const origin =
|
|
153
|
+
const origin =
|
|
154
|
+
env.AB_REPOSITORY?.trim() || options.repository || (await resolveRepoOrigin(targetRepo, exec))
|
|
134
155
|
if (origin === undefined || origin === '')
|
|
135
156
|
throw new Error(
|
|
136
157
|
'[tickets].source = "github" needs the repository\'s origin remote on github.com; set the checkout\'s origin or export AB_REPOSITORY',
|
|
@@ -141,7 +162,12 @@ async function rawTicketSource(
|
|
|
141
162
|
`[tickets].source = "github" needs an origin on github.com; origin is ${origin}`,
|
|
142
163
|
)
|
|
143
164
|
return new GitHubTicketSource({
|
|
144
|
-
transport:
|
|
165
|
+
transport:
|
|
166
|
+
options.transport ??
|
|
167
|
+
createGitHubFetchTransport({
|
|
168
|
+
token: githubTokenSource(env),
|
|
169
|
+
requireCredential: githubCredentialRequirement(env, options.requireCredential),
|
|
170
|
+
}),
|
|
145
171
|
repository: coordinates,
|
|
146
172
|
lifecycle: ticketLifecycle(config),
|
|
147
173
|
readyLabels: config.readyLabels ?? ['autobuild'],
|
|
@@ -222,7 +248,9 @@ export async function createTicketSource(
|
|
|
222
248
|
// Plugins load after config parse, so the capability is checked here, on
|
|
223
249
|
// the constructed source, rather than in the schema.
|
|
224
250
|
const owner = plugins?.ticketSources.get(config.source)?.owner
|
|
225
|
-
|
|
251
|
+
const plugin = owner?.kind === 'plugin' ? owner.name : undefined
|
|
252
|
+
assertReadyAssigneeSupported(config, source, plugin)
|
|
253
|
+
assertCreateAssigneeSupported(config, source, plugin)
|
|
226
254
|
return compatibleTicketSource(source)
|
|
227
255
|
}
|
|
228
256
|
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
* adapter read of those fails a test with a 404.
|
|
15
15
|
* Identity routes answer for the requesting credential: `GET user` returns
|
|
16
16
|
* its login (or 403 for `transportAs(null)`), and the assignee-check route
|
|
17
|
-
* answers 204 for `assignable` logins.
|
|
17
|
+
* answers 204 for `assignable` logins. Issue create and edit set the
|
|
18
|
+
* `assignees` they name, silently dropping any login that is not `assignable`,
|
|
19
|
+
* or every one under `dropAssignees`, as GitHub does without push access.
|
|
18
20
|
*
|
|
19
21
|
* UI-style mutators simulate what people do on GitHub outside the adapter.
|
|
20
22
|
*/
|
|
@@ -141,6 +143,9 @@ export class FakeGitHubIssues {
|
|
|
141
143
|
/** Simulates a token without push access: GitHub silently drops label
|
|
142
144
|
* changes on issue create and edit. */
|
|
143
145
|
dropLabels = false
|
|
146
|
+
/** Simulates a token without push access: GitHub silently drops assignee
|
|
147
|
+
* changes on issue create and edit. */
|
|
148
|
+
dropAssignees = false
|
|
144
149
|
/** When false, UI labelling leaves `updated_at` untouched. */
|
|
145
150
|
labelsBumpUpdatedAt = true
|
|
146
151
|
searchLagMs: number
|
|
@@ -803,10 +808,18 @@ export class FakeGitHubIssues {
|
|
|
803
808
|
}
|
|
804
809
|
}
|
|
805
810
|
|
|
811
|
+
/** The assignees an edit leaves: the requested assignable logins, or the
|
|
812
|
+
* current set unchanged under `dropAssignees`. */
|
|
813
|
+
private assigned(requested: string[], current: string[]): string[] {
|
|
814
|
+
if (this.dropAssignees) return current
|
|
815
|
+
return [...new Set(requested)].filter((login) => this.assignable.has(login.toLowerCase()))
|
|
816
|
+
}
|
|
817
|
+
|
|
806
818
|
private createIssue(body: unknown): { json: unknown; status: number } {
|
|
807
|
-
const input = body as { title?: string; body?: string; labels?: string[] }
|
|
819
|
+
const input = body as { title?: string; body?: string; labels?: string[]; assignees?: string[] }
|
|
808
820
|
if (!input?.title) throw new GitHubApiError(422, 'Validation Failed', { message: 'title' })
|
|
809
821
|
const issue = this.insert(input.title, input.body ?? null, [])
|
|
822
|
+
if (input.assignees !== undefined) issue.assignees = this.assigned(input.assignees, [])
|
|
810
823
|
if (!this.dropLabels)
|
|
811
824
|
for (const name of input.labels ?? []) {
|
|
812
825
|
const label = this.ensureLabel(name)
|
|
@@ -825,8 +838,11 @@ export class FakeGitHubIssues {
|
|
|
825
838
|
labels?: string[]
|
|
826
839
|
state?: 'open' | 'closed'
|
|
827
840
|
state_reason?: string | null
|
|
841
|
+
assignees?: string[]
|
|
828
842
|
}
|
|
829
843
|
if (input.title !== undefined) issue.title = input.title
|
|
844
|
+
if (input.assignees !== undefined)
|
|
845
|
+
issue.assignees = this.assigned(input.assignees, issue.assignees)
|
|
830
846
|
if (input.body !== undefined) issue.body = input.body
|
|
831
847
|
if (input.labels !== undefined && !this.dropLabels) {
|
|
832
848
|
const next = input.labels.map((name) => this.ensureLabel(name).name)
|
|
@@ -24,7 +24,16 @@
|
|
|
24
24
|
* A `readyAssignee` narrows the ready read itself
|
|
25
25
|
* (its `assignee` query parameter); `"me"` costs one `GET /user` per
|
|
26
26
|
* dispatcher start, sent by `prepareReadyAssignee` before the loop and never
|
|
27
|
-
* during a tick.
|
|
27
|
+
* during a tick. It also adds one conditional `assignee=none` read per ready
|
|
28
|
+
* scan, plus one per further page, that reports ready issues with no
|
|
29
|
+
* assignee as diagnostics; its failures, rate limits included, never fail
|
|
30
|
+
* the scan or arm the source cooldown.
|
|
31
|
+
* Assignees cost reads nothing: every issue payload already carries them. A
|
|
32
|
+
* write naming assignees sends one `GET /repos/{o}/{r}/assignees/{login}` per
|
|
33
|
+
* distinct login per instance (positive answers are memoized) and resolves
|
|
34
|
+
* `"me"` through the same memoized `GET /user`; a dispatcher prepared it at
|
|
35
|
+
* startup, so a harvest proposal filed under `createAssignee = "me"` adds no
|
|
36
|
+
* `GET /user` and an idle tick adds nothing.
|
|
28
37
|
*/
|
|
29
38
|
import { z } from 'zod'
|
|
30
39
|
import {
|
|
@@ -85,7 +94,12 @@ import {
|
|
|
85
94
|
validCreationKey,
|
|
86
95
|
writeForState,
|
|
87
96
|
} from './github-issues'
|
|
88
|
-
import {
|
|
97
|
+
import {
|
|
98
|
+
GITHUB_CREATE_ASSIGNEE,
|
|
99
|
+
GITHUB_READY_ASSIGNEE,
|
|
100
|
+
githubAssigneeForm,
|
|
101
|
+
} from '../../config/ready-assignee'
|
|
102
|
+
import { MAX_TICKET_ASSIGNEES } from './assignees'
|
|
89
103
|
import { type GitHubValidatorStore, MemoryGitHubValidatorStore } from './github-validators'
|
|
90
104
|
import { normalizeIssueLinks } from './issue-links'
|
|
91
105
|
import { holdsState, type TicketLifecycle } from './lifecycle'
|
|
@@ -115,6 +129,8 @@ const LINK_LABEL_DESCRIPTION = 'Autobuild issue link'
|
|
|
115
129
|
const NODE_LABEL_DESCRIPTION = 'Autobuild integration node'
|
|
116
130
|
/** GitHub limits a label description to 100 characters. */
|
|
117
131
|
const LABEL_DESCRIPTION_MAX = 100
|
|
132
|
+
/** Ready issues with no assignee a scan names before counting the rest. */
|
|
133
|
+
const UNASSIGNED_REPORT_LIMIT = 10
|
|
118
134
|
|
|
119
135
|
/** A keyed create reached the source without the key's reservation time. */
|
|
120
136
|
export class TicketCreationKeyReservationRequired extends Error {
|
|
@@ -203,6 +219,12 @@ function etagOf(read: { etag?: string }): { etag?: string } {
|
|
|
203
219
|
return read.etag !== undefined ? { etag: read.etag } : {}
|
|
204
220
|
}
|
|
205
221
|
|
|
222
|
+
/** Requested logins the issue does not hold, compared case-insensitively. */
|
|
223
|
+
function missingAssignees(issue: GitHubIssue, requested: readonly string[]): string[] {
|
|
224
|
+
const held = loginSet(assigneeLogins(issue))
|
|
225
|
+
return requested.filter((login) => !held.has(login.toLowerCase()))
|
|
226
|
+
}
|
|
227
|
+
|
|
206
228
|
function blockerList(ids: string[]): string {
|
|
207
229
|
return ids.length > 0 ? ids.map((id) => `"${id}"`).join(', ') : 'none'
|
|
208
230
|
}
|
|
@@ -217,14 +239,30 @@ const githubCommentSchema = z
|
|
|
217
239
|
/** Who the credential belongs to, as `prepareReadyAssignee` found it. */
|
|
218
240
|
type Viewer = { login: string } | { noUser: true } | { failed: string }
|
|
219
241
|
|
|
220
|
-
|
|
221
|
-
|
|
242
|
+
type AssigneeKey = 'readyAssignee' | 'createAssignee'
|
|
243
|
+
|
|
244
|
+
const NO_USER_ASSIGNEE = (key: AssigneeKey): string =>
|
|
245
|
+
`github tickets: [tickets].${key} = "me" but the GitHub credential has no user (a GitHub App installation token has none) — set ${key} to a GitHub username`
|
|
246
|
+
|
|
247
|
+
/** The key-neutral form, for a write whose assignees name `me`. */
|
|
248
|
+
const NO_USER_WRITE =
|
|
249
|
+
'the GitHub credential has no user (a GitHub App installation token has none) — name a GitHub username instead of me'
|
|
250
|
+
|
|
251
|
+
/** Logins compared as GitHub does: case-insensitively. */
|
|
252
|
+
function loginSet(logins: readonly string[]): Set<string> {
|
|
253
|
+
return new Set(logins.map((login) => login.toLowerCase()))
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function assigneeLogins(issue: GitHubIssue): string[] {
|
|
257
|
+
return (issue.assignees ?? []).map((assignee) => assignee.login)
|
|
258
|
+
}
|
|
222
259
|
|
|
223
260
|
export class GitHubTicketSource implements TicketSource {
|
|
224
261
|
readonly name = 'github'
|
|
225
262
|
readonly issueLinks = true
|
|
226
263
|
readonly allocatesIds = true
|
|
227
264
|
readonly readyAssignee = true
|
|
265
|
+
readonly assignees = true
|
|
228
266
|
readonly integrationTree = true
|
|
229
267
|
|
|
230
268
|
private readonly transport: GitHubRequest
|
|
@@ -236,6 +274,9 @@ export class GitHubTicketSource implements TicketSource {
|
|
|
236
274
|
private readonly now: () => number
|
|
237
275
|
private readonly credentialMiss?: () => Promise<string | undefined>
|
|
238
276
|
private cooldown?: TicketSourceRateLimitError
|
|
277
|
+
/** A rate limit hit by the unassigned-ready report, kept apart from
|
|
278
|
+
* `cooldown` so it never refuses the listing or claim reads. */
|
|
279
|
+
private unassignedCooldownUntil?: number
|
|
239
280
|
/** Exact label name (lowercased) → the one registry write in progress. */
|
|
240
281
|
private readonly pendingLabels = new Map<string, Promise<void>>()
|
|
241
282
|
/** Labels this instance created or saw created, lowercased. */
|
|
@@ -245,6 +286,8 @@ export class GitHubTicketSource implements TicketSource {
|
|
|
245
286
|
private creationScan?: { floor: number; newest: number; keys: Map<string, number> }
|
|
246
287
|
/** The credential's owner, memoized for the instance's lifetime. */
|
|
247
288
|
private viewer?: Viewer
|
|
289
|
+
/** Logins (lowercased) GitHub confirmed can be assigned issues here. */
|
|
290
|
+
private readonly assignable = new Set<string>()
|
|
248
291
|
|
|
249
292
|
constructor(opts: GitHubTicketSourceOptions) {
|
|
250
293
|
for (const label of opts.readyLabels) {
|
|
@@ -452,6 +495,17 @@ export class GitHubTicketSource implements TicketSource {
|
|
|
452
495
|
`github ${operation}: token lacks push access; label changes were dropped on #${number} (${issue.html_url})`,
|
|
453
496
|
)
|
|
454
497
|
}
|
|
498
|
+
// Assignees the token may not set are dropped the same way.
|
|
499
|
+
if (Array.isArray(body.assignees)) {
|
|
500
|
+
const wanted = loginSet(body.assignees as string[])
|
|
501
|
+
const held = loginSet(assigneeLogins(issue))
|
|
502
|
+
if (wanted.size !== held.size || [...wanted].some((login) => !held.has(login)))
|
|
503
|
+
throw new Error(
|
|
504
|
+
`github ${operation}: #${number} (${issue.html_url}) was written but its assignees were not applied — GitHub holds ${
|
|
505
|
+
held.size > 0 ? [...held].join(', ') : 'none (it is unassigned)'
|
|
506
|
+
} instead of ${wanted.size > 0 ? [...wanted].join(', ') : 'none'}; the token needs push access to assign`,
|
|
507
|
+
)
|
|
508
|
+
}
|
|
455
509
|
return issue
|
|
456
510
|
}
|
|
457
511
|
|
|
@@ -798,6 +852,8 @@ export class GitHubTicketSource implements TicketSource {
|
|
|
798
852
|
labels: ticketLabelsOf(issue),
|
|
799
853
|
...(blockedBy.length > 0 ? { blockedBy } : {}),
|
|
800
854
|
issueLinks,
|
|
855
|
+
// Not part of the revision: ticketRevision picks its fields explicitly.
|
|
856
|
+
assignees: assigneeLogins(issue),
|
|
801
857
|
}
|
|
802
858
|
ticket.revision = ticketRevision(ticket)
|
|
803
859
|
return ticket
|
|
@@ -975,7 +1031,7 @@ export class GitHubTicketSource implements TicketSource {
|
|
|
975
1031
|
// A label state: the ready listing is the recurring dispatcher read, so
|
|
976
1032
|
// it alone is remembered, oldest first for a stable order.
|
|
977
1033
|
const recurring = holdsState(wanted, this.lifecycle.ready)
|
|
978
|
-
|
|
1034
|
+
const listing = await this.listing(
|
|
979
1035
|
await listIssues(
|
|
980
1036
|
'listReady',
|
|
981
1037
|
{
|
|
@@ -989,6 +1045,75 @@ export class GitHubTicketSource implements TicketSource {
|
|
|
989
1045
|
holds,
|
|
990
1046
|
recurring,
|
|
991
1047
|
)
|
|
1048
|
+
if (!recurring || login === undefined) return listing
|
|
1049
|
+
return {
|
|
1050
|
+
tickets: listing.tickets,
|
|
1051
|
+
diagnostics: [...listing.diagnostics, ...(await this.unassignedReady(wanted, labels, login))],
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* Ready issues no `readyAssignee` read can see because nobody is assigned:
|
|
1057
|
+
* one remembered `assignee=none` listing, never hydrated. It only reports;
|
|
1058
|
+
* a failure becomes a diagnostic and leaves the source cooldown as it was,
|
|
1059
|
+
* so assigned tickets are still listed and claimed.
|
|
1060
|
+
*/
|
|
1061
|
+
private async unassignedReady(state: string, labels: string[], login: string): Promise<string[]> {
|
|
1062
|
+
const failed = (reason: string) => [
|
|
1063
|
+
`github tickets: could not check ready issues for a missing assignee (${reason}); assigned ready issues are unaffected`,
|
|
1064
|
+
]
|
|
1065
|
+
const rateLimited = (resetAt: number) =>
|
|
1066
|
+
failed(`rate limited until ${new Date(resetAt).toISOString()}`)
|
|
1067
|
+
if (this.unassignedCooldownUntil !== undefined) {
|
|
1068
|
+
if (this.now() < this.unassignedCooldownUntil)
|
|
1069
|
+
return rateLimited(this.unassignedCooldownUntil)
|
|
1070
|
+
this.unassignedCooldownUntil = undefined
|
|
1071
|
+
}
|
|
1072
|
+
const prior = this.cooldown
|
|
1073
|
+
let issues: GitHubIssue[]
|
|
1074
|
+
try {
|
|
1075
|
+
issues = await this.listIssues(
|
|
1076
|
+
'listReadyUnassigned',
|
|
1077
|
+
{
|
|
1078
|
+
state: 'open',
|
|
1079
|
+
sort: 'created',
|
|
1080
|
+
direction: 'asc',
|
|
1081
|
+
labels: [stateLabel(state), ...labels].join(','),
|
|
1082
|
+
assignee: 'none',
|
|
1083
|
+
},
|
|
1084
|
+
true,
|
|
1085
|
+
)
|
|
1086
|
+
} catch (error) {
|
|
1087
|
+
this.cooldown = prior
|
|
1088
|
+
if (error instanceof TicketSourceRateLimitError) {
|
|
1089
|
+
this.unassignedCooldownUntil = error.resetAt
|
|
1090
|
+
return rateLimited(error.resetAt)
|
|
1091
|
+
}
|
|
1092
|
+
return failed(message(error))
|
|
1093
|
+
}
|
|
1094
|
+
const required = labels.map((label) => label.toLowerCase())
|
|
1095
|
+
const numbers = issues
|
|
1096
|
+
.filter((issue) => {
|
|
1097
|
+
if (issue.state !== 'open' || (issue.assignees ?? []).length > 0) return false
|
|
1098
|
+
const current = issueState(issue, this.lifecycle)
|
|
1099
|
+
if ('malformed' in current || !holdsState(current.state, state)) return false
|
|
1100
|
+
const held = ticketLabelsOf(issue).map((label) => label.toLowerCase())
|
|
1101
|
+
return required.every((label) => held.includes(label))
|
|
1102
|
+
})
|
|
1103
|
+
.map((issue) => issue.number)
|
|
1104
|
+
.sort((a, b) => a - b)
|
|
1105
|
+
const diagnostics = numbers
|
|
1106
|
+
.slice(0, UNASSIGNED_REPORT_LIMIT)
|
|
1107
|
+
.map(
|
|
1108
|
+
(number) =>
|
|
1109
|
+
`github #${number}: ready but unassigned — [tickets].readyAssignee claims only issues assigned to ${login}; assign it to make it claimable`,
|
|
1110
|
+
)
|
|
1111
|
+
const more = numbers.length - UNASSIGNED_REPORT_LIMIT
|
|
1112
|
+
if (more > 0)
|
|
1113
|
+
diagnostics.push(
|
|
1114
|
+
`github: ${more} more ready issues are unassigned and unclaimed — assign them to make them claimable`,
|
|
1115
|
+
)
|
|
1116
|
+
return diagnostics
|
|
992
1117
|
}
|
|
993
1118
|
|
|
994
1119
|
private async listing(
|
|
@@ -1231,6 +1356,8 @@ export class GitHubTicketSource implements TicketSource {
|
|
|
1231
1356
|
: Date.parse(opts.idempotencyKeyReservedAt)
|
|
1232
1357
|
if (!Number.isFinite(reservedAt)) throw new TicketCreationKeyReservationRequired()
|
|
1233
1358
|
}
|
|
1359
|
+
const assignees =
|
|
1360
|
+
draft.assignees === undefined ? [] : await this.resolveAssignees('create', draft.assignees)
|
|
1234
1361
|
const state = await this.resolveTarget('create', opts.state ?? this.lifecycle.create)
|
|
1235
1362
|
const target =
|
|
1236
1363
|
draft.target === undefined || draft.target === null
|
|
@@ -1240,7 +1367,7 @@ export class GitHubTicketSource implements TicketSource {
|
|
|
1240
1367
|
const write = writeForState(state, this.lifecycle, [...labels, ...links.map(linkLabel)])
|
|
1241
1368
|
if (key !== undefined && reservedAt !== undefined) {
|
|
1242
1369
|
const adopted = await this.findByCreationKey(key, reservedAt)
|
|
1243
|
-
if (adopted !== undefined) return this.adopt(adopted, blockedBy)
|
|
1370
|
+
if (adopted !== undefined) return this.adopt(adopted, blockedBy, assignees)
|
|
1244
1371
|
}
|
|
1245
1372
|
// A closing create state opens the issue without a state label and
|
|
1246
1373
|
// closes it as a follow-up.
|
|
@@ -1257,6 +1384,7 @@ export class GitHubTicketSource implements TicketSource {
|
|
|
1257
1384
|
title: draft.title,
|
|
1258
1385
|
body: key === undefined ? draft.body : encodeCreationMarker(draft.body, key, intent),
|
|
1259
1386
|
labels: initial,
|
|
1387
|
+
...(assignees.length > 0 ? { assignees } : {}),
|
|
1260
1388
|
},
|
|
1261
1389
|
})
|
|
1262
1390
|
const issue = this.parseIssue('create', response.json)
|
|
@@ -1265,6 +1393,13 @@ export class GitHubTicketSource implements TicketSource {
|
|
|
1265
1393
|
throw new Error(
|
|
1266
1394
|
`github create: token lacks push access; labels were dropped on #${issue.number} (${issue.html_url})`,
|
|
1267
1395
|
)
|
|
1396
|
+
// GitHub silently drops assignees the token may not set. A keyed create's
|
|
1397
|
+
// marker stays pending, so a retry adopts this issue and reconciles them.
|
|
1398
|
+
const dropped = missingAssignees(issue, assignees)
|
|
1399
|
+
if (dropped.length > 0)
|
|
1400
|
+
throw new Error(
|
|
1401
|
+
`github create: #${issue.number} (${issue.html_url}) was created but is unassigned — GitHub dropped assignee(s) ${dropped.join(', ')}; the token needs push access to assign`,
|
|
1402
|
+
)
|
|
1268
1403
|
return this.finishCreate(issue, intent, key, false)
|
|
1269
1404
|
}
|
|
1270
1405
|
|
|
@@ -1324,10 +1459,22 @@ export class GitHubTicketSource implements TicketSource {
|
|
|
1324
1459
|
return read.issue
|
|
1325
1460
|
}
|
|
1326
1461
|
|
|
1327
|
-
/** A retry found the issue its key opened.
|
|
1328
|
-
* first
|
|
1329
|
-
* blockers from this retry, as
|
|
1330
|
-
|
|
1462
|
+
/** A retry found the issue its key opened. Missing requested assignees are
|
|
1463
|
+
* added first. A pending marker finishes the first attempt's recorded
|
|
1464
|
+
* intent; a plain one reconciles only missing blockers from this retry, as
|
|
1465
|
+
* Linear does. */
|
|
1466
|
+
private async adopt(
|
|
1467
|
+
found: GitHubIssue,
|
|
1468
|
+
retryBlockers: string[],
|
|
1469
|
+
assignees: string[],
|
|
1470
|
+
): Promise<Ticket> {
|
|
1471
|
+
let issue = found
|
|
1472
|
+
if (missingAssignees(issue, assignees).length > 0) {
|
|
1473
|
+
const held = assigneeLogins(issue)
|
|
1474
|
+
issue = await this.patchIssue('create', issue.number, {
|
|
1475
|
+
assignees: [...held, ...missingAssignees(issue, assignees)],
|
|
1476
|
+
})
|
|
1477
|
+
}
|
|
1331
1478
|
const marker = splitCreationMarker(issue.body).marker!
|
|
1332
1479
|
if (marker.pending !== undefined)
|
|
1333
1480
|
return this.finishCreate(issue, marker.pending, marker.key, true)
|
|
@@ -1636,9 +1783,14 @@ export class GitHubTicketSource implements TicketSource {
|
|
|
1636
1783
|
if (local !== canonical) parentWrite = { set: canonical, replace: parentIsNode }
|
|
1637
1784
|
}
|
|
1638
1785
|
}
|
|
1639
|
-
if (ticketLabels?.includes(NODE_LABEL) && !held.includes(NODE_LABEL))
|
|
1640
|
-
await this.ensureNodeLabel('update')
|
|
1641
1786
|
}
|
|
1787
|
+
const assignees =
|
|
1788
|
+
validated.assignees === undefined
|
|
1789
|
+
? undefined
|
|
1790
|
+
: await this.resolveAssignees('update', validated.assignees)
|
|
1791
|
+
// The first write: every refusal above, assignees included, writes nothing.
|
|
1792
|
+
if (ticketLabels?.includes(NODE_LABEL) && !held.includes(NODE_LABEL))
|
|
1793
|
+
await this.ensureNodeLabel('update')
|
|
1642
1794
|
const body: Record<string, unknown> = {}
|
|
1643
1795
|
if (validated.title !== undefined) body.title = validated.title
|
|
1644
1796
|
if (validated.body !== undefined) {
|
|
@@ -1655,6 +1807,7 @@ export class GitHubTicketSource implements TicketSource {
|
|
|
1655
1807
|
await this.ensureLabels('update', labels)
|
|
1656
1808
|
body.labels = [...new Set(labels)]
|
|
1657
1809
|
}
|
|
1810
|
+
if (assignees !== undefined) body.assignees = assignees
|
|
1658
1811
|
const fields = Object.keys(body)
|
|
1659
1812
|
if (fields.length > 0) await this.patchIssue('update', number, body)
|
|
1660
1813
|
if (parentWrite === undefined) return
|
|
@@ -1920,43 +2073,108 @@ export class GitHubTicketSource implements TicketSource {
|
|
|
1920
2073
|
}
|
|
1921
2074
|
}
|
|
1922
2075
|
|
|
1923
|
-
|
|
1924
|
-
|
|
2076
|
+
private assigneeRefusal(key: AssigneeKey, value: string): string | undefined {
|
|
2077
|
+
const form = key === 'readyAssignee' ? GITHUB_READY_ASSIGNEE : GITHUB_CREATE_ASSIGNEE
|
|
2078
|
+
if (!form.accepts(value)) return form.message
|
|
1925
2079
|
if (value !== 'me') return undefined
|
|
1926
2080
|
if (this.viewer === undefined || 'failed' in this.viewer)
|
|
1927
|
-
return `github tickets: [tickets]
|
|
2081
|
+
return `github tickets: [tickets].${key} = "me" but the GitHub credential owner could not be resolved at dispatcher startup (${
|
|
1928
2082
|
this.viewer === undefined ? 'not prepared' : this.viewer.failed
|
|
1929
|
-
}); restart dispatch to enable
|
|
1930
|
-
return 'noUser' in this.viewer ? NO_USER_ASSIGNEE : undefined
|
|
2083
|
+
}); restart dispatch to enable ${key} = "me"`
|
|
2084
|
+
return 'noUser' in this.viewer ? NO_USER_ASSIGNEE(key) : undefined
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2087
|
+
readyAssigneeRefusal(value: string): string | undefined {
|
|
2088
|
+
return this.assigneeRefusal('readyAssignee', value)
|
|
1931
2089
|
}
|
|
1932
2090
|
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
2091
|
+
createAssigneeRefusal(value: string): string | undefined {
|
|
2092
|
+
return this.assigneeRefusal('createAssignee', value)
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
/** The login a value names. An unprepared one-shot surface (`ab ticket
|
|
2096
|
+
* list`, `ab ticket create`, init validation) resolves `"me"` once, lazily. */
|
|
2097
|
+
private async assigneeLogin(value: string, noUser = NO_USER_ASSIGNEE('readyAssignee')) {
|
|
1936
2098
|
if (value !== 'me') return value
|
|
1937
2099
|
if (this.viewer === undefined || 'failed' in this.viewer) this.viewer = await this.readViewer()
|
|
1938
|
-
if ('noUser' in this.viewer) throw new Error(
|
|
2100
|
+
if ('noUser' in this.viewer) throw new Error(noUser)
|
|
1939
2101
|
return (this.viewer as { login: string }).login
|
|
1940
2102
|
}
|
|
1941
2103
|
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
if (
|
|
1946
|
-
const login = await this.assigneeLogin(value)
|
|
2104
|
+
/** Whether GitHub lets `login` be assigned issues here: one 204/404 read,
|
|
2105
|
+
* memoized when positive. */
|
|
2106
|
+
private async canAssign(operation: string, login: string): Promise<boolean> {
|
|
2107
|
+
if (this.assignable.has(login.toLowerCase())) return true
|
|
1947
2108
|
const check = await this.request(
|
|
1948
|
-
|
|
2109
|
+
operation,
|
|
1949
2110
|
'GET',
|
|
1950
2111
|
this.path(`/assignees/${encodeURIComponent(login)}`),
|
|
1951
2112
|
{ missing: true },
|
|
1952
2113
|
)
|
|
1953
|
-
if (check === null)
|
|
2114
|
+
if (check === null) return false
|
|
2115
|
+
this.assignable.add(login.toLowerCase())
|
|
2116
|
+
return true
|
|
2117
|
+
}
|
|
2118
|
+
|
|
2119
|
+
private async describeAssignee(key: AssigneeKey, value: string): Promise<string> {
|
|
2120
|
+
if (value === 'me') await this.prepareReadyAssignee()
|
|
2121
|
+
const refusal = this.assigneeRefusal(key, value)
|
|
2122
|
+
if (refusal !== undefined) throw new Error(refusal)
|
|
2123
|
+
const login = await this.assigneeLogin(value, NO_USER_ASSIGNEE(key))
|
|
2124
|
+
if (!(await this.canAssign(key, login)))
|
|
1954
2125
|
throw new Error(
|
|
1955
|
-
`github tickets: [tickets]
|
|
2126
|
+
`github tickets: [tickets].${key} "${login}" cannot be assigned issues in ${this.fullName} — use a GitHub username with access to the repository, or "me"`,
|
|
1956
2127
|
)
|
|
1957
2128
|
return `${value} → @${login}`
|
|
1958
2129
|
}
|
|
1959
2130
|
|
|
2131
|
+
async describeReadyAssignee(value: string): Promise<string> {
|
|
2132
|
+
return this.describeAssignee('readyAssignee', value)
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
async describeCreateAssignee(value: string): Promise<string> {
|
|
2136
|
+
return this.describeAssignee('createAssignee', value)
|
|
2137
|
+
}
|
|
2138
|
+
|
|
2139
|
+
/**
|
|
2140
|
+
* The exact logins a write names, before anything is written: each entry's
|
|
2141
|
+
* form, at most ten (GitHub's limit), `me` resolved to the credential's
|
|
2142
|
+
* owner, duplicates dropped, and each login confirmed assignable.
|
|
2143
|
+
*/
|
|
2144
|
+
private async resolveAssignees(operation: string, entries: readonly string[]): Promise<string[]> {
|
|
2145
|
+
const form = githubAssigneeForm('createAssignee')
|
|
2146
|
+
for (const entry of entries)
|
|
2147
|
+
if (!form.accepts(entry))
|
|
2148
|
+
throw new Error(
|
|
2149
|
+
`github ${operation}: assignee "${entry}" must be "me" or a GitHub username — nothing was written`,
|
|
2150
|
+
)
|
|
2151
|
+
const logins: string[] = []
|
|
2152
|
+
const seen = new Set<string>()
|
|
2153
|
+
for (const entry of entries) {
|
|
2154
|
+
let login: string
|
|
2155
|
+
try {
|
|
2156
|
+
login = await this.assigneeLogin(entry, NO_USER_WRITE)
|
|
2157
|
+
} catch (error) {
|
|
2158
|
+
throw new Error(`github ${operation}: ${message(error)} — nothing was written`, {
|
|
2159
|
+
cause: error,
|
|
2160
|
+
})
|
|
2161
|
+
}
|
|
2162
|
+
if (seen.has(login.toLowerCase())) continue
|
|
2163
|
+
seen.add(login.toLowerCase())
|
|
2164
|
+
logins.push(login)
|
|
2165
|
+
}
|
|
2166
|
+
if (logins.length > MAX_TICKET_ASSIGNEES)
|
|
2167
|
+
throw new Error(
|
|
2168
|
+
`github ${operation}: at most ${MAX_TICKET_ASSIGNEES} assignees per issue — nothing was written`,
|
|
2169
|
+
)
|
|
2170
|
+
for (const login of logins)
|
|
2171
|
+
if (!(await this.canAssign(operation, login)))
|
|
2172
|
+
throw new Error(
|
|
2173
|
+
`github ${operation}: "${login}" cannot be assigned issues in ${this.fullName} — nothing was written`,
|
|
2174
|
+
)
|
|
2175
|
+
return logins
|
|
2176
|
+
}
|
|
2177
|
+
|
|
1960
2178
|
// ── Init validation ───────────────────────────────────────────────────────
|
|
1961
2179
|
|
|
1962
2180
|
/** One specific message per access problem, for `ab init --validate`. */
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
TicketIssueLinksUnsupported,
|
|
6
6
|
} from './issue-links'
|
|
7
7
|
import { refuseUnsupportedPriority, TicketPriorityUnsupported } from './priority'
|
|
8
|
+
import { refuseUnsupportedAssignees, TicketAssigneesUnsupported } from './assignees'
|
|
8
9
|
import {
|
|
9
10
|
mutateTicketIfRevision,
|
|
10
11
|
TicketRevisionConflict,
|
|
@@ -69,7 +70,8 @@ function passthrough(error: unknown): boolean {
|
|
|
69
70
|
error instanceof TicketRevisionConflict ||
|
|
70
71
|
error instanceof TicketRevisionUnsupported ||
|
|
71
72
|
error instanceof TicketIssueLinksUnsupported ||
|
|
72
|
-
error instanceof TicketPriorityUnsupported
|
|
73
|
+
error instanceof TicketPriorityUnsupported ||
|
|
74
|
+
error instanceof TicketAssigneesUnsupported
|
|
73
75
|
)
|
|
74
76
|
}
|
|
75
77
|
|
|
@@ -99,6 +101,7 @@ export async function createTicket(
|
|
|
99
101
|
): Promise<Ticket> {
|
|
100
102
|
refuseUnsupportedIssueLinks(source, input)
|
|
101
103
|
refuseUnsupportedPriority(source, input)
|
|
104
|
+
refuseUnsupportedAssignees(source, input)
|
|
102
105
|
source = compatibleTicketSource(source)
|
|
103
106
|
const blockedBy = await knownBlockers(
|
|
104
107
|
source,
|
|
@@ -117,6 +120,7 @@ export async function createTicket(
|
|
|
117
120
|
? { issueLinks: normalizeIssueLinks(input.issueLinks) }
|
|
118
121
|
: {}),
|
|
119
122
|
...(input.priority !== undefined ? { priority: input.priority } : {}),
|
|
123
|
+
...(input.assignees !== undefined ? { assignees: [...input.assignees] } : {}),
|
|
120
124
|
}
|
|
121
125
|
try {
|
|
122
126
|
return input.state === undefined
|
|
@@ -140,6 +144,7 @@ export async function updateTicket(
|
|
|
140
144
|
): Promise<Ticket | null> {
|
|
141
145
|
refuseUnsupportedIssueLinks(source, patch)
|
|
142
146
|
refuseUnsupportedPriority(source, patch)
|
|
147
|
+
refuseUnsupportedAssignees(source, patch)
|
|
143
148
|
source = compatibleTicketSource(source)
|
|
144
149
|
try {
|
|
145
150
|
if (expectedRevision !== undefined)
|