@clickview/ship-it 0.0.4-rc.0 → 0.0.5-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/config.json +5 -0
  2. package/lib/config.json +5 -0
  3. package/lib/src/api-clients/git-lab/GitLabApiClient.js +101 -17
  4. package/lib/src/api-clients/git-lab/GitLabMapper.js +19 -1
  5. package/lib/src/api-clients/index.js +1 -0
  6. package/lib/src/api-clients/team-city/TeamCityApiClient.js +85 -0
  7. package/lib/src/commands/ReleaseCommand.js +12 -3
  8. package/lib/src/commands/StartConsumingProjectBuildsCommand.js +76 -0
  9. package/lib/src/commands/TagMasterCommand.js +76 -0
  10. package/lib/src/commands/index.js +2 -0
  11. package/lib/src/constants/CommandTypeMapping.js +3 -1
  12. package/lib/src/constants/TeamCityBuildIDs.js +13 -0
  13. package/lib/src/interfaces/command-cli-options/MilestoneCommandCliOptions.js +2 -0
  14. package/lib/src/interfaces/command-cli-options/ReleaseCommandCliOptions.js +2 -0
  15. package/lib/src/interfaces/command-cli-options/index.js +18 -0
  16. package/lib/src/interfaces/command-options/DockerMilestoneCommandOptions.js +2 -0
  17. package/lib/src/interfaces/command-options/ReleaseCommandOptions.js +2 -0
  18. package/lib/src/interfaces/command-options/index.js +2 -1
  19. package/lib/src/interfaces/index.js +2 -0
  20. package/lib/src/interfaces/models/Label.js +2 -0
  21. package/lib/src/interfaces/models/Release.js +2 -0
  22. package/lib/src/interfaces/models/index.js +2 -0
  23. package/lib/src/inversify.config.js +10 -0
  24. package/lib/src/services/GitLabService.js +163 -13
  25. package/lib/src/services/TeamCityService.js +34 -0
  26. package/lib/src/services/index.js +1 -0
  27. package/lib/src/startup/AddMilestoneCommand.js +14 -5
  28. package/lib/src/startup/SetupCommands.js +90 -3
  29. package/lib/src/tasks/CommitPackageVersionsTask.js +12 -1
  30. package/lib/src/tasks/CreateMergeRequestTask.js +1 -1
  31. package/lib/src/tasks/InstallPackagesTask.js +28 -47
  32. package/lib/src/tasks/StartConsumingProjectBuildsTask.js +148 -0
  33. package/lib/src/tasks/StartMonorepoBuildTask.js +95 -0
  34. package/lib/src/tasks/TagMasterTask.js +122 -0
  35. package/lib/src/tasks/ValidateDescriptionsTask.js +15 -11
  36. package/lib/src/tasks/ValidateMergeRequestTask.js +12 -6
  37. package/lib/src/tasks/ValidateTask.js +2 -2
  38. package/lib/src/tasks/index.js +3 -0
  39. package/lib/src/types.js +10 -2
  40. package/lib/src/utils/Descriptions.js +12 -8
  41. package/lib/src/utils/ProjectIds.js +4 -8
  42. package/package.json +4 -3
  43. /package/lib/src/interfaces/{command-options/InstallPackagesCommandOptions.js → MergeRequestState.js} +0 -0
