@scarn/sdk 0.8.2 → 0.8.4
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/dist/automations/define-automation.d.ts +20 -0
- package/dist/automations/index.d.ts +8 -0
- package/dist/automations/index.js +21 -0
- package/dist/automations/targets.d.ts +36 -0
- package/dist/automations/types.d.ts +116 -0
- package/dist/{chunk-nb0nkt71.js → chunk-01nfqm18.js} +1 -0
- package/dist/chunk-0vzq22dj.js +73 -0
- package/dist/chunk-11hbmexe.js +250 -0
- package/dist/{chunk-2fn95pdd.js → chunk-3gy0cb5f.js} +5 -1
- package/dist/{chunk-qrasq5xe.js → chunk-43y7tfn4.js} +33 -414
- package/dist/chunk-61jf8b6s.js +53 -0
- package/dist/chunk-76d1bwwz.js +119 -0
- package/dist/chunk-8z1wa3kd.js +109 -0
- package/dist/{chunk-p7yrcmqm.js → chunk-cnxaagfj.js} +2 -52
- package/dist/{chunk-cdanncng.js → chunk-ejzfdm1z.js} +21 -5
- package/dist/{chunk-gds7w7zh.js → chunk-fgfhvsee.js} +1 -4
- package/dist/{chunk-x9788y82.js → chunk-hyaez4ee.js} +145 -16
- package/dist/{chunk-mz53r914.js → chunk-jj9pezwb.js} +22 -119
- package/dist/{chunk-8pyhrdgy.js → chunk-wnfj3wyx.js} +55 -11
- package/dist/chunk-x0hjhqrf.js +416 -0
- package/dist/chunk-y11p1q7r.js +159 -0
- package/dist/client.js +4 -2
- package/dist/contracts/automation-document/index.d.ts +5 -0
- package/dist/contracts/automation-document/index.js +34 -0
- package/dist/contracts/automation-document/schema.d.ts +363 -0
- package/dist/contracts/pipeline-document/built-ins.d.ts +1 -1
- package/dist/contracts/pipeline-document/index.js +9 -7
- package/dist/contracts/pipeline-document/schema.d.ts +3 -3
- package/dist/contracts/work-item-changes.d.ts +6 -4
- package/dist/contracts/work-item-changes.js +2 -2
- package/dist/defaults/index.js +2 -2
- package/dist/definitions/automations/automations-client.d.ts +178 -0
- package/dist/definitions/automations/index.d.ts +1 -0
- package/dist/definitions/automations/index.js +12 -0
- package/dist/definitions/pipelines/index.d.ts +0 -1
- package/dist/definitions/pipelines/index.js +4 -12
- package/dist/definitions/pipelines/work-item-fields.d.ts +11 -22
- package/dist/definitions/steps/define-code-step.d.ts +8 -5
- package/dist/definitions/steps/define-step.d.ts +22 -11
- package/dist/definitions/steps/index.js +13 -6
- package/dist/definitions/steps/repo.d.ts +11 -3
- package/dist/definitions/steps/runtime.d.ts +11 -12
- package/dist/definitions/steps/step-definitions-client.d.ts +105 -3
- package/dist/definitions/steps/step-features.d.ts +89 -6
- package/dist/definitions/steps/step-handle.d.ts +6 -1
- package/dist/definitions/validation/index.js +2 -2
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/sdk.gen.d.ts +38 -6
- package/dist/generated/types.gen.d.ts +3026 -1889
- package/dist/index.d.ts +1 -0
- package/dist/index.js +44 -30
- package/dist/pipelines/define-pipeline.d.ts +7 -7
- package/dist/pipelines/handles.d.ts +0 -5
- package/dist/pipelines/index.js +7 -4
- package/dist/pipelines/types.d.ts +13 -1
- package/dist/push/collect-definitions.d.ts +3 -8
- package/dist/push/collect-pipeline-documents.d.ts +13 -3
- package/dist/push/index.d.ts +2 -2
- package/dist/push/index.js +87 -124
- package/dist/push/push-from-directory.d.ts +10 -6
- package/dist/repo-config.d.ts +14 -4
- package/dist/repo-config.js +5 -1
- package/dist/task-plane-client.d.ts +71 -1
- package/package.json +13 -1
- package/dist/chunk-ra53p0v8.js +0 -256
- package/dist/definitions/pipelines/define-default-pipeline-assignment.d.ts +0 -263
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `defineAutomation` and `onEvent`: runs each rule's callbacks once, with an
|
|
3
|
+
* `r` of placeholders for the event, and compiles the rules to an automation
|
|
4
|
+
* JSON document (format in `contracts/automation-document/schema.ts`). It
|
|
5
|
+
* throws `PipelineBuildError` when a rule can't be compiled; whether its
|
|
6
|
+
* targets exist is checked when the automation is published.
|
|
7
|
+
*/
|
|
8
|
+
import { type AutomationEvent, type AutomationScope } from "../contracts/automation-document";
|
|
9
|
+
import type { AutomationConfig, AutomationDefinition, AutomationTarget, Rule, RuleOptions } from "./types";
|
|
10
|
+
/** Does nothing: a route that matches and starts nothing. */
|
|
11
|
+
export declare const skip: AutomationTarget<AutomationScope>;
|
|
12
|
+
/** Attaches another automation to the work item. Only in project automations. */
|
|
13
|
+
export declare function attach(automation: AutomationDefinition<"workItem">): AutomationTarget<"project">;
|
|
14
|
+
/**
|
|
15
|
+
* One rule: what to start when `event` happens, as one target (`to`) or as
|
|
16
|
+
* routes chosen by conditions, like a pipeline's `.next(...)`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function onEvent<const E extends AutomationEvent>(options: RuleOptions<E>): Rule<E>;
|
|
19
|
+
/** Compiles an automation to its JSON document. Throws `PipelineBuildError`. */
|
|
20
|
+
export declare function defineAutomation<const S extends AutomationScope>(config: AutomationConfig<S>): AutomationDefinition<S>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The automation authoring SDK: rules that start steps or pipelines when
|
|
3
|
+
* something happens to a work item, compiled to an automation JSON document
|
|
4
|
+
* with `defineAutomation`. Conditions are the pipeline condition helpers.
|
|
5
|
+
*/
|
|
6
|
+
export { defineAutomation, onEvent, attach, skip } from "./define-automation";
|
|
7
|
+
export type { AutomationConfig, AutomationDefinition, AutomationTarget, BareStep, ChildEvent, EventContext, EventOf, EventWorkItem, PipelineCall, Rule, RuleOptions, RuleRoute, RuleRoutesOptions, RuleTarget, RuleTargetArg, RuleToOptions, ScopeOf, } from "./types";
|
|
8
|
+
export type { AutomationDocument, AutomationEvent, AutomationScope, AutomationSubject, ProjectAutomationEvent, WorkItemAutomationEvent, } from "../contracts/automation-document";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
attach,
|
|
4
|
+
defineAutomation,
|
|
5
|
+
onEvent,
|
|
6
|
+
skip
|
|
7
|
+
} from "../chunk-11hbmexe.js";
|
|
8
|
+
import"../chunk-x0hjhqrf.js";
|
|
9
|
+
import"../chunk-76d1bwwz.js";
|
|
10
|
+
import"../chunk-61jf8b6s.js";
|
|
11
|
+
import"../chunk-cnxaagfj.js";
|
|
12
|
+
import"../chunk-y11p1q7r.js";
|
|
13
|
+
import"../chunk-01nfqm18.js";
|
|
14
|
+
import"../chunk-skzxcba3.js";
|
|
15
|
+
import"../chunk-y64skrwp.js";
|
|
16
|
+
export {
|
|
17
|
+
attach,
|
|
18
|
+
defineAutomation,
|
|
19
|
+
onEvent,
|
|
20
|
+
skip
|
|
21
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automation targets at run time: `skip`, `attach(...)` and `.on(...)` on a
|
|
3
|
+
* step call or pipeline. Each is an opaque frozen value whose data lives in
|
|
4
|
+
* a WeakMap, like pipeline targets. This module imports nothing that builds
|
|
5
|
+
* handles, so step handles and `definePipeline` can attach `.on` without an
|
|
6
|
+
* import cycle.
|
|
7
|
+
*/
|
|
8
|
+
import type { AutomationSubject } from "../contracts/automation-document";
|
|
9
|
+
import type { TargetData } from "../pipelines/model";
|
|
10
|
+
import { type SourceSite } from "../pipelines/source";
|
|
11
|
+
export type AutomationTargetData = {
|
|
12
|
+
kind: "step";
|
|
13
|
+
target: TargetData;
|
|
14
|
+
on: AutomationSubject;
|
|
15
|
+
site: SourceSite | null;
|
|
16
|
+
} | {
|
|
17
|
+
kind: "pipeline";
|
|
18
|
+
pipeline: string;
|
|
19
|
+
on: AutomationSubject;
|
|
20
|
+
site: SourceSite | null;
|
|
21
|
+
} | {
|
|
22
|
+
kind: "attach";
|
|
23
|
+
automation: string;
|
|
24
|
+
site: SourceSite | null;
|
|
25
|
+
} | {
|
|
26
|
+
kind: "skip";
|
|
27
|
+
site: SourceSite | null;
|
|
28
|
+
};
|
|
29
|
+
export declare function registerAutomationTarget(data: AutomationTargetData): object;
|
|
30
|
+
export declare function automationTargetOf(value: unknown): AutomationTargetData | undefined;
|
|
31
|
+
/** Marks `value` as `r.workItem` or `r.child`, for `.on(...)`. */
|
|
32
|
+
export declare function markSubject<T extends object>(value: T, subject: AutomationSubject): T;
|
|
33
|
+
/** `.on(subject)` on a step call: the step's Task, for that work item. */
|
|
34
|
+
export declare function stepOn(target: TargetData): (subject: object) => object;
|
|
35
|
+
/** `.on(subject)` on a pipeline: a run of it, for that work item. */
|
|
36
|
+
export declare function pipelineOn(pipeline: string): (subject: object) => object;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The public types of automations. An automation's `scope` picks the events
|
|
3
|
+
* its rules may name, each event picks what `r` holds, and the scope picks
|
|
4
|
+
* which targets a rule may start, so a rule that doesn't fit its automation
|
|
5
|
+
* is a type error at the `onEvent(...)` call.
|
|
6
|
+
*/
|
|
7
|
+
import type { AutomationDocument, AutomationScope, AutomationSubject, ProjectAutomationEvent, WorkItemAutomationEvent } from "../contracts/automation-document";
|
|
8
|
+
import type { StepRef } from "../definitions/steps/step-ref";
|
|
9
|
+
import type { Condition } from "../pipelines/condition-data";
|
|
10
|
+
import type { PipelineDefinition } from "../pipelines/define-pipeline";
|
|
11
|
+
import type { Placeholder, UntypedPlaceholder } from "../pipelines/ref-types";
|
|
12
|
+
import type { SourceSite } from "../pipelines/source";
|
|
13
|
+
import type { StepTarget, targetBrand } from "../pipelines/types";
|
|
14
|
+
export declare const subjectBrand: unique symbol;
|
|
15
|
+
export declare const automationTargetBrand: unique symbol;
|
|
16
|
+
export declare const ruleBrand: unique symbol;
|
|
17
|
+
export type ChildEvent = Extract<WorkItemAutomationEvent, `child.${string}`>;
|
|
18
|
+
/** The events an automation of scope `S` reacts to. */
|
|
19
|
+
export type EventOf<S extends AutomationScope> = S extends "workItem" ? WorkItemAutomationEvent : ProjectAutomationEvent;
|
|
20
|
+
/** The scope whose automations react to `E`. */
|
|
21
|
+
export type ScopeOf<E> = E extends WorkItemAutomationEvent ? "workItem" : "project";
|
|
22
|
+
/**
|
|
23
|
+
* A work item an event is about: `r.workItem` or `r.child`. Its properties
|
|
24
|
+
* are refs, and passing it to `.on(...)` starts the target for it.
|
|
25
|
+
*/
|
|
26
|
+
export interface EventWorkItem<K extends AutomationSubject> {
|
|
27
|
+
readonly [subjectBrand]: K;
|
|
28
|
+
readonly title: Placeholder<string>;
|
|
29
|
+
readonly description: Placeholder<string | null>;
|
|
30
|
+
/** The work item's form fields, by name. */
|
|
31
|
+
readonly fields: UntypedPlaceholder;
|
|
32
|
+
readonly labels: Placeholder<string[]>;
|
|
33
|
+
readonly state: Placeholder<"open" | "closed">;
|
|
34
|
+
}
|
|
35
|
+
type NoKeys = Record<never, never>;
|
|
36
|
+
/** `r` in a rule's callbacks: what the event `E` carries. */
|
|
37
|
+
export type EventContext<E> = {
|
|
38
|
+
/** The work item the rule is about. */
|
|
39
|
+
readonly workItem: EventWorkItem<"workItem">;
|
|
40
|
+
} & (E extends ChildEvent ? {
|
|
41
|
+
/** The child work item the event happened to. */
|
|
42
|
+
readonly child: EventWorkItem<"child">;
|
|
43
|
+
} : NoKeys) & (E extends "workItem.label.added" ? {
|
|
44
|
+
/** The label that was added. */
|
|
45
|
+
readonly label: Placeholder<string>;
|
|
46
|
+
} : NoKeys);
|
|
47
|
+
/**
|
|
48
|
+
* Something a rule starts, usable in automations of scope `S`: the brand is
|
|
49
|
+
* a function of the scope, so a target for any scope fits both, and an
|
|
50
|
+
* `attach(...)` (project only) doesn't fit a work-item automation.
|
|
51
|
+
*/
|
|
52
|
+
export interface AutomationTarget<S extends AutomationScope> {
|
|
53
|
+
readonly [automationTargetBrand]: (scope: S) => void;
|
|
54
|
+
}
|
|
55
|
+
/** A pipeline started from a rule: for `r.workItem` unless `.on(...)` says otherwise. */
|
|
56
|
+
export interface PipelineCall extends AutomationTarget<AutomationScope> {
|
|
57
|
+
/** Starts the pipeline run for `workItem` (`r.workItem` or `r.child`). */
|
|
58
|
+
on(workItem: EventWorkItem<AutomationSubject>): AutomationTarget<AutomationScope>;
|
|
59
|
+
}
|
|
60
|
+
/** A step handle whose input has no required keys, used without calling it. */
|
|
61
|
+
export type BareStep = {
|
|
62
|
+
readonly [targetBrand]: true;
|
|
63
|
+
} & StepRef<unknown, unknown>;
|
|
64
|
+
/** What a rule of scope `S` may start. */
|
|
65
|
+
export type RuleTarget<S extends AutomationScope> = AutomationTarget<S> | StepTarget | BareStep | PipelineDefinition;
|
|
66
|
+
/** A target, or a callback receiving `r` that returns one. */
|
|
67
|
+
export type RuleTargetArg<E> = RuleTarget<ScopeOf<E>> | ((r: EventContext<E>) => RuleTarget<ScopeOf<E>>);
|
|
68
|
+
/** One route of a rule: taken when `when` matches (or always, with no `when`). */
|
|
69
|
+
export interface RuleRoute<E> {
|
|
70
|
+
when?: (r: EventContext<E>) => Condition;
|
|
71
|
+
to: RuleTargetArg<E>;
|
|
72
|
+
}
|
|
73
|
+
/** A rule that starts one target whenever its event happens. */
|
|
74
|
+
export interface RuleToOptions<E> {
|
|
75
|
+
event: E;
|
|
76
|
+
to: RuleTargetArg<E>;
|
|
77
|
+
routes?: never;
|
|
78
|
+
match?: never;
|
|
79
|
+
otherwise?: never;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A rule with routes, like a pipeline's `.next({ routes })`: in `"first"`
|
|
83
|
+
* mode (the default) the first matching route is taken, in `"all"` mode
|
|
84
|
+
* every matching route is.
|
|
85
|
+
*/
|
|
86
|
+
export interface RuleRoutesOptions<E> {
|
|
87
|
+
event: E;
|
|
88
|
+
to?: never;
|
|
89
|
+
match?: "first" | "all";
|
|
90
|
+
routes: readonly [RuleRoute<E>, ...RuleRoute<E>[]];
|
|
91
|
+
/** Taken when no route with a `when` matched. */
|
|
92
|
+
otherwise?: RuleTargetArg<E>;
|
|
93
|
+
}
|
|
94
|
+
export type RuleOptions<E> = RuleToOptions<E> | RuleRoutesOptions<E>;
|
|
95
|
+
/** A finished rule, from `onEvent(...)`, for an automation's `rules`. */
|
|
96
|
+
export interface Rule<E> {
|
|
97
|
+
readonly [ruleBrand]: true;
|
|
98
|
+
readonly event: E;
|
|
99
|
+
}
|
|
100
|
+
export interface AutomationConfig<S extends AutomationScope> {
|
|
101
|
+
key: string;
|
|
102
|
+
title?: string;
|
|
103
|
+
/** `"workItem"`: attached to one work item. `"project"`: enabled for a whole project. */
|
|
104
|
+
scope: S;
|
|
105
|
+
rules: readonly Rule<EventOf<S>>[];
|
|
106
|
+
}
|
|
107
|
+
/** What `defineAutomation` returns: the compiled document and its source sites. */
|
|
108
|
+
export interface AutomationDefinition<S extends AutomationScope = AutomationScope> {
|
|
109
|
+
readonly _tag: "automation_document";
|
|
110
|
+
readonly key: string;
|
|
111
|
+
readonly scope: S;
|
|
112
|
+
readonly document: AutomationDocument;
|
|
113
|
+
/** TS source sites by JSON pointer (`/rules/1/next/routes/0`), for error messages. */
|
|
114
|
+
readonly sourceMap: Readonly<Record<string, SourceSite>>;
|
|
115
|
+
}
|
|
116
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
Automations,
|
|
4
|
+
createClient
|
|
5
|
+
} from "./chunk-wnfj3wyx.js";
|
|
6
|
+
import {
|
|
7
|
+
exports_external
|
|
8
|
+
} from "./chunk-skzxcba3.js";
|
|
9
|
+
|
|
10
|
+
// src/definitions/automations/automations-client.ts
|
|
11
|
+
var automationDocumentIssueSchema = exports_external.object({
|
|
12
|
+
code: exports_external.string(),
|
|
13
|
+
path: exports_external.string(),
|
|
14
|
+
message: exports_external.string(),
|
|
15
|
+
hint: exports_external.string().optional()
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
class AutomationsApiError extends Error {
|
|
19
|
+
code;
|
|
20
|
+
issues;
|
|
21
|
+
constructor(error) {
|
|
22
|
+
super(error.detail ?? error.title ?? JSON.stringify(error));
|
|
23
|
+
this.name = "AutomationsApiError";
|
|
24
|
+
this.code = error.code;
|
|
25
|
+
const errors = error.meta?.["errors"];
|
|
26
|
+
this.issues = Array.isArray(errors) ? errors.flatMap((issue) => {
|
|
27
|
+
const parsed = automationDocumentIssueSchema.safeParse(issue);
|
|
28
|
+
return parsed.success ? [parsed.data] : [];
|
|
29
|
+
}) : [];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function unwrap(result) {
|
|
33
|
+
if (result.error !== undefined) {
|
|
34
|
+
throw new AutomationsApiError(result.error);
|
|
35
|
+
}
|
|
36
|
+
return result.data;
|
|
37
|
+
}
|
|
38
|
+
function createAutomationsClient(baseUrl) {
|
|
39
|
+
const client = createClient({ baseUrl });
|
|
40
|
+
return buildAutomationsClient(new Automations({ client }));
|
|
41
|
+
}
|
|
42
|
+
var buildAutomationsClient = (automations) => ({
|
|
43
|
+
listByProjectId: async (projectId, options) => unwrap(await automations.listAutomations({
|
|
44
|
+
path: { projectId },
|
|
45
|
+
headers: options?.headers
|
|
46
|
+
})),
|
|
47
|
+
publish: async (projectId, key, document, options) => unwrap(await automations.publishAutomation({
|
|
48
|
+
path: { projectId, key },
|
|
49
|
+
body: { document },
|
|
50
|
+
headers: options?.headers
|
|
51
|
+
})),
|
|
52
|
+
enable: async (projectId, key, options) => unwrap(await automations.enableAutomation({
|
|
53
|
+
path: { projectId, key },
|
|
54
|
+
headers: options?.headers
|
|
55
|
+
})),
|
|
56
|
+
disable: async (projectId, key, options) => unwrap(await automations.disableAutomation({
|
|
57
|
+
path: { projectId, key },
|
|
58
|
+
headers: options?.headers
|
|
59
|
+
})),
|
|
60
|
+
listForWorkItem: async (workItemId, options) => unwrap(await automations.listWorkItemAutomations({
|
|
61
|
+
path: { workItemId },
|
|
62
|
+
headers: options?.headers
|
|
63
|
+
})),
|
|
64
|
+
attach: async (workItemId, key, options) => unwrap(await automations.attachWorkItemAutomation({
|
|
65
|
+
path: { workItemId, key },
|
|
66
|
+
headers: options?.headers
|
|
67
|
+
})),
|
|
68
|
+
detach: async (workItemId, key, options) => unwrap(await automations.detachWorkItemAutomation({
|
|
69
|
+
path: { workItemId, key },
|
|
70
|
+
headers: options?.headers
|
|
71
|
+
}))
|
|
72
|
+
});
|
|
73
|
+
export { AutomationsApiError, createAutomationsClient };
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
argEntries,
|
|
4
|
+
attempt,
|
|
5
|
+
compileArg,
|
|
6
|
+
compileCondition,
|
|
7
|
+
conditionData,
|
|
8
|
+
issue,
|
|
9
|
+
mapSource,
|
|
10
|
+
newState,
|
|
11
|
+
rootPlaceholder,
|
|
12
|
+
withOwners,
|
|
13
|
+
withTracker
|
|
14
|
+
} from "./chunk-x0hjhqrf.js";
|
|
15
|
+
import {
|
|
16
|
+
eventHasChild,
|
|
17
|
+
scopeOfEvent
|
|
18
|
+
} from "./chunk-76d1bwwz.js";
|
|
19
|
+
import {
|
|
20
|
+
AuthoringError,
|
|
21
|
+
PipelineBuildError,
|
|
22
|
+
automationTargetOf,
|
|
23
|
+
captureSite,
|
|
24
|
+
markSubject,
|
|
25
|
+
nodeOf,
|
|
26
|
+
registerAutomationTarget,
|
|
27
|
+
targetOf
|
|
28
|
+
} from "./chunk-y11p1q7r.js";
|
|
29
|
+
|
|
30
|
+
// src/automations/define-automation.ts
|
|
31
|
+
var rules = new WeakMap;
|
|
32
|
+
var PROPERTY_SCHEMAS = {
|
|
33
|
+
title: { type: "string" },
|
|
34
|
+
description: { type: ["string", "null"] },
|
|
35
|
+
fields: undefined,
|
|
36
|
+
labels: { type: "array", items: { type: "string" } },
|
|
37
|
+
state: { type: "string", enum: ["open", "closed"] }
|
|
38
|
+
};
|
|
39
|
+
function eventWorkItem(subject, owner) {
|
|
40
|
+
const value = {};
|
|
41
|
+
for (const [property, schema] of Object.entries(PROPERTY_SCHEMAS)) {
|
|
42
|
+
Object.defineProperty(value, property, {
|
|
43
|
+
get: () => rootPlaceholder(`event.${subject}.${property}`, schema, { owner }),
|
|
44
|
+
enumerable: true
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return markSubject(value, subject);
|
|
48
|
+
}
|
|
49
|
+
function eventContext(event) {
|
|
50
|
+
const context = {};
|
|
51
|
+
context["workItem"] = eventWorkItem("workItem", context);
|
|
52
|
+
if (eventHasChild(event)) {
|
|
53
|
+
context["child"] = eventWorkItem("child", context);
|
|
54
|
+
}
|
|
55
|
+
if (event === "workItem.label.added") {
|
|
56
|
+
Object.defineProperty(context, "label", {
|
|
57
|
+
get: () => rootPlaceholder("event.label", { type: "string" }, { owner: context }),
|
|
58
|
+
enumerable: true
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return context;
|
|
62
|
+
}
|
|
63
|
+
var skip = registerAutomationTarget({ kind: "skip", site: null });
|
|
64
|
+
function attach(automation) {
|
|
65
|
+
if (automation?._tag !== "automation_document") {
|
|
66
|
+
throw new AuthoringError("attach(...) takes an automation: the value defineAutomation returns");
|
|
67
|
+
}
|
|
68
|
+
return registerAutomationTarget({
|
|
69
|
+
kind: "attach",
|
|
70
|
+
automation: automation.key,
|
|
71
|
+
site: captureSite()
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function onEvent(options) {
|
|
75
|
+
const site = captureSite();
|
|
76
|
+
const rule = options.routes === undefined ? {
|
|
77
|
+
event: options.event,
|
|
78
|
+
match: undefined,
|
|
79
|
+
routes: [{ when: undefined, target: options.to }],
|
|
80
|
+
otherwise: undefined,
|
|
81
|
+
site
|
|
82
|
+
} : {
|
|
83
|
+
event: options.event,
|
|
84
|
+
match: options.match,
|
|
85
|
+
routes: options.routes.map((route) => ({
|
|
86
|
+
when: route.when,
|
|
87
|
+
target: route.to
|
|
88
|
+
})),
|
|
89
|
+
otherwise: options.otherwise,
|
|
90
|
+
site
|
|
91
|
+
};
|
|
92
|
+
const value = Object.freeze({
|
|
93
|
+
_tag: "automation_rule",
|
|
94
|
+
event: options.event
|
|
95
|
+
});
|
|
96
|
+
rules.set(value, rule);
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
function pipelineKeyOf(value) {
|
|
100
|
+
const tagged = value;
|
|
101
|
+
return tagged._tag === "pipeline_document" && typeof tagged.key === "string" ? tagged.key : undefined;
|
|
102
|
+
}
|
|
103
|
+
function resolveTarget(spec, context) {
|
|
104
|
+
const handle = nodeOf(spec);
|
|
105
|
+
if (handle?.kind === "step") {
|
|
106
|
+
return {
|
|
107
|
+
kind: "step",
|
|
108
|
+
target: { node: handle, args: undefined, site: null },
|
|
109
|
+
on: "workItem",
|
|
110
|
+
site: null
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const value = typeof spec === "function" ? spec(context) : spec;
|
|
114
|
+
const automation = automationTargetOf(value);
|
|
115
|
+
if (automation !== undefined) {
|
|
116
|
+
return automation;
|
|
117
|
+
}
|
|
118
|
+
const target = targetOf(value);
|
|
119
|
+
if (target?.node.kind === "step" && target.partial !== true) {
|
|
120
|
+
return { kind: "step", target, on: "workItem", site: target.site };
|
|
121
|
+
}
|
|
122
|
+
const pipeline = pipelineKeyOf(value);
|
|
123
|
+
if (pipeline !== undefined) {
|
|
124
|
+
return { kind: "pipeline", pipeline, on: "workItem", site: null };
|
|
125
|
+
}
|
|
126
|
+
throw new AuthoringError("this isn't an automation target: use a step call (step({ ... })), a pipeline, attach(automation) or skip");
|
|
127
|
+
}
|
|
128
|
+
function compileArgs(state, target, pointer, owners) {
|
|
129
|
+
if (target.args === undefined) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const out = {};
|
|
133
|
+
for (const [name, value] of argEntries(target.args)) {
|
|
134
|
+
const compiled = attempt(state, [...pointer, name], target.site, () => withOwners(owners, () => compileArg(name, value)));
|
|
135
|
+
if (compiled !== undefined) {
|
|
136
|
+
out[name] = compiled;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
function compileTarget(state, scope, rule, spec, context, pointer) {
|
|
142
|
+
const target = attempt(state, pointer, rule.site, () => withOwners([context], () => resolveTarget(spec, context)));
|
|
143
|
+
if (target === undefined) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
mapSource(state, pointer, target.site ?? rule.site);
|
|
147
|
+
const report = (message) => {
|
|
148
|
+
issue(state, target.site ?? rule.site, pointer, message);
|
|
149
|
+
};
|
|
150
|
+
if ((target.kind === "step" || target.kind === "pipeline") && target.on === "child" && !eventHasChild(rule.event)) {
|
|
151
|
+
report(`"${rule.event}" has no child work item; .on(r.child) only works on child.* events`);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
switch (target.kind) {
|
|
155
|
+
case "skip":
|
|
156
|
+
return { kind: "skip" };
|
|
157
|
+
case "attach":
|
|
158
|
+
if (scope !== "project") {
|
|
159
|
+
report("only a project automation can attach automations; a work-item automation is attached to one work item");
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
return { kind: "attach", automation: target.automation };
|
|
163
|
+
case "pipeline":
|
|
164
|
+
return { kind: "pipeline", to: target.pipeline, on: target.on };
|
|
165
|
+
case "step": {
|
|
166
|
+
const args = compileArgs(state, target.target, [...pointer, "args"], [context]);
|
|
167
|
+
const step = target.target.node.kind === "step" ? target.target.node.step : "";
|
|
168
|
+
return {
|
|
169
|
+
kind: "step",
|
|
170
|
+
to: step,
|
|
171
|
+
...args === undefined ? {} : { args },
|
|
172
|
+
on: target.on
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function compileRule(state, scope, rule, index) {
|
|
178
|
+
const base = ["rules", index];
|
|
179
|
+
mapSource(state, base, rule.site);
|
|
180
|
+
if (scopeOfEvent(rule.event) !== scope) {
|
|
181
|
+
issue(state, rule.site, [...base, "event"], `"${rule.event}" isn't an event of a ${scope === "workItem" ? "work-item" : "project"} automation`);
|
|
182
|
+
}
|
|
183
|
+
const context = eventContext(rule.event);
|
|
184
|
+
const route = (when, target, pointer) => {
|
|
185
|
+
const entry = {};
|
|
186
|
+
if (when !== undefined) {
|
|
187
|
+
const compiled = attempt(state, [...pointer, "when"], rule.site, () => withOwners([context], () => compileCondition(conditionData(when(context)))));
|
|
188
|
+
if (compiled !== undefined) {
|
|
189
|
+
entry["when"] = compiled;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
...entry,
|
|
194
|
+
...compileTarget(state, scope, rule, target, context, pointer)
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
const next = {};
|
|
198
|
+
if (rule.match === "all") {
|
|
199
|
+
next["match"] = "all";
|
|
200
|
+
} else if (rule.routes.length > 1) {
|
|
201
|
+
rule.routes.forEach((entry, routeIndex) => {
|
|
202
|
+
if (entry.when === undefined) {
|
|
203
|
+
issue(state, rule.site, [...base, "next", "routes", routeIndex], `rule ${String(index)} has more than one route, so in "first" mode every route needs a "when"; move this target to "otherwise", or use match: "all"`);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
next["routes"] = rule.routes.map((entry, routeIndex) => route(entry.when, entry.target, [...base, "next", "routes", routeIndex]));
|
|
208
|
+
if (rule.otherwise !== undefined) {
|
|
209
|
+
next["otherwise"] = route(undefined, rule.otherwise, [
|
|
210
|
+
...base,
|
|
211
|
+
"next",
|
|
212
|
+
"otherwise"
|
|
213
|
+
]);
|
|
214
|
+
}
|
|
215
|
+
return { event: rule.event, next };
|
|
216
|
+
}
|
|
217
|
+
function defineAutomation(config) {
|
|
218
|
+
const site = captureSite();
|
|
219
|
+
const state = newState();
|
|
220
|
+
const compiled = withTracker(state.tracker, () => config.rules.map((value, index) => {
|
|
221
|
+
const rule = rules.get(value);
|
|
222
|
+
if (rule === undefined) {
|
|
223
|
+
issue(state, site, ["rules", index], "rules only take onEvent(...) rules");
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
return compileRule(state, config.scope, rule, index);
|
|
227
|
+
}));
|
|
228
|
+
if (state.issues.length > 0) {
|
|
229
|
+
throw new PipelineBuildError(config.key, state.issues);
|
|
230
|
+
}
|
|
231
|
+
const document = {
|
|
232
|
+
kind: "automation",
|
|
233
|
+
schemaVersion: 1,
|
|
234
|
+
key: config.key,
|
|
235
|
+
...config.title === undefined ? {} : { title: config.title },
|
|
236
|
+
scope: config.scope,
|
|
237
|
+
rules: compiled
|
|
238
|
+
};
|
|
239
|
+
return {
|
|
240
|
+
_tag: "automation_document",
|
|
241
|
+
key: config.key,
|
|
242
|
+
scope: config.scope,
|
|
243
|
+
document,
|
|
244
|
+
sourceMap: {
|
|
245
|
+
"": site ?? { file: "<unknown>", line: 0, column: 0 },
|
|
246
|
+
...state.sourceMap
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
export { skip, attach, onEvent, defineAutomation };
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
ScarnClient,
|
|
4
4
|
TaskRuns,
|
|
5
5
|
createClient
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-wnfj3wyx.js";
|
|
7
7
|
// src/task-plane-client.ts
|
|
8
8
|
function unwrap(result) {
|
|
9
9
|
if (result.error)
|
|
@@ -33,6 +33,10 @@ var buildTaskPlaneClient = (taskRuns) => {
|
|
|
33
33
|
taskRunId,
|
|
34
34
|
...body
|
|
35
35
|
}) => unwrap(await taskRuns.getTaskRunWorkerContext({ path: { taskRunId }, body })),
|
|
36
|
+
readTaskRunWorkItem: async ({
|
|
37
|
+
taskRunId,
|
|
38
|
+
...body
|
|
39
|
+
}) => unwrap(await taskRuns.readTaskRunWorkItem({ path: { taskRunId }, body })),
|
|
36
40
|
completeTaskRun: async ({
|
|
37
41
|
taskRunId,
|
|
38
42
|
...body
|