@clickview/ship-it 0.0.2-dev.2 → 0.0.2

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 (47) hide show
  1. package/lib/src/api-clients/GitLabApiClient.js +1 -1
  2. package/lib/src/api-clients/index.js +1 -1
  3. package/lib/src/commands/BumpPackagesCommand.js +4 -12
  4. package/lib/src/commands/CreateBranchCommand.js +8 -8
  5. package/lib/src/commands/CreateMergeRequestCommand.js +10 -10
  6. package/lib/src/commands/CreateReleaseNotesCommand.js +4 -4
  7. package/lib/src/commands/ReleaseCommand.js +14 -14
  8. package/lib/src/commands/StatusCommand.js +2 -2
  9. package/lib/src/commands/VersionCommand.js +2 -2
  10. package/lib/src/commands/index.js +0 -1
  11. package/lib/src/index.js +85 -2
  12. package/lib/src/interfaces/index.js +1 -2
  13. package/lib/src/inversify.config.js +0 -3
  14. package/lib/src/services/GitLabService.js +33 -60
  15. package/lib/src/tasks/BumpPackagesTask.js +239 -102
  16. package/lib/src/tasks/BumpVersionTxtTask.js +26 -13
  17. package/lib/src/tasks/CreateBranchTask.js +32 -17
  18. package/lib/src/tasks/CreateMergeRequestTask.js +36 -21
  19. package/lib/src/tasks/CreateReleaseNotesTask.js +6 -2
  20. package/lib/src/tasks/ValidateCommitsTask.js +14 -6
  21. package/lib/src/tasks/ValidateDescriptionsTask.js +8 -4
  22. package/lib/src/tasks/ValidateTask.js +6 -5
  23. package/lib/src/tasks/VersionTask.js +20 -7
  24. package/lib/src/tasks/index.js +0 -2
  25. package/lib/src/types.js +1 -4
  26. package/lib/src/utils/Descriptions.js +4 -5
  27. package/lib/src/utils/ProjectIds.js +2 -6
  28. package/package.json +22 -22
  29. package/lib/src/api-clients/git-lab/GitLabApiClient.js +0 -285
  30. package/lib/src/api-clients/git-lab/GitLabMapper.js +0 -51
  31. package/lib/src/commands/CommitPackageVersionsCommand.js +0 -78
  32. package/lib/src/commands/InstallPackagesCommand.js +0 -78
  33. package/lib/src/constants/CommandTypeMapping.js +0 -14
  34. package/lib/src/constants/MonorepoPackageJsonFiles.js +0 -13
  35. package/lib/src/constants/index.js +0 -18
  36. package/lib/src/errors/ShipItError.js +0 -32
  37. package/lib/src/errors/index.js +0 -17
  38. package/lib/src/interfaces/VersionType.js +0 -2
  39. package/lib/src/interfaces/command-options/BumpPackagesCommandOptions.js +0 -2
  40. package/lib/src/interfaces/command-options/CommitPackageVersionsCommandOptions.js +0 -2
  41. package/lib/src/interfaces/command-options/MilestoneCommandOptions.js +0 -2
  42. package/lib/src/interfaces/command-options/index.js +0 -18
  43. package/lib/src/startup/AddMilestoneCommand.js +0 -75
  44. package/lib/src/startup/SetupCommands.js +0 -66
  45. package/lib/src/tasks/CommitLocalPackagesTask.js +0 -137
  46. package/lib/src/tasks/CommitPackageVersionsTask.js +0 -111
  47. package/lib/src/tasks/InstallPackagesTask.js +0 -317
@@ -47,165 +47,302 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
47
47
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
48
  }
49
49
  };
50
+ var __importDefault = (this && this.__importDefault) || function (mod) {
51
+ return (mod && mod.__esModule) ? mod : { "default": mod };
52
+ };
50
53
  Object.defineProperty(exports, "__esModule", { value: true });
51
54
  exports.BumpPackagesTask = void 0;
52
55
  require("reflect-metadata");
53
56
  var inversify_1 = require("inversify");
54
- var child_process_1 = require("child_process");
57
+ var fs_extra_1 = __importDefault(require("fs-extra"));
58
+ var semver_1 = __importDefault(require("semver"));
59
+ var child_process_1 = __importDefault(require("child_process"));
55
60
  var types_1 = require("../types");
56
61
  var services_1 = require("../services");
57
- var MonorepoPackageJsonFiles_1 = require("../constants/MonorepoPackageJsonFiles");
58
62
  var utils_1 = require("../utils");
