UNPKG

7.64 kBTypeScriptView Raw
1import { RetryOptions } from "@atomist/automation-client/lib/util/retry";
2import { InterpretLog } from "../../spi/log/InterpretedLog";
3import { DefaultFacts, StatefulPushListenerInvocation } from "../dsl/goalContribution";
4import { GoalExecutionListener } from "../listener/GoalStatusListener";
5import { Registerable } from "../machine/Registerable";
6import { SoftwareDeliveryMachine } from "../machine/SoftwareDeliveryMachine";
7import { PushTest } from "../mapping/PushTest";
8import { ServiceRegistration } from "../registration/ServiceRegistration";
9import { WaitRules } from "./common/createGoal";
10import { Goal, GoalDefinition, GoalWithPrecondition } from "./Goal";
11import { ExecuteGoal, GoalProjectListenerRegistration } from "./GoalInvocation";
12import { Goals } from "./Goals";
13import { ReportProgress } from "./progress/ReportProgress";
14import { GoalEnvironment } from "./support/environment";
15import { GoalFulfillmentCallback } from "./support/GoalImplementationMapper";
16export declare type Fulfillment = Implementation | SideEffect;
17/**
18 * Register a fulfillment with basic details
19 */
20export interface FulfillmentRegistration {
21 /**
22 * Name of goal implementation
23 */
24 name: string;
25 /**
26 * Optional push test to identify the types of projects and pushes this implementation
27 * should get invoked on when the goal gets scheduled
28 */
29 pushTest?: PushTest;
30}
31/**
32 * Register a goal implementation with required details
33 */
34export interface ImplementationRegistration extends FulfillmentRegistration {
35 /**
36 * Optional log interpreter for this goal implementations log output
37 */
38 logInterpreter?: InterpretLog;
39 /**
40 * Optional progress reporter for this goal implementation
41 */
42 progressReporter?: ReportProgress;
43}
44export interface Implementation extends ImplementationRegistration {
45 goalExecutor: ExecuteGoal;
46}
47export declare function isImplementation(f: Fulfillment): f is Implementation;
48export interface SideEffect {
49 name: string;
50 registration: string;
51 pushTest?: PushTest;
52}
53export declare function isSideEffect(f: Fulfillment): f is SideEffect;
54/**
55 * Subset of the GoalDefinition interface to use by typed Goals to allow
56 * specifying some aspect of the Goal that are specific to the current use case.
57 */
58export interface FulfillableGoalDetails {
59 displayName?: string;
60 uniqueName?: string;
61 environment?: string | GoalEnvironment;
62 approval?: boolean;
63 preApproval?: boolean;
64 retry?: boolean;
65 isolate?: boolean;
66 descriptions?: {
67 planned?: string;
68 requested?: string;
69 completed?: string;
70 inProcess?: string;
71 failed?: string;
72 waitingForApproval?: string;
73 waitingForPreApproval?: string;
74 canceled?: string;
75 stopped?: string;
76 };
77 preCondition?: WaitRules;
78 retryCondition?: RetryOptions;
79}
80/**
81 * Extension to GoalDefinition that allows to specify additional WaitRules.
82 */
83export interface PredicatedGoalDefinition extends GoalDefinition {
84 preCondition?: WaitRules;
85 retryCondition?: RetryOptions;
86}
87export interface Parameterized {
88 parameters?: DefaultFacts;
89}
90export interface PlannedGoal extends Parameterized {
91 details?: Omit<FulfillableGoalDetails, "uniqueName" | "environment">;
92 fulfillment?: {
93 registration: string;
94 name: string;
95 };
96}
97export declare type PlannedGoals = Record<string, {
98 goals: PlannedGoal | Array<PlannedGoal | PlannedGoal[]>;
99 dependsOn?: string | string[];
100}>;
101export interface PlannableGoal {
102 plan?(pli: StatefulPushListenerInvocation, goals: Goals): Promise<PlannedGoals | PlannedGoal>;
103}
104/**
105 * Goal that registers goal implementations, side effects and callbacks on the
106 * current SDM. No additional registration with the SDM is needed.
107 */
108export declare abstract class FulfillableGoal extends GoalWithPrecondition implements Registerable, PlannableGoal {
109 definitionOrGoal: PredicatedGoalDefinition | Goal;
110 readonly fulfillments: Fulfillment[];
111 readonly callbacks: GoalFulfillmentCallback[];
112 readonly projectListeners: GoalProjectListenerRegistration[];
113 readonly goalListeners: GoalExecutionListener[];
114 sdm: SoftwareDeliveryMachine;
115 constructor(definitionOrGoal: PredicatedGoalDefinition | Goal, ...dependsOn: Goal[]);
116 register(sdm: SoftwareDeliveryMachine): void;
117 withProjectListener(listener: GoalProjectListenerRegistration): this;
118 withExecutionListener(listener: GoalExecutionListener): this;
119 withService(registration: ServiceRegistration<any>): this;
120 protected addFulfillmentCallback(cb: GoalFulfillmentCallback): this;
121 protected addFulfillment(fulfillment: Fulfillment): this;
122 private registerFulfillment;
123 plan(pli: StatefulPushListenerInvocation, goals: Goals): Promise<PlannedGoals | PlannedGoal>;
124 private registerCallback;
125}
126/**
127 * Goal that accepts registrations of R.
128 */
129export declare abstract class FulfillableGoalWithRegistrations<R> extends FulfillableGoal {
130 definitionOrGoal: PredicatedGoalDefinition | Goal;
131 readonly registrations: R[];
132 constructor(definitionOrGoal: PredicatedGoalDefinition | Goal, ...dependsOn: Goal[]);
133 with(registration: R): this;
134}
135/**
136 * Goal that accepts registrations of R and listeners of L.
137 */
138export declare abstract class FulfillableGoalWithRegistrationsAndListeners<R, L> extends FulfillableGoalWithRegistrations<R> {
139 definitionOrGoal: PredicatedGoalDefinition | Goal;
140 readonly listeners: L[];
141 constructor(definitionOrGoal: PredicatedGoalDefinition | Goal, ...dependsOn: Goal[]);
142 withListener(listener: L): this;
143}
144/**
145 * Generic goal that can be used with a GoalDefinition.
146 * Register goal implementations or side effects to this goal instance.
147 */
148export declare class GoalWithFulfillment extends FulfillableGoal {
149 withCallback(cb: GoalFulfillmentCallback): this;
150 with(fulfillment: Fulfillment): this;
151}
152/**
153 * Creates a new GoalWithFulfillment instance using conventions if overwrites aren't provided
154 *
155 * Call this from your machine.ts where you configure your sdm to create a custom goal.
156 *
157 * Caution: if you wrap this in another function, then you MUST provide details.uniqueName,
158 * because the default is based on where in the code this `goal` function is called.
159 *
160 * @param details It is highly recommended that you supply at least uniqueName.
161 * @param goalExecutor
162 * @param options
163 */
164export declare function goal(details?: FulfillableGoalDetails, goalExecutor?: ExecuteGoal, options?: {
165 pushTest?: PushTest;
166 logInterpreter?: InterpretLog;
167 progressReporter?: ReportProgress;
168 plan?: (pli: StatefulPushListenerInvocation, goals: Goals) => Promise<PlannedGoals | PlannedGoal>;
169}): GoalWithFulfillment;
170/**
171 * Construct a PredicatedGoalDefinition from the provided goalDetails
172 * @param goalDetails
173 * @param uniqueName
174 * @param definition
175 */
176export declare function getGoalDefinitionFrom(goalDetails: FulfillableGoalDetails | string, uniqueName: string, definition?: GoalDefinition): {
177 uniqueName: string;
178} | PredicatedGoalDefinition;
179/**
180 * Merge Goal configuration options into a final options object.
181 * Starts off by merging the explicitly provided options over the provided defaults; finally merges the configuration
182 * values at the given configuration path (prefixed with sdm.) over the previous merge.
183 * @param defaults
184 * @param explicit
185 * @param configurationPath
186 */
187export declare function mergeOptions<OPTIONS>(defaults: OPTIONS, explicit: OPTIONS, configurationPath?: string): OPTIONS;
188//# sourceMappingURL=GoalWithFulfillment.d.ts.map
\No newline at end of file