@clickview/ship-it 0.0.2 → 0.0.4-dev.0

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 (69) hide show
  1. package/config.json +5 -0
  2. package/lib/config.json +5 -0
  3. package/lib/src/api-clients/GitLabApiClient.js +1 -1
  4. package/lib/src/api-clients/git-lab/GitLabApiClient.js +341 -0
  5. package/lib/src/api-clients/git-lab/GitLabMapper.js +61 -0
  6. package/lib/src/api-clients/index.js +2 -1
  7. package/lib/src/api-clients/team-city/TeamCityApiClient.js +85 -0
  8. package/lib/src/commands/BumpPackagesCommand.js +12 -6
  9. package/lib/src/commands/CommitPackageVersionsCommand.js +78 -0
  10. package/lib/src/commands/CreateBranchCommand.js +12 -14
  11. package/lib/src/commands/CreateMergeRequestCommand.js +16 -18
  12. package/lib/src/commands/CreateReleaseNotesCommand.js +6 -8
  13. package/lib/src/commands/InstallPackagesCommand.js +76 -0
  14. package/lib/src/commands/ReleaseCommand.js +31 -24
  15. package/lib/src/commands/StartConsumingProjectBuildsCommand.js +76 -0
  16. package/lib/src/commands/StatusCommand.js +3 -5
  17. package/lib/src/commands/ValidateMergeRequestCommand.js +76 -0
  18. package/lib/src/commands/VersionCommand.js +3 -5
  19. package/lib/src/commands/index.js +3 -0
  20. package/lib/src/constants/CommandTypeMapping.js +16 -0
  21. package/lib/src/constants/MonorepoPackageJsonFiles.js +13 -0
  22. package/lib/src/constants/TeamCityBuildIDs.js +13 -0
  23. package/lib/src/constants/index.js +18 -0
  24. package/lib/src/errors/ShipItError.js +32 -0
  25. package/lib/src/errors/index.js +17 -0
  26. package/lib/src/index.js +2 -85
  27. package/lib/src/interfaces/VersionType.js +2 -0
  28. package/lib/src/interfaces/command-cli-options/MilestoneCommandCliOptions.js +2 -0
  29. package/lib/src/interfaces/command-cli-options/ReleaseCommandCliOptions.js +2 -0
  30. package/lib/src/interfaces/command-cli-options/index.js +18 -0
  31. package/lib/src/interfaces/command-options/BumpPackagesCommandOptions.js +2 -0
  32. package/lib/src/interfaces/command-options/CommitPackageVersionsCommandOptions.js +2 -0
  33. package/lib/src/interfaces/command-options/DockerMilestoneCommandOptions.js +2 -0
  34. package/lib/src/interfaces/command-options/InstallPackagesCommandOptions.js +2 -0
  35. package/lib/src/interfaces/command-options/MilestoneCommandOptions.js +2 -0
  36. package/lib/src/interfaces/command-options/ReleaseCommandOptions.js +2 -0
  37. package/lib/src/interfaces/command-options/ValidateMRCommandOptions.js +2 -0
  38. package/lib/src/interfaces/command-options/index.js +21 -0
  39. package/lib/src/interfaces/index.js +3 -1
  40. package/lib/src/interfaces/models/Milestone.js +2 -0
  41. package/lib/src/interfaces/models/index.js +1 -0
  42. package/lib/src/inversify.config.js +13 -0
  43. package/lib/src/services/GitLabService.js +128 -34
  44. package/lib/src/services/TeamCityService.js +34 -0
  45. package/lib/src/services/index.js +1 -0
  46. package/lib/src/startup/AddMilestoneCommand.js +81 -0
  47. package/lib/src/startup/GetAction.js +68 -0
  48. package/lib/src/startup/SetupCommands.js +114 -0
  49. package/lib/src/tasks/BumpPackagesTask.js +114 -238
  50. package/lib/src/tasks/BumpVersionTxtTask.js +13 -26
  51. package/lib/src/tasks/CommitLocalPackagesTask.js +137 -0
  52. package/lib/src/tasks/CommitPackageVersionsTask.js +105 -0
  53. package/lib/src/tasks/CreateBranchTask.js +35 -32
  54. package/lib/src/tasks/CreateMergeRequestTask.js +22 -37
  55. package/lib/src/tasks/CreateReleaseNotesTask.js +2 -6
  56. package/lib/src/tasks/InstallPackagesTask.js +337 -0
  57. package/lib/src/tasks/StartConsumingProjectBuildsTask.js +143 -0
  58. package/lib/src/tasks/StartMonorepoBuildTask.js +95 -0
  59. package/lib/src/tasks/ValidateCommitsTask.js +6 -14
  60. package/lib/src/tasks/ValidateDescriptionsTask.js +15 -16
  61. package/lib/src/tasks/ValidateMergeRequestTask.js +108 -0
  62. package/lib/src/tasks/ValidateTask.js +7 -8
  63. package/lib/src/tasks/VersionTask.js +7 -20
  64. package/lib/src/tasks/index.js +5 -0
  65. package/lib/src/types.js +13 -2
  66. package/lib/src/utils/BranchNames.js +2 -0
  67. package/lib/src/utils/Descriptions.js +28 -23
  68. package/lib/src/utils/ProjectIds.js +10 -6
  69. package/package.json +24 -23
