UNPKG

2.01 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright © 2020 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 });
18exports.transformToProjectListener = void 0;
19const HandlerResult_1 = require("@atomist/automation-client/lib/HandlerResult");
20const GoalInvocation_1 = require("../goal/GoalInvocation");
21const commonPushTests_1 = require("../mapping/support/commonPushTests");
22function isTransformResult(tr) {
23 const maybe = tr;
24 return maybe && maybe.success !== undefined;
25}
26/**
27 * Convert a CodeTransform to a GoalProjectListener
28 * @param transform
29 * @param name
30 * @param pushTest
31 */
32function transformToProjectListener(transform, name, pushTest = commonPushTests_1.AnyPush) {
33 return {
34 name,
35 pushTest,
36 events: [GoalInvocation_1.GoalProjectListenerEvent.before],
37 listener: async (p, gi) => {
38 try {
39 const result = await transform(p, Object.assign({}, gi), {});
40 if (isTransformResult(result)) {
41 return {
42 code: result.success === true ? 0 : 1,
43 };
44 }
45 }
46 catch (e) {
47 return {
48 code: 1,
49 message: e.message,
50 };
51 }
52 return HandlerResult_1.Success;
53 },
54 };
55}
56exports.transformToProjectListener = transformToProjectListener;
57//# sourceMappingURL=transformUtils.js.map
\No newline at end of file