UNPKG

2.34 kBPlain TextView Raw
1/*
2 * Copyright © 2019 Atomist, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import { SoftwareDeliveryMachine } from "@atomist/sdm";
18import { toArray } from "../../util/misc/array";
19import {
20 DeliveryGoals,
21 GoalData,
22} from "../configure";
23import { ConfigureYamlOptions } from "./configureYaml";
24import {
25 GoalMaker,
26 mapGoals,
27} from "./mapGoals";
28import {
29 mapTests,
30 PushTestMaker,
31} from "./mapPushTests";
32import { camelCase } from "./util";
33
34export 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}