UNPKG

2.44 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright © 2017 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 */
17var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21 return c > 3 && r && Object.defineProperty(target, key, r), r;
22};
23Object.defineProperty(exports, "__esModule", { value: true });
24const GraphQL = require("@atomist/automation-client/graph/graphQL");
25const HandlerResult_1 = require("@atomist/automation-client/HandlerResult");
26const Handlers_1 = require("@atomist/automation-client/Handlers");
27const logger_1 = require("@atomist/automation-client/internal/util/logger");
28let NotifyOnPush = class NotifyOnPush {
29 handle(e, ctx) {
30 logger_1.logger.info(`incoming event is ${JSON.stringify(e.data)}`);
31 return Promise.all(e.data.Push.map(p => {
32 if (p.repo && p.repo.channels && p.repo.channels.length > 0) {
33 return ctx.messageClient.addressChannels(`Got a push with sha \`${p.after.sha}\``, p.repo.channels.map(c => c.name));
34 }
35 else {
36 return HandlerResult_1.Success;
37 }
38 }))
39 .then(() => HandlerResult_1.Success)
40 .catch(() => HandlerResult_1.Failure);
41 }
42};
43NotifyOnPush = __decorate([
44 Handlers_1.EventHandler("notify repo channels when there is a push", GraphQL.subscriptionFromFile("graphql/push")),
45 Handlers_1.Tags("push", "notification")
46], NotifyOnPush);
47exports.NotifyOnPush = NotifyOnPush;
48//# sourceMappingURL=NotifyOnPush.js.map
\No newline at end of file