UNPKG

1.19 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright © 2018 Atomist, Inc.
4 *
5 * See LICENSE file.
6 */
7Object.defineProperty(exports, "__esModule", { value: true });
8const axios_1 = require("axios");
9const stringify = require("json-stringify-safe");
10const retry_1 = require("./util/retry");
11/**
12 * Scheme and hostname (authority) of the Atomist webhook URL.
13 */
14function webhookBaseUrl() {
15 return process.env.ATOMIST_WEBHOOK_BASEURL || "https://webhook.atomist.com";
16}
17exports.webhookBaseUrl = webhookBaseUrl;
18/**
19 * Post payload to the Atomist webhook URL. It will retry
20 * several times.
21 *
22 * @param webhook type of webhook
23 * @param payload object to post
24 * @param teamId Atomist team ID
25 * @param retryOptions change default retry options
26 * @return response of post operation
27 */
28function postAtomistWebhook(webhook, payload, teamId, retryOptions = retry_1.DefaultRetryOptions) {
29 const url = `${webhookBaseUrl()}/atomist/${webhook}/teams/${teamId}`;
30 const desc = `posting '${stringify(payload)}' to '${url}'`;
31 return retry_1.doWithRetry(() => axios_1.default.post(url, payload), desc, retryOptions);
32}
33exports.postAtomistWebhook = postAtomistWebhook;
34//# sourceMappingURL=atomistWebhook.js.map
\No newline at end of file