UNPKG

2.01 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright © 2018 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 automation_client_1 = require("@atomist/automation-client");
19const https = require("https");
20const K8TargetBase = "deploy/atomist/k8s/";
21async function findLastK8sDeployment(ctx, rr, branch, environment) {
22 const result = await ctx.graphClient.query({
23 name: "LastEndpoint",
24 variables: {
25 name: rr.repo,
26 owner: rr.owner,
27 branch,
28 statusContext: K8TargetBase + environment,
29 },
30 });
31 if (!result || !result.Repo[0]) {
32 throw new Error(`No commit found on ${rr.owner}/${rr.repo}#${branch}`);
33 }
34 const commit = result.Repo[0].branches[0].commit;
35 automation_client_1.logger.debug(`Found a commit for ${rr.owner}/${rr.repo}#${branch}: ${commit.sha}`);
36 const statuses = commit.statuses;
37 if (!statuses || statuses.length === 0) {
38 throw new Error(`No commit found on ${rr.owner}/${rr.repo}#${branch}`);
39 }
40 const endpointStatus = statuses[0];
41 if (endpointStatus.state !== "success") {
42 throw new Error(`The k8s deployment on ${commit.sha} was not successful`);
43 }
44 return endpointStatus.targetUrl;
45}
46exports.findLastK8sDeployment = findLastK8sDeployment;
47exports.notPicky = {
48 httpsAgent: new https.Agent({
49 rejectUnauthorized: false,
50 }),
51};
52//# sourceMappingURL=findLastDeployment.js.map
\No newline at end of file