@@ -13,14 +13,17 @@ function createContainer(config) {
13
13
  * Misc
14
14
  */
15
15
  container.bind(types_1.MISC.GitLabConfig).toConstantValue(config.gitLab);
16
+ container.bind(types_1.MISC.TeamCityConfig).toConstantValue(config.teamCity);
16
17
  /**
17
18
  * Clients
18
19
  */
19
20
  container.bind(types_1.API_CLIENTS.GitLabApiClient).to(api_clients_1.GitLabApiClient);
21
+ container.bind(types_1.API_CLIENTS.TeamCityApiClient).to(api_clients_1.TeamCityApiClient);
20
22
  /**
21
23
  * Services
22
24
  */
23
25
  container.bind(types_1.SERVICES.GitLabService).to(services_1.GitLabService).inSingletonScope();
26
+ container.bind(types_1.SERVICES.TeamCityService).to(services_1.TeamCityService).inSingletonScope();
24
27
  /**
25
28
  * Tasks
26
29
  */
@@ -36,6 +39,10 @@ function createContainer(config) {
36
39
  container.bind(types_1.TASKS.BumpPackagesTask).to(tasks_1.BumpPackagesTask);
37
40
  container.bind(types_1.TASKS.CommitPackageVersionsTask).to(tasks_1.CommitPackageVersionsTask);
38
41
  container.bind(types_1.TASKS.ValidateMergeRequestTask).to(tasks_1.ValidateMergeRequestTask);
42
+ container.bind(types_1.TASKS.StartMonorepoBuildTask).to(tasks_1.StartMonorepoBuildTask);
43
+ container.bind(types_1.TASKS.TagMasterTask).to(tasks_1.TagMasterTask);
44
+ container.bind(types_1.TASKS.StartConsumingProjectBuildsTask)
45
+ .to(tasks_1.StartConsumingProjectBuildsTask);
39
46
  /**
40
47
  * Commands
41
48
  */
@@ -48,6 +55,9 @@ function createContainer(config) {
48
55
  container.bind(types_1.COMMANDS.InstallPackagesCommand).to(commands_1.InstallPackagesCommand);
49
56
  container.bind(types_1.COMMANDS.BumpPackagesCommand).to(commands_1.BumpPackagesCommand);
50
57
  container.bind(types_1.COMMANDS.ValidateMergeRequestCommand).to(commands_1.ValidateMergeRequestCommand);
58
+ container.bind(types_1.COMMANDS.TagMasterCommand).to(commands_1.TagMasterCommand);
59
+ container.bind(types_1.COMMANDS.StartConsumingProjectBuildsCommand)
60
+ .to(commands_1.StartConsumingProjectBuildsCommand);
51
61
  return container;
52
62
  }
53
63
  exports.createContainer = createContainer;
@@ -71,30 +71,113 @@ var types_1 = require("../types");
71
71
  var api_clients_1 = require("../api-clients");
72
72
  var errors_1 = require("../errors");
73
73
  var utils_1 = require("../utils");
74
+ /**
75
+ * These are projects that will try to use tags to pull in extra projects
76
+ */
77
+ var MONOREPO_IDS = [
78
+ utils_1.ProjectIds.MONOREPO_PROJECT_ID
79
+ ];
74
80
  var GitLabService = /** @class */ (function () {
75
81
  function GitLabService(apiClient) {
76
82
  this.apiClient = apiClient;
77
83
  }
78
84
  GitLabService.prototype.getProjects = function (options) {
85
+ var _a;
79
86
  return __awaiter(this, void 0, void 0, function () {
80
- var mergeRequests, projectIds, projects;
81
- return __generator(this, function (_a) {
82
- switch (_a.label) {
87
+ var allMergeRequests, mergeRequests, projectIds, projects, mappedProjects, _i, mappedProjects_1, mappedProject, extraProjects;
88
+ return __generator(this, function (_b) {
89
+ switch (_b.label) {
83
90
  case 0:
84
91
  if (this.projects)
85
92
  return [2 /*return*/, this.projects];
86
93
  return [4 /*yield*/, this.apiClient.getMergeRequests(options)];
87
94
  case 1:
88
- mergeRequests = _a.sent();
95
+ allMergeRequests = _b.sent();
96
+ mergeRequests = allMergeRequests.filter(function (mr) { return mr.targetBranch !== 'master'; });
89
97
  if (!(mergeRequests === null || mergeRequests === void 0 ? void 0 : mergeRequests.length))
90
98
  throw new errors_1.ShipItError('Could not find any merge requests for the specified options');
91
99
  projectIds = lodash_1.default.uniqBy(mergeRequests, function (m) { return m.projectId; }).map(function (m) { return m.projectId; });
92
100
  return [4 /*yield*/, this.apiClient.getProjectsByIds(projectIds)];
93
101
  case 2:
94
- projects = _a.sent();
102
+ projects = _b.sent();
95
103
  if (!(projects === null || projects === void 0 ? void 0 : projects.length) || projects.length !== projectIds.length)
96
104
  throw new errors_1.ShipItError('Could not find all projects for the found merge requests');
97
- return [2 /*return*/, (this.projects = projects.map(function (p) { return (__assign(__assign({}, p), { mergeRequests: mergeRequests.filter(function (mr) { return mr.projectId === p.id; }) })); }))];
105
+ mappedProjects = projects.map(function (p) { return (__assign(__assign({}, p), { mergeRequests: mergeRequests.filter(function (mr) { return mr.projectId === p.id; }) })); });
106
+ _i = 0, mappedProjects_1 = mappedProjects;
107
+ _b.label = 3;
108
+ case 3:
109
+ if (!(_i < mappedProjects_1.length)) return [3 /*break*/, 6];
110
+ mappedProject = mappedProjects_1[_i];
111
+ return [4 /*yield*/, this.getExtraProjects(mappedProject, projectIds)];
112
+ case 4:
113
+ extraProjects = _b.sent();
114
+ Array.prototype.push.apply(mappedProjects, extraProjects.map(function (p) { return (__assign(__assign({}, p), { mergeRequests: [] })); }));
115
+ _b.label = 5;
116
+ case 5:
117
+ _i++;
118
+ return [3 /*break*/, 3];
119
+ case 6:
120
+ /**
121
+ * We need to filter our relevant projects after we've added extra projects via tags
122
+ */
123
+ if ((_a = options.projectIds) === null || _a === void 0 ? void 0 : _a.length) {
124
+ mappedProjects = mappedProjects.filter(function (p) {
125
+ var _a;
126
+ return (_a = options.projectIds) === null || _a === void 0 ? void 0 : _a.some(function (pid) { return p.id.toString() === pid; });
127
+ });
128
+ }
129
+ return [2 /*return*/, (this.projects = mappedProjects)];
130
+ }
131
+ });
132
+ });
133
+ };
134
+ /**
135
+ * Fetches any projects that are not already included via MRs by checking the project labels.
136
+ * We only do this for a whitelist of projects
137
+ */
138
+ GitLabService.prototype.getExtraProjects = function (project, existingProjectIds) {
139
+ return __awaiter(this, void 0, void 0, function () {
140
+ var labels, mrLabelNames, mrLabels, projectIds, extraProjectIds;
141
+ return __generator(this, function (_a) {
142
+ switch (_a.label) {
143
+ case 0:
144
+ if (!MONOREPO_IDS.includes(project.id.toString()))
145
+ return [2 /*return*/, []];
146
+ return [4 /*yield*/, this.getProjectLabels(project.id)];
147
+ case 1:
148
+ labels = _a.sent();
149
+ mrLabelNames = lodash_1.default.chain(project.mergeRequests)
150
+ .map(function (m) { return m.labels; })
151
+ .flatten()
152
+ .uniq()
153
+ .value();
154
+ mrLabels = lodash_1.default.intersection(labels.map(function (l) { return l.name; }), mrLabelNames);
155
+ projectIds = mrLabels.map(function (m) { var _a; return (_a = labels.find(function (l) { return l.name === m; })) === null || _a === void 0 ? void 0 : _a.description; });
156
+ extraProjectIds = lodash_1.default.difference(projectIds, existingProjectIds.map(function (p) { return p.toString(); }));
157
+ return [4 /*yield*/, this.apiClient.getProjectsByIds(extraProjectIds)];
158
+ case 2:
159
+ // fetches and returns the extra projects
160
+ return [2 /*return*/, _a.sent()];
161
+ }
162
+ });
163
+ });
164
+ };
165
+ /**
166
+ * Gets labels that have a projectId as their description
167
+ */
168
+ GitLabService.prototype.getProjectLabels = function (projectId) {
169
+ return __awaiter(this, void 0, void 0, function () {
170
+ var labels;
171
+ return __generator(this, function (_a) {
172
+ switch (_a.label) {
173
+ case 0: return [4 /*yield*/, this.apiClient.getLabels(projectId)];
174
+ case 1:
175
+ labels = _a.sent();
176
+ return [2 /*return*/, labels.filter(function (l) {
177
+ if (!l.description)
178
+ return false;
179
+ return !isNaN(+l.description);
180
+ })];
98
181
  }
99
182
  });
100
183
  });
@@ -129,8 +212,13 @@ var GitLabService = /** @class */ (function () {
129
212
  (title === null || title === void 0 ? void 0 : title.includes('dev'))) {
130
213
  commits.pop();
131
214
  }
132
- if (!(commits === null || commits === void 0 ? void 0 : commits.length))
133
- throw new errors_1.ShipItError("Could not find any commits in dev for projectId: ".concat(projectId, " since ").concat(sinceSha));
215
+ /**
216
+ * This is commented out right now because of a problem with the logic of this approach of validating MRs.
217
+ * We need to find a way to fetch all commits that will be included in this release. Leaving this commented
218
+ * until we figure that out - Sha
219
+ */
220
+ // if (!commits?.length)
221
+ // throw new ShipItError(`Could not find any commits in dev for projectId: ${projectId} since ${sinceSha}`);
134
222
  return [2 /*return*/, commits];
135
223
  }
136
224
  });
@@ -177,14 +265,13 @@ var GitLabService = /** @class */ (function () {
177
265
  });
178
266
  });
179
267
  };
180
- GitLabService.prototype.getMergeRequest = function (projectId, branchName) {
181
- return this.apiClient.getMergeRequest(projectId, branchName, 'master');
268
+ GitLabService.prototype.getMergeRequest = function (projectId, branchName, state) {
269
+ return this.apiClient.getMergeRequest(projectId, branchName, 'master', state);
182
270
  };
183
271
  GitLabService.prototype.getMergeRequestById = function (projectId, mergeRequestId) {
184
- var idAsNumber = lodash_1.default.toNumber(mergeRequestId);
185
- if (!lodash_1.default.isNumber(idAsNumber))
272
+ if (isNaN(+mergeRequestId))
186
273
  throw new errors_1.ShipItError("MergeRequest Id must be a number: ".concat(mergeRequestId));
187
- return this.apiClient.getMergeRequestById(projectId, idAsNumber);
274
+ return this.apiClient.getMergeRequestById(projectId, +mergeRequestId);
188
275
  };
189
276
  GitLabService.prototype.createMergeRequest = function (projectId, branchName, description, milestoneName) {
190
277
  return __awaiter(this, void 0, void 0, function () {
@@ -202,6 +289,39 @@ var GitLabService = /** @class */ (function () {
202
289
  GitLabService.prototype.getMilestone = function (projectId, milestoneName) {
203
290
  return this.apiClient.getMilestone(projectId, milestoneName);
204
291
  };
292
+ GitLabService.prototype.getReleaseBranchNameMilestone = function (projectId, milestone) {
293
+ return __awaiter(this, void 0, void 0, function () {
294
+ var releaseMR;
295
+ return __generator(this, function (_a) {
296
+ switch (_a.label) {
297
+ case 0: return [4 /*yield*/, this.apiClient.getReleaseMergeRequest(projectId, milestone)];
298
+ case 1:
299
+ releaseMR = _a.sent();
300
+ if (!releaseMR)
301
+ return [2 /*return*/, null];
302
+ return [2 /*return*/, releaseMR.sourceBranch];
303
+ }
304
+ });
305
+ });
306
+ };
307
+ GitLabService.prototype.getMilestoneByBranchName = function (projectId, branchName) {
308
+ var _a, _b;
309
+ return __awaiter(this, void 0, void 0, function () {
310
+ var mergeRequest;
311
+ return __generator(this, function (_c) {
312
+ switch (_c.label) {
313
+ case 0: return [4 /*yield*/, this.getMergeRequest(projectId, branchName, 'opened')];
314
+ case 1:
315
+ mergeRequest = _c.sent();
316
+ if (!mergeRequest)
317
+ throw new errors_1.ShipItError("No merge request in project \"monorepo\" with branch name \"".concat(branchName, "\" could be found."));
318
+ if (!mergeRequest.milestone)
319
+ throw new errors_1.ShipItError("No milestone could be found on merge request \"".concat(mergeRequest.title, "\". Please attach a milestone then try again: ").concat(mergeRequest.url));
320
+ return [2 /*return*/, (_b = (_a = mergeRequest.milestone) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : ''];
321
+ }
322
+ });
323
+ });
324
+ };
205
325
  GitLabService.prototype.bumpVersionTxt = function (projectId, branchName, newVersion) {
206
326
  return __awaiter(this, void 0, void 0, function () {
207
327
  var versionTxt, buff, text;
@@ -249,6 +369,36 @@ var GitLabService = /** @class */ (function () {
249
369
  });
250
370
  });
251
371
  };
372
+ GitLabService.prototype.getTag = function (projectId, tagName) {
373
+ return __awaiter(this, void 0, void 0, function () {
374
+ return __generator(this, function (_a) {
375
+ switch (_a.label) {
376
+ case 0: return [4 /*yield*/, this.apiClient.getTag(projectId, tagName)];
377
+ case 1: return [2 /*return*/, _a.sent()];
378
+ }
379
+ });
380
+ });
381
+ };
382
+ GitLabService.prototype.createTag = function (projectId, tagName, sha) {
383
+ return __awaiter(this, void 0, void 0, function () {
384
+ return __generator(this, function (_a) {
385
+ switch (_a.label) {
386
+ case 0: return [4 /*yield*/, this.apiClient.createTag(projectId, tagName, sha)];
387
+ case 1: return [2 /*return*/, _a.sent()];
388
+ }
389
+ });
390
+ });
391
+ };
392
+ GitLabService.prototype.createRelease = function (projectId, release) {
393
+ return __awaiter(this, void 0, void 0, function () {
394
+ return __generator(this, function (_a) {
395
+ switch (_a.label) {
396
+ case 0: return [4 /*yield*/, this.apiClient.createRelease(projectId, release)];
397
+ case 1: return [2 /*return*/, _a.sent()];
398
+ }
399
+ });
400
+ });
401
+ };
252
402
  /**
253
403
  * We use the latest valid semver tag in master to determine what the current version
254
404
  * of a project is
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.TeamCityService = void 0;
16
+ require("reflect-metadata");
17
+ var inversify_1 = require("inversify");
18
+ var types_1 = require("../types");
19
+ var api_clients_1 = require("../api-clients");
20
+ var TeamCityService = /** @class */ (function () {
21
+ function TeamCityService(apiClient) {
22
+ this.apiClient = apiClient;
23
+ }
24
+ TeamCityService.prototype.startBuild = function (buildId, branchName) {
25
+ return this.apiClient.startBuild(buildId, branchName);
26
+ };
27
+ TeamCityService = __decorate([
28
+ (0, inversify_1.injectable)(),
29
+ __param(0, (0, inversify_1.inject)(types_1.API_CLIENTS.TeamCityApiClient)),
30
+ __metadata("design:paramtypes", [api_clients_1.TeamCityApiClient])
31
+ ], TeamCityService);
32
+ return TeamCityService;
33
+ }());
34
+ exports.TeamCityService = TeamCityService;
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./GitLabService"), exports);
18
+ __exportStar(require("./TeamCityService"), exports);
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -36,13 +47,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
47
  }
37
48
  };
38
49
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.getAddMilestoneCommand = void 0;
50
+ exports.processMilestoneCommandOptions = exports.getAddMilestoneCommand = void 0;
40
51
  var utils_1 = require("../utils");
41
52
  function processOptions(options) {
42
- var opts = {
43
- milestone: options.milestone,
44
- version: 'minor'
45
- };
53
+ var opts = __assign(__assign({}, options), { version: 'minor' });
46
54
  if (options.projectIds)
47
55
  opts.projectIds = utils_1.ProjectIds.getProjectIds(options.projectIds);
48
56
  if (options.hotfix && options.major)
@@ -53,6 +61,7 @@ function processOptions(options) {
53
61
  opts.version = 'patch';
54
62
  return opts;
55
63
  }
64
+ exports.processMilestoneCommandOptions = processOptions;
56
65
  var getAddMilestoneCommand = function (program, getAction) {
57
66
  return function addMilestoneCommand(name, description) {
58
67
  var _this = this;
@@ -1,9 +1,46 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
3
39
  exports.setupCommands = void 0;
4
40
  var AddMilestoneCommand_1 = require("./AddMilestoneCommand");
5
41
  var GetAction_1 = require("./GetAction");
6
42
  function setupCommands(program, container) {
43
+ var _this = this;
7
44
  var getAction = (0, GetAction_1.getActionBuilder)(program, container);
8
45
  var addMilestoneCommand = (0, AddMilestoneCommand_1.getAddMilestoneCommand)(program, getAction);
9
46
  // All commands below accept the same options
@@ -12,7 +49,27 @@ function setupCommands(program, container) {
12
49
  addMilestoneCommand('create-branches', 'Create release branches for all projects that are part of a milestone');
13
50
  addMilestoneCommand('create-mrs', 'Create merge requests for all projects that are part of a milestone');
14
51
  addMilestoneCommand('create-notes', 'Builds descriptions for all projects that are part of a milestone');
15
- addMilestoneCommand('release', 'Create releases for all projects that are part of a milestone');
52
+ addMilestoneCommand('tag-master', 'Tags master for all release MRs that are part of a milestone');
53
+ program.command('release')
54
+ .description('Create releases for all projects that are part of a milestone')
55
+ .requiredOption('-m, --milestone <milestone>')
56
+ .option('-p, --projectIds <projectIds...>')
57
+ .option('--hotfix')
58
+ .option('--major')
59
+ .option('--trigger-monorepo-build')
60
+ .action(function (opts) { return __awaiter(_this, void 0, void 0, function () {
61
+ var options;
62
+ return __generator(this, function (_a) {
63
+ switch (_a.label) {
64
+ case 0:
65
+ options = (0, AddMilestoneCommand_1.processMilestoneCommandOptions)(opts);
66
+ return [4 /*yield*/, getAction('release')(options)];
67
+ case 1:
68
+ _a.sent();
69
+ return [2 /*return*/];
70
+ }
71
+ });
72
+ }); });
16
73
  program.command('bump-packages')
17
74
  .description('Bump clickview npm package versions in monorepo to their next version')
18
75
  .requiredOption('-b, --branchName <branchName>')
@@ -21,13 +78,43 @@ function setupCommands(program, container) {
21
78
  program.command('install-packages')
22
79
  .description('Install the latest clickview npm packages in all consuming projects that are part of a milestone')
23
80
  .option('-m, --milestone <milestone>')
24
- .option('-b, --branchName <branchName>')
81
+ .option('-b, --monorepoBranchName <monorepoBranchName>')
25
82
  .option('-p, --projectIds <projectIds...>')
26
- .action(getAction('install-packages'));
83
+ .action(function (opts) { return __awaiter(_this, void 0, void 0, function () {
84
+ var options;
85
+ return __generator(this, function (_a) {
86
+ switch (_a.label) {
87
+ case 0:
88
+ options = (0, AddMilestoneCommand_1.processMilestoneCommandOptions)(opts);
89
+ return [4 /*yield*/, getAction('install-packages')(options)];
90
+ case 1:
91
+ _a.sent();
92
+ return [2 /*return*/];
93
+ }
94
+ });
95
+ }); });
27
96
  program.command('validate-mr')
28
97
  .description('Validate a merge request in a single project, ensuring it has a milestone and valid description')
29
98
  .option('-p, --projectId <projectId>')
30
99
  .option('-b, --branchName <branchName>')
31
100
  .action(getAction('validate-mr'));
101
+ program.command('start-consuming-project-builds')
102
+ .description('Trigger TeamCity builds in all consuming projects that are a part of a milestone')
103
+ .option('-m, --milestone <milestone>')
104
+ .option('--monorepoBranchName <monorepoBranchName>')
105
+ .option('-p, --projectIds <projectIds...>')
106
+ .action(function (opts) { return __awaiter(_this, void 0, void 0, function () {
107
+ var options;
108
+ return __generator(this, function (_a) {
109
+ switch (_a.label) {
110
+ case 0:
111
+ options = (0, AddMilestoneCommand_1.processMilestoneCommandOptions)(opts);
112
+ return [4 /*yield*/, getAction('start-consuming-project-builds')(options)];
113
+ case 1:
114
+ _a.sent();
115
+ return [2 /*return*/];
116
+ }
117
+ });
118
+ }); });
32
119
  }
33
120
  exports.setupCommands = setupCommands;
@@ -88,9 +88,20 @@ var CommitPackageVersionsTask = /** @class */ (function () {
88
88
  var commitFiles = [];
89
89
  for (var _i = 0, MONOREPO_PACKAGE_JSON_FILES_1 = MonorepoPackageJsonFiles_1.MONOREPO_PACKAGE_JSON_FILES; _i < MONOREPO_PACKAGE_JSON_FILES_1.length; _i++) {
90
90
  var filePath = MONOREPO_PACKAGE_JSON_FILES_1[_i];
91
+ var content = '';
92
+ try {
93
+ content = (0, fs_1.readFileSync)(filePath, { encoding: 'utf8' });
94
+ }
95
+ catch (_a) {
96
+ /**
97
+ * If the file doesn't exist, ignore the error.
98
+ * This will occur when TC Docker runs this script as it doesn't copy over @clickview/tooling
99
+ */
100
+ continue;
101
+ }
91
102
  commitFiles.push({
92
103
  filePath: filePath,
93
- content: (0, fs_1.readFileSync)(filePath, { encoding: 'utf8' })
104
+ content: content
94
105
  });
95
106
  }
96
107
  return commitFiles;
@@ -80,7 +80,7 @@ var CreateMergeRequestTask = /** @class */ (function () {
80
80
  utils_1.Logger.logError("[".concat(project.title, "]: [").concat(branchName, "] does not exist"));
81
81
  return [3 /*break*/, 6];
82
82
  }
83
- return [4 /*yield*/, this.service.getMergeRequest(project.id, branchName)];
83
+ return [4 /*yield*/, this.service.getMergeRequest(project.id, branchName, 'opened')];
84
84
  case 4:
85
85
  mergeRequest = _b.sent();
86
86
  if (mergeRequest) {
@@ -84,18 +84,28 @@ var InstallPackagesTask = /** @class */ (function () {
84
84
  switch (_c.label) {
85
85
  case 0:
86
86
  utils_1.Logger.logTask('Installing npm packages');
87
- return [4 /*yield*/, this.getMilestone(_options)];
87
+ if (!_options.monorepoBranchName && !_options.milestone) {
88
+ utils_1.Logger.logError('Please provide either a milestone or branch name argument.');
89
+ return [2 /*return*/, false];
90
+ }
91
+ milestone = _options.milestone;
92
+ if (!!milestone) return [3 /*break*/, 2];
93
+ utils_1.Logger.logInfo("Searching for a merge request in project \"monorepo\" with branch name \"".concat(_options.monorepoBranchName, "\"..."));
94
+ return [4 /*yield*/, this.service.getMilestoneByBranchName(utils_1.ProjectIds.MONOREPO_PROJECT_ID, _options.monorepoBranchName)];
88
95
  case 1:
89
96
  milestone = _c.sent();
97
+ _c.label = 2;
98
+ case 2:
90
99
  if (!milestone)
91
100
  return [2 /*return*/, false];
101
+ utils_1.Logger.logInfo("Found milestone \"".concat(milestone, "\". Proceeding to install packages in consuming projects..."));
92
102
  options = {
93
103
  version: _options.version,
94
104
  projectIds: _options.projectIds,
95
105
  milestone: milestone
96
106
  };
97
107
  return [4 /*yield*/, this.service.getProjects(options)];
98
- case 2:
108
+ case 3:
99
109
  projects = _c.sent();
100
110
  monorepo = projects.find(function (p) { return p.id.toString() === utils_1.ProjectIds.MONOREPO_PROJECT_ID; });
101
111
  consumingProjects = projects.filter(function (p) { return p.id.toString() !== utils_1.ProjectIds.MONOREPO_PROJECT_ID; });
@@ -108,14 +118,14 @@ var InstallPackagesTask = /** @class */ (function () {
108
118
  return [2 /*return*/, false];
109
119
  }
110
120
  return [4 /*yield*/, this.service.getNextBranchInfo(monorepo.id, options.version)];
111
- case 3:
121
+ case 4:
112
122
  _a = _c.sent(), monorepoBranch = _a.branch, monorepoBranchName = _a.branchName;
113
123
  if (!monorepoBranch) {
114
124
  utils_1.Logger.logError("[".concat(monorepo.title, "]: [").concat(monorepoBranchName, "] branch does not exist"));
115
125
  return [2 /*return*/, false];
116
126
  }
117
127
  return [4 /*yield*/, this.getPackageVersions(monorepoBranchName)];
118
- case 4:
128
+ case 5:
119
129
  versions = _c.sent();
120
130
  utils_1.Logger.logMessage("Versions identified for ".concat(monorepoBranchName));
121
131
  Object.keys(versions).forEach(function (key) {
@@ -123,26 +133,26 @@ var InstallPackagesTask = /** @class */ (function () {
123
133
  });
124
134
  utils_1.Logger.logMessage('\nInstalling packages:\n');
125
135
  _i = 0, consumingProjects_1 = consumingProjects;
126
- _c.label = 5;
127
- case 5:
128
- if (!(_i < consumingProjects_1.length)) return [3 /*break*/, 10];
136
+ _c.label = 6;
137
+ case 6:
138
+ if (!(_i < consumingProjects_1.length)) return [3 /*break*/, 11];
129
139
  project = consumingProjects_1[_i];
130
140
  return [4 /*yield*/, this.service.getNextBranchInfo(project.id, options.version)];
131
- case 6:
141
+ case 7:
132
142
  _b = _c.sent(), branch = _b.branch, branchName = _b.branchName;
133
143
  if (!branch) {
134
144
  utils_1.Logger.logError("[".concat(project.title, "]: [").concat(branchName, "] does not exist"));
135
- return [3 /*break*/, 9];
145
+ return [3 /*break*/, 10];
136
146
  }
137
147
  return [4 /*yield*/, this.updateAndSavePackageFiles(project, options.milestone, branchName, versions)];
138
- case 7:
148
+ case 8:
139
149
  hasUpdates = _c.sent();
140
150
  /**
141
151
  * If there are no changes to the versions, we're done here
142
152
  */
143
153
  if (!hasUpdates) {
144
154
  utils_1.Logger.logWarning("[".concat(project.title, "]: [").concat(branchName, "] does not require any updates"));
145
- return [3 /*break*/, 9];
155
+ return [3 /*break*/, 10];
146
156
  }
147
157
  /**
148
158
  * Run npm i to update our package log file
@@ -154,48 +164,17 @@ var InstallPackagesTask = /** @class */ (function () {
154
164
  * Commit our updated package.json and package-lock.json
155
165
  */
156
166
  return [4 /*yield*/, this.commitUpdatedFiles(project, options.milestone, branchName)];
157
- case 8:
167
+ case 9:
158
168
  /**
159
169
  * Commit our updated package.json and package-lock.json
160
170
  */
161
171
  _c.sent();
162
172
  utils_1.Logger.logMessage("[".concat(project.title, "]: File changes committed"));
163
- _c.label = 9;
164
- case 9:
173
+ _c.label = 10;
174
+ case 10:
165
175
  _i++;
166
- return [3 /*break*/, 5];
167
- case 10: return [2 /*return*/, true];
168
- }
169
- });
170
- });
171
- };
172
- InstallPackagesTask.prototype.getMilestone = function (options) {
173
- var _a, _b;
174
- return __awaiter(this, void 0, void 0, function () {
175
- var mergeRequest;
176
- return __generator(this, function (_c) {
177
- switch (_c.label) {
178
- case 0:
179
- if (options.milestone)
180
- return [2 /*return*/, options.milestone];
181
- if (!options.branchName) {
182
- utils_1.Logger.logError('Please provide either a milestone or branch name argument.');
183
- return [2 /*return*/, ''];
184
- }
185
- utils_1.Logger.logInfo("Searching for a merge request in project \"monorepo\" with branch name \"".concat(options.branchName, "\"..."));
186
- return [4 /*yield*/, this.service.getMergeRequest(utils_1.ProjectIds.MONOREPO_PROJECT_ID, options.branchName)];
187
- case 1:
188
- mergeRequest = _c.sent();
189
- if (!mergeRequest) {
190
- utils_1.Logger.logError("No merge request in project \"monorepo\" with branch name \"".concat(options.branchName, "\" could be found."));
191
- return [2 /*return*/, ''];
192
- }
193
- if (!mergeRequest.milestone) {
194
- utils_1.Logger.logError("No milestone could be found on merge request \"".concat(mergeRequest.title, "\". Please attach a milestone then try again: ").concat(mergeRequest.url));
195
- return [2 /*return*/, ''];
196
- }
197
- utils_1.Logger.logInfo("Found milestone \"".concat(mergeRequest.milestone.name, "\". Proceeding to install packages in consuming projects..."));
198
- return [2 /*return*/, (_b = (_a = mergeRequest.milestone) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : ''];
176
+ return [3 /*break*/, 6];
177
+ case 11: return [2 /*return*/, true];
199
178
  }
200
179
  });
201
180
  });
@@ -246,6 +225,8 @@ var InstallPackagesTask = /** @class */ (function () {
246
225
  switch (_a.label) {
247
226
  case 0:
248
227
  rootDir = ROOT_DIRECTORIES[project.id];
228
+ if (!rootDir)
229
+ return [2 /*return*/, false];
249
230
  return [4 /*yield*/, this.getFileText(project.id, branchName, "".concat(rootDir, "/package.json"))];
250
231
  case 1:
251
232
  packageJson = _a.sent();