package/lib/src/index.js CHANGED
@@ -1,101 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
- return new (P || (P = Promise))(function (resolve, reject) {
6
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
- step((generator = generator.apply(thisArg, _arguments || [])).next());
10
- });
11
- };
12
- var __generator = (this && this.__generator) || function (thisArg, body) {
13
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
14
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
15
- function verb(n) { return function (v) { return step([n, v]); }; }
16
- function step(op) {
17
- if (f) throw new TypeError("Generator is already executing.");
18
- while (_) try {
19
- 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;
20
- if (y = 0, t) op = [op[0] & 2, t.value];
21
- switch (op[0]) {
22
- case 0: case 1: t = op; break;
23
- case 4: _.label++; return { value: op[1], done: false };
24
- case 5: _.label++; y = op[1]; op = [0]; continue;
25
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
26
- default:
27
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
28
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
29
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
30
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
31
- if (t[2]) _.ops.pop();
32
- _.trys.pop(); continue;
33
- }
34
- op = body.call(thisArg, _);
35
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
36
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
37
- }
38
- };
39
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
40
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
41
5
  };
42
6
  Object.defineProperty(exports, "__esModule", { value: true });
43
7
  var commander_1 = require("commander");
44
8
  var inversify_config_1 = require("./inversify.config");
45
- var types_1 = require("./types");
46
- var utils_1 = require("./utils");
9
+ var SetupCommands_1 = require("./startup/SetupCommands");
47
10
  var config_json_1 = __importDefault(require("../config.json"));
48
- function processOptions(options) {
49
- var opts = {
50
- milestone: options.milestone,
51
- version: 'minor'
52
- };
53
- if (options.projectIds)
54
- opts.projectIds = utils_1.ProjectIds.getProjectIds(options.projectIds);
55
- if (options.hotfix && options.major)
56
- throw new Error('Cannot pass both --hotfix and --major options');
57
- if (options.major)
58
- opts.version = 'major';
59
- if (options.hotfix)
60
- opts.version = 'patch';
61
- return opts;
62
- }
63
- var commandTypeMapping = {
64
- 'status': types_1.COMMANDS.StatusCommand,
65
- 'version': types_1.COMMANDS.VersionCommand,
66
- 'release': types_1.COMMANDS.ReleaseCommand,
67
- 'create-branches': types_1.COMMANDS.CreateBranchCommand,
68
- 'create-mrs': types_1.COMMANDS.CreateMergeRequestCommand,
69
- 'create-notes': types_1.COMMANDS.CreateReleaseNotesCommand,
70
- 'bump-packages': types_1.COMMANDS.BumpPackagesCommand
71
- };
72
- function addCommand(name, description) {
73
- var _this = this;
74
- program.command(name)
75
- .description(description)
76
- .requiredOption('-m, --milestone <milestone>')
77
- .option('-p, --projectIds <projectIds...>')
78
- .option('--hotfix')
79
- .option('--major')
80
- .action(function (options) { return __awaiter(_this, void 0, void 0, function () {
81
- return __generator(this, function (_a) {
82
- container.get(commandTypeMapping[name])
83
- .run(processOptions(options));
84
- return [2 /*return*/];
85
- });
86
- }); });
87
- }
88
11
  var program = new commander_1.Command();
