UNPKG

2.79 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 {
18 DefaultGoalNameGenerator,
19 ExecuteGoal,
20 FulfillableGoal,
21 FulfillableGoalDetails,
22 getGoalDefinitionFrom,
23 Goal,
24 SoftwareDeliveryMachine,
25} from "@atomist/sdm";
26import { executeTag } from "../../internal/delivery/build/executeTag";
27
28/**
29 * Properties to customize [[Tag]] goal.
30 */
31export interface TagRegistration {
32 /** Set fulfillment goal executor. */
33 goalExecutor?: ExecuteGoal;
34 /** Name for fulfillment. */
35 name?: string;
36}
37
38/**
39 * Goal that performs project tagging using Git. If no fulfillment is
40 * added to the goal, one is added during registration that tags using
41 * the goal set pre-release version as created by the [[Version]]
42 * goal.
43 */
44export class Tag extends FulfillableGoal {
45
46 constructor(goalDetailsOrUniqueName: FulfillableGoalDetails | string = DefaultGoalNameGenerator.generateName("tag"), ...dependsOn: Goal[]) {
47 super({
48 workingDescription: "Tagging",
49 completedDescription: "Tagged",
50 failedDescription: "Failed to create Tag",
51 ...getGoalDefinitionFrom(goalDetailsOrUniqueName, DefaultGoalNameGenerator.generateName("tag")),
52 displayName: "tag",
53 }, ...dependsOn);
54 }
55
56 /**
57 * Called by the SDM on initialization. This function calls
58 * `super.register` and adds a startup listener to the SDM.
59 *
60 * The startup listener registers a default goal fulfillment that
61 * calles [[executeTag]] with no arguments.
62 */
63 public register(sdm: SoftwareDeliveryMachine): void {
64 super.register(sdm);
65
66 sdm.addStartupListener(async () => {
67 if (this.fulfillments.length === 0 && this.callbacks.length === 0) {
68 this.with();
69 }
70 });
71 }
72
73 /**
74 * Add fulfillment to this goal.
75 */
76 public with(registration: TagRegistration = {}): this {
77 const name = registration.name || DefaultGoalNameGenerator.generateName((registration.goalExecutor) ? "custom-tag" : "prerelease-tag");
78 const goalExecutor = registration.goalExecutor || executeTag();
79 super.addFulfillment({ name, goalExecutor });
80 return this;
81 }
82
83}