UNPKG

@atomist/sdm-core

Version:

Atomist Software Delivery Machine - Implementation

83 lines 3.59 kB
"use strict"; /* * Copyright © 2019 Atomist, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const automation_client_1 = require("@atomist/automation-client"); const RequestProcessor_1 = require("@atomist/automation-client/lib/internal/transport/RequestProcessor"); /** * Prepare the CommandInvocation instance to be sent for execution * * This pieces apart provided values form the parameters into the command's parameter, mapped parameter * and secret structures. */ function prepareCommandInvocation(md, parameters = {}) { // Flatten the provided parameters before creating the CommandInvocation const params = automation_client_1.mergeParameters(parameters, {}); const ci = { name: md.name, args: md.parameters.filter(p => params[p.name] !== undefined).map(p => ({ name: p.name, value: params[p.name], })), mappedParameters: md.mapped_parameters.filter(p => params[p.name] !== undefined).map(p => ({ name: p.name, value: params[p.name], })), secrets: md.secrets.map(p => ({ uri: p.uri, value: params[p.name] || "null", })), }; return ci; } exports.prepareCommandInvocation = prepareCommandInvocation; /** * Decorate the HandlerContext to support response messages for this event handler invocation. * * Task execution happens is rooted in an event handler executing; this would prevent response * messages to work out of the box which is why this function adds the respond function to the * MessageClient if possible. */ function prepareHandlerContext(ctx, trigger) { if (RequestProcessor_1.isCommandIncoming(trigger)) { const source = trigger.source; if (!!source) { ctx.messageClient.respond = (msg, options) => { return ctx.messageClient.send(msg, new automation_client_1.SourceDestination(source, source.user_agent), options); }; } } else if (RequestProcessor_1.isEventIncoming(trigger)) { ctx.messageClient.respond = () => __awaiter(this, void 0, void 0, function* () { return; }); } if (!!trigger) { ctx.trigger = trigger; } return ctx; } exports.prepareHandlerContext = prepareHandlerContext; //# sourceMappingURL=helpers.js.map