89
12
  program
90
13
  .name('ship-it')
91
14
  .description('ClickView Release Manager')
92
15
  .version('0.0.0');
93
16
  var container = (0, inversify_config_1.createContainer)(config_json_1.default);
94
- addCommand('status', 'Get the status of all MRs in a milestone');
95
- addCommand('version', 'Display the versions that will be used for the release');
96
- addCommand('create-branches', 'Create release branches for all projects that are part of a milestone');
97
- addCommand('create-mrs', 'Create merge requests for all projects that are part of a milestone');
98
- addCommand('create-notes', 'Builds descriptions for all projects that are part of a milestone');
99
- addCommand('release', 'Create releases for all projects that are part of a milestone');
100
- addCommand('bump-packages', 'Bump consuming project npm packages for all projects that are part of a milestone');
17
+ (0, SetupCommands_1.setupCommands)(program, container);
101
18
  program.parseAsync();
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./MilestoneCommandCliOptions"), exports);
18
+ __exportStar(require("./ReleaseCommandCliOptions"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./BumpPackagesCommandOptions"), exports);
18
+ __exportStar(require("./DockerMilestoneCommandOptions"), exports);
19
+ __exportStar(require("./MilestoneCommandOptions"), exports);
20
+ __exportStar(require("./ValidateMRCommandOptions"), exports);
21
+ __exportStar(require("./ReleaseCommandOptions"), exports);
@@ -14,9 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./command-cli-options"), exports);
18
+ __exportStar(require("./command-options"), exports);
17
19
  __exportStar(require("./models"), exports);
18
20
  __exportStar(require("./view-models"), exports);
19
21
  __exportStar(require("./Config"), exports);
20
22
  __exportStar(require("./ShipItCommand"), exports);
21
- __exportStar(require("./ShipItOptions"), exports);
22
23
  __exportStar(require("./ShipItTask"), exports);
24
+ __exportStar(require("./VersionType"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -19,5 +19,6 @@ __exportStar(require("./Commit"), exports);
19
19
  __exportStar(require("./CommitFile"), exports);
20
20
  __exportStar(require("./File"), exports);
21
21
  __exportStar(require("./MergeRequest"), exports);
22
+ __exportStar(require("./Milestone"), exports);
22
23
  __exportStar(require("./Project"), exports);
23
24
  __exportStar(require("./Tag"), exports);
@@ -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
  */
@@ -32,7 +35,13 @@ function createContainer(config) {
32
35
  container.bind(types_1.TASKS.CreateMergeRequestTask).to(tasks_1.CreateMergeRequestTask);
33
36
  container.bind(types_1.TASKS.ValidateDescriptionsTask).to(tasks_1.ValidateDescriptionsTask);
34
37
  container.bind(types_1.TASKS.CreateReleaseNotesTask).to(tasks_1.CreateReleaseNotesTask);
38
+ container.bind(types_1.TASKS.InstallPackagesTask).to(tasks_1.InstallPackagesTask);
35
39
  container.bind(types_1.TASKS.BumpPackagesTask).to(tasks_1.BumpPackagesTask);
40
+ container.bind(types_1.TASKS.CommitPackageVersionsTask).to(tasks_1.CommitPackageVersionsTask);
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.StartConsumingProjectBuildsTask)
44
+ .to(tasks_1.StartConsumingProjectBuildsTask);
36
45
  /**
37
46
  * Commands
38
47
  */
@@ -42,7 +51,11 @@ function createContainer(config) {
42
51
  container.bind(types_1.COMMANDS.CreateMergeRequestCommand).to(commands_1.CreateMergeRequestCommand);
43
52
  container.bind(types_1.COMMANDS.ReleaseCommand).to(commands_1.ReleaseCommand);
44
53
  container.bind(types_1.COMMANDS.CreateReleaseNotesCommand).to(commands_1.CreateReleaseNotesCommand);
54
+ container.bind(types_1.COMMANDS.InstallPackagesCommand).to(commands_1.InstallPackagesCommand);
45
55
  container.bind(types_1.COMMANDS.BumpPackagesCommand).to(commands_1.BumpPackagesCommand);
56
+ container.bind(types_1.COMMANDS.ValidateMergeRequestCommand).to(commands_1.ValidateMergeRequestCommand);
57
+ container.bind(types_1.COMMANDS.StartConsumingProjectBuildsCommand)
58
+ .to(commands_1.StartConsumingProjectBuildsCommand);
46
59
  return container;
47
60
  }
48
61
  exports.createContainer = createContainer;
@@ -69,9 +69,11 @@ var lodash_1 = __importDefault(require("lodash"));
69
69
  var semver_1 = __importDefault(require("semver"));
70
70
  var types_1 = require("../types");
71
71
  var api_clients_1 = require("../api-clients");
72
+ var errors_1 = require("../errors");
73
+ var utils_1 = require("../utils");
72
74
  var GitLabService = /** @class */ (function () {
73
75
  function GitLabService(apiClient) {
74
- this._apiClient = apiClient;
76
+ this.apiClient = apiClient;
75
77
  }
76
78
  GitLabService.prototype.getProjects = function (options) {
77
79
  return __awaiter(this, void 0, void 0, function () {
@@ -79,20 +81,35 @@ var GitLabService = /** @class */ (function () {
79
81
  return __generator(this, function (_a) {
80
82
  switch (_a.label) {
81
83
  case 0:
82
- if (this._projects)
83
- return [2 /*return*/, this._projects];
84
- return [4 /*yield*/, this._apiClient.getMergeRequests(options)];
84
+ if (this.projects)
85
+ return [2 /*return*/, this.projects];
86
+ return [4 /*yield*/, this.apiClient.getMergeRequests(options)];
85
87
  case 1:
86
88
  mergeRequests = _a.sent();
87
89
  if (!(mergeRequests === null || mergeRequests === void 0 ? void 0 : mergeRequests.length))
88
- throw new Error('Could not find any merge requests for the specified options');
90
+ throw new errors_1.ShipItError('Could not find any merge requests for the specified options');
89
91
  projectIds = lodash_1.default.uniqBy(mergeRequests, function (m) { return m.projectId; }).map(function (m) { return m.projectId; });
90
- return [4 /*yield*/, this._apiClient.getProjectsByIds(projectIds)];
92
+ return [4 /*yield*/, this.apiClient.getProjectsByIds(projectIds)];
91
93
  case 2:
92
94
  projects = _a.sent();
93
95
  if (!(projects === null || projects === void 0 ? void 0 : projects.length) || projects.length !== projectIds.length)
94
- throw new Error('Could not find all projects for the found merge requests');
95
- return [2 /*return*/, (this._projects = projects.map(function (p) { return (__assign(__assign({}, p), { mergeRequests: mergeRequests.filter(function (mr) { return mr.projectId === p.id; }) })); }))];
96
+ 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; }) })); }))];
98
+ }
99
+ });
100
+ });
101
+ };
102
+ GitLabService.prototype.getProject = function (projectId) {
103
+ return __awaiter(this, void 0, void 0, function () {
104
+ var projects;
105
+ return __generator(this, function (_a) {
106
+ switch (_a.label) {
107
+ case 0: return [4 /*yield*/, this.apiClient.getProjectsByIds([projectId])];
108
+ case 1:
109
+ projects = _a.sent();
110
+ if (!projects.length)
111
+ throw new errors_1.ShipItError("Could not find project projectId: ".concat(projectId));
112
+ return [2 /*return*/, projects[0]];
96
113
  }
97
114
  });
98
115
  });
@@ -102,7 +119,7 @@ var GitLabService = /** @class */ (function () {
102
119
  var commits, lastDevCommit, title;
103
120
  return __generator(this, function (_a) {
104
121
  switch (_a.label) {
105
- case 0: return [4 /*yield*/, this._apiClient.getCommitsSince(projectId, 'dev', sinceSha)];
122
+ case 0: return [4 /*yield*/, this.apiClient.getCommitsSince(projectId, 'dev', sinceSha)];
106
123
  case 1:
107
124
  commits = _a.sent();
108
125
  lastDevCommit = lodash_1.default.last(commits);
@@ -113,7 +130,7 @@ var GitLabService = /** @class */ (function () {
113
130
  commits.pop();
114
131
  }
115
132
  if (!(commits === null || commits === void 0 ? void 0 : commits.length))
116
- throw new Error("Could not find any commits in dev for projectId: ".concat(projectId, " since ").concat(sinceSha));
133
+ throw new errors_1.ShipItError("Could not find any commits in dev for projectId: ".concat(projectId, " since ").concat(sinceSha));
117
134
  return [2 /*return*/, commits];
118
135
  }
119
136
  });
@@ -123,7 +140,7 @@ var GitLabService = /** @class */ (function () {
123
140
  return __awaiter(this, void 0, void 0, function () {
124
141
  return __generator(this, function (_a) {
125
142
  switch (_a.label) {
126
- case 0: return [4 /*yield*/, this._apiClient.getBranch(projectId, branchName)];
143
+ case 0: return [4 /*yield*/, this.apiClient.getBranch(projectId, branchName)];
127
144
  case 1: return [2 /*return*/, _a.sent()];
128
145
  }
129
146
  });
@@ -131,53 +148,99 @@ var GitLabService = /** @class */ (function () {
131
148
  };
132
149
  GitLabService.prototype.createBranch = function (project, branchFrom, branchName, cherryPick) {
133
150
  return __awaiter(this, void 0, void 0, function () {
134
- var newBranch_1, i, mr, newBranch;
151
+ var newBranch, i, mr;
135
152
  return __generator(this, function (_a) {
136
153
  switch (_a.label) {
137
154
  case 0:
138
155
  if (!cherryPick) return [3 /*break*/, 6];
139
- return [4 /*yield*/, this._apiClient.createBranch(project.id, branchName, 'master')];
156
+ return [4 /*yield*/, this.apiClient.createBranch(project.id, branchName, 'master')];
140
157
  case 1:
141
- newBranch_1 = _a.sent();
142
- if (!newBranch_1)
143
- throw new Error("Failed to create branch from master for projectId: ".concat(project.id));
158
+ newBranch = _a.sent();
144
159
  i = 0;
145
160
  _a.label = 2;
146
161
  case 2:
147
162
  if (!(i < project.mergeRequests.length)) return [3 /*break*/, 5];
148
163
  mr = project.mergeRequests[i];
149
164
  if (!mr.mergeCommit)
150
- throw new Error("Could not find the merge commit sha for MR: ".concat(mr.title, " in projectId: ").concat(project.id));
151
- return [4 /*yield*/, this._apiClient.cherryPick(project.id, mr.mergeCommit, branchName)];
165
+ throw new errors_1.ShipItError("Could not find the merge commit sha for MR: ".concat(mr.title, " in projectId: ").concat(project.id));
166
+ return [4 /*yield*/, this.apiClient.cherryPick(project.id, mr.mergeCommit, branchName)];
152
167
  case 3:
153
168
  _a.sent();
154
169
  _a.label = 4;
155
170
  case 4:
156
171
  i++;
157
172
  return [3 /*break*/, 2];
158
- case 5: return [2 /*return*/, newBranch_1];
159
- case 6: return [4 /*yield*/, this._apiClient.createBranch(project.id, branchName, branchFrom)];
160
- case 7:
161
- newBranch = _a.sent();
162
- if (!newBranch)
163
- throw new Error("Failed to create branch from master for projectId: ".concat(project.id));
164
- return [2 /*return*/, newBranch];
173
+ case 5: return [2 /*return*/, newBranch];
174
+ case 6: return [4 /*yield*/, this.apiClient.createBranch(project.id, branchName, branchFrom)];
175
+ case 7: return [2 /*return*/, _a.sent()];
165
176
  }
166
177
  });
167
178
  });
168
179
  };
169
180
  GitLabService.prototype.getMergeRequest = function (projectId, branchName) {
170
- return this._apiClient.getMergeRequest(projectId, branchName, 'master');
181
+ return this.apiClient.getMergeRequest(projectId, branchName, 'master');
182
+ };
183
+ GitLabService.prototype.getMergeRequestById = function (projectId, mergeRequestId) {
184
+ var idAsNumber = lodash_1.default.toNumber(mergeRequestId);
185
+ if (!lodash_1.default.isNumber(idAsNumber))
186
+ throw new errors_1.ShipItError("MergeRequest Id must be a number: ".concat(mergeRequestId));
187
+ return this.apiClient.getMergeRequestById(projectId, idAsNumber);
188
+ };
189
+ GitLabService.prototype.createMergeRequest = function (projectId, branchName, description, milestoneName) {
190
+ return __awaiter(this, void 0, void 0, function () {
191
+ var milestone;
192
+ return __generator(this, function (_a) {
193
+ switch (_a.label) {
194
+ case 0: return [4 /*yield*/, this.getMilestone(projectId, milestoneName)];
195
+ case 1:
196
+ milestone = _a.sent();
197
+ return [2 /*return*/, this.apiClient.createMergeRequest(projectId, branchName, 'master', branchName, description, milestone)];
198
+ }
199
+ });
200
+ });
201
+ };
202
+ GitLabService.prototype.getMilestone = function (projectId, milestoneName) {
203
+ return this.apiClient.getMilestone(projectId, milestoneName);
204
+ };
205
+ GitLabService.prototype.getReleaseBranchNameMilestone = function (projectId, milestone) {
206
+ return __awaiter(this, void 0, void 0, function () {
207
+ var releaseMR;
208
+ return __generator(this, function (_a) {
209
+ switch (_a.label) {
210
+ case 0: return [4 /*yield*/, this.apiClient.getReleaseMergeRequest(projectId, milestone)];
211
+ case 1:
212
+ releaseMR = _a.sent();
213
+ if (!releaseMR)
214
+ return [2 /*return*/, null];
215
+ return [2 /*return*/, releaseMR.sourceBranch];
216
+ }
217
+ });
218
+ });
171
219
  };
172
- GitLabService.prototype.createMergeRequest = function (projectId, branchName, description) {
173
- return this._apiClient.createMergeRequest(projectId, branchName, 'master', branchName, description);
220
+ GitLabService.prototype.getMilestoneByBranchName = function (projectId, branchName) {
221
+ var _a, _b;
222
+ return __awaiter(this, void 0, void 0, function () {
223
+ var mergeRequest;
224
+ return __generator(this, function (_c) {
225
+ switch (_c.label) {
226
+ case 0: return [4 /*yield*/, this.getMergeRequest(projectId, branchName)];
227
+ case 1:
228
+ mergeRequest = _c.sent();
229
+ if (!mergeRequest)
230
+ throw new errors_1.ShipItError("No merge request in project \"monorepo\" with branch name \"".concat(branchName, "\" could be found."));
231
+ if (!mergeRequest.milestone)
232
+ 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));
233
+ return [2 /*return*/, (_b = (_a = mergeRequest.milestone) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : ''];
234
+ }
235
+ });
236
+ });
174
237
  };
175
238
  GitLabService.prototype.bumpVersionTxt = function (projectId, branchName, newVersion) {
176
239
  return __awaiter(this, void 0, void 0, function () {
177
240
  var versionTxt, buff, text;
178
241
  return __generator(this, function (_a) {
179
242
  switch (_a.label) {
180
- case 0: return [4 /*yield*/, this._apiClient.getFile(projectId, 'version.txt', branchName)];
243
+ case 0: return [4 /*yield*/, this.apiClient.getFile(projectId, 'version.txt', branchName)];
181
244
  case 1:
182
245
  versionTxt = _a.sent();
183
246
  if (!versionTxt)
@@ -186,7 +249,7 @@ var GitLabService = /** @class */ (function () {
186
249
  text = buff.toString('utf-8');
187
250
  if (text === newVersion)
188
251
  return [2 /*return*/, false];
189
- return [4 /*yield*/, this._apiClient.updateFile(projectId, 'version.txt', branchName, newVersion, 'Bumping version.txt')];
252
+ return [4 /*yield*/, this.apiClient.updateFile(projectId, 'version.txt', branchName, newVersion, 'Bumping version.txt')];
190
253
  case 2:
191
254
  _a.sent();
192
255
  return [2 /*return*/, true];
@@ -198,20 +261,20 @@ var GitLabService = /** @class */ (function () {
198
261
  return __awaiter(this, void 0, void 0, function () {
199
262
  return __generator(this, function (_a) {
200
263
  switch (_a.label) {
201
- case 0: return [4 /*yield*/, this._apiClient.getFile(projectId, file, branchName)];
264
+ case 0: return [4 /*yield*/, this.apiClient.getFile(projectId, file, branchName)];
202
265
  case 1: return [2 /*return*/, _a.sent()];
203
266
  }
204
267
  });
205
268
  });
206
269
  };
207
270
  GitLabService.prototype.updateFile = function (projectId, filePath, branchName, content, commit) {
208
- return this._apiClient.updateFile(projectId, filePath, branchName, content, commit);
271
+ return this.apiClient.updateFile(projectId, filePath, branchName, content, commit);
209
272
  };
210
273
  GitLabService.prototype.commit = function (projectId, branchName, commitMessage, files) {
211
274
  return __awaiter(this, void 0, void 0, function () {
212
275
  return __generator(this, function (_a) {
213
276
  switch (_a.label) {
214
- case 0: return [4 /*yield*/, this._apiClient.commit(projectId, branchName, files, commitMessage)];
277
+ case 0: return [4 /*yield*/, this.apiClient.commit(projectId, branchName, files, commitMessage)];
215
278
  case 1:
216
279
  _a.sent();
217
280
  return [2 /*return*/];
@@ -219,12 +282,16 @@ var GitLabService = /** @class */ (function () {
219
282
  });
220
283
  });
221
284
  };
285
+ /**
286
+ * We use the latest valid semver tag in master to determine what the current version
287
+ * of a project is
288
+ */
222
289
  GitLabService.prototype.getCurrentVersionTag = function (projectId) {
223
290
  return __awaiter(this, void 0, void 0, function () {
224
291
  var tags, tagNames, sortedTagNames, currentVersion, currentTag;
225
292
  return __generator(this, function (_a) {
226
293
  switch (_a.label) {
227
- case 0: return [4 /*yield*/, this._apiClient.getLatestTags(projectId)];
294
+ case 0: return [4 /*yield*/, this.apiClient.getLatestTags(projectId)];
228
295
  case 1:
229
296
  tags = _a.sent();
230
297
  if (!(tags === null || tags === void 0 ? void 0 : tags.length))
@@ -242,6 +309,33 @@ var GitLabService = /** @class */ (function () {
242
309
  });
243
310
  });
244
311
  };
312
+ GitLabService.prototype.getNextBranchInfo = function (projectId, version) {
313
+ return __awaiter(this, void 0, void 0, function () {
314
+ var tag, nextVersion, branchName, branch;
315
+ return __generator(this, function (_a) {
316
+ switch (_a.label) {
317
+ case 0: return [4 /*yield*/, this.getCurrentVersionTag(projectId)];
318
+ case 1:
319
+ tag = _a.sent();
320
+ if (!tag)
321
+ throw new errors_1.ShipItError("Could not find the latest semver tag for projectId: ".concat(projectId));
322
+ nextVersion = utils_1.Versions.getNextVersion(tag.name, version);
323
+ branchName = version === 'patch' ?
324
+ utils_1.BranchNames.getHotfix(nextVersion) :
325
+ utils_1.BranchNames.getRelease(nextVersion);
326
+ return [4 /*yield*/, this.getBranch(projectId, branchName)];
327
+ case 2:
328
+ branch = _a.sent();
329
+ return [2 /*return*/, {
330
+ nextVersion: nextVersion,
331
+ branchName: branchName,
332
+ branch: branch,
333
+ tag: tag
334
+ }];
335
+ }
336
+ });
337
+ });
338
+ };
245
339
  GitLabService = __decorate([
246
340
  (0, inversify_1.injectable)(),
247
341
  __param(0, (0, inversify_1.inject)(types_1.API_CLIENTS.GitLabApiClient)),
@@ -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);