59
- var RELEASE_BRANCH_REGEX = /^release\/(\d|\.)+$/;
60
- var HOTFIX_BRANCH_REGEX = /^hotfix\/(\d|\.)+$/;
61
- var DEV_VERSION_REGEX = /-dev\.\d+$/;
62
- var RC_VERSION_REGEX = /-rc\.\d+$/;
63
- var SHARED_LERNA_OPTIONS = '--exact --no-git-tag-version --no-push --yes';
63
+ var MONOREPO_PACKAGES_FILES = [
64
+ 'packages/libs/analytics/package.json',
65
+ 'packages/libs/styles/package.json',
66
+ 'packages/libs/tooling/package.json',
67
+ 'packages/projects/curator/package.json',
68
+ 'packages/projects/library-editor/package.json',
69
+ 'packages/projects/lite/package.json',
70
+ 'packages/projects/online/package.json',
71
+ 'packages/projects/reports/package.json'
72
+ ];
73
+ var ROOT_DIRECTORIES = {
74
+ // Curator
75
+ 62: 'src/ClickView.Curator.Web/Assets',
76
+ // Library Editor
77
+ 534: 'src/ClickView.Cloud',
78
+ // Lite
79
+ 822: 'src/ClickView.Lite',
80
+ // Online
81
+ 109: 'src/ClickView.Web.Online.Pages',
82
+ // Reports
83
+ 970: 'src/ClickView.Analytics.Web'
84
+ };
64
85
  var BumpPackagesTask = /** @class */ (function () {
65
86
  function BumpPackagesTask(service) {
66
- this.isReleaseBranch = false;
67
- this.isHotfixBranch = false;
68
- this.service = service;
87
+ this._service = service;
69
88
  }
70
89
  BumpPackagesTask.prototype.run = function (options) {
71
90
  return __awaiter(this, void 0, void 0, function () {
72
- var branch, isValid, lernaVersionCmd;
73
- return __generator(this, function (_a) {
74
- switch (_a.label) {
91
+ var projects, monorepo, consumingProjects, monorepoBranchName, versions, _i, consumingProjects_1, project, branchName, _a, consumingProjects_2, project, _b, consumingProjects_3, project, branchName;
92
+ return __generator(this, function (_c) {
93
+ switch (_c.label) {
75
94
  case 0:
76
- utils_1.Logger.logTask('Bumping clickview npm package versions');
77
- this.isReleaseBranch = RELEASE_BRANCH_REGEX.test(options.branchName);
78
- this.isHotfixBranch = HOTFIX_BRANCH_REGEX.test(options.branchName);
79
- return [4 /*yield*/, this.service.getBranch(utils_1.ProjectIds.MONOREPO_PROJECT_ID, options.branchName)];
95
+ utils_1.Logger.logTask('Bumping npm packages');
96
+ return [4 /*yield*/, this._service.getProjects(options)];
80
97
  case 1:
81
- branch = _a.sent();
82
- if (!branch) {
83
- utils_1.Logger.logError("Branch with name ".concat(options.branchName, " was not be found."));
98
+ projects = _c.sent();
99
+ monorepo = projects.find(function (p) { return p.id.toString() === utils_1.ProjectIds.MONOREPO_PROJECT_ID; });
100
+ consumingProjects = projects.filter(function (p) { return p.id.toString() !== utils_1.ProjectIds.MONOREPO_PROJECT_ID; });
101
+ if (!monorepo) {
102
+ utils_1.Logger.logError("Monorepo was not in this release");
84
103
  return [2 /*return*/, false];
85
104
  }
86
- isValid = this.validateOptions(options);
87
- if (!isValid)
105
+ if (!consumingProjects.length) {
106
+ utils_1.Logger.logError("No projects that consume monorepo could be found");
88
107
  return [2 /*return*/, false];
89
- return [4 /*yield*/, this.getLernaCommand(options)];
108
+ }
109
+ return [4 /*yield*/, this.getBranchName(monorepo.id, options.version)];
90
110
  case 2:
91
- lernaVersionCmd = _a.sent();
92
- if (!lernaVersionCmd) {
93
- utils_1.Logger.logError('Something went wrong while trying to detect which versioning script to run with Lerna.');
111
+ monorepoBranchName = _c.sent();
112
+ if (!monorepoBranchName) {
113
+ utils_1.Logger.logError("[".concat(monorepo.title, "] branch does not exist"));
94
114
  return [2 /*return*/, false];
95
115
  }
96
- (0, child_process_1.execSync)(lernaVersionCmd);
97
- return [2 /*return*/, true];
116
+ return [4 /*yield*/, this.getPackageVersions(monorepoBranchName)];
117
+ case 3:
118
+ versions = _c.sent();
119
+ utils_1.Logger.logMessage("Versions identified for ".concat(monorepoBranchName));
120
+ Object.keys(versions).forEach(function (key) {
121
+ utils_1.Logger.logMessage("- [".concat(key, "]: ").concat(versions[key]));
122
+ });
123
+ // let cont = true;
124
+ utils_1.Logger.logMessage('\nBumping packages:\n');
125
+ _i = 0, consumingProjects_1 = consumingProjects;
126
+ _c.label = 4;
127
+ case 4:
128
+ if (!(_i < consumingProjects_1.length)) return [3 /*break*/, 8];
129
+ project = consumingProjects_1[_i];
130
+ return [4 /*yield*/, this.getBranchName(project.id, options.version)];
131
+ case 5:
132
+ branchName = _c.sent();
133
+ // TODO: potentially add a validate branches task and removing the branch checking from this task
134
+ // so that bump packages can't be run until create release is run
135
+ if (!branchName) {
136
+ utils_1.Logger.logError("[".concat(project.title, "]: branch does not exist"));
137
+ return [3 /*break*/, 7];
138
+ }
139
+ return [4 /*yield*/, this.updateAndSavePackageFiles(project, options.milestone, branchName, versions)];
140
+ case 6:
141
+ _c.sent();
142
+ _c.label = 7;
143
+ case 7:
144
+ _i++;
145
+ return [3 /*break*/, 4];
146
+ case 8:
147
+ for (_a = 0, consumingProjects_2 = consumingProjects; _a < consumingProjects_2.length; _a++) {
148
+ project = consumingProjects_2[_a];
149
+ utils_1.Logger.logInfo("[".concat(project.title, "]: Running npm i --package-lock-only"));
150
+ this.npmInstall(project, options.milestone);
151
+ utils_1.Logger.logInfo('\n');
152
+ }
153
+ /**
154
+ * TODO: Need to not commit when there's no changes
155
+ */
156
+ utils_1.Logger.logMessage('Committing files');
157
+ _b = 0, consumingProjects_3 = consumingProjects;
158
+ _c.label = 9;
159
+ case 9:
160
+ if (!(_b < consumingProjects_3.length)) return [3 /*break*/, 13];
161
+ project = consumingProjects_3[_b];
162
+ return [4 /*yield*/, this.getBranchName(project.id, options.version)];
163
+ case 10:
164
+ branchName = _c.sent();
165
+ if (!branchName) {
166
+ utils_1.Logger.logError("[".concat(project.title, "]: branch does not exist"));
167
+ return [3 /*break*/, 12];
168
+ }
169
+ return [4 /*yield*/, this.commitUpdatedFiles(project, options.milestone, branchName)];
170
+ case 11:
171
+ _c.sent();
172
+ utils_1.Logger.logMessage("[".concat(project.title, "]: File changes committed"));
173
+ _c.label = 12;
174
+ case 12:
175
+ _b++;
176
+ return [3 /*break*/, 9];
177
+ case 13: return [2 /*return*/, true];
98
178
  }
99
179
  });
100
180
  });
101
181
  };
102
- BumpPackagesTask.prototype.validateOptions = function (options) {
103
- var isValidReleaseBranch = this.isReleaseBranch || this.isHotfixBranch;
104
- if (options.preId && options.preId !== 'rc' && options.preId !== 'dev') {
105
- utils_1.Logger.logError("Argument for \"preId\" can only be \"rc\" or \"dev\". You entered: ".concat(options.preId));
106
- return false;
107
- }
108
- if (options.preId === 'dev' && isValidReleaseBranch) {
109
- utils_1.Logger.logError('Dev versions cannot be generated on release or hotfix branches.');
110
- return false;
111
- }
112
- if (options.preId === 'rc' && !isValidReleaseBranch) {
113
- utils_1.Logger.logError('Release Candidate versions can only be generated on release or hotfix branches.');
114
- return false;
115
- }
116
- if (!options.preId && !isValidReleaseBranch) {
117
- utils_1.Logger.logError('Production package versions can only be generated on release or hotfix branches.');
118
- return false;
119
- }
120
- return true;
121
- };
122
- BumpPackagesTask.prototype.getFileText = function (projectId, branchName, fileName) {
182
+ BumpPackagesTask.prototype.commitUpdatedFiles = function (project, milestone, branchName) {
123
183
  return __awaiter(this, void 0, void 0, function () {
124
- var file, buff;
125
- return __generator(this, function (_a) {
126
- switch (_a.label) {
127
- case 0: return [4 /*yield*/, this.service.getFile(projectId, branchName, fileName)];
184
+ var rootDir, outputPath, commitFiles, _a;
185
+ var _b, _c;
186
+ return __generator(this, function (_d) {
187
+ switch (_d.label) {
188
+ case 0:
189
+ rootDir = ROOT_DIRECTORIES[project.id];
190
+ outputPath = this.getOutputPath(project, milestone);
191
+ _b = {
192
+ filePath: "".concat(rootDir, "/package.json")
193
+ };
194
+ return [4 /*yield*/, fs_extra_1.default.readFile("".concat(outputPath, "/package.json"), 'utf8')];
128
195
  case 1:
129
- file = _a.sent();
130
- if (!file)
131
- return [2 /*return*/, ''];
132
- buff = Buffer.from(file.content, 'base64');
133
- return [2 /*return*/, buff.toString('utf-8')];
196
+ _a = [(_b.content = _d.sent(),
197
+ _b)];
198
+ _c = {
199
+ filePath: "".concat(rootDir, "/package-lock.json")
200
+ };
201
+ return [4 /*yield*/, fs_extra_1.default.readFile("".concat(outputPath, "/package-lock.json"), 'utf8')];
202
+ case 2:
203
+ commitFiles = _a.concat([(_c.content = _d.sent(),
204
+ _c)]);
205
+ return [4 /*yield*/, this._service.commit(project.id, branchName, 'Bumping @clickview npm packages', commitFiles)];
206
+ case 3:
207
+ _d.sent();
208
+ return [2 /*return*/];
134
209
  }
135
210
  });
136
211
  });
137
212
  };
138
- BumpPackagesTask.prototype.getLernaCommand = function (options) {
213
+ BumpPackagesTask.prototype.npmInstall = function (project, milestone) {
214
+ var outputPath = this.getOutputPath(project, milestone);
215
+ child_process_1.default.execSync('npm i --package-lock-only', {
216
+ cwd: outputPath,
217
+ // Uncomment if we want to silence
218
+ // stdio: 'pipe'
219
+ });
220
+ };
221
+ BumpPackagesTask.prototype.updateAndSavePackageFiles = function (project, milestone, branchName, versions) {
139
222
  return __awaiter(this, void 0, void 0, function () {
140
- var isInPrerelease;
223
+ var rootDir, packageJson, packageLock, packageJsonObj, outputPath;
141
224
  return __generator(this, function (_a) {
142
225
  switch (_a.label) {
143
- case 0: return [4 /*yield*/, this.isInPrerelease(options.branchName)];
226
+ case 0:
227
+ rootDir = ROOT_DIRECTORIES[project.id];
228
+ return [4 /*yield*/, this.getFileText(project.id, branchName, "".concat(rootDir, "/package.json"))];
144
229
  case 1:
145
- isInPrerelease = _a.sent();
146
- /**
147
- * The `lerna version prerelease` script only cares about incrementing the preId part
148
- * of the version number. That's why we run this if `isInPrerelease` is true.
149
- *
150
- * E.g. this would change 0.0.1-dev.0 to 0.0.0-dev.1
151
- */
152
- if (isInPrerelease && options.preId)
153
- return [2 /*return*/, "lerna version prerelease --preid ".concat(options.preId, " ").concat(SHARED_LERNA_OPTIONS)];
154
- // Bump the patch with the preId "dev". We currently only support dev prereleases on patch versions
155
- if (options.preId === 'dev')
156
- return [2 /*return*/, "lerna version prepatch --preid dev ".concat(SHARED_LERNA_OPTIONS)];
157
- if (options.preId === 'rc') {
158
- // Bump the minor number with the preId "rc". Release branches always bump the minor number.
159
- if (this.isReleaseBranch)
160
- return [2 /*return*/, "lerna version preminor --preid rc ".concat(SHARED_LERNA_OPTIONS)];
161
- // Bump the patch with the preId "rc". Hotfix branches always bump the patch number.
162
- if (this.isHotfixBranch)
163
- return [2 /*return*/, "lerna version prepatch --preid rc ".concat(SHARED_LERNA_OPTIONS)];
164
- }
230
+ packageJson = _a.sent();
231
+ return [4 /*yield*/, this.getFileText(project.id, branchName, "".concat(rootDir, "/package-lock.json"))];
232
+ case 2:
233
+ packageLock = _a.sent();
234
+ packageJsonObj = JSON.parse(packageJson);
235
+ utils_1.Logger.logMessage(project.title);
165
236
  /**
166
- * If no preId is provided, we bump the version number to a production version.
167
- *
168
- * Release branch = minor bump
169
- * Hotfix branch = patch bump
237
+ * Annoyingly some projects have clickview packages sitting in dependencies
238
+ * and others have it in devDependencies
170
239
  */
171
- if (this.isReleaseBranch)
172
- return [2 /*return*/, "lerna version minor ".concat(SHARED_LERNA_OPTIONS)];
173
- if (this.isHotfixBranch)
174
- return [2 /*return*/, "lerna version patch ".concat(SHARED_LERNA_OPTIONS)];
175
- // Should never be reached
176
- return [2 /*return*/, ''];
240
+ if (packageJsonObj.dependencies)
241
+ packageJson = this.replaceVersions(packageJson, versions, packageJsonObj.dependencies);
242
+ if (packageJsonObj.devDependencies)
243
+ packageJson = this.replaceVersions(packageJson, versions, packageJsonObj.devDependencies);
244
+ outputPath = this.getOutputPath(project, milestone);
245
+ return [4 /*yield*/, fs_extra_1.default.outputFile("".concat(outputPath, "/package.json"), packageJson, { encoding: 'utf8' })];
246
+ case 3:
247
+ _a.sent();
248
+ return [4 /*yield*/, fs_extra_1.default.outputFile("".concat(outputPath, "/package-lock.json"), packageLock, { encoding: 'utf8' })];
249
+ case 4:
250
+ _a.sent();
251
+ return [2 /*return*/];
177
252
  }
178
253
  });
179
254
  });
180
255
  };
181
- BumpPackagesTask.prototype.isInPrerelease = function (branchName) {
256
+ BumpPackagesTask.prototype.replaceVersions = function (packageJson, versions, deps) {
257
+ Object.keys(deps).forEach(function (key) {
258
+ if (!key.startsWith('@clickview'))
259
+ return;
260
+ if (!versions[key])
261
+ return;
262
+ var oldVersion = deps[key];
263
+ var newVersion = versions[key];
264
+ if (oldVersion === newVersion) {
265
+ utils_1.Logger.logWarning("- [".concat(key, "]: ").concat(versions[key], " is up to date"));
266
+ return;
267
+ }
268
+ if (semver_1.default.compare(oldVersion, newVersion) === 1) {
269
+ utils_1.Logger.logError("- [".concat(key, "]: ").concat(deps[key], " -> ").concat(versions[key], " downgrade detected"));
270
+ return;
271
+ }
272
+ packageJson = packageJson.replace("\"".concat(key, "\": \"").concat(deps[key], "\""), "\"".concat(key, "\": \"").concat(versions[key], "\""));
273
+ utils_1.Logger.logMessage("- [".concat(key, "]: ").concat(deps[key], " -> ").concat(versions[key]));
274
+ });
275
+ return packageJson;
276
+ };
277
+ BumpPackagesTask.prototype.getPackageVersions = function (branchName) {
182
278
  return __awaiter(this, void 0, void 0, function () {
183
- var _i, MONOREPO_PACKAGE_JSON_FILES_1, file, text, json;
279
+ var monorepoPackages, _i, MONOREPO_PACKAGES_FILES_1, file, text, json;
184
280
  return __generator(this, function (_a) {
185
281
  switch (_a.label) {
186
282
  case 0:
187
- _i = 0, MONOREPO_PACKAGE_JSON_FILES_1 = MonorepoPackageJsonFiles_1.MONOREPO_PACKAGE_JSON_FILES;
283
+ monorepoPackages = {};
284
+ _i = 0, MONOREPO_PACKAGES_FILES_1 = MONOREPO_PACKAGES_FILES;
188
285
  _a.label = 1;
189
286
  case 1:
190
- if (!(_i < MONOREPO_PACKAGE_JSON_FILES_1.length)) return [3 /*break*/, 4];
191
- file = MONOREPO_PACKAGE_JSON_FILES_1[_i];
287
+ if (!(_i < MONOREPO_PACKAGES_FILES_1.length)) return [3 /*break*/, 4];
288
+ file = MONOREPO_PACKAGES_FILES_1[_i];
192
289
  return [4 /*yield*/, this.getFileText(utils_1.ProjectIds.MONOREPO_PROJECT_ID, branchName, file)];
193
290
  case 2:
194
291
  text = _a.sent();
195
- json = JSON.parse(JSON.stringify(text));
196
- if (RC_VERSION_REGEX.test(json.version))
197
- return [2 /*return*/, true];
198
- if (DEV_VERSION_REGEX.test(json.version))
199
- return [2 /*return*/, true];
292
+ json = JSON.parse(text);
293
+ monorepoPackages[json.name] = json.version;
200
294
  _a.label = 3;
201
295
  case 3:
202
296
  _i++;
203
297
  return [3 /*break*/, 1];
204
- case 4: return [2 /*return*/, false];
298
+ case 4: return [2 /*return*/, monorepoPackages];
299
+ }
300
+ });
301
+ });
302
+ };
303
+ BumpPackagesTask.prototype.getFileText = function (projectId, branchName, fileName) {
304
+ return __awaiter(this, void 0, void 0, function () {
305
+ var file, buff;
306
+ return __generator(this, function (_a) {
307
+ switch (_a.label) {
308
+ case 0: return [4 /*yield*/, this._service.getFile(projectId, branchName, fileName)];
309
+ case 1:
310
+ file = _a.sent();
311
+ if (!file)
312
+ return [2 /*return*/, ''];
313
+ buff = Buffer.from(file.content, 'base64');
314
+ return [2 /*return*/, buff.toString('utf-8')];
315
+ }
316
+ });
317
+ });
318
+ };
319
+ BumpPackagesTask.prototype.getBranchName = function (projectId, version) {
320
+ return __awaiter(this, void 0, void 0, function () {
321
+ var currentVersionTag, nextVersion, branchName, branch;
322
+ return __generator(this, function (_a) {
323
+ switch (_a.label) {
324
+ case 0: return [4 /*yield*/, this._service.getCurrentVersionTag(projectId)];
325
+ case 1:
326
+ currentVersionTag = _a.sent();
327
+ if (!currentVersionTag)
328
+ return [2 /*return*/, null];
329
+ return [4 /*yield*/, utils_1.Versions.getNextVersion(currentVersionTag.name, version)];
330
+ case 2:
331
+ nextVersion = _a.sent();
332
+ branchName = utils_1.BranchNames.getRelease(nextVersion);
333
+ return [4 /*yield*/, this._service.getBranch(projectId, branchName)];
334
+ case 3:
335
+ branch = _a.sent();
336
+ if (!branch)
337
+ return [2 /*return*/, null];
338
+ return [2 /*return*/, branchName];
205
339
  }
206
340
  });
207
341
  });
208
342
  };
343
+ BumpPackagesTask.prototype.getOutputPath = function (project, milestone) {
344
+ return "./temp/".concat(milestone, "/").concat(project.title);
345
+ };
209
346
  BumpPackagesTask = __decorate([
210
347
  (0, inversify_1.injectable)(),
211
348
  __param(0, (0, inversify_1.inject)(types_1.SERVICES.GitLabService)),
@@ -54,40 +54,53 @@ var inversify_1 = require("inversify");
54
54
  var Logger_1 = require("../utils/Logger");
55
55
  var types_1 = require("../types");
56
56
  var services_1 = require("../services");
57
+ var utils_1 = require("../utils");
57
58
  var BumpVersionTxtTask = /** @class */ (function () {
58
59
  function BumpVersionTxtTask(service) {
59
- this.service = service;
60
+ this._service = service;
60
61
  }
61
62
  BumpVersionTxtTask.prototype.run = function (options) {
62
63
  return __awaiter(this, void 0, void 0, function () {
63
- var projects, _i, projects_1, project, _a, nextVersion, branchName, versionBumped;
64
- return __generator(this, function (_b) {
65
- switch (_b.label) {
64
+ var projects, cont, _i, projects_1, project, currentVersionTag, nextVersion, branchName, versionBumped;
65
+ return __generator(this, function (_a) {
66
+ switch (_a.label) {
66
67
  case 0:
67
68
  Logger_1.Logger.logTask('Bumping version.txt');
68
- return [4 /*yield*/, this.service.getProjects(options)];
69
+ return [4 /*yield*/, this._service.getProjects(options)];
69
70
  case 1:
70
- projects = _b.sent();
71
+ projects = _a.sent();
72
+ if (!projects.length) {
73
+ Logger_1.Logger.logError("No projects could be found with the specified options");
74
+ return [2 /*return*/, false];
75
+ }
76
+ cont = true;
71
77
  _i = 0, projects_1 = projects;
72
- _b.label = 2;
78
+ _a.label = 2;
73
79
  case 2:
74
80
  if (!(_i < projects_1.length)) return [3 /*break*/, 6];
75
81
  project = projects_1[_i];
76
- return [4 /*yield*/, this.service.getNextBranchInfo(project.id, options.version)];
82
+ return [4 /*yield*/, this._service.getCurrentVersionTag(project.id)];
77
83
  case 3:
78
- _a = _b.sent(), nextVersion = _a.nextVersion, branchName = _a.branchName;
79
- return [4 /*yield*/, this.service.bumpVersionTxt(project.id, branchName, nextVersion)];
84
+ currentVersionTag = _a.sent();
85
+ if (currentVersionTag === null) {
86
+ Logger_1.Logger.logError("[".concat(project.title, "]: Could not find current version tag"));
87
+ cont = false;
88
+ return [3 /*break*/, 5];
89
+ }
90
+ nextVersion = utils_1.Versions.getNextVersion(currentVersionTag.name, options.version);
91
+ branchName = utils_1.BranchNames.getRelease(nextVersion);
92
+ return [4 /*yield*/, this._service.bumpVersionTxt(project.id, branchName, nextVersion)];
80
93
  case 4:
81
- versionBumped = _b.sent();
94
+ versionBumped = _a.sent();
82
95
  if (versionBumped)
83
96
  Logger_1.Logger.logMessage("[".concat(project.title, "]: Bumped to ").concat(nextVersion));
84
97
  else
85
98
  Logger_1.Logger.logWarning("[".concat(project.title, "]: Has already been bumped, or does not have a version.txt"));
86
- _b.label = 5;
99
+ _a.label = 5;
87
100
  case 5:
88
101
  _i++;
89
102
  return [3 /*break*/, 2];
90
- case 6: return [2 /*return*/, true];
103
+ case 6: return [2 /*return*/, cont];
91
104
  }
92
105
  });
93
106
  });
@@ -56,40 +56,55 @@ var services_1 = require("../services");
56
56
  var utils_1 = require("../utils");
57
57
  var CreateBranchTask = /** @class */ (function () {
58
58
  function CreateBranchTask(service) {
59
- this.service = service;
59
+ this._service = service;
60
60
  }
61
61
  CreateBranchTask.prototype.run = function (options) {
62
62
  return __awaiter(this, void 0, void 0, function () {
63
- var projects, _i, projects_1, project, _a, branch, branchName, branchFrom;
64
- return __generator(this, function (_b) {
65
- switch (_b.label) {
63
+ var projects, _i, projects_1, project, currentVersionTag, nextVersion, branchName, branch, branchFrom;
64
+ return __generator(this, function (_a) {
65
+ switch (_a.label) {
66
66
  case 0:
67
67
  utils_1.Logger.logTask('Creating release branches');
68
- return [4 /*yield*/, this.service.getProjects(options)];
68
+ return [4 /*yield*/, this._service.getProjects(options)];
69
69
  case 1:
70
- projects = _b.sent();
70
+ projects = _a.sent();
71
+ if (!projects.length) {
72
+ utils_1.Logger.logError("No projects could be found with the specified options");
73
+ return [2 /*return*/, false];
74
+ }
71
75
  _i = 0, projects_1 = projects;
72
- _b.label = 2;
76
+ _a.label = 2;
73
77
  case 2:
74
- if (!(_i < projects_1.length)) return [3 /*break*/, 6];
78
+ if (!(_i < projects_1.length)) return [3 /*break*/, 8];
75
79
  project = projects_1[_i];
76
- return [4 /*yield*/, this.service.getNextBranchInfo(project.id, options.version)];
80
+ return [4 /*yield*/, this._service.getCurrentVersionTag(project.id)];
77
81
  case 3:
78
- _a = _b.sent(), branch = _a.branch, branchName = _a.branchName;
82
+ currentVersionTag = _a.sent();
83
+ if (!currentVersionTag) {
84
+ utils_1.Logger.logError("Could not find the next version for: ".concat(project.title));
85
+ return [2 /*return*/, false];
86
+ }
87
+ return [4 /*yield*/, utils_1.Versions.getNextVersion(currentVersionTag.name, options.version)];
88
+ case 4:
89
+ nextVersion = _a.sent();
90
+ branchName = utils_1.BranchNames.getRelease(nextVersion);
91
+ return [4 /*yield*/, this._service.getBranch(project.id, branchName)];
92
+ case 5:
93
+ branch = _a.sent();
79
94
  if (branch) {
80
95
  utils_1.Logger.logWarning("[".concat(project.title, "]: [").concat(branchName, "] Already exists"));
81
- return [3 /*break*/, 5];
96
+ return [3 /*break*/, 7];
82
97
  }
83
98
  branchFrom = options.version === 'patch' ? 'master' : 'dev';
84
- return [4 /*yield*/, this.service.createBranch(project, branchFrom, branchName, false)];
85
- case 4:
86
- _b.sent();
99
+ return [4 /*yield*/, this._service.createBranch(project, branchFrom, branchName, false)];
100
+ case 6:
101
+ _a.sent();
87
102
  utils_1.Logger.logMessage("[".concat(project.title, "]: [").concat(branchName, "] Has been created"));
88
- _b.label = 5;
89
- case 5:
103
+ _a.label = 7;
104
+ case 7:
90
105
  _i++;
91
106
  return [3 /*break*/, 2];
92
- case 6: return [2 /*return*/, true];
107
+ case 8: return [2 /*return*/, true];
93
108
  }
94
109
  });
95
110
  });
@@ -56,51 +56,66 @@ var services_1 = require("../services");
56
56
  var utils_1 = require("../utils");
57
57
  var CreateMergeRequestTask = /** @class */ (function () {
58
58
  function CreateMergeRequestTask(service) {
59
- this.service = service;
59
+ this._service = service;
60
60
  }
61
61
  CreateMergeRequestTask.prototype.run = function (options) {
62
62
  return __awaiter(this, void 0, void 0, function () {
63
- var projects, _i, projects_1, project, _a, branch, branchName, mergeRequest, description;
64
- return __generator(this, function (_b) {
65
- switch (_b.label) {
63
+ var projects, _i, projects_1, project, currentVersionTag, nextVersion, branchName, branch, mergeRequest, description;
64
+ return __generator(this, function (_a) {
65
+ switch (_a.label) {
66
66
  case 0:
67
67
  utils_1.Logger.logTask('Creating Merge Requests');
68
- return [4 /*yield*/, this.service.getProjects(options)];
68
+ return [4 /*yield*/, this._service.getProjects(options)];
69
69
  case 1:
70
- projects = _b.sent();
70
+ projects = _a.sent();
71
+ if (!projects.length) {
72
+ utils_1.Logger.logError("No projects could be found with the specified options");
73
+ return [2 /*return*/, false];
74
+ }
71
75
  _i = 0, projects_1 = projects;
72
- _b.label = 2;
76
+ _a.label = 2;
73
77
  case 2:
74
- if (!(_i < projects_1.length)) return [3 /*break*/, 7];
78
+ if (!(_i < projects_1.length)) return [3 /*break*/, 9];
75
79
  project = projects_1[_i];
76
- return [4 /*yield*/, this.service.getNextBranchInfo(project.id, options.version)];
80
+ return [4 /*yield*/, this._service.getCurrentVersionTag(project.id)];
77
81
  case 3:
78
- _a = _b.sent(), branch = _a.branch, branchName = _a.branchName;
82
+ currentVersionTag = _a.sent();
83
+ if (!currentVersionTag) {
84
+ utils_1.Logger.logError("Could not find the next version for: ".concat(project.title));
85
+ return [2 /*return*/, false];
86
+ }
87
+ return [4 /*yield*/, utils_1.Versions.getNextVersion(currentVersionTag.name, options.version)];
88
+ case 4:
89
+ nextVersion = _a.sent();
90
+ branchName = utils_1.BranchNames.getRelease(nextVersion);
91
+ return [4 /*yield*/, this._service.getBranch(project.id, branchName)];
92
+ case 5:
93
+ branch = _a.sent();
79
94
  if (!branch) {
80
95
  utils_1.Logger.logError("[".concat(project.title, "]: [").concat(branchName, "] does not exist"));
81
- return [3 /*break*/, 6];
96
+ return [3 /*break*/, 8];
82
97
  }
83
- return [4 /*yield*/, this.service.getMergeRequest(project.id, branchName)];
84
- case 4:
85
- mergeRequest = _b.sent();
98
+ return [4 /*yield*/, this._service.getMergeRequest(project.id, branchName)];
99
+ case 6:
100
+ mergeRequest = _a.sent();
86
101
  if (mergeRequest) {
87
102
  utils_1.Logger.logWarning("[".concat(project.title, "]: MR already existed"));
88
103
  utils_1.Logger.logInfo(mergeRequest.url);
89
- return [3 /*break*/, 6];
104
+ return [3 /*break*/, 8];
90
105
  }
91
106
  description = project.id.toString() === utils_1.ProjectIds.MONOREPO_PROJECT_ID ?
92
107
  utils_1.Descriptions.getMonorepoCombinedDescription(project.mergeRequests) :
93
108
  utils_1.Descriptions.getCombinedDescription(project.mergeRequests);
94
- return [4 /*yield*/, this.service.createMergeRequest(project.id, branchName, description)];
95
- case 5:
96
- mergeRequest = _b.sent();
109
+ return [4 /*yield*/, this._service.createMergeRequest(project.id, branchName, description)];
110
+ case 7:
111
+ mergeRequest = _a.sent();
97
112
  utils_1.Logger.logMessage("[".concat(project.title, "]: MR created"));
98
113
  utils_1.Logger.logInfo(mergeRequest.url);
99
- _b.label = 6;
100
- case 6:
114
+ _a.label = 8;
115
+ case 8:
101
116
  _i++;
102
117
  return [3 /*break*/, 2];
103
- case 7: return [2 /*return*/, true];
118
+ case 9: return [2 /*return*/, true];
104
119
  }
105
120
  });
106
121
  });