@clickview/ship-it 0.0.25 → 0.0.26

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 (109) hide show
  1. package/Dockerfile +33 -0
  2. package/README.md +48 -48
  3. package/config.json +19 -10
  4. package/lib/config.json +20 -11
  5. package/lib/src/api-clients/git-lab/GitLabApiClient.js +404 -404
  6. package/lib/src/api-clients/git-lab/GitLabMapper.js +81 -81
  7. package/lib/src/api-clients/index.js +20 -18
  8. package/lib/src/api-clients/slack/SlackApiClient.js +206 -0
  9. package/lib/src/api-clients/team-city/TeamCityApiClient.js +100 -100
  10. package/lib/src/api-clients/trello/TrelloApiClient.js +145 -0
  11. package/lib/src/commands/BumpPackagesCommand.js +84 -84
  12. package/lib/src/commands/CreateBranchCommand.js +100 -100
  13. package/lib/src/commands/CreateMergeRequestCommand.js +107 -107
  14. package/lib/src/commands/CreateReleaseNotesCommand.js +84 -84
  15. package/lib/src/commands/CreateTestingNotesCommand.js +84 -84
  16. package/lib/src/commands/{StartConsumingProjectBuildsCommand.js → CreateTrelloCardsCommand.js} +77 -76
  17. package/lib/src/commands/InstallPackagesCommand.js +76 -76
  18. package/lib/src/commands/ListProjectsCommand.js +76 -76
  19. package/lib/src/commands/ReleaseCommand.js +129 -129
  20. package/lib/src/commands/StartProjectBuildsCommand.js +76 -76
  21. package/lib/src/commands/StatusCommand.js +88 -88
  22. package/lib/src/commands/TagMasterCommand.js +76 -76
  23. package/lib/src/commands/ValidateMergeRequestCommand.js +76 -76
  24. package/lib/src/commands/VersionCommand.js +76 -76
  25. package/lib/src/commands/index.js +30 -29
  26. package/lib/src/constants/CommandTypeMapping.js +20 -19
  27. package/lib/src/constants/GitLabMemberIds.js +6 -6
  28. package/lib/src/constants/MonorepoPackageJsonFiles.js +17 -17
  29. package/lib/src/constants/MonorepoProjectNames.js +16 -16
  30. package/lib/src/constants/ProjectNames.js +67 -67
  31. package/lib/src/constants/SlackUserEmailList.js +13 -0
  32. package/lib/src/constants/TeamCityBuildIDs.js +44 -44
  33. package/lib/src/constants/index.js +19 -19
  34. package/lib/src/errors/ShipItError.js +32 -32
  35. package/lib/src/errors/index.js +17 -17
  36. package/lib/src/index.js +18 -18
  37. package/lib/src/interfaces/Config.js +2 -2
  38. package/lib/src/interfaces/MergeRequestState.js +2 -2
  39. package/lib/src/interfaces/ProjectNames.js +2 -2
  40. package/lib/src/interfaces/ShipItCommand.js +2 -2
  41. package/lib/src/interfaces/ShipItTask.js +2 -2
  42. package/lib/src/interfaces/VersionType.js +2 -2
  43. package/lib/src/interfaces/command-cli-options/MilestoneCommandCliOptions.js +2 -2
  44. package/lib/src/interfaces/command-cli-options/ReleaseCommandCliOptions.js +2 -2
  45. package/lib/src/interfaces/command-cli-options/StatusCommandCliOptions.js +2 -0
  46. package/lib/src/interfaces/command-cli-options/index.js +19 -18
  47. package/lib/src/interfaces/command-options/BaseCommandOptions.js +2 -2
  48. package/lib/src/interfaces/command-options/BumpPackagesCommandOptions.js +2 -2
  49. package/lib/src/interfaces/command-options/DockerMilestoneCommandOptions.js +2 -2
  50. package/lib/src/interfaces/command-options/MilestoneCommandOptions.js +2 -2
  51. package/lib/src/interfaces/command-options/ReleaseCommandOptions.js +2 -2
  52. package/lib/src/interfaces/command-options/StatusCommandOptions.js +2 -0
  53. package/lib/src/interfaces/command-options/ValidateMRCommandOptions.js +2 -2
  54. package/lib/src/interfaces/command-options/index.js +22 -21
  55. package/lib/src/interfaces/index.js +26 -26
  56. package/lib/src/interfaces/models/Branch.js +2 -2
  57. package/lib/src/interfaces/models/Commit.js +2 -2
  58. package/lib/src/interfaces/models/CommitFile.js +2 -2
  59. package/lib/src/interfaces/models/File.js +2 -2
  60. package/lib/src/interfaces/models/Label.js +2 -2
  61. package/lib/src/interfaces/models/MergeRequest.js +2 -2
  62. package/lib/src/interfaces/models/Milestone.js +2 -2
  63. package/lib/src/interfaces/models/Project.js +2 -2
  64. package/lib/src/interfaces/models/ProjectConfig.js +9 -9
  65. package/lib/src/interfaces/models/Release.js +2 -2
  66. package/lib/src/interfaces/models/Tag.js +2 -2
  67. package/lib/src/interfaces/models/index.js +26 -26
  68. package/lib/src/interfaces/view-models/MilestoneProject.js +2 -2
  69. package/lib/src/interfaces/view-models/index.js +17 -17
  70. package/lib/src/inversify.config.js +75 -67
  71. package/lib/src/services/GitLabService.js +498 -498
  72. package/lib/src/services/SlackService.js +142 -0
  73. package/lib/src/services/TeamCityService.js +37 -37
  74. package/lib/src/services/TrelloService.js +84 -0
  75. package/lib/src/services/index.js +20 -18
  76. package/lib/src/startup/AddMilestoneCommand.js +95 -95
  77. package/lib/src/startup/GetAction.js +68 -68
  78. package/lib/src/startup/SetupCommands.js +166 -128
  79. package/lib/src/tasks/BumpPackagesTask.js +229 -229
  80. package/lib/src/tasks/BumpVersionTxtTask.js +110 -110
  81. package/lib/src/tasks/CommitPackageVersionsTask.js +116 -116
  82. package/lib/src/tasks/CreateBranchTask.js +104 -104
  83. package/lib/src/tasks/CreateMergeRequestTask.js +118 -118
  84. package/lib/src/tasks/CreateReleaseNotesTask.js +144 -122
  85. package/lib/src/tasks/CreateTestingNotesTask.js +135 -135
  86. package/lib/src/tasks/InstallPackagesTask.js +407 -407
  87. package/lib/src/tasks/ListProjectsTask.js +87 -87
  88. package/lib/src/tasks/PopulateTrelloBoardTask.js +140 -0
  89. package/lib/src/tasks/StartMonorepoBuildTask.js +109 -109
  90. package/lib/src/tasks/StartProjectBuildsTask.js +149 -149
  91. package/lib/src/tasks/TagMasterTask.js +121 -121
  92. package/lib/src/tasks/ValidateCommitsTask.js +143 -119
  93. package/lib/src/tasks/ValidateDescriptionsTask.js +178 -151
  94. package/lib/src/tasks/ValidateMergeRequestTask.js +115 -115
  95. package/lib/src/tasks/ValidateTask.js +344 -240
  96. package/lib/src/tasks/VersionTask.js +98 -98
  97. package/lib/src/tasks/index.js +34 -33
  98. package/lib/src/types.js +57 -49
  99. package/lib/src/utils/BranchNames.js +11 -11
  100. package/lib/src/utils/Commits.js +55 -55
  101. package/lib/src/utils/Csv.js +54 -54
  102. package/lib/src/utils/Descriptions.js +237 -237
  103. package/lib/src/utils/GroupIds.js +6 -6
  104. package/lib/src/utils/Logger.js +62 -62
  105. package/lib/src/utils/ProjectIds.js +47 -47
  106. package/lib/src/utils/Versions.js +20 -20
  107. package/lib/src/utils/index.js +22 -22
  108. package/package.json +50 -47
  109. package/lib/src/tasks/StartConsumingProjectBuildsTask.js +0 -149
@@ -1,404 +1,404 @@
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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
- var __generator = (this && this.__generator) || function (thisArg, body) {
24
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
25
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
26
- function verb(n) { return function (v) { return step([n, v]); }; }
27
- function step(op) {
28
- if (f) throw new TypeError("Generator is already executing.");
29
- while (_) try {
30
- 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;
31
- if (y = 0, t) op = [op[0] & 2, t.value];
32
- switch (op[0]) {
33
- case 0: case 1: t = op; break;
34
- case 4: _.label++; return { value: op[1], done: false };
35
- case 5: _.label++; y = op[1]; op = [0]; continue;
36
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
37
- default:
38
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
39
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
40
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
41
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
42
- if (t[2]) _.ops.pop();
43
- _.trys.pop(); continue;
44
- }
45
- op = body.call(thisArg, _);
46
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
47
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
- }
49
- };
50
- Object.defineProperty(exports, "__esModule", { value: true });
51
- exports.GitLabApiClient = void 0;
52
- require("reflect-metadata");
53
- var inversify_1 = require("inversify");
54
- var node_1 = require("@gitbeaker/node");
55
- var types_1 = require("../../types");
56
- var errors_1 = require("../../errors");
57
- var GitLabMapper_1 = require("./GitLabMapper");
58
- var GroupIds_1 = require("../../utils/GroupIds");
59
- var GitLabMemberIds_1 = require("../../constants/GitLabMemberIds");
60
- var GitLabApiClient = /** @class */ (function () {
61
- function GitLabApiClient(config) {
62
- this.config = config;
63
- this.client = new node_1.Gitlab({
64
- token: this.config.accessToken,
65
- host: this.config.url
66
- });
67
- }
68
- GitLabApiClient.prototype.getMergeRequests = function (options) {
69
- return __awaiter(this, void 0, void 0, function () {
70
- var milestone, projectIds, mergeRequests;
71
- return __generator(this, function (_a) {
72
- switch (_a.label) {
73
- case 0:
74
- milestone = options.milestone, projectIds = options.projectIds;
75
- if (!milestone && !(projectIds === null || projectIds === void 0 ? void 0 : projectIds.length))
76
- throw new errors_1.ShipItError('Must specify one of the following: Milestone or ProjectIds');
77
- return [4 /*yield*/, this.client.MergeRequests.all({
78
- milestone: milestone,
79
- scope: 'all'
80
- })];
81
- case 1:
82
- mergeRequests = _a.sent();
83
- return [2 /*return*/, mergeRequests.map(GitLabMapper_1.GitLabMapper.mergeRequest)];
84
- }
85
- });
86
- });
87
- };
88
- GitLabApiClient.prototype.getProjectsByIds = function (projectIds) {
89
- return __awaiter(this, void 0, void 0, function () {
90
- var promises, projects;
91
- var _this = this;
92
- return __generator(this, function (_a) {
93
- switch (_a.label) {
94
- case 0:
95
- promises = projectIds.map(function (p) { return _this.client.Projects.show(p); });
96
- return [4 /*yield*/, Promise.all(promises)];
97
- case 1:
98
- projects = _a.sent();
99
- return [2 /*return*/, projects.map(GitLabMapper_1.GitLabMapper.project)];
100
- }
101
- });
102
- });
103
- };
104
- GitLabApiClient.prototype.getLatestTags = function (projectId) {
105
- return __awaiter(this, void 0, void 0, function () {
106
- var tags;
107
- return __generator(this, function (_a) {
108
- switch (_a.label) {
109
- case 0: return [4 /*yield*/, this.client.Tags.all(projectId, { maxPages: 1, perPage: 20 })];
110
- case 1:
111
- tags = _a.sent();
112
- return [2 /*return*/, tags.map(GitLabMapper_1.GitLabMapper.tag)];
113
- }
114
- });
115
- });
116
- };
117
- GitLabApiClient.prototype.getTag = function (projectId, tagName) {
118
- return __awaiter(this, void 0, void 0, function () {
119
- var tag, _a;
120
- return __generator(this, function (_b) {
121
- switch (_b.label) {
122
- case 0:
123
- _b.trys.push([0, 2, , 3]);
124
- return [4 /*yield*/, this.client.Tags.show(projectId, tagName)];
125
- case 1:
126
- tag = _b.sent();
127
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.tag(tag)];
128
- case 2:
129
- _a = _b.sent();
130
- return [2 /*return*/, null];
131
- case 3: return [2 /*return*/];
132
- }
133
- });
134
- });
135
- };
136
- GitLabApiClient.prototype.createTag = function (projectId, tagName, sha) {
137
- return __awaiter(this, void 0, void 0, function () {
138
- var tag;
139
- return __generator(this, function (_a) {
140
- switch (_a.label) {
141
- case 0: return [4 /*yield*/, this.client.Tags.create(projectId, tagName, sha)];
142
- case 1:
143
- tag = _a.sent();
144
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.tag(tag)];
145
- }
146
- });
147
- });
148
- };
149
- GitLabApiClient.prototype.createRelease = function (projectId, release) {
150
- return __awaiter(this, void 0, void 0, function () {
151
- var newRelease;
152
- return __generator(this, function (_a) {
153
- switch (_a.label) {
154
- case 0: return [4 /*yield*/, this.client.Releases.create(projectId, {
155
- id: projectId,
156
- name: release.name,
157
- tag_name: release.tag,
158
- description: release.description,
159
- ref: release.ref
160
- })];
161
- case 1:
162
- newRelease = _a.sent();
163
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.release(newRelease)];
164
- }
165
- });
166
- });
167
- };
168
- GitLabApiClient.prototype.getCommitsForRelease = function (projectId, dateSince) {
169
- return __awaiter(this, void 0, void 0, function () {
170
- var commits;
171
- return __generator(this, function (_a) {
172
- switch (_a.label) {
173
- case 0: return [4 /*yield*/, this.client.Commits.all(projectId, {
174
- ref_name: 'dev',
175
- since: dateSince,
176
- /**
177
- * This allows us to get merge commits of MRs being accepted
178
- */
179
- first_parent: true
180
- })];
181
- case 1:
182
- commits = _a.sent();
183
- return [2 /*return*/, commits.map(GitLabMapper_1.GitLabMapper.commit)];
184
- }
185
- });
186
- });
187
- };
188
- GitLabApiClient.prototype.getBranch = function (projectId, branchName) {
189
- return __awaiter(this, void 0, void 0, function () {
190
- var branch, _a;
191
- return __generator(this, function (_b) {
192
- switch (_b.label) {
193
- case 0:
194
- _b.trys.push([0, 2, , 3]);
195
- return [4 /*yield*/, this.client.Branches.show(projectId, branchName)];
196
- case 1:
197
- branch = _b.sent();
198
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.branch(branch)];
199
- case 2:
200
- _a = _b.sent();
201
- return [2 /*return*/, null];
202
- case 3: return [2 /*return*/];
203
- }
204
- });
205
- });
206
- };
207
- GitLabApiClient.prototype.createBranch = function (projectId, branchName, branchFrom) {
208
- return __awaiter(this, void 0, void 0, function () {
209
- var newBranch;
210
- return __generator(this, function (_a) {
211
- switch (_a.label) {
212
- case 0: return [4 /*yield*/, this.client.Branches.create(projectId, branchName, branchFrom)];
213
- case 1:
214
- newBranch = _a.sent();
215
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.branch(newBranch)];
216
- }
217
- });
218
- });
219
- };
220
- GitLabApiClient.prototype.cherryPick = function (projectId, sha, branchName) {
221
- return __awaiter(this, void 0, void 0, function () {
222
- return __generator(this, function (_a) {
223
- switch (_a.label) {
224
- case 0: return [4 /*yield*/, this.client.Commits.cherryPick(projectId, sha, branchName)];
225
- case 1:
226
- _a.sent();
227
- return [2 /*return*/];
228
- }
229
- });
230
- });
231
- };
232
- GitLabApiClient.prototype.getMergeRequest = function (projectId, sourceBranch, targetBranch, state) {
233
- return __awaiter(this, void 0, void 0, function () {
234
- var opts, mergeRequests, mergeRequest;
235
- return __generator(this, function (_a) {
236
- switch (_a.label) {
237
- case 0:
238
- opts = {
239
- projectId: projectId,
240
- sourceBranch: sourceBranch,
241
- targetBranch: targetBranch
242
- };
243
- /**
244
- * We only care about open MRs, this allows us to close any MR and run the CLI again if needed
245
- */
246
- if (state)
247
- opts.state = state;
248
- return [4 /*yield*/, this.client.MergeRequests.all(opts)];
249
- case 1:
250
- mergeRequests = _a.sent();
251
- mergeRequest = mergeRequests[0];
252
- if (!mergeRequest)
253
- return [2 /*return*/, null];
254
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(mergeRequest)];
255
- }
256
- });
257
- });
258
- };
259
- GitLabApiClient.prototype.getMergeRequestById = function (projectId, mergeRequestId) {
260
- return __awaiter(this, void 0, void 0, function () {
261
- var mergeRequest;
262
- return __generator(this, function (_a) {
263
- switch (_a.label) {
264
- case 0: return [4 /*yield*/, this.client.MergeRequests.show(projectId, mergeRequestId)];
265
- case 1:
266
- mergeRequest = _a.sent();
267
- if (!mergeRequest)
268
- return [2 /*return*/, null];
269
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(mergeRequest)];
270
- }
271
- });
272
- });
273
- };
274
- GitLabApiClient.prototype.getReleaseMergeRequest = function (projectId, milestone) {
275
- return __awaiter(this, void 0, void 0, function () {
276
- var mergeRequests, releaseMR;
277
- return __generator(this, function (_a) {
278
- switch (_a.label) {
279
- case 0: return [4 /*yield*/, this.client.MergeRequests.all({
280
- projectId: projectId,
281
- targetBranch: 'master',
282
- /**
283
- * We only care about open MRs, this allows us to close any MR and run the CLI again if needed
284
- */
285
- state: 'opened',
286
- milestone: milestone
287
- })];
288
- case 1:
289
- mergeRequests = _a.sent();
290
- releaseMR = mergeRequests[0];
291
- if (!releaseMR)
292
- return [2 /*return*/, null];
293
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(releaseMR)];
294
- }
295
- });
296
- });
297
- };
298
- GitLabApiClient.prototype.createMergeRequest = function (projectId, sourceBranch, targetBranch, title, description, milestone) {
299
- return __awaiter(this, void 0, void 0, function () {
300
- var mergeRequest;
301
- return __generator(this, function (_a) {
302
- switch (_a.label) {
303
- case 0: return [4 /*yield*/, this.client.MergeRequests.create(projectId, sourceBranch, targetBranch, title, {
304
- description: description,
305
- milestoneId: milestone.id,
306
- assigneeId: GitLabMemberIds_1.GitLabMemberIds.SHIP_IT
307
- })];
308
- case 1:
309
- mergeRequest = _a.sent();
310
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(mergeRequest)];
311
- }
312
- });
313
- });
314
- };
315
- GitLabApiClient.prototype.getFile = function (projectId, filePath, branchName) {
316
- return __awaiter(this, void 0, void 0, function () {
317
- var file, _a;
318
- return __generator(this, function (_b) {
319
- switch (_b.label) {
320
- case 0:
321
- _b.trys.push([0, 2, , 3]);
322
- return [4 /*yield*/, this.client.RepositoryFiles.show(projectId, filePath, branchName)];
323
- case 1:
324
- file = _b.sent();
325
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.file(file)];
326
- case 2:
327
- _a = _b.sent();
328
- return [2 /*return*/, null];
329
- case 3: return [2 /*return*/];
330
- }
331
- });
332
- });
333
- };
334
- GitLabApiClient.prototype.updateFile = function (projectId, filePath, branchName, content, commitMessage) {
335
- return __awaiter(this, void 0, void 0, function () {
336
- return __generator(this, function (_a) {
337
- switch (_a.label) {
338
- case 0: return [4 /*yield*/, this.client.RepositoryFiles.edit(projectId, filePath, branchName, content, commitMessage)];
339
- case 1:
340
- _a.sent();
341
- return [2 /*return*/];
342
- }
343
- });
344
- });
345
- };
346
- GitLabApiClient.prototype.commit = function (projectId, branchName, files, commitMessage) {
347
- return __awaiter(this, void 0, void 0, function () {
348
- return __generator(this, function (_a) {
349
- switch (_a.label) {
350
- case 0: return [4 /*yield*/, this.client.Commits.create(projectId, branchName, commitMessage, files.map(function (f) { return ({
351
- action: 'update',
352
- filePath: f.filePath,
353
- content: f.content
354
- }); }))];
355
- case 1:
356
- _a.sent();
357
- return [2 /*return*/];
358
- }
359
- });
360
- });
361
- };
362
- GitLabApiClient.prototype.getMilestone = function (projectId, milestoneName) {
363
- return __awaiter(this, void 0, void 0, function () {
364
- var groupMilestones, milestone, projectMilestones;
365
- return __generator(this, function (_a) {
366
- switch (_a.label) {
367
- case 0: return [4 /*yield*/, this.client.GroupMilestones.all(GroupIds_1.GroupIds.CLICKVIEW)];
368
- case 1:
369
- groupMilestones = _a.sent();
370
- milestone = groupMilestones.find(function (milestone) { return milestone.title === milestoneName; });
371
- if (milestone)
372
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.milestone(milestone)];
373
- return [4 /*yield*/, this.client.ProjectMilestones.all(projectId)];
374
- case 2:
375
- projectMilestones = _a.sent();
376
- milestone = projectMilestones.find(function (milestone) { return milestone.title === milestoneName; });
377
- if (!milestone)
378
- return [2 /*return*/, null];
379
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.milestone(milestone)];
380
- }
381
- });
382
- });
383
- };
384
- GitLabApiClient.prototype.getLabels = function (projectId) {
385
- return __awaiter(this, void 0, void 0, function () {
386
- var labels;
387
- return __generator(this, function (_a) {
388
- switch (_a.label) {
389
- case 0: return [4 /*yield*/, this.client.Labels.all(projectId)];
390
- case 1:
391
- labels = _a.sent();
392
- return [2 /*return*/, labels.map(GitLabMapper_1.GitLabMapper.label)];
393
- }
394
- });
395
- });
396
- };
397
- GitLabApiClient = __decorate([
398
- (0, inversify_1.injectable)(),
399
- __param(0, (0, inversify_1.inject)(types_1.MISC.GitLabConfig)),
400
- __metadata("design:paramtypes", [Object])
401
- ], GitLabApiClient);
402
- return GitLabApiClient;
403
- }());
404
- exports.GitLabApiClient = GitLabApiClient;
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ var __generator = (this && this.__generator) || function (thisArg, body) {
24
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
25
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
26
+ function verb(n) { return function (v) { return step([n, v]); }; }
27
+ function step(op) {
28
+ if (f) throw new TypeError("Generator is already executing.");
29
+ while (_) try {
30
+ 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;
31
+ if (y = 0, t) op = [op[0] & 2, t.value];
32
+ switch (op[0]) {
33
+ case 0: case 1: t = op; break;
34
+ case 4: _.label++; return { value: op[1], done: false };
35
+ case 5: _.label++; y = op[1]; op = [0]; continue;
36
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
37
+ default:
38
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
39
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
40
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
41
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
42
+ if (t[2]) _.ops.pop();
43
+ _.trys.pop(); continue;
44
+ }
45
+ op = body.call(thisArg, _);
46
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
47
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
+ }
49
+ };
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ exports.GitLabApiClient = void 0;
52
+ require("reflect-metadata");
53
+ var inversify_1 = require("inversify");
54
+ var node_1 = require("@gitbeaker/node");
55
+ var types_1 = require("../../types");
56
+ var errors_1 = require("../../errors");
57
+ var GitLabMapper_1 = require("./GitLabMapper");
58
+ var GroupIds_1 = require("../../utils/GroupIds");
59
+ var GitLabMemberIds_1 = require("../../constants/GitLabMemberIds");
60
+ var GitLabApiClient = /** @class */ (function () {
61
+ function GitLabApiClient(config) {
62
+ this.config = config;
63
+ this.client = new node_1.Gitlab({
64
+ token: this.config.accessToken,
65
+ host: this.config.url
66
+ });
67
+ }
68
+ GitLabApiClient.prototype.getMergeRequests = function (options) {
69
+ return __awaiter(this, void 0, void 0, function () {
70
+ var milestone, projectIds, mergeRequests;
71
+ return __generator(this, function (_a) {
72
+ switch (_a.label) {
73
+ case 0:
74
+ milestone = options.milestone, projectIds = options.projectIds;
75
+ if (!milestone && !(projectIds === null || projectIds === void 0 ? void 0 : projectIds.length))
76
+ throw new errors_1.ShipItError('Must specify one of the following: Milestone or ProjectIds');
77
+ return [4 /*yield*/, this.client.MergeRequests.all({
78
+ milestone: milestone,
79
+ scope: 'all'
80
+ })];
81
+ case 1:
82
+ mergeRequests = _a.sent();
83
+ return [2 /*return*/, mergeRequests.map(GitLabMapper_1.GitLabMapper.mergeRequest)];
84
+ }
85
+ });
86
+ });
87
+ };
88
+ GitLabApiClient.prototype.getProjectsByIds = function (projectIds) {
89
+ return __awaiter(this, void 0, void 0, function () {
90
+ var promises, projects;
91
+ var _this = this;
92
+ return __generator(this, function (_a) {
93
+ switch (_a.label) {
94
+ case 0:
95
+ promises = projectIds.map(function (p) { return _this.client.Projects.show(p); });
96
+ return [4 /*yield*/, Promise.all(promises)];
97
+ case 1:
98
+ projects = _a.sent();
99
+ return [2 /*return*/, projects.map(GitLabMapper_1.GitLabMapper.project)];
100
+ }
101
+ });
102
+ });
103
+ };
104
+ GitLabApiClient.prototype.getLatestTags = function (projectId) {
105
+ return __awaiter(this, void 0, void 0, function () {
106
+ var tags;
107
+ return __generator(this, function (_a) {
108
+ switch (_a.label) {
109
+ case 0: return [4 /*yield*/, this.client.Tags.all(projectId, { maxPages: 1, perPage: 20 })];
110
+ case 1:
111
+ tags = _a.sent();
112
+ return [2 /*return*/, tags.map(GitLabMapper_1.GitLabMapper.tag)];
113
+ }
114
+ });
115
+ });
116
+ };
117
+ GitLabApiClient.prototype.getTag = function (projectId, tagName) {
118
+ return __awaiter(this, void 0, void 0, function () {
119
+ var tag, _a;
120
+ return __generator(this, function (_b) {
121
+ switch (_b.label) {
122
+ case 0:
123
+ _b.trys.push([0, 2, , 3]);
124
+ return [4 /*yield*/, this.client.Tags.show(projectId, tagName)];
125
+ case 1:
126
+ tag = _b.sent();
127
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.tag(tag)];
128
+ case 2:
129
+ _a = _b.sent();
130
+ return [2 /*return*/, null];
131
+ case 3: return [2 /*return*/];
132
+ }
133
+ });
134
+ });
135
+ };
136
+ GitLabApiClient.prototype.createTag = function (projectId, tagName, sha) {
137
+ return __awaiter(this, void 0, void 0, function () {
138
+ var tag;
139
+ return __generator(this, function (_a) {
140
+ switch (_a.label) {
141
+ case 0: return [4 /*yield*/, this.client.Tags.create(projectId, tagName, sha)];
142
+ case 1:
143
+ tag = _a.sent();
144
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.tag(tag)];
145
+ }
146
+ });
147
+ });
148
+ };
149
+ GitLabApiClient.prototype.createRelease = function (projectId, release) {
150
+ return __awaiter(this, void 0, void 0, function () {
151
+ var newRelease;
152
+ return __generator(this, function (_a) {
153
+ switch (_a.label) {
154
+ case 0: return [4 /*yield*/, this.client.Releases.create(projectId, {
155
+ id: projectId,
156
+ name: release.name,
157
+ tag_name: release.tag,
158
+ description: release.description,
159
+ ref: release.ref
160
+ })];
161
+ case 1:
162
+ newRelease = _a.sent();
163
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.release(newRelease)];
164
+ }
165
+ });
166
+ });
167
+ };
168
+ GitLabApiClient.prototype.getCommitsForRelease = function (projectId, dateSince) {
169
+ return __awaiter(this, void 0, void 0, function () {
170
+ var commits;
171
+ return __generator(this, function (_a) {
172
+ switch (_a.label) {
173
+ case 0: return [4 /*yield*/, this.client.Commits.all(projectId, {
174
+ ref_name: 'dev',
175
+ since: dateSince,
176
+ /**
177
+ * This allows us to get merge commits of MRs being accepted
178
+ */
179
+ first_parent: true
180
+ })];
181
+ case 1:
182
+ commits = _a.sent();
183
+ return [2 /*return*/, commits.map(GitLabMapper_1.GitLabMapper.commit)];
184
+ }
185
+ });
186
+ });
187
+ };
188
+ GitLabApiClient.prototype.getBranch = function (projectId, branchName) {
189
+ return __awaiter(this, void 0, void 0, function () {
190
+ var branch, _a;
191
+ return __generator(this, function (_b) {
192
+ switch (_b.label) {
193
+ case 0:
194
+ _b.trys.push([0, 2, , 3]);
195
+ return [4 /*yield*/, this.client.Branches.show(projectId, branchName)];
196
+ case 1:
197
+ branch = _b.sent();
198
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.branch(branch)];
199
+ case 2:
200
+ _a = _b.sent();
201
+ return [2 /*return*/, null];
202
+ case 3: return [2 /*return*/];
203
+ }
204
+ });
205
+ });
206
+ };
207
+ GitLabApiClient.prototype.createBranch = function (projectId, branchName, branchFrom) {
208
+ return __awaiter(this, void 0, void 0, function () {
209
+ var newBranch;
210
+ return __generator(this, function (_a) {
211
+ switch (_a.label) {
212
+ case 0: return [4 /*yield*/, this.client.Branches.create(projectId, branchName, branchFrom)];
213
+ case 1:
214
+ newBranch = _a.sent();
215
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.branch(newBranch)];
216
+ }
217
+ });
218
+ });
219
+ };
220
+ GitLabApiClient.prototype.cherryPick = function (projectId, sha, branchName) {
221
+ return __awaiter(this, void 0, void 0, function () {
222
+ return __generator(this, function (_a) {
223
+ switch (_a.label) {
224
+ case 0: return [4 /*yield*/, this.client.Commits.cherryPick(projectId, sha, branchName)];
225
+ case 1:
226
+ _a.sent();
227
+ return [2 /*return*/];
228
+ }
229
+ });
230
+ });
231
+ };
232
+ GitLabApiClient.prototype.getMergeRequest = function (projectId, sourceBranch, targetBranch, state) {
233
+ return __awaiter(this, void 0, void 0, function () {
234
+ var opts, mergeRequests, mergeRequest;
235
+ return __generator(this, function (_a) {
236
+ switch (_a.label) {
237
+ case 0:
238
+ opts = {
239
+ projectId: projectId,
240
+ sourceBranch: sourceBranch,
241
+ targetBranch: targetBranch
242
+ };
243
+ /**
244
+ * We only care about open MRs, this allows us to close any MR and run the CLI again if needed
245
+ */
246
+ if (state)
247
+ opts.state = state;
248
+ return [4 /*yield*/, this.client.MergeRequests.all(opts)];
249
+ case 1:
250
+ mergeRequests = _a.sent();
251
+ mergeRequest = mergeRequests[0];
252
+ if (!mergeRequest)
253
+ return [2 /*return*/, null];
254
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(mergeRequest)];
255
+ }
256
+ });
257
+ });
258
+ };
259
+ GitLabApiClient.prototype.getMergeRequestById = function (projectId, mergeRequestId) {
260
+ return __awaiter(this, void 0, void 0, function () {
261
+ var mergeRequest;
262
+ return __generator(this, function (_a) {
263
+ switch (_a.label) {
264
+ case 0: return [4 /*yield*/, this.client.MergeRequests.show(projectId, mergeRequestId)];
265
+ case 1:
266
+ mergeRequest = _a.sent();
267
+ if (!mergeRequest)
268
+ return [2 /*return*/, null];
269
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(mergeRequest)];
270
+ }
271
+ });
272
+ });
273
+ };
274
+ GitLabApiClient.prototype.getReleaseMergeRequest = function (projectId, milestone) {
275
+ return __awaiter(this, void 0, void 0, function () {
276
+ var mergeRequests, releaseMR;
277
+ return __generator(this, function (_a) {
278
+ switch (_a.label) {
279
+ case 0: return [4 /*yield*/, this.client.MergeRequests.all({
280
+ projectId: projectId,
281
+ targetBranch: 'master',
282
+ /**
283
+ * We only care about open MRs, this allows us to close any MR and run the CLI again if needed
284
+ */
285
+ state: 'opened',
286
+ milestone: milestone
287
+ })];
288
+ case 1:
289
+ mergeRequests = _a.sent();
290
+ releaseMR = mergeRequests[0];
291
+ if (!releaseMR)
292
+ return [2 /*return*/, null];
293
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(releaseMR)];
294
+ }
295
+ });
296
+ });
297
+ };
298
+ GitLabApiClient.prototype.createMergeRequest = function (projectId, sourceBranch, targetBranch, title, description, milestone) {
299
+ return __awaiter(this, void 0, void 0, function () {
300
+ var mergeRequest;
301
+ return __generator(this, function (_a) {
302
+ switch (_a.label) {
303
+ case 0: return [4 /*yield*/, this.client.MergeRequests.create(projectId, sourceBranch, targetBranch, title, {
304
+ description: description,
305
+ milestoneId: milestone.id,
306
+ assigneeId: GitLabMemberIds_1.GitLabMemberIds.SHIP_IT
307
+ })];
308
+ case 1:
309
+ mergeRequest = _a.sent();
310
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(mergeRequest)];
311
+ }
312
+ });
313
+ });
314
+ };
315
+ GitLabApiClient.prototype.getFile = function (projectId, filePath, branchName) {
316
+ return __awaiter(this, void 0, void 0, function () {
317
+ var file, _a;
318
+ return __generator(this, function (_b) {
319
+ switch (_b.label) {
320
+ case 0:
321
+ _b.trys.push([0, 2, , 3]);
322
+ return [4 /*yield*/, this.client.RepositoryFiles.show(projectId, filePath, branchName)];
323
+ case 1:
324
+ file = _b.sent();
325
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.file(file)];
326
+ case 2:
327
+ _a = _b.sent();
328
+ return [2 /*return*/, null];
329
+ case 3: return [2 /*return*/];
330
+ }
331
+ });
332
+ });
333
+ };
334
+ GitLabApiClient.prototype.updateFile = function (projectId, filePath, branchName, content, commitMessage) {
335
+ return __awaiter(this, void 0, void 0, function () {
336
+ return __generator(this, function (_a) {
337
+ switch (_a.label) {
338
+ case 0: return [4 /*yield*/, this.client.RepositoryFiles.edit(projectId, filePath, branchName, content, commitMessage)];
339
+ case 1:
340
+ _a.sent();
341
+ return [2 /*return*/];
342
+ }
343
+ });
344
+ });
345
+ };
346
+ GitLabApiClient.prototype.commit = function (projectId, branchName, files, commitMessage) {
347
+ return __awaiter(this, void 0, void 0, function () {
348
+ return __generator(this, function (_a) {
349
+ switch (_a.label) {
350
+ case 0: return [4 /*yield*/, this.client.Commits.create(projectId, branchName, commitMessage, files.map(function (f) { return ({
351
+ action: 'update',
352
+ filePath: f.filePath,
353
+ content: f.content
354
+ }); }))];
355
+ case 1:
356
+ _a.sent();
357
+ return [2 /*return*/];
358
+ }
359
+ });
360
+ });
361
+ };
362
+ GitLabApiClient.prototype.getMilestone = function (projectId, milestoneName) {
363
+ return __awaiter(this, void 0, void 0, function () {
364
+ var groupMilestones, milestone, projectMilestones;
365
+ return __generator(this, function (_a) {
366
+ switch (_a.label) {
367
+ case 0: return [4 /*yield*/, this.client.GroupMilestones.all(GroupIds_1.GroupIds.CLICKVIEW)];
368
+ case 1:
369
+ groupMilestones = _a.sent();
370
+ milestone = groupMilestones.find(function (milestone) { return milestone.title === milestoneName; });
371
+ if (milestone)
372
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.milestone(milestone)];
373
+ return [4 /*yield*/, this.client.ProjectMilestones.all(projectId)];
374
+ case 2:
375
+ projectMilestones = _a.sent();
376
+ milestone = projectMilestones.find(function (milestone) { return milestone.title === milestoneName; });
377
+ if (!milestone)
378
+ return [2 /*return*/, null];
379
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.milestone(milestone)];
380
+ }
381
+ });
382
+ });
383
+ };
384
+ GitLabApiClient.prototype.getLabels = function (projectId) {
385
+ return __awaiter(this, void 0, void 0, function () {
386
+ var labels;
387
+ return __generator(this, function (_a) {
388
+ switch (_a.label) {
389
+ case 0: return [4 /*yield*/, this.client.Labels.all(projectId)];
390
+ case 1:
391
+ labels = _a.sent();
392
+ return [2 /*return*/, labels.map(GitLabMapper_1.GitLabMapper.label)];
393
+ }
394
+ });
395
+ });
396
+ };
397
+ GitLabApiClient = __decorate([
398
+ (0, inversify_1.injectable)(),
399
+ __param(0, (0, inversify_1.inject)(types_1.MISC.GitLabConfig)),
400
+ __metadata("design:paramtypes", [Object])
401
+ ], GitLabApiClient);
402
+ return GitLabApiClient;
403
+ }());
404
+ exports.GitLabApiClient = GitLabApiClient;