1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | const automation_client_1 = require("@atomist/automation-client");
|
19 | const https = require("https");
|
20 | const K8TargetBase = "deploy/atomist/k8s/";
|
21 | async 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 | }
|
46 | exports.findLastK8sDeployment = findLastK8sDeployment;
|
47 | exports.notPicky = {
|
48 | httpsAgent: new https.Agent({
|
49 | rejectUnauthorized: false,
|
50 | }),
|
51 | };
|
52 |
|
\ | No newline at end of file |