@clickview/ship-it 0.0.33 → 0.0.34

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 (175) hide show
  1. package/Dockerfile +33 -33
  2. package/README.md +48 -48
  3. package/config.json +19 -19
  4. package/dist/F1/Analytics Web.md +8 -0
  5. package/dist/F1/AutoCaptions.md +30 -0
  6. package/dist/F1/Classroom.Api.md +23 -0
  7. package/dist/F1/ClickView Online.md +17 -0
  8. package/dist/F1/ClickView.Curator.md +100 -0
  9. package/dist/F1/ClickView.EmailService.md +53 -0
  10. package/dist/F1/ClickView.OnlineApi.md +13 -0
  11. package/dist/F1/Clients.md +19 -0
  12. package/dist/F1/Domain.Api.md +23 -0
  13. package/dist/F1/Exchange.Web.md +8 -0
  14. package/dist/F1/Image.Api.md +8 -0
  15. package/dist/F1/Integrations.Api.md +23 -0
  16. package/dist/F1/Krakend.md +8 -0
  17. package/dist/F1/Library Editor.md +0 -0
  18. package/dist/F1/Lite.md +60 -0
  19. package/dist/F1/Master.Api.md +58 -0
  20. package/dist/F1/Master.Auth.md +22 -0
  21. package/dist/F1/Objects.Api.md +12 -0
  22. package/dist/F1/Permissions.Api.md +12 -0
  23. package/dist/F1/RealtimeSalesforceSync.md +14 -0
  24. package/dist/F1/Release Notes.md +990 -0
  25. package/dist/F1/Search.Api.md +12 -0
  26. package/dist/F1/StreamableLearning.Web.md +35 -0
  27. package/dist/F1/Users.Api.md +13 -0
  28. package/dist/F1/VideoProcessorService.md +23 -0
  29. package/dist/F1/clickview.md +321 -0
  30. package/dist/F2/Analytics Web.md +7 -0
  31. package/dist/F2/Batch.Api.md +27 -0
  32. package/dist/F2/ClickView Online.md +12 -0
  33. package/dist/F2/ClickView.Curator.md +166 -0
  34. package/dist/F2/Clients.md +14 -0
  35. package/dist/F2/CurriculumIngestion.Api.md +13 -0
  36. package/dist/F2/Discover.Api.md +64 -0
  37. package/dist/F2/Domain.Api.md +16 -0
  38. package/dist/F2/Exchange.Web.md +7 -0
  39. package/dist/F2/Krakend.md +12 -0
  40. package/dist/F2/Library Editor.md +11 -0
  41. package/dist/F2/Lite.md +30 -0
  42. package/dist/F2/Objects.Api.md +12 -0
  43. package/dist/F2/Release Notes.md +759 -0
  44. package/dist/F2/Search.Api.md +30 -0
  45. package/dist/F2/Share.Api.md +12 -0
  46. package/dist/F2/StreamableLearning.Web.md +14 -0
  47. package/dist/F2/Subjects.API.md +12 -0
  48. package/dist/F2/Tv.Web.md +8 -0
  49. package/dist/F2/Users.Api.md +21 -0
  50. package/dist/F2/clickview.md +200 -0
  51. package/dist/F2/shortcode-api.md +8 -0
  52. package/dist/F3.1/Analytics Web.md +8 -0
  53. package/dist/F3.1/ClickView.Curator.md +14 -0
  54. package/dist/F3.1/Discover.Api.md +14 -0
  55. package/dist/F3.1/Domain.Api.md +7 -0
  56. package/dist/F3.1/Exchange.Web.md +8 -0
  57. package/dist/F3.1/Library Editor.md +8 -0
  58. package/dist/F3.1/Lite.md +8 -0
  59. package/dist/F3.1/Objects.Api.md +7 -0
  60. package/dist/F3.1/Release Notes.md +207 -0
  61. package/dist/F3.1/Search.Api.md +14 -0
  62. package/dist/F3.1/Share.Api.md +10 -0
  63. package/dist/F3.1/Subjects.API.md +35 -0
  64. package/dist/F3.1/VideoViews.Api.md +7 -0
  65. package/dist/F3.1/clickview.md +28 -0
  66. package/lib/config.json +20 -20
  67. package/lib/src/api-clients/git-lab/GitLabApiClient.js +439 -439
  68. package/lib/src/api-clients/git-lab/GitLabMapper.js +82 -82
  69. package/lib/src/api-clients/index.js +20 -20
  70. package/lib/src/api-clients/slack/SlackApiClient.js +206 -206
  71. package/lib/src/api-clients/team-city/TeamCityApiClient.js +100 -100
  72. package/lib/src/api-clients/trello/TrelloApiClient.js +145 -145
  73. package/lib/src/commands/BumpPackagesCommand.js +84 -84
  74. package/lib/src/commands/CreateBranchCommand.js +100 -100
  75. package/lib/src/commands/CreateMergeRequestCommand.js +107 -107
  76. package/lib/src/commands/CreateNotesAuditCommand.js +84 -84
  77. package/lib/src/commands/CreateReleaseNotesCommand.js +95 -95
  78. package/lib/src/commands/CreateTestingNotesCommand.js +84 -0
  79. package/lib/src/commands/CreateTrelloCardsCommand.js +77 -77
  80. package/lib/src/commands/InstallPackagesCommand.js +76 -76
  81. package/lib/src/commands/ListProjectsCommand.js +76 -76
  82. package/lib/src/commands/ReleaseCommand.js +129 -129
  83. package/lib/src/commands/StartConsumingProjectBuildsCommand.js +76 -0
  84. package/lib/src/commands/StartProjectBuildsCommand.js +76 -76
  85. package/lib/src/commands/StatusCommand.js +88 -88
  86. package/lib/src/commands/TagMasterCommand.js +76 -76
  87. package/lib/src/commands/ValidateMergeRequestCommand.js +76 -76
  88. package/lib/src/commands/VersionCommand.js +76 -76
  89. package/lib/src/commands/index.js +30 -30
  90. package/lib/src/constants/CommandTypeMapping.js +20 -20
  91. package/lib/src/constants/GitLabMemberIds.js +6 -6
  92. package/lib/src/constants/MonorepoPackageJsonFiles.js +17 -17
  93. package/lib/src/constants/MonorepoProjectNames.js +16 -16
  94. package/lib/src/constants/ProjectNames.js +68 -68
  95. package/lib/src/constants/SlackUserEmailList.js +13 -13
  96. package/lib/src/constants/TeamCityBuildIDs.js +45 -45
  97. package/lib/src/constants/index.js +19 -19
  98. package/lib/src/errors/ShipItError.js +32 -32
  99. package/lib/src/errors/index.js +17 -17
  100. package/lib/src/index.js +18 -18
  101. package/lib/src/interfaces/Config.js +2 -2
  102. package/lib/src/interfaces/MergeRequestState.js +2 -2
  103. package/lib/src/interfaces/ProjectNames.js +2 -2
  104. package/lib/src/interfaces/ShipItCommand.js +2 -2
  105. package/lib/src/interfaces/ShipItTask.js +2 -2
  106. package/lib/src/interfaces/VersionType.js +2 -2
  107. package/lib/src/interfaces/command-cli-options/MilestoneCommandCliOptions.js +2 -2
  108. package/lib/src/interfaces/command-cli-options/ReleaseCommandCliOptions.js +2 -2
  109. package/lib/src/interfaces/command-cli-options/StatusCommandCliOptions.js +2 -2
  110. package/lib/src/interfaces/command-cli-options/index.js +19 -19
  111. package/lib/src/interfaces/command-options/BaseCommandOptions.js +2 -2
  112. package/lib/src/interfaces/command-options/BumpPackagesCommandOptions.js +2 -2
  113. package/lib/src/interfaces/command-options/DockerMilestoneCommandOptions.js +2 -2
  114. package/lib/src/interfaces/command-options/MilestoneCommandOptions.js +2 -2
  115. package/lib/src/interfaces/command-options/ReleaseCommandOptions.js +2 -2
  116. package/lib/src/interfaces/command-options/StatusCommandOptions.js +2 -2
  117. package/lib/src/interfaces/command-options/ValidateMRCommandOptions.js +2 -2
  118. package/lib/src/interfaces/command-options/index.js +22 -22
  119. package/lib/src/interfaces/index.js +26 -26
  120. package/lib/src/interfaces/models/Branch.js +2 -2
  121. package/lib/src/interfaces/models/Commit.js +2 -2
  122. package/lib/src/interfaces/models/CommitFile.js +2 -2
  123. package/lib/src/interfaces/models/File.js +2 -2
  124. package/lib/src/interfaces/models/Label.js +2 -2
  125. package/lib/src/interfaces/models/MergeRequest.js +2 -2
  126. package/lib/src/interfaces/models/Milestone.js +2 -2
  127. package/lib/src/interfaces/models/Project.js +2 -2
  128. package/lib/src/interfaces/models/ProjectConfig.js +9 -9
  129. package/lib/src/interfaces/models/Release.js +2 -2
  130. package/lib/src/interfaces/models/Tag.js +2 -2
  131. package/lib/src/interfaces/models/index.js +26 -26
  132. package/lib/src/interfaces/view-models/MilestoneProject.js +2 -2
  133. package/lib/src/interfaces/view-models/index.js +17 -17
  134. package/lib/src/inversify.config.js +75 -75
  135. package/lib/src/services/GitLabService.js +508 -508
  136. package/lib/src/services/SlackService.js +142 -142
  137. package/lib/src/services/TeamCityService.js +37 -37
  138. package/lib/src/services/TrelloService.js +84 -84
  139. package/lib/src/services/index.js +20 -20
  140. package/lib/src/startup/AddMilestoneCommand.js +96 -96
  141. package/lib/src/startup/GetAction.js +68 -68
  142. package/lib/src/startup/SetupCommands.js +168 -168
  143. package/lib/src/tasks/BumpPackagesTask.js +229 -229
  144. package/lib/src/tasks/BumpVersionTxtTask.js +110 -110
  145. package/lib/src/tasks/CommitPackageVersionsTask.js +116 -116
  146. package/lib/src/tasks/CreateBranchTask.js +104 -104
  147. package/lib/src/tasks/CreateMergeRequestTask.js +118 -118
  148. package/lib/src/tasks/CreateNotesAuditTask.js +140 -140
  149. package/lib/src/tasks/CreateReleaseNotesTask.js +144 -144
  150. package/lib/src/tasks/CreateTestingNotesTask.js +135 -0
  151. package/lib/src/tasks/InstallPackagesTask.js +407 -407
  152. package/lib/src/tasks/ListProjectsTask.js +87 -87
  153. package/lib/src/tasks/MergeMasterToDevTask.js +147 -0
  154. package/lib/src/tasks/PopulateTrelloBoardTask.js +140 -140
  155. package/lib/src/tasks/StartConsumingProjectBuildsTask.js +149 -0
  156. package/lib/src/tasks/StartMonorepoBuildTask.js +109 -109
  157. package/lib/src/tasks/StartProjectBuildsTask.js +170 -170
  158. package/lib/src/tasks/TagMasterTask.js +186 -186
  159. package/lib/src/tasks/ValidateCommitsTask.js +143 -143
  160. package/lib/src/tasks/ValidateDescriptionsTask.js +178 -178
  161. package/lib/src/tasks/ValidateMergeRequestTask.js +115 -115
  162. package/lib/src/tasks/ValidateTask.js +419 -419
  163. package/lib/src/tasks/VersionTask.js +98 -98
  164. package/lib/src/tasks/index.js +34 -34
  165. package/lib/src/types.js +57 -57
  166. package/lib/src/utils/BranchNames.js +11 -11
  167. package/lib/src/utils/Commits.js +55 -55
  168. package/lib/src/utils/Csv.js +54 -54
  169. package/lib/src/utils/Descriptions.js +274 -274
  170. package/lib/src/utils/GroupIds.js +6 -6
  171. package/lib/src/utils/Logger.js +62 -62
  172. package/lib/src/utils/ProjectIds.js +47 -47
  173. package/lib/src/utils/Versions.js +20 -20
  174. package/lib/src/utils/index.js +22 -22
  175. package/package.json +50 -50
@@ -1,508 +1,508 @@
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
- };
13
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
14
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
16
- 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;
17
- return c > 3 && r && Object.defineProperty(target, key, r), r;
18
- };
19
- var __metadata = (this && this.__metadata) || function (k, v) {
20
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
21
- };
22
- var __param = (this && this.__param) || function (paramIndex, decorator) {
23
- return function (target, key) { decorator(target, key, paramIndex); }
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (_) try {
41
- 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;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
61
- var __importDefault = (this && this.__importDefault) || function (mod) {
62
- return (mod && mod.__esModule) ? mod : { "default": mod };
63
- };
64
- Object.defineProperty(exports, "__esModule", { value: true });
65
- exports.GitLabService = void 0;
66
- require("reflect-metadata");
67
- var inversify_1 = require("inversify");
68
- var lodash_1 = __importDefault(require("lodash"));
69
- var semver_1 = __importDefault(require("semver"));
70
- var types_1 = require("../types");
71
- var api_clients_1 = require("../api-clients");
72
- var errors_1 = require("../errors");
73
- var utils_1 = require("../utils");
74
- var ProjectConfig_1 = require("../interfaces/models/ProjectConfig");
75
- /**
76
- * These are projects that will try to use tags to pull in extra projects
77
- */
78
- var MONOREPO_IDS = [
79
- utils_1.ProjectIds.MONOREPO_PROJECT_ID
80
- ];
81
- var GitLabService = /** @class */ (function () {
82
- function GitLabService(apiClient) {
83
- this.projectConfigCache = {};
84
- this.apiClient = apiClient;
85
- }
86
- GitLabService.prototype.getProjects = function (options) {
87
- var _a, _b;
88
- return __awaiter(this, void 0, void 0, function () {
89
- var allMergeRequests, mergeRequests, projectIds, projects, mappedProjects, _i, mappedProjects_1, mappedProject, extraProjects;
90
- return __generator(this, function (_c) {
91
- switch (_c.label) {
92
- case 0:
93
- if (this.projects)
94
- return [2 /*return*/, this.projects];
95
- return [4 /*yield*/, this.apiClient.getMergeRequests(options)];
96
- case 1:
97
- allMergeRequests = _c.sent();
98
- mergeRequests = allMergeRequests.filter(function (mr) { return mr.targetBranch !== 'master'; });
99
- if (!(mergeRequests === null || mergeRequests === void 0 ? void 0 : mergeRequests.length))
100
- throw new errors_1.ShipItError('Could not find any merge requests for the specified options');
101
- projectIds = lodash_1.default.uniqBy(mergeRequests, function (m) { return m.projectId; }).map(function (m) { return m.projectId; });
102
- return [4 /*yield*/, this.apiClient.getProjectsByIds(projectIds)];
103
- case 2:
104
- projects = _c.sent();
105
- if (!(projects === null || projects === void 0 ? void 0 : projects.length) || projects.length !== projectIds.length)
106
- throw new errors_1.ShipItError('Could not find all projects for the found merge requests');
107
- mappedProjects = projects.map(function (p) { return (__assign(__assign({}, p), { mergeRequests: mergeRequests.filter(function (mr) { return mr.projectId === p.id; }) })); });
108
- _i = 0, mappedProjects_1 = mappedProjects;
109
- _c.label = 3;
110
- case 3:
111
- if (!(_i < mappedProjects_1.length)) return [3 /*break*/, 6];
112
- mappedProject = mappedProjects_1[_i];
113
- return [4 /*yield*/, this.getExtraProjects(mappedProject, projectIds)];
114
- case 4:
115
- extraProjects = _c.sent();
116
- Array.prototype.push.apply(mappedProjects, extraProjects.map(function (p) { return (__assign(__assign({}, p), { mergeRequests: [] })); }));
117
- _c.label = 5;
118
- case 5:
119
- _i++;
120
- return [3 /*break*/, 3];
121
- case 6:
122
- /**
123
- * We need to filter our relevant projects after we've added extra projects via tags
124
- */
125
- if ((_a = options.projectIds) === null || _a === void 0 ? void 0 : _a.length) {
126
- mappedProjects = mappedProjects.filter(function (p) {
127
- var _a;
128
- return (_a = options.projectIds) === null || _a === void 0 ? void 0 : _a.some(function (pid) { return p.id.toString() === pid; });
129
- });
130
- }
131
- if ((_b = options.omittedProjectIds) === null || _b === void 0 ? void 0 : _b.length) {
132
- mappedProjects = mappedProjects.filter(function (p) {
133
- var _a;
134
- return !((_a = options.omittedProjectIds) === null || _a === void 0 ? void 0 : _a.some(function (pid) { return p.id.toString() === pid; }));
135
- });
136
- }
137
- return [2 /*return*/, (this.projects = mappedProjects)];
138
- }
139
- });
140
- });
141
- };
142
- /**
143
- * Fetches any projects that are not already included via MRs by checking the project labels.
144
- * We only do this for a whitelist of projects
145
- */
146
- GitLabService.prototype.getExtraProjects = function (project, existingProjectIds) {
147
- return __awaiter(this, void 0, void 0, function () {
148
- var labels, mrLabelNames, mrLabels, projectIds, extraProjectIds;
149
- return __generator(this, function (_a) {
150
- switch (_a.label) {
151
- case 0:
152
- if (!MONOREPO_IDS.includes(project.id.toString()))
153
- return [2 /*return*/, []];
154
- return [4 /*yield*/, this.getProjectLabels(project.id)];
155
- case 1:
156
- labels = _a.sent();
157
- mrLabelNames = lodash_1.default.chain(project.mergeRequests)
158
- .map(function (m) { return m.labels; })
159
- .flatten()
160
- .uniq()
161
- .value();
162
- mrLabels = lodash_1.default.intersection(labels.map(function (l) { return l.name; }), mrLabelNames);
163
- 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; });
164
- extraProjectIds = lodash_1.default.difference(projectIds, existingProjectIds.map(function (p) { return p.toString(); }));
165
- return [4 /*yield*/, this.apiClient.getProjectsByIds(extraProjectIds)];
166
- case 2:
167
- // fetches and returns the extra projects
168
- return [2 /*return*/, _a.sent()];
169
- }
170
- });
171
- });
172
- };
173
- /**
174
- * Gets labels that have a projectId as their description
175
- */
176
- GitLabService.prototype.getProjectLabels = function (projectId) {
177
- return __awaiter(this, void 0, void 0, function () {
178
- var labels;
179
- return __generator(this, function (_a) {
180
- switch (_a.label) {
181
- case 0: return [4 /*yield*/, this.apiClient.getLabels(projectId)];
182
- case 1:
183
- labels = _a.sent();
184
- return [2 /*return*/, labels.filter(function (l) {
185
- if (!l.description)
186
- return false;
187
- return !isNaN(+l.description);
188
- })];
189
- }
190
- });
191
- });
192
- };
193
- GitLabService.prototype.getProject = function (projectId) {
194
- return __awaiter(this, void 0, void 0, function () {
195
- var projects;
196
- return __generator(this, function (_a) {
197
- switch (_a.label) {
198
- case 0: return [4 /*yield*/, this.apiClient.getProjectsByIds([projectId])];
199
- case 1:
200
- projects = _a.sent();
201
- if (!projects.length)
202
- throw new errors_1.ShipItError("Could not find project projectId: ".concat(projectId));
203
- return [2 /*return*/, projects[0]];
204
- }
205
- });
206
- });
207
- };
208
- GitLabService.prototype.getCommitsForRelease = function (projectId, dateSince) {
209
- return __awaiter(this, void 0, void 0, function () {
210
- return __generator(this, function (_a) {
211
- switch (_a.label) {
212
- case 0: return [4 /*yield*/, this.apiClient.getCommitsForRelease(projectId, dateSince)];
213
- case 1: return [2 /*return*/, _a.sent()];
214
- }
215
- });
216
- });
217
- };
218
- GitLabService.prototype.getBranch = function (projectId, branchName) {
219
- return __awaiter(this, void 0, void 0, function () {
220
- return __generator(this, function (_a) {
221
- switch (_a.label) {
222
- case 0: return [4 /*yield*/, this.apiClient.getBranch(projectId, branchName)];
223
- case 1: return [2 /*return*/, _a.sent()];
224
- }
225
- });
226
- });
227
- };
228
- GitLabService.prototype.createBranch = function (project, branchFrom, branchName, cherryPick) {
229
- return __awaiter(this, void 0, void 0, function () {
230
- var newBranch, i, mr;
231
- return __generator(this, function (_a) {
232
- switch (_a.label) {
233
- case 0:
234
- if (!cherryPick) return [3 /*break*/, 6];
235
- return [4 /*yield*/, this.apiClient.createBranch(project.id, branchName, 'master')];
236
- case 1:
237
- newBranch = _a.sent();
238
- i = 0;
239
- _a.label = 2;
240
- case 2:
241
- if (!(i < project.mergeRequests.length)) return [3 /*break*/, 5];
242
- mr = project.mergeRequests[i];
243
- if (!mr.mergeCommit)
244
- throw new errors_1.ShipItError("Could not find the merge commit sha for MR: ".concat(mr.title, " in projectId: ").concat(project.id));
245
- return [4 /*yield*/, this.apiClient.cherryPick(project.id, mr.mergeCommit, branchName)];
246
- case 3:
247
- _a.sent();
248
- _a.label = 4;
249
- case 4:
250
- i++;
251
- return [3 /*break*/, 2];
252
- case 5: return [2 /*return*/, newBranch];
253
- case 6: return [4 /*yield*/, this.apiClient.createBranch(project.id, branchName, branchFrom)];
254
- case 7: return [2 /*return*/, _a.sent()];
255
- }
256
- });
257
- });
258
- };
259
- GitLabService.prototype.getMergeRequest = function (projectId, branchName, state) {
260
- return this.apiClient.getMergeRequest(projectId, branchName, 'master', state);
261
- };
262
- GitLabService.prototype.getMergeRequestById = function (projectId, mergeRequestId) {
263
- if (isNaN(+mergeRequestId))
264
- throw new errors_1.ShipItError("MergeRequest Id must be a number: ".concat(mergeRequestId));
265
- return this.apiClient.getMergeRequestById(projectId, +mergeRequestId);
266
- };
267
- GitLabService.prototype.createMergeRequest = function (projectId, branchName, targetBranch, title, description, milestoneName) {
268
- return __awaiter(this, void 0, void 0, function () {
269
- var milestone;
270
- return __generator(this, function (_a) {
271
- switch (_a.label) {
272
- case 0: return [4 /*yield*/, this.getMilestone(milestoneName, projectId)];
273
- case 1:
274
- milestone = _a.sent();
275
- return [2 /*return*/, this.apiClient.createMergeRequest(projectId, branchName, targetBranch, title, description, milestone)];
276
- }
277
- });
278
- });
279
- };
280
- GitLabService.prototype.AcceptMergeRequest = function (projectId, mergerequestIId) {
281
- return this.apiClient.AcceptMergeRequest(projectId, mergerequestIId);
282
- };
283
- GitLabService.prototype.getMilestone = function (milestoneName, projectId) {
284
- return this.apiClient.getMilestone(milestoneName, projectId);
285
- };
286
- GitLabService.prototype.getReleaseBranchNameMilestone = function (projectId, milestone) {
287
- return __awaiter(this, void 0, void 0, function () {
288
- var releaseMR;
289
- return __generator(this, function (_a) {
290
- switch (_a.label) {
291
- case 0: return [4 /*yield*/, this.apiClient.getReleaseMergeRequest(projectId, milestone)];
292
- case 1:
293
- releaseMR = _a.sent();
294
- if (!releaseMR)
295
- return [2 /*return*/, null];
296
- return [2 /*return*/, releaseMR.sourceBranch];
297
- }
298
- });
299
- });
300
- };
301
- GitLabService.prototype.getMilestoneByBranchName = function (projectId, branchName) {
302
- var _a, _b;
303
- return __awaiter(this, void 0, void 0, function () {
304
- var mergeRequest;
305
- return __generator(this, function (_c) {
306
- switch (_c.label) {
307
- case 0: return [4 /*yield*/, this.getMergeRequest(projectId, branchName, 'opened')];
308
- case 1:
309
- mergeRequest = _c.sent();
310
- if (!mergeRequest)
311
- throw new errors_1.ShipItError("No merge request in project \"monorepo\" with branch name \"".concat(branchName, "\" could be found."));
312
- if (!mergeRequest.milestone)
313
- 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));
314
- return [2 /*return*/, (_b = (_a = mergeRequest.milestone) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : ''];
315
- }
316
- });
317
- });
318
- };
319
- GitLabService.prototype.bumpVersionTxt = function (projectId, branchName, newVersion) {
320
- return __awaiter(this, void 0, void 0, function () {
321
- var versionTxt, buff, text;
322
- return __generator(this, function (_a) {
323
- switch (_a.label) {
324
- case 0: return [4 /*yield*/, this.apiClient.getFile(projectId, 'version.txt', branchName)];
325
- case 1:
326
- versionTxt = _a.sent();
327
- if (!versionTxt)
328
- return [2 /*return*/, false];
329
- buff = Buffer.from(versionTxt.content, 'base64');
330
- text = buff.toString('utf-8');
331
- if (text === newVersion)
332
- return [2 /*return*/, false];
333
- return [4 /*yield*/, this.apiClient.updateFile(projectId, 'version.txt', branchName, newVersion, 'Bumping version.txt')];
334
- case 2:
335
- _a.sent();
336
- return [2 /*return*/, true];
337
- }
338
- });
339
- });
340
- };
341
- GitLabService.prototype.getFile = function (projectId, branchName, file) {
342
- return __awaiter(this, void 0, void 0, function () {
343
- return __generator(this, function (_a) {
344
- switch (_a.label) {
345
- case 0: return [4 /*yield*/, this.apiClient.getFile(projectId, file, branchName)];
346
- case 1: return [2 /*return*/, _a.sent()];
347
- }
348
- });
349
- });
350
- };
351
- GitLabService.prototype.updateFile = function (projectId, filePath, branchName, content, commit) {
352
- return this.apiClient.updateFile(projectId, filePath, branchName, content, commit);
353
- };
354
- GitLabService.prototype.commit = function (projectId, branchName, commitMessage, files) {
355
- return __awaiter(this, void 0, void 0, function () {
356
- return __generator(this, function (_a) {
357
- switch (_a.label) {
358
- case 0: return [4 /*yield*/, this.apiClient.commit(projectId, branchName, files, commitMessage)];
359
- case 1:
360
- _a.sent();
361
- return [2 /*return*/];
362
- }
363
- });
364
- });
365
- };
366
- GitLabService.prototype.getTag = function (projectId, tagName) {
367
- return __awaiter(this, void 0, void 0, function () {
368
- return __generator(this, function (_a) {
369
- switch (_a.label) {
370
- case 0: return [4 /*yield*/, this.apiClient.getTag(projectId, tagName)];
371
- case 1: return [2 /*return*/, _a.sent()];
372
- }
373
- });
374
- });
375
- };
376
- GitLabService.prototype.createTag = function (projectId, tagName, sha) {
377
- return __awaiter(this, void 0, void 0, function () {
378
- return __generator(this, function (_a) {
379
- switch (_a.label) {
380
- case 0: return [4 /*yield*/, this.apiClient.createTag(projectId, tagName, sha)];
381
- case 1: return [2 /*return*/, _a.sent()];
382
- }
383
- });
384
- });
385
- };
386
- GitLabService.prototype.createRelease = function (projectId, release) {
387
- return __awaiter(this, void 0, void 0, function () {
388
- return __generator(this, function (_a) {
389
- switch (_a.label) {
390
- case 0: return [4 /*yield*/, this.apiClient.createRelease(projectId, release)];
391
- case 1: return [2 /*return*/, _a.sent()];
392
- }
393
- });
394
- });
395
- };
396
- /**
397
- * We use the latest valid semver tag in master to determine what the current version
398
- * of a project is
399
- */
400
- GitLabService.prototype.getCurrentMinorVersionTag = function (projectId) {
401
- return __awaiter(this, void 0, void 0, function () {
402
- var tags, tagNames, sortedTagNames, latestMinorVersion, currentTag;
403
- return __generator(this, function (_a) {
404
- switch (_a.label) {
405
- case 0: return [4 /*yield*/, this.apiClient.getLatestTags(projectId)];
406
- case 1:
407
- tags = _a.sent();
408
- if (!(tags === null || tags === void 0 ? void 0 : tags.length))
409
- throw new errors_1.ShipItError("Project ".concat(projectId, " does not have any tags"));
410
- tagNames = tags.map(function (t) { return t.name; }).filter(function (t) { return semver_1.default.valid(t); });
411
- if (!tagNames.length)
412
- return [2 /*return*/, null];
413
- sortedTagNames = semver_1.default.sort(tagNames).reverse();
414
- latestMinorVersion = sortedTagNames.find(function (tag) { return tag.endsWith('.0'); });
415
- currentTag = tags.find(function (t) { return t.name === latestMinorVersion; });
416
- if (!currentTag)
417
- return [2 /*return*/, null];
418
- return [2 /*return*/, currentTag];
419
- }
420
- });
421
- });
422
- };
423
- GitLabService.prototype.hasSomeTags = function (projectId) {
424
- return __awaiter(this, void 0, void 0, function () {
425
- var tags;
426
- return __generator(this, function (_a) {
427
- switch (_a.label) {
428
- case 0: return [4 /*yield*/, this.apiClient.getLatestTags(projectId)];
429
- case 1:
430
- tags = _a.sent();
431
- return [2 /*return*/, !!(tags === null || tags === void 0 ? void 0 : tags.length)];
432
- }
433
- });
434
- });
435
- };
436
- GitLabService.prototype.getNextBranchInfo = function (projectId, version) {
437
- return __awaiter(this, void 0, void 0, function () {
438
- var tag, nextVersion, branchName, branch;
439
- return __generator(this, function (_a) {
440
- switch (_a.label) {
441
- case 0: return [4 /*yield*/, this.getCurrentMinorVersionTag(projectId)];
442
- case 1:
443
- tag = _a.sent();
444
- if (!tag)
445
- throw new errors_1.ShipItError("Could not find the latest semver tag for projectId: ".concat(projectId));
446
- nextVersion = utils_1.Versions.getNextVersion(tag.name, version);
447
- branchName = version === 'patch' ?
448
- utils_1.BranchNames.getHotfix(nextVersion) :
449
- utils_1.BranchNames.getRelease(nextVersion);
450
- return [4 /*yield*/, this.getBranch(projectId, branchName)];
451
- case 2:
452
- branch = _a.sent();
453
- return [2 /*return*/, {
454
- nextVersion: nextVersion,
455
- branchName: branchName,
456
- branch: branch,
457
- tag: tag
458
- }];
459
- }
460
- });
461
- });
462
- };
463
- GitLabService.prototype.getProjectConfig = function (projectId, branchName) {
464
- return __awaiter(this, void 0, void 0, function () {
465
- var cacheKey, configFileName, configFile, buff, text, json, projectConfig;
466
- return __generator(this, function (_a) {
467
- switch (_a.label) {
468
- case 0:
469
- cacheKey = projectId + ':' + branchName;
470
- if (this.projectConfigCache[cacheKey])
471
- return [2 /*return*/, this.projectConfigCache[cacheKey]];
472
- configFileName = '.ship-it.config';
473
- return [4 /*yield*/, this.apiClient.getFile(projectId, configFileName, branchName)];
474
- case 1:
475
- configFile = _a.sent();
476
- if (!configFile)
477
- return [2 /*return*/, ProjectConfig_1.DefaultProjectConfig];
478
- try {
479
- buff = Buffer.from(configFile.content, 'base64');
480
- text = buff.toString('utf-8');
481
- json = JSON.parse(text);
482
- projectConfig = lodash_1.default.merge({}, ProjectConfig_1.DefaultProjectConfig, json);
483
- this.projectConfigCache[cacheKey] = projectConfig;
484
- return [2 /*return*/, projectConfig];
485
- }
486
- catch (_b) {
487
- throw new errors_1.ShipItError("Failed to parse ".concat(configFileName));
488
- }
489
- return [2 /*return*/];
490
- }
491
- });
492
- });
493
- };
494
- GitLabService.prototype.updateMilestone = function (projectId, mergeRequestID, newMilestoneId) {
495
- return __awaiter(this, void 0, void 0, function () {
496
- return __generator(this, function (_a) {
497
- return [2 /*return*/, this.apiClient.updateMilestone(projectId, mergeRequestID, newMilestoneId)];
498
- });
499
- });
500
- };
501
- GitLabService = __decorate([
502
- (0, inversify_1.injectable)(),
503
- __param(0, (0, inversify_1.inject)(types_1.API_CLIENTS.GitLabApiClient)),
504
- __metadata("design:paramtypes", [api_clients_1.GitLabApiClient])
505
- ], GitLabService);
506
- return GitLabService;
507
- }());
508
- exports.GitLabService = GitLabService;
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
+ };
13
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
14
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
16
+ 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;
17
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
18
+ };
19
+ var __metadata = (this && this.__metadata) || function (k, v) {
20
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
21
+ };
22
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
23
+ return function (target, key) { decorator(target, key, paramIndex); }
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (_) try {
41
+ 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;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ var __importDefault = (this && this.__importDefault) || function (mod) {
62
+ return (mod && mod.__esModule) ? mod : { "default": mod };
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.GitLabService = void 0;
66
+ require("reflect-metadata");
67
+ var inversify_1 = require("inversify");
68
+ var lodash_1 = __importDefault(require("lodash"));
69
+ var semver_1 = __importDefault(require("semver"));
70
+ var types_1 = require("../types");
71
+ var api_clients_1 = require("../api-clients");
72
+ var errors_1 = require("../errors");
73
+ var utils_1 = require("../utils");
74
+ var ProjectConfig_1 = require("../interfaces/models/ProjectConfig");
75
+ /**
76
+ * These are projects that will try to use tags to pull in extra projects
77
+ */
78
+ var MONOREPO_IDS = [
79
+ utils_1.ProjectIds.MONOREPO_PROJECT_ID
80
+ ];
81
+ var GitLabService = /** @class */ (function () {
82
+ function GitLabService(apiClient) {
83
+ this.projectConfigCache = {};
84
+ this.apiClient = apiClient;
85
+ }
86
+ GitLabService.prototype.getProjects = function (options) {
87
+ var _a, _b;
88
+ return __awaiter(this, void 0, void 0, function () {
89
+ var allMergeRequests, mergeRequests, projectIds, projects, mappedProjects, _i, mappedProjects_1, mappedProject, extraProjects;
90
+ return __generator(this, function (_c) {
91
+ switch (_c.label) {
92
+ case 0:
93
+ if (this.projects)
94
+ return [2 /*return*/, this.projects];
95
+ return [4 /*yield*/, this.apiClient.getMergeRequests(options)];
96
+ case 1:
97
+ allMergeRequests = _c.sent();
98
+ mergeRequests = allMergeRequests.filter(function (mr) { return mr.targetBranch !== 'master'; });
99
+ if (!(mergeRequests === null || mergeRequests === void 0 ? void 0 : mergeRequests.length))
100
+ throw new errors_1.ShipItError('Could not find any merge requests for the specified options');
101
+ projectIds = lodash_1.default.uniqBy(mergeRequests, function (m) { return m.projectId; }).map(function (m) { return m.projectId; });
102
+ return [4 /*yield*/, this.apiClient.getProjectsByIds(projectIds)];
103
+ case 2:
104
+ projects = _c.sent();
105
+ if (!(projects === null || projects === void 0 ? void 0 : projects.length) || projects.length !== projectIds.length)
106
+ throw new errors_1.ShipItError('Could not find all projects for the found merge requests');
107
+ mappedProjects = projects.map(function (p) { return (__assign(__assign({}, p), { mergeRequests: mergeRequests.filter(function (mr) { return mr.projectId === p.id; }) })); });
108
+ _i = 0, mappedProjects_1 = mappedProjects;
109
+ _c.label = 3;
110
+ case 3:
111
+ if (!(_i < mappedProjects_1.length)) return [3 /*break*/, 6];
112
+ mappedProject = mappedProjects_1[_i];
113
+ return [4 /*yield*/, this.getExtraProjects(mappedProject, projectIds)];
114
+ case 4:
115
+ extraProjects = _c.sent();
116
+ Array.prototype.push.apply(mappedProjects, extraProjects.map(function (p) { return (__assign(__assign({}, p), { mergeRequests: [] })); }));
117
+ _c.label = 5;
118
+ case 5:
119
+ _i++;
120
+ return [3 /*break*/, 3];
121
+ case 6:
122
+ /**
123
+ * We need to filter our relevant projects after we've added extra projects via tags
124
+ */
125
+ if ((_a = options.projectIds) === null || _a === void 0 ? void 0 : _a.length) {
126
+ mappedProjects = mappedProjects.filter(function (p) {
127
+ var _a;
128
+ return (_a = options.projectIds) === null || _a === void 0 ? void 0 : _a.some(function (pid) { return p.id.toString() === pid; });
129
+ });
130
+ }
131
+ if ((_b = options.omittedProjectIds) === null || _b === void 0 ? void 0 : _b.length) {
132
+ mappedProjects = mappedProjects.filter(function (p) {
133
+ var _a;
134
+ return !((_a = options.omittedProjectIds) === null || _a === void 0 ? void 0 : _a.some(function (pid) { return p.id.toString() === pid; }));
135
+ });
136
+ }
137
+ return [2 /*return*/, (this.projects = mappedProjects)];
138
+ }
139
+ });
140
+ });
141
+ };
142
+ /**
143
+ * Fetches any projects that are not already included via MRs by checking the project labels.
144
+ * We only do this for a whitelist of projects
145
+ */
146
+ GitLabService.prototype.getExtraProjects = function (project, existingProjectIds) {
147
+ return __awaiter(this, void 0, void 0, function () {
148
+ var labels, mrLabelNames, mrLabels, projectIds, extraProjectIds;
149
+ return __generator(this, function (_a) {
150
+ switch (_a.label) {
151
+ case 0:
152
+ if (!MONOREPO_IDS.includes(project.id.toString()))
153
+ return [2 /*return*/, []];
154
+ return [4 /*yield*/, this.getProjectLabels(project.id)];
155
+ case 1:
156
+ labels = _a.sent();
157
+ mrLabelNames = lodash_1.default.chain(project.mergeRequests)
158
+ .map(function (m) { return m.labels; })
159
+ .flatten()
160
+ .uniq()
161
+ .value();
162
+ mrLabels = lodash_1.default.intersection(labels.map(function (l) { return l.name; }), mrLabelNames);
163
+ 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; });
164
+ extraProjectIds = lodash_1.default.difference(projectIds, existingProjectIds.map(function (p) { return p.toString(); }));
165
+ return [4 /*yield*/, this.apiClient.getProjectsByIds(extraProjectIds)];
166
+ case 2:
167
+ // fetches and returns the extra projects
168
+ return [2 /*return*/, _a.sent()];
169
+ }
170
+ });
171
+ });
172
+ };
173
+ /**
174
+ * Gets labels that have a projectId as their description
175
+ */
176
+ GitLabService.prototype.getProjectLabels = function (projectId) {
177
+ return __awaiter(this, void 0, void 0, function () {
178
+ var labels;
179
+ return __generator(this, function (_a) {
180
+ switch (_a.label) {
181
+ case 0: return [4 /*yield*/, this.apiClient.getLabels(projectId)];
182
+ case 1:
183
+ labels = _a.sent();
184
+ return [2 /*return*/, labels.filter(function (l) {
185
+ if (!l.description)
186
+ return false;
187
+ return !isNaN(+l.description);
188
+ })];
189
+ }
190
+ });
191
+ });
192
+ };
193
+ GitLabService.prototype.getProject = function (projectId) {
194
+ return __awaiter(this, void 0, void 0, function () {
195
+ var projects;
196
+ return __generator(this, function (_a) {
197
+ switch (_a.label) {
198
+ case 0: return [4 /*yield*/, this.apiClient.getProjectsByIds([projectId])];
199
+ case 1:
200
+ projects = _a.sent();
201
+ if (!projects.length)
202
+ throw new errors_1.ShipItError("Could not find project projectId: ".concat(projectId));
203
+ return [2 /*return*/, projects[0]];
204
+ }
205
+ });
206
+ });
207
+ };
208
+ GitLabService.prototype.getCommitsForRelease = function (projectId, dateSince) {
209
+ return __awaiter(this, void 0, void 0, function () {
210
+ return __generator(this, function (_a) {
211
+ switch (_a.label) {
212
+ case 0: return [4 /*yield*/, this.apiClient.getCommitsForRelease(projectId, dateSince)];
213
+ case 1: return [2 /*return*/, _a.sent()];
214
+ }
215
+ });
216
+ });
217
+ };
218
+ GitLabService.prototype.getBranch = function (projectId, branchName) {
219
+ return __awaiter(this, void 0, void 0, function () {
220
+ return __generator(this, function (_a) {
221
+ switch (_a.label) {
222
+ case 0: return [4 /*yield*/, this.apiClient.getBranch(projectId, branchName)];
223
+ case 1: return [2 /*return*/, _a.sent()];
224
+ }
225
+ });
226
+ });
227
+ };
228
+ GitLabService.prototype.createBranch = function (project, branchFrom, branchName, cherryPick) {
229
+ return __awaiter(this, void 0, void 0, function () {
230
+ var newBranch, i, mr;
231
+ return __generator(this, function (_a) {
232
+ switch (_a.label) {
233
+ case 0:
234
+ if (!cherryPick) return [3 /*break*/, 6];
235
+ return [4 /*yield*/, this.apiClient.createBranch(project.id, branchName, 'master')];
236
+ case 1:
237
+ newBranch = _a.sent();
238
+ i = 0;
239
+ _a.label = 2;
240
+ case 2:
241
+ if (!(i < project.mergeRequests.length)) return [3 /*break*/, 5];
242
+ mr = project.mergeRequests[i];
243
+ if (!mr.mergeCommit)
244
+ throw new errors_1.ShipItError("Could not find the merge commit sha for MR: ".concat(mr.title, " in projectId: ").concat(project.id));
245
+ return [4 /*yield*/, this.apiClient.cherryPick(project.id, mr.mergeCommit, branchName)];
246
+ case 3:
247
+ _a.sent();
248
+ _a.label = 4;
249
+ case 4:
250
+ i++;
251
+ return [3 /*break*/, 2];
252
+ case 5: return [2 /*return*/, newBranch];
253
+ case 6: return [4 /*yield*/, this.apiClient.createBranch(project.id, branchName, branchFrom)];
254
+ case 7: return [2 /*return*/, _a.sent()];
255
+ }
256
+ });
257
+ });
258
+ };
259
+ GitLabService.prototype.getMergeRequest = function (projectId, branchName, state) {
260
+ return this.apiClient.getMergeRequest(projectId, branchName, 'master', state);
261
+ };
262
+ GitLabService.prototype.getMergeRequestById = function (projectId, mergeRequestId) {
263
+ if (isNaN(+mergeRequestId))
264
+ throw new errors_1.ShipItError("MergeRequest Id must be a number: ".concat(mergeRequestId));
265
+ return this.apiClient.getMergeRequestById(projectId, +mergeRequestId);
266
+ };
267
+ GitLabService.prototype.createMergeRequest = function (projectId, branchName, targetBranch, title, description, milestoneName) {
268
+ return __awaiter(this, void 0, void 0, function () {
269
+ var milestone;
270
+ return __generator(this, function (_a) {
271
+ switch (_a.label) {
272
+ case 0: return [4 /*yield*/, this.getMilestone(milestoneName, projectId)];
273
+ case 1:
274
+ milestone = _a.sent();
275
+ return [2 /*return*/, this.apiClient.createMergeRequest(projectId, branchName, targetBranch, title, description, milestone)];
276
+ }
277
+ });
278
+ });
279
+ };
280
+ GitLabService.prototype.AcceptMergeRequest = function (projectId, mergerequestIId) {
281
+ return this.apiClient.AcceptMergeRequest(projectId, mergerequestIId);
282
+ };
283
+ GitLabService.prototype.getMilestone = function (milestoneName, projectId) {
284
+ return this.apiClient.getMilestone(milestoneName, projectId);
285
+ };
286
+ GitLabService.prototype.getReleaseBranchNameMilestone = function (projectId, milestone) {
287
+ return __awaiter(this, void 0, void 0, function () {
288
+ var releaseMR;
289
+ return __generator(this, function (_a) {
290
+ switch (_a.label) {
291
+ case 0: return [4 /*yield*/, this.apiClient.getReleaseMergeRequest(projectId, milestone)];
292
+ case 1:
293
+ releaseMR = _a.sent();
294
+ if (!releaseMR)
295
+ return [2 /*return*/, null];
296
+ return [2 /*return*/, releaseMR.sourceBranch];
297
+ }
298
+ });
299
+ });
300
+ };
301
+ GitLabService.prototype.getMilestoneByBranchName = function (projectId, branchName) {
302
+ var _a, _b;
303
+ return __awaiter(this, void 0, void 0, function () {
304
+ var mergeRequest;
305
+ return __generator(this, function (_c) {
306
+ switch (_c.label) {
307
+ case 0: return [4 /*yield*/, this.getMergeRequest(projectId, branchName, 'opened')];
308
+ case 1:
309
+ mergeRequest = _c.sent();
310
+ if (!mergeRequest)
311
+ throw new errors_1.ShipItError("No merge request in project \"monorepo\" with branch name \"".concat(branchName, "\" could be found."));
312
+ if (!mergeRequest.milestone)
313
+ 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));
314
+ return [2 /*return*/, (_b = (_a = mergeRequest.milestone) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : ''];
315
+ }
316
+ });
317
+ });
318
+ };
319
+ GitLabService.prototype.bumpVersionTxt = function (projectId, branchName, newVersion) {
320
+ return __awaiter(this, void 0, void 0, function () {
321
+ var versionTxt, buff, text;
322
+ return __generator(this, function (_a) {
323
+ switch (_a.label) {
324
+ case 0: return [4 /*yield*/, this.apiClient.getFile(projectId, 'version.txt', branchName)];
325
+ case 1:
326
+ versionTxt = _a.sent();
327
+ if (!versionTxt)
328
+ return [2 /*return*/, false];
329
+ buff = Buffer.from(versionTxt.content, 'base64');
330
+ text = buff.toString('utf-8');
331
+ if (text === newVersion)
332
+ return [2 /*return*/, false];
333
+ return [4 /*yield*/, this.apiClient.updateFile(projectId, 'version.txt', branchName, newVersion, 'Bumping version.txt')];
334
+ case 2:
335
+ _a.sent();
336
+ return [2 /*return*/, true];
337
+ }
338
+ });
339
+ });
340
+ };
341
+ GitLabService.prototype.getFile = function (projectId, branchName, file) {
342
+ return __awaiter(this, void 0, void 0, function () {
343
+ return __generator(this, function (_a) {
344
+ switch (_a.label) {
345
+ case 0: return [4 /*yield*/, this.apiClient.getFile(projectId, file, branchName)];
346
+ case 1: return [2 /*return*/, _a.sent()];
347
+ }
348
+ });
349
+ });
350
+ };
351
+ GitLabService.prototype.updateFile = function (projectId, filePath, branchName, content, commit) {
352
+ return this.apiClient.updateFile(projectId, filePath, branchName, content, commit);
353
+ };
354
+ GitLabService.prototype.commit = function (projectId, branchName, commitMessage, files) {
355
+ return __awaiter(this, void 0, void 0, function () {
356
+ return __generator(this, function (_a) {
357
+ switch (_a.label) {
358
+ case 0: return [4 /*yield*/, this.apiClient.commit(projectId, branchName, files, commitMessage)];
359
+ case 1:
360
+ _a.sent();
361
+ return [2 /*return*/];
362
+ }
363
+ });
364
+ });
365
+ };
366
+ GitLabService.prototype.getTag = function (projectId, tagName) {
367
+ return __awaiter(this, void 0, void 0, function () {
368
+ return __generator(this, function (_a) {
369
+ switch (_a.label) {
370
+ case 0: return [4 /*yield*/, this.apiClient.getTag(projectId, tagName)];
371
+ case 1: return [2 /*return*/, _a.sent()];
372
+ }
373
+ });
374
+ });
375
+ };
376
+ GitLabService.prototype.createTag = function (projectId, tagName, sha) {
377
+ return __awaiter(this, void 0, void 0, function () {
378
+ return __generator(this, function (_a) {
379
+ switch (_a.label) {
380
+ case 0: return [4 /*yield*/, this.apiClient.createTag(projectId, tagName, sha)];
381
+ case 1: return [2 /*return*/, _a.sent()];
382
+ }
383
+ });
384
+ });
385
+ };
386
+ GitLabService.prototype.createRelease = function (projectId, release) {
387
+ return __awaiter(this, void 0, void 0, function () {
388
+ return __generator(this, function (_a) {
389
+ switch (_a.label) {
390
+ case 0: return [4 /*yield*/, this.apiClient.createRelease(projectId, release)];
391
+ case 1: return [2 /*return*/, _a.sent()];
392
+ }
393
+ });
394
+ });
395
+ };
396
+ /**
397
+ * We use the latest valid semver tag in master to determine what the current version
398
+ * of a project is
399
+ */
400
+ GitLabService.prototype.getCurrentMinorVersionTag = function (projectId) {
401
+ return __awaiter(this, void 0, void 0, function () {
402
+ var tags, tagNames, sortedTagNames, latestMinorVersion, currentTag;
403
+ return __generator(this, function (_a) {
404
+ switch (_a.label) {
405
+ case 0: return [4 /*yield*/, this.apiClient.getLatestTags(projectId)];
406
+ case 1:
407
+ tags = _a.sent();
408
+ if (!(tags === null || tags === void 0 ? void 0 : tags.length))
409
+ throw new errors_1.ShipItError("Project ".concat(projectId, " does not have any tags"));
410
+ tagNames = tags.map(function (t) { return t.name; }).filter(function (t) { return semver_1.default.valid(t); });
411
+ if (!tagNames.length)
412
+ return [2 /*return*/, null];
413
+ sortedTagNames = semver_1.default.sort(tagNames).reverse();
414
+ latestMinorVersion = sortedTagNames.find(function (tag) { return tag.endsWith('.0'); });
415
+ currentTag = tags.find(function (t) { return t.name === latestMinorVersion; });
416
+ if (!currentTag)
417
+ return [2 /*return*/, null];
418
+ return [2 /*return*/, currentTag];
419
+ }
420
+ });
421
+ });
422
+ };
423
+ GitLabService.prototype.hasSomeTags = function (projectId) {
424
+ return __awaiter(this, void 0, void 0, function () {
425
+ var tags;
426
+ return __generator(this, function (_a) {
427
+ switch (_a.label) {
428
+ case 0: return [4 /*yield*/, this.apiClient.getLatestTags(projectId)];
429
+ case 1:
430
+ tags = _a.sent();
431
+ return [2 /*return*/, !!(tags === null || tags === void 0 ? void 0 : tags.length)];
432
+ }
433
+ });
434
+ });
435
+ };
436
+ GitLabService.prototype.getNextBranchInfo = function (projectId, version) {
437
+ return __awaiter(this, void 0, void 0, function () {
438
+ var tag, nextVersion, branchName, branch;
439
+ return __generator(this, function (_a) {
440
+ switch (_a.label) {
441
+ case 0: return [4 /*yield*/, this.getCurrentMinorVersionTag(projectId)];
442
+ case 1:
443
+ tag = _a.sent();
444
+ if (!tag)
445
+ throw new errors_1.ShipItError("Could not find the latest semver tag for projectId: ".concat(projectId));
446
+ nextVersion = utils_1.Versions.getNextVersion(tag.name, version);
447
+ branchName = version === 'patch' ?
448
+ utils_1.BranchNames.getHotfix(nextVersion) :
449
+ utils_1.BranchNames.getRelease(nextVersion);
450
+ return [4 /*yield*/, this.getBranch(projectId, branchName)];
451
+ case 2:
452
+ branch = _a.sent();
453
+ return [2 /*return*/, {
454
+ nextVersion: nextVersion,
455
+ branchName: branchName,
456
+ branch: branch,
457
+ tag: tag
458
+ }];
459
+ }
460
+ });
461
+ });
462
+ };
463
+ GitLabService.prototype.getProjectConfig = function (projectId, branchName) {
464
+ return __awaiter(this, void 0, void 0, function () {
465
+ var cacheKey, configFileName, configFile, buff, text, json, projectConfig;
466
+ return __generator(this, function (_a) {
467
+ switch (_a.label) {
468
+ case 0:
469
+ cacheKey = projectId + ':' + branchName;
470
+ if (this.projectConfigCache[cacheKey])
471
+ return [2 /*return*/, this.projectConfigCache[cacheKey]];
472
+ configFileName = '.ship-it.config';
473
+ return [4 /*yield*/, this.apiClient.getFile(projectId, configFileName, branchName)];
474
+ case 1:
475
+ configFile = _a.sent();
476
+ if (!configFile)
477
+ return [2 /*return*/, ProjectConfig_1.DefaultProjectConfig];
478
+ try {
479
+ buff = Buffer.from(configFile.content, 'base64');
480
+ text = buff.toString('utf-8');
481
+ json = JSON.parse(text);
482
+ projectConfig = lodash_1.default.merge({}, ProjectConfig_1.DefaultProjectConfig, json);
483
+ this.projectConfigCache[cacheKey] = projectConfig;
484
+ return [2 /*return*/, projectConfig];
485
+ }
486
+ catch (_b) {
487
+ throw new errors_1.ShipItError("Failed to parse ".concat(configFileName));
488
+ }
489
+ return [2 /*return*/];
490
+ }
491
+ });
492
+ });
493
+ };
494
+ GitLabService.prototype.updateMilestone = function (projectId, mergeRequestID, newMilestoneId) {
495
+ return __awaiter(this, void 0, void 0, function () {
496
+ return __generator(this, function (_a) {
497
+ return [2 /*return*/, this.apiClient.updateMilestone(projectId, mergeRequestID, newMilestoneId)];
498
+ });
499
+ });
500
+ };
501
+ GitLabService = __decorate([
502
+ (0, inversify_1.injectable)(),
503
+ __param(0, (0, inversify_1.inject)(types_1.API_CLIENTS.GitLabApiClient)),
504
+ __metadata("design:paramtypes", [api_clients_1.GitLabApiClient])
505
+ ], GitLabService);
506
+ return GitLabService;
507
+ }());
508
+ exports.GitLabService = GitLabService;