UNPKG

9.73 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright © 2019 Atomist, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18const sdm_1 = require("@atomist/sdm");
19const _ = require("lodash");
20const ReactToSemanticDiffsOnPushImpact_1 = require("../../handlers/events/delivery/code/ReactToSemanticDiffsOnPushImpact");
21const FulfillGoalOnRequested_1 = require("../../handlers/events/delivery/goals/FulfillGoalOnRequested");
22const RequestDownstreamGoalsOnGoalSuccess_1 = require("../../handlers/events/delivery/goals/RequestDownstreamGoalsOnGoalSuccess");
23const RespondOnGoalCompletion_1 = require("../../handlers/events/delivery/goals/RespondOnGoalCompletion");
24const SetGoalsOnPush_1 = require("../../handlers/events/delivery/goals/SetGoalsOnPush");
25const SkipDownstreamGoalsOnGoalFailure_1 = require("../../handlers/events/delivery/goals/SkipDownstreamGoalsOnGoalFailure");
26const VoteOnGoalApprovalRequest_1 = require("../../handlers/events/delivery/goals/VoteOnGoalApprovalRequest");
27const ClosedIssueHandler_1 = require("../../handlers/events/issue/ClosedIssueHandler");
28const NewIssueHandler_1 = require("../../handlers/events/issue/NewIssueHandler");
29const UpdatedIssueHandler_1 = require("../../handlers/events/issue/UpdatedIssueHandler");
30const OnChannelLink_1 = require("../../handlers/events/repo/OnChannelLink");
31const OnFirstPushToRepo_1 = require("../../handlers/events/repo/OnFirstPushToRepo");
32const OnPullRequest_1 = require("../../handlers/events/repo/OnPullRequest");
33const OnRepoCreation_1 = require("../../handlers/events/repo/OnRepoCreation");
34const OnRepoOnboarded_1 = require("../../handlers/events/repo/OnRepoOnboarded");
35const OnTag_1 = require("../../handlers/events/repo/OnTag");
36const OnUserJoiningChannel_1 = require("../../handlers/events/repo/OnUserJoiningChannel");
37/**
38 * Implementation of SoftwareDeliveryMachine based on Atomist event handlers.
39 * Not intended for direct user instantiation. See machineFactory.ts
40 */
41class HandlerBasedSoftwareDeliveryMachine extends sdm_1.AbstractSoftwareDeliveryMachine {
42 get onRepoCreation() {
43 return this.repoCreationListeners.length > 0 ?
44 () => new OnRepoCreation_1.OnRepoCreation(this.repoCreationListeners, this.configuration.sdm.repoRefResolver, this.configuration.sdm.credentialsResolver, this.configuration.sdm.preferenceStoreFactory) :
45 undefined;
46 }
47 get onFirstPush() {
48 return this.firstPushListeners.length > 0 ?
49 () => new OnFirstPushToRepo_1.OnFirstPushToRepo(this.firstPushListeners, this.configuration.sdm.repoRefResolver, this.configuration.sdm.credentialsResolver, this.configuration.sdm.preferenceStoreFactory) :
50 undefined;
51 }
52 get semanticDiffReactor() {
53 return this.fingerprintDifferenceListeners.length > 0 ?
54 () => new ReactToSemanticDiffsOnPushImpact_1.ReactToSemanticDiffsOnPushImpact(this.fingerprintDifferenceListeners, this.configuration.sdm.repoRefResolver, this.configuration.sdm.credentialsResolver, this.configuration.sdm.preferenceStoreFactory) :
55 undefined;
56 }
57 get goalSetting() {
58 if (this.pushMapping) {
59 return {
60 eventHandlers: [() => new SetGoalsOnPush_1.SetGoalsOnPush(this.configuration.sdm.projectLoader, this.configuration.sdm.repoRefResolver, this.pushMapping, this.goalsSetListeners, this.goalFulfillmentMapper, this.configuration.sdm.credentialsResolver, this.configuration.sdm.preferenceStoreFactory, this.configuration.sdm.enrichGoal)],
61 commandHandlers: [],
62 ingesters: [],
63 };
64 }
65 else {
66 return {
67 eventHandlers: [],
68 commandHandlers: [],
69 ingesters: [],
70 };
71 }
72 }
73 get goalConsequences() {
74 if (this.pushMapping) {
75 return {
76 eventHandlers: [
77 () => new SkipDownstreamGoalsOnGoalFailure_1.SkipDownstreamGoalsOnGoalFailure(),
78 () => new RequestDownstreamGoalsOnGoalSuccess_1.RequestDownstreamGoalsOnGoalSuccess(this.configuration.name, this.goalFulfillmentMapper, this.configuration.sdm.repoRefResolver, this.configuration.sdm.credentialsResolver, this.configuration.sdm.preferenceStoreFactory),
79 () => new RespondOnGoalCompletion_1.RespondOnGoalCompletion(this.configuration.sdm.repoRefResolver, this.configuration.sdm.credentialsResolver, this.goalCompletionListeners, this.configuration.sdm.preferenceStoreFactory),
80 () => new VoteOnGoalApprovalRequest_1.VoteOnGoalApprovalRequest(this.configuration.sdm.repoRefResolver, this.configuration.sdm.credentialsResolver, this.goalApprovalRequestVoters, this.goalApprovalRequestVoteDecisionManager, this.goalFulfillmentMapper, this.configuration.sdm.preferenceStoreFactory)
81 ],
82 commandHandlers: [],
83 ingesters: [],
84 };
85 }
86 else {
87 return {
88 eventHandlers: [],
89 commandHandlers: [],
90 ingesters: [],
91 };
92 }
93 }
94 get allFunctionalUnits() {
95 return []
96 .concat([
97 this.goalSetting,
98 this.goalConsequences,
99 ]);
100 }
101 get eventHandlers() {
102 return this.registrationManager.eventHandlers
103 .concat(this.pushMapping ? () => new FulfillGoalOnRequested_1.FulfillGoalOnRequested(this.goalFulfillmentMapper, this.goalExecutionListeners) : undefined)
104 .concat(_.flatten(this.allFunctionalUnits.map(fu => fu.eventHandlers)))
105 .concat([
106 this.userJoiningChannelListeners.length > 0 ?
107 () => new OnUserJoiningChannel_1.OnUserJoiningChannel(this.userJoiningChannelListeners, this.configuration.sdm.repoRefResolver, this.configuration.sdm.credentialsResolver, this.configuration.sdm.preferenceStoreFactory) :
108 undefined,
109 this.tagListeners.length > 0 ?
110 () => new OnTag_1.OnTag(this.tagListeners, this.configuration.sdm.repoRefResolver, this.configuration.sdm.credentialsResolver, this.configuration.sdm.preferenceStoreFactory) :
111 undefined,
112 this.newIssueListeners.length > 0 ?
113 () => new NewIssueHandler_1.NewIssueHandler(this.newIssueListeners, this.configuration.sdm.repoRefResolver, this.configuration.sdm.credentialsResolver, this.configuration.sdm.preferenceStoreFactory) :
114 undefined,
115 this.updatedIssueListeners.length > 0 ?
116 () => new UpdatedIssueHandler_1.UpdatedIssueHandler(this.updatedIssueListeners, this.configuration.sdm.repoRefResolver, this.configuration.sdm.credentialsResolver, this.configuration.sdm.preferenceStoreFactory) :
117 undefined,
118 this.closedIssueListeners.length > 0 ?
119 () => new ClosedIssueHandler_1.ClosedIssueHandler(this.closedIssueListeners, this.configuration.sdm.repoRefResolver, this.configuration.sdm.credentialsResolver, this.configuration.sdm.preferenceStoreFactory) :
120 undefined,
121 this.channelLinkListeners.length > 0 ?
122 () => new OnChannelLink_1.OnChannelLink(this.configuration.sdm.projectLoader, this.configuration.sdm.repoRefResolver, this.channelLinkListeners, this.configuration.sdm.credentialsResolver, this.configuration.sdm.preferenceStoreFactory) :
123 undefined,
124 this.pullRequestListeners.length > 0 ?
125 () => new OnPullRequest_1.OnPullRequest(this.configuration.sdm.projectLoader, this.configuration.sdm.repoRefResolver, this.pullRequestListeners, this.configuration.sdm.credentialsResolver, this.configuration.sdm.preferenceStoreFactory) : undefined,
126 this.repoOnboardingListeners.length > 0 ?
127 () => new OnRepoOnboarded_1.OnRepoOnboarded(this.repoOnboardingListeners, this.configuration.sdm.repoRefResolver, this.configuration.sdm.credentialsResolver, this.configuration.sdm.preferenceStoreFactory) :
128 undefined,
129 this.onRepoCreation,
130 this.onFirstPush,
131 this.semanticDiffReactor,
132 ])
133 .filter(m => !!m);
134 }
135 get commandHandlers() {
136 return this.registrationManager.commandHandlers
137 .concat(_.flatten(this.allFunctionalUnits.map(fu => fu.commandHandlers)))
138 .filter(m => !!m);
139 }
140 get ingesters() {
141 return this.registrationManager.ingesters
142 .concat(_.flatten(this.allFunctionalUnits.map(fu => fu.ingesters)))
143 .filter(m => !!m);
144 }
145 /**
146 * Construct a new software delivery machine, with zero or
147 * more goal setters.
148 * @param {string} name
149 * @param configuration automation client configuration we're running in
150 * @param {GoalSetter} goalSetters tell me what to do on a push. Hint: start with "whenPushSatisfies(...)"
151 */
152 constructor(name, configuration, goalSetters) {
153 super(name, configuration, goalSetters);
154 }
155}
156exports.HandlerBasedSoftwareDeliveryMachine = HandlerBasedSoftwareDeliveryMachine;
157//# sourceMappingURL=HandlerBasedSoftwareDeliveryMachine.js.map
\No newline at end of file