1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import { SoftwareDeliveryMachine } from "@atomist/sdm";
|
18 | import { toArray } from "../../util/misc/array";
|
19 | import {
|
20 | DeliveryGoals,
|
21 | GoalData,
|
22 | } from "../configure";
|
23 | import { ConfigureYamlOptions } from "./configureYaml";
|
24 | import {
|
25 | GoalMaker,
|
26 | mapGoals,
|
27 | } from "./mapGoals";
|
28 | import {
|
29 | mapTests,
|
30 | PushTestMaker,
|
31 | } from "./mapPushTests";
|
32 | import { camelCase } from "./util";
|
33 |
|
34 | export async function mapRules(rules: any,
|
35 | goalData: GoalData,
|
36 | sdm: SoftwareDeliveryMachine,
|
37 | options: ConfigureYamlOptions<any>,
|
38 | additionalGoals: DeliveryGoals,
|
39 | goalMakers: Record<string, GoalMaker>,
|
40 | testMakers: Record<string, PushTestMaker>): Promise<void> {
|
41 |
|
42 | for (const rule of camelCase(toArray(rules))) {
|
43 | if (!rule.name) {
|
44 | throw new Error(`Property 'name' missing in push rule:\n${JSON.stringify(rule, undefined, 2)}`);
|
45 | }
|
46 | if (!rule.goals) {
|
47 | throw new Error(`Property 'goals' missing in push rule:\n${JSON.stringify(rule, undefined, 2)}`);
|
48 | }
|
49 |
|
50 | const test = !!rule.tests || !!rule.test ? await mapTests(
|
51 | rule.tests || rule.test,
|
52 | options.tests || {},
|
53 | testMakers) : [];
|
54 |
|
55 | const goals = await mapGoals(
|
56 | sdm,
|
57 | rule.goals,
|
58 | additionalGoals,
|
59 | goalMakers,
|
60 | options.tests || {},
|
61 | testMakers);
|
62 | const dependsOn = rule.dependsOn;
|
63 |
|
64 | goalData[rule.name] = {
|
65 | test: toArray(test).length > 0 ? test : undefined,
|
66 | dependsOn,
|
67 | goals,
|
68 | };
|
69 | }
|
70 | }
|