1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
18 | return new (P || (P = Promise))(function (resolve, reject) {
|
19 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
20 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
21 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
22 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
23 | });
|
24 | };
|
25 | Object.defineProperty(exports, "__esModule", { value: true });
|
26 | const automation_client_1 = require("@atomist/automation-client");
|
27 | const https = require("https");
|
28 | const K8TargetBase = "deploy/atomist/k8s/";
|
29 | function findLastK8sDeployment(ctx, rr, branch, environment) {
|
30 | return __awaiter(this, void 0, void 0, function* () {
|
31 | const result = yield ctx.graphClient.query({
|
32 | name: "LastEndpoint",
|
33 | variables: {
|
34 | name: rr.repo,
|
35 | owner: rr.owner,
|
36 | branch,
|
37 | statusContext: K8TargetBase + environment,
|
38 | },
|
39 | });
|
40 | if (!result || !result.Repo[0]) {
|
41 | throw new Error(`No commit found on ${rr.owner}/${rr.repo}#${branch}`);
|
42 | }
|
43 | const commit = result.Repo[0].branches[0].commit;
|
44 | automation_client_1.logger.debug(`Found a commit for ${rr.owner}/${rr.repo}#${branch}: ${commit.sha}`);
|
45 | const statuses = commit.statuses;
|
46 | if (!statuses || statuses.length === 0) {
|
47 | throw new Error(`No commit found on ${rr.owner}/${rr.repo}#${branch}`);
|
48 | }
|
49 | const endpointStatus = statuses[0];
|
50 | if (endpointStatus.state !== "success") {
|
51 | throw new Error(`The k8s deployment on ${commit.sha} was not successful`);
|
52 | }
|
53 | return endpointStatus.targetUrl;
|
54 | });
|
55 | }
|
56 | exports.findLastK8sDeployment = findLastK8sDeployment;
|
57 | exports.notPicky = {
|
58 | httpsAgent: new https.Agent({
|
59 | rejectUnauthorized: false,
|
60 | }),
|
61 | };
|
62 |
|
\ | No newline at end of file |