@clickview/ship-it 0.0.40 → 0.0.41

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 (124) hide show
  1. package/Dockerfile +33 -33
  2. package/README.md +48 -48
  3. package/config.json +19 -19
  4. package/dist/I3/I3 Notes Audit.csv +127 -0
  5. package/dist/J1/J1 Notes Audit.csv +38 -0
  6. package/dist/J2/J2 Notes Audit.csv +52 -0
  7. package/dist/L1/L1 Notes Audit.csv +139 -0
  8. package/lib/config.json +20 -20
  9. package/lib/src/api-clients/git-lab/GitLabApiClient.js +561 -557
  10. package/lib/src/api-clients/git-lab/GitLabMapper.js +122 -122
  11. package/lib/src/api-clients/index.js +20 -20
  12. package/lib/src/api-clients/slack/SlackApiClient.js +206 -206
  13. package/lib/src/api-clients/team-city/TeamCityApiClient.js +100 -100
  14. package/lib/src/api-clients/trello/TrelloApiClient.js +145 -145
  15. package/lib/src/commands/BumpPackagesCommand.js +76 -76
  16. package/lib/src/commands/ConfigureProjectsCommand.js +84 -84
  17. package/lib/src/commands/CreateBranchCommand.js +100 -100
  18. package/lib/src/commands/CreateMergeRequestCommand.js +107 -107
  19. package/lib/src/commands/CreateNotesAuditCommand.js +84 -84
  20. package/lib/src/commands/CreateReleaseNotesCommand.js +95 -95
  21. package/lib/src/commands/CreateTrelloCardsCommand.js +77 -77
  22. package/lib/src/commands/InstallPackagesCommand.js +76 -76
  23. package/lib/src/commands/ListProjectsCommand.js +76 -76
  24. package/lib/src/commands/ReleaseCommand.js +136 -136
  25. package/lib/src/commands/StartProjectBuildsCommand.js +76 -76
  26. package/lib/src/commands/StatusCommand.js +93 -93
  27. package/lib/src/commands/TagMasterCommand.js +76 -76
  28. package/lib/src/commands/ValidateMergeRequestCommand.js +76 -76
  29. package/lib/src/commands/VersionCommand.js +76 -76
  30. package/lib/src/commands/index.js +31 -31
  31. package/lib/src/constants/CommandTypeMapping.js +21 -21
  32. package/lib/src/constants/GitLabMemberIds.js +6 -6
  33. package/lib/src/constants/MonorepoPackageJsonFiles.js +41 -41
  34. package/lib/src/constants/MonorepoProjectNames.js +16 -16
  35. package/lib/src/constants/ProjectNames.js +69 -69
  36. package/lib/src/constants/SlackUserEmailList.js +13 -13
  37. package/lib/src/constants/TeamCityBuildIDs.js +46 -46
  38. package/lib/src/constants/index.js +19 -19
  39. package/lib/src/errors/ShipItError.js +32 -32
  40. package/lib/src/errors/index.js +17 -17
  41. package/lib/src/index.js +18 -18
  42. package/lib/src/interfaces/Config.js +2 -2
  43. package/lib/src/interfaces/MergeRequestState.js +2 -2
  44. package/lib/src/interfaces/ProjectNames.js +2 -2
  45. package/lib/src/interfaces/ShipItCommand.js +2 -2
  46. package/lib/src/interfaces/ShipItTask.js +2 -2
  47. package/lib/src/interfaces/VersionType.js +2 -2
  48. package/lib/src/interfaces/command-cli-options/MilestoneCommandCliOptions.js +2 -2
  49. package/lib/src/interfaces/command-cli-options/ReleaseCommandCliOptions.js +2 -2
  50. package/lib/src/interfaces/command-cli-options/StatusCommandCliOptions.js +2 -2
  51. package/lib/src/interfaces/command-cli-options/index.js +19 -19
  52. package/lib/src/interfaces/command-options/BaseCommandOptions.js +2 -2
  53. package/lib/src/interfaces/command-options/BumpPackagesCommandOptions.js +2 -2
  54. package/lib/src/interfaces/command-options/ConfigureProjectsOptions.js +2 -2
  55. package/lib/src/interfaces/command-options/DockerMilestoneCommandOptions.js +2 -2
  56. package/lib/src/interfaces/command-options/MilestoneCommandOptions.js +2 -2
  57. package/lib/src/interfaces/command-options/ReleaseCommandOptions.js +2 -2
  58. package/lib/src/interfaces/command-options/StatusCommandOptions.js +2 -2
  59. package/lib/src/interfaces/command-options/ValidateMRCommandOptions.js +2 -2
  60. package/lib/src/interfaces/command-options/index.js +23 -23
  61. package/lib/src/interfaces/index.js +26 -26
  62. package/lib/src/interfaces/models/ApprovalRule.js +2 -2
  63. package/lib/src/interfaces/models/ApprovalRuleConfiguration.js +2 -2
  64. package/lib/src/interfaces/models/Branch.js +2 -2
  65. package/lib/src/interfaces/models/Commit.js +2 -2
  66. package/lib/src/interfaces/models/CommitFile.js +2 -2
  67. package/lib/src/interfaces/models/CreateApprovalRuleRequest.js +2 -2
  68. package/lib/src/interfaces/models/File.js +2 -2
  69. package/lib/src/interfaces/models/Group.js +2 -2
  70. package/lib/src/interfaces/models/Label.js +2 -2
  71. package/lib/src/interfaces/models/MergeRequest.js +2 -2
  72. package/lib/src/interfaces/models/Milestone.js +2 -2
  73. package/lib/src/interfaces/models/Project.js +2 -2
  74. package/lib/src/interfaces/models/ProjectConfig.js +9 -9
  75. package/lib/src/interfaces/models/ProtectedBranch.js +2 -2
  76. package/lib/src/interfaces/models/Release.js +2 -2
  77. package/lib/src/interfaces/models/Tag.js +2 -2
  78. package/lib/src/interfaces/models/index.js +32 -32
  79. package/lib/src/interfaces/view-models/MilestoneProject.js +2 -2
  80. package/lib/src/interfaces/view-models/index.js +17 -17
  81. package/lib/src/inversify.config.js +79 -79
  82. package/lib/src/services/GitLabService.js +544 -544
  83. package/lib/src/services/SlackService.js +142 -142
  84. package/lib/src/services/TeamCityService.js +37 -37
  85. package/lib/src/services/TrelloService.js +84 -84
  86. package/lib/src/services/index.js +20 -20
  87. package/lib/src/startup/AddMilestoneCommand.js +96 -96
  88. package/lib/src/startup/GetAction.js +68 -68
  89. package/lib/src/startup/SetupCommands.js +180 -180
  90. package/lib/src/tasks/BumpPackagesTask.js +230 -230
  91. package/lib/src/tasks/BumpVersionTxtTask.js +110 -110
  92. package/lib/src/tasks/CommitPackageVersionsTask.js +116 -0
  93. package/lib/src/tasks/CreateBranchTask.js +104 -104
  94. package/lib/src/tasks/CreateMergeRequestTask.js +118 -118
  95. package/lib/src/tasks/CreateNotesAuditTask.js +140 -140
  96. package/lib/src/tasks/CreateReleaseNotesTask.js +144 -144
  97. package/lib/src/tasks/InstallPackagesTask.js +415 -415
  98. package/lib/src/tasks/ListProjectsTask.js +87 -87
  99. package/lib/src/tasks/PopulateTrelloBoardTask.js +140 -140
  100. package/lib/src/tasks/StartMonorepoBuildTask.js +109 -109
  101. package/lib/src/tasks/StartProjectBuildsTask.js +170 -170
  102. package/lib/src/tasks/TagMasterTask.js +189 -189
  103. package/lib/src/tasks/ValidateCommitsTask.js +143 -143
  104. package/lib/src/tasks/ValidateDescriptionsTask.js +178 -178
  105. package/lib/src/tasks/ValidateMergeRequestTask.js +115 -115
  106. package/lib/src/tasks/ValidateTask.js +419 -419
  107. package/lib/src/tasks/VersionTask.js +98 -98
  108. package/lib/src/tasks/configure-projects/AddApprovalRulesTask.js +199 -182
  109. package/lib/src/tasks/configure-projects/CreateToolingBranchTask.js +138 -136
  110. package/lib/src/tasks/configure-projects/EnsureApprovalRulesTask.js +106 -106
  111. package/lib/src/tasks/configure-projects/index.js +18 -18
  112. package/lib/src/tasks/configure-projects/primitives/BaseConfigureProjectsTask.js +98 -98
  113. package/lib/src/tasks/index.js +34 -34
  114. package/lib/src/types.js +60 -60
  115. package/lib/src/utils/BranchNames.js +11 -11
  116. package/lib/src/utils/Commits.js +55 -55
  117. package/lib/src/utils/Csv.js +54 -54
  118. package/lib/src/utils/Descriptions.js +274 -274
  119. package/lib/src/utils/GroupIds.js +6 -6
  120. package/lib/src/utils/Logger.js +62 -62
  121. package/lib/src/utils/ProjectIds.js +47 -47
  122. package/lib/src/utils/Versions.js +20 -20
  123. package/lib/src/utils/index.js +22 -22
  124. package/package.json +50 -50
@@ -1,557 +1,561 @@
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, updatedAfter, 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
- updatedAfter = new Date();
78
- updatedAfter.setMonth(updatedAfter.getMonth() - 3);
79
- return [4 /*yield*/, this.client.MergeRequests.all({
80
- milestone: milestone,
81
- updatedAfter: updatedAfter.toISOString(),
82
- scope: 'all'
83
- })];
84
- case 1:
85
- mergeRequests = _a.sent();
86
- return [2 /*return*/, mergeRequests.map(GitLabMapper_1.GitLabMapper.mergeRequest)];
87
- }
88
- });
89
- });
90
- };
91
- GitLabApiClient.prototype.getProjectsByIds = function (projectIds) {
92
- return __awaiter(this, void 0, void 0, function () {
93
- var promises, projects;
94
- var _this = this;
95
- return __generator(this, function (_a) {
96
- switch (_a.label) {
97
- case 0:
98
- promises = projectIds.map(function (p) { return _this.client.Projects.show(p); });
99
- return [4 /*yield*/, Promise.all(promises)];
100
- case 1:
101
- projects = _a.sent();
102
- return [2 /*return*/, projects.map(GitLabMapper_1.GitLabMapper.project)];
103
- }
104
- });
105
- });
106
- };
107
- GitLabApiClient.prototype.getAllProjects = function () {
108
- return __awaiter(this, void 0, void 0, function () {
109
- var projects;
110
- return __generator(this, function (_a) {
111
- switch (_a.label) {
112
- case 0: return [4 /*yield*/, this.client.Projects.all()];
113
- case 1:
114
- projects = _a.sent();
115
- return [2 /*return*/, projects.map(GitLabMapper_1.GitLabMapper.project)];
116
- }
117
- });
118
- });
119
- };
120
- GitLabApiClient.prototype.getAllGroupProjects = function (groupId) {
121
- return __awaiter(this, void 0, void 0, function () {
122
- var projects;
123
- return __generator(this, function (_a) {
124
- switch (_a.label) {
125
- case 0: return [4 /*yield*/, this.client.Groups.projects(groupId)];
126
- case 1:
127
- projects = _a.sent();
128
- return [2 /*return*/, projects.map(GitLabMapper_1.GitLabMapper.project)];
129
- }
130
- });
131
- });
132
- };
133
- GitLabApiClient.prototype.getLatestTags = function (projectId) {
134
- return __awaiter(this, void 0, void 0, function () {
135
- var tags;
136
- return __generator(this, function (_a) {
137
- switch (_a.label) {
138
- case 0: return [4 /*yield*/, this.client.Tags.all(projectId, { maxPages: 1, perPage: 20 })];
139
- case 1:
140
- tags = _a.sent();
141
- return [2 /*return*/, tags.map(GitLabMapper_1.GitLabMapper.tag)];
142
- }
143
- });
144
- });
145
- };
146
- GitLabApiClient.prototype.getTag = function (projectId, tagName) {
147
- return __awaiter(this, void 0, void 0, function () {
148
- var tag, _a;
149
- return __generator(this, function (_b) {
150
- switch (_b.label) {
151
- case 0:
152
- _b.trys.push([0, 2, , 3]);
153
- return [4 /*yield*/, this.client.Tags.show(projectId, tagName)];
154
- case 1:
155
- tag = _b.sent();
156
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.tag(tag)];
157
- case 2:
158
- _a = _b.sent();
159
- return [2 /*return*/, null];
160
- case 3: return [2 /*return*/];
161
- }
162
- });
163
- });
164
- };
165
- GitLabApiClient.prototype.createTag = function (projectId, tagName, sha) {
166
- return __awaiter(this, void 0, void 0, function () {
167
- var tag;
168
- return __generator(this, function (_a) {
169
- switch (_a.label) {
170
- case 0: return [4 /*yield*/, this.client.Tags.create(projectId, tagName, sha)];
171
- case 1:
172
- tag = _a.sent();
173
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.tag(tag)];
174
- }
175
- });
176
- });
177
- };
178
- GitLabApiClient.prototype.createRelease = function (projectId, release) {
179
- return __awaiter(this, void 0, void 0, function () {
180
- var newRelease;
181
- return __generator(this, function (_a) {
182
- switch (_a.label) {
183
- case 0: return [4 /*yield*/, this.client.Releases.create(projectId, {
184
- id: projectId,
185
- name: release.name,
186
- tag_name: release.tag,
187
- description: release.description,
188
- ref: release.ref
189
- })];
190
- case 1:
191
- newRelease = _a.sent();
192
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.release(newRelease)];
193
- }
194
- });
195
- });
196
- };
197
- GitLabApiClient.prototype.getCommitsForRelease = function (projectId, dateSince) {
198
- return __awaiter(this, void 0, void 0, function () {
199
- var commits;
200
- return __generator(this, function (_a) {
201
- switch (_a.label) {
202
- case 0: return [4 /*yield*/, this.client.Commits.all(projectId, {
203
- ref_name: 'dev',
204
- since: dateSince,
205
- /**
206
- * This allows us to get merge commits of MRs being accepted
207
- */
208
- first_parent: true
209
- })];
210
- case 1:
211
- commits = _a.sent();
212
- return [2 /*return*/, commits.map(GitLabMapper_1.GitLabMapper.commit)];
213
- }
214
- });
215
- });
216
- };
217
- GitLabApiClient.prototype.getBranch = function (projectId, branchName) {
218
- return __awaiter(this, void 0, void 0, function () {
219
- var branch, _a;
220
- return __generator(this, function (_b) {
221
- switch (_b.label) {
222
- case 0:
223
- _b.trys.push([0, 2, , 3]);
224
- return [4 /*yield*/, this.client.Branches.show(projectId, branchName)];
225
- case 1:
226
- branch = _b.sent();
227
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.branch(branch)];
228
- case 2:
229
- _a = _b.sent();
230
- return [2 /*return*/, null];
231
- case 3: return [2 /*return*/];
232
- }
233
- });
234
- });
235
- };
236
- GitLabApiClient.prototype.createBranch = function (projectId, branchName, branchFrom) {
237
- return __awaiter(this, void 0, void 0, function () {
238
- var newBranch;
239
- return __generator(this, function (_a) {
240
- switch (_a.label) {
241
- case 0: return [4 /*yield*/, this.client.Branches.create(projectId, branchName, branchFrom)];
242
- case 1:
243
- newBranch = _a.sent();
244
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.branch(newBranch)];
245
- }
246
- });
247
- });
248
- };
249
- GitLabApiClient.prototype.cherryPick = function (projectId, sha, branchName) {
250
- return __awaiter(this, void 0, void 0, function () {
251
- return __generator(this, function (_a) {
252
- switch (_a.label) {
253
- case 0: return [4 /*yield*/, this.client.Commits.cherryPick(projectId, sha, branchName)];
254
- case 1:
255
- _a.sent();
256
- return [2 /*return*/];
257
- }
258
- });
259
- });
260
- };
261
- GitLabApiClient.prototype.getMergeRequest = function (projectId, sourceBranch, targetBranch, state) {
262
- return __awaiter(this, void 0, void 0, function () {
263
- var opts, mergeRequests, mergeRequest;
264
- return __generator(this, function (_a) {
265
- switch (_a.label) {
266
- case 0:
267
- opts = {
268
- projectId: projectId,
269
- sourceBranch: sourceBranch,
270
- targetBranch: targetBranch
271
- };
272
- /**
273
- * We only care about open MRs, this allows us to close any MR and run the CLI again if needed
274
- */
275
- if (state)
276
- opts.state = state;
277
- return [4 /*yield*/, this.client.MergeRequests.all(opts)];
278
- case 1:
279
- mergeRequests = _a.sent();
280
- mergeRequest = mergeRequests[0];
281
- if (!mergeRequest)
282
- return [2 /*return*/, null];
283
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(mergeRequest)];
284
- }
285
- });
286
- });
287
- };
288
- GitLabApiClient.prototype.getMergeRequestById = function (projectId, mergeRequestId) {
289
- return __awaiter(this, void 0, void 0, function () {
290
- var mergeRequest;
291
- return __generator(this, function (_a) {
292
- switch (_a.label) {
293
- case 0: return [4 /*yield*/, this.client.MergeRequests.show(projectId, mergeRequestId)];
294
- case 1:
295
- mergeRequest = _a.sent();
296
- if (!mergeRequest)
297
- return [2 /*return*/, null];
298
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(mergeRequest)];
299
- }
300
- });
301
- });
302
- };
303
- GitLabApiClient.prototype.getReleaseMergeRequest = function (projectId, milestone) {
304
- return __awaiter(this, void 0, void 0, function () {
305
- var mergeRequests, releaseMR;
306
- return __generator(this, function (_a) {
307
- switch (_a.label) {
308
- case 0: return [4 /*yield*/, this.client.MergeRequests.all({
309
- projectId: projectId,
310
- targetBranch: 'master',
311
- /**
312
- * We only care about open MRs, this allows us to close any MR and run the CLI again if needed
313
- */
314
- state: 'opened',
315
- milestone: milestone
316
- })];
317
- case 1:
318
- mergeRequests = _a.sent();
319
- releaseMR = mergeRequests[0];
320
- if (!releaseMR)
321
- return [2 /*return*/, null];
322
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(releaseMR)];
323
- }
324
- });
325
- });
326
- };
327
- GitLabApiClient.prototype.createMergeRequest = function (projectId, sourceBranch, targetBranch, title, description, milestone) {
328
- return __awaiter(this, void 0, void 0, function () {
329
- var mergeRequest;
330
- return __generator(this, function (_a) {
331
- switch (_a.label) {
332
- case 0: return [4 /*yield*/, this.client.MergeRequests.create(projectId, sourceBranch, targetBranch, title, {
333
- description: description,
334
- milestoneId: milestone.id,
335
- assigneeId: GitLabMemberIds_1.GitLabMemberIds.SHIP_IT
336
- })];
337
- case 1:
338
- mergeRequest = _a.sent();
339
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(mergeRequest)];
340
- }
341
- });
342
- });
343
- };
344
- GitLabApiClient.prototype.AcceptMergeRequest = function (projectId, mergerequestIId) {
345
- return __awaiter(this, void 0, void 0, function () {
346
- var mergeRequest;
347
- return __generator(this, function (_a) {
348
- switch (_a.label) {
349
- case 0: return [4 /*yield*/, this.client.MergeRequests.accept(projectId, mergerequestIId)];
350
- case 1:
351
- mergeRequest = _a.sent();
352
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(mergeRequest)];
353
- }
354
- });
355
- });
356
- };
357
- GitLabApiClient.prototype.getFile = function (projectId, filePath, branchName) {
358
- return __awaiter(this, void 0, void 0, function () {
359
- var file, _a;
360
- return __generator(this, function (_b) {
361
- switch (_b.label) {
362
- case 0:
363
- _b.trys.push([0, 2, , 3]);
364
- return [4 /*yield*/, this.client.RepositoryFiles.show(projectId, filePath, branchName)];
365
- case 1:
366
- file = _b.sent();
367
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.file(file)];
368
- case 2:
369
- _a = _b.sent();
370
- return [2 /*return*/, null];
371
- case 3: return [2 /*return*/];
372
- }
373
- });
374
- });
375
- };
376
- GitLabApiClient.prototype.updateFile = function (projectId, filePath, branchName, content, commitMessage) {
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.client.RepositoryFiles.edit(projectId, filePath, branchName, content, commitMessage)];
381
- case 1:
382
- _a.sent();
383
- return [2 /*return*/];
384
- }
385
- });
386
- });
387
- };
388
- GitLabApiClient.prototype.commit = function (projectId, branchName, files, commitMessage) {
389
- return __awaiter(this, void 0, void 0, function () {
390
- return __generator(this, function (_a) {
391
- switch (_a.label) {
392
- case 0: return [4 /*yield*/, this.client.Commits.create(projectId, branchName, commitMessage, files.map(function (f) { return ({
393
- action: 'update',
394
- filePath: f.filePath,
395
- content: f.content
396
- }); }))];
397
- case 1:
398
- _a.sent();
399
- return [2 /*return*/];
400
- }
401
- });
402
- });
403
- };
404
- GitLabApiClient.prototype.getMilestone = function (milestoneName, projectId) {
405
- return __awaiter(this, void 0, void 0, function () {
406
- var groupMilestones, milestone, projectMilestones;
407
- return __generator(this, function (_a) {
408
- switch (_a.label) {
409
- case 0: return [4 /*yield*/, this.client.GroupMilestones.all(GroupIds_1.GroupIds.CLICKVIEW)];
410
- case 1:
411
- groupMilestones = _a.sent();
412
- milestone = groupMilestones.find(function (milestone) { return milestone.title === milestoneName; });
413
- if (milestone)
414
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.milestone(milestone)];
415
- if (!projectId)
416
- return [2 /*return*/, null];
417
- return [4 /*yield*/, this.client.ProjectMilestones.all(projectId)];
418
- case 2:
419
- projectMilestones = _a.sent();
420
- milestone = projectMilestones.find(function (milestone) { return milestone.title === milestoneName; });
421
- if (!milestone)
422
- return [2 /*return*/, null];
423
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.milestone(milestone)];
424
- }
425
- });
426
- });
427
- };
428
- GitLabApiClient.prototype.updateMilestone = function (projectId, mergeRequestId, newMilestoneId) {
429
- return __awaiter(this, void 0, void 0, function () {
430
- var updated;
431
- return __generator(this, function (_a) {
432
- switch (_a.label) {
433
- case 0: return [4 /*yield*/, this.client.MergeRequests.edit(projectId, mergeRequestId, {
434
- milestoneId: newMilestoneId,
435
- })];
436
- case 1:
437
- updated = _a.sent();
438
- if (!updated)
439
- return [2 /*return*/, null];
440
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.milestone(updated.milestone)];
441
- }
442
- });
443
- });
444
- };
445
- GitLabApiClient.prototype.getLabels = function (projectId) {
446
- return __awaiter(this, void 0, void 0, function () {
447
- var labels;
448
- return __generator(this, function (_a) {
449
- switch (_a.label) {
450
- case 0: return [4 /*yield*/, this.client.Labels.all(projectId)];
451
- case 1:
452
- labels = _a.sent();
453
- return [2 /*return*/, labels.map(GitLabMapper_1.GitLabMapper.label)];
454
- }
455
- });
456
- });
457
- };
458
- GitLabApiClient.prototype.getApprovalRuleConfiguration = function (projectId) {
459
- return __awaiter(this, void 0, void 0, function () {
460
- var configuration;
461
- return __generator(this, function (_a) {
462
- switch (_a.label) {
463
- case 0: return [4 /*yield*/, this.client.MergeRequestApprovals.configuration(projectId)];
464
- case 1:
465
- configuration = _a.sent();
466
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.approvalRuleConfiguration(configuration)];
467
- }
468
- });
469
- });
470
- };
471
- GitLabApiClient.prototype.updateApprovalRuleConfiguration = function (projectId, configuration) {
472
- return __awaiter(this, void 0, void 0, function () {
473
- var mapping, response;
474
- return __generator(this, function (_a) {
475
- switch (_a.label) {
476
- case 0:
477
- mapping = GitLabMapper_1.GitLabMapper.reverseApprovalRuleConfiguration(configuration);
478
- return [4 /*yield*/, this.client.MergeRequestApprovals.editConfiguration(projectId, mapping)];
479
- case 1:
480
- response = _a.sent();
481
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.approvalRuleConfiguration(response)];
482
- }
483
- });
484
- });
485
- };
486
- GitLabApiClient.prototype.getApprovalRules = function (projectId) {
487
- return __awaiter(this, void 0, void 0, function () {
488
- var approvalRules;
489
- return __generator(this, function (_a) {
490
- switch (_a.label) {
491
- case 0: return [4 /*yield*/, this.client.MergeRequestApprovals.approvalRules(projectId)];
492
- case 1:
493
- approvalRules = _a.sent();
494
- return [2 /*return*/, approvalRules.map(GitLabMapper_1.GitLabMapper.approvalRule)];
495
- }
496
- });
497
- });
498
- };
499
- GitLabApiClient.prototype.createApprovalRule = function (projectId, rule) {
500
- return __awaiter(this, void 0, void 0, function () {
501
- var approvalRule;
502
- return __generator(this, function (_a) {
503
- switch (_a.label) {
504
- case 0: return [4 /*yield*/, this.client.MergeRequestApprovals.addApprovalRule(projectId, rule.name, rule.approvalsRequired, {
505
- applies_to_all_protected_branches: rule.appliesToAllProtectedBranches,
506
- group_ids: rule.groupIds,
507
- protected_branch_ids: rule.protectedBranchIds,
508
- user_ids: rule.userIds,
509
- usernames: rule.usernames
510
- })];
511
- case 1:
512
- approvalRule = _a.sent();
513
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.approvalRule(approvalRule)];
514
- }
515
- });
516
- });
517
- };
518
- GitLabApiClient.prototype.updateApprovalRule = function (projectId, approvalRuleId, rule) {
519
- return __awaiter(this, void 0, void 0, function () {
520
- var approvalRule;
521
- return __generator(this, function (_a) {
522
- switch (_a.label) {
523
- case 0: return [4 /*yield*/, this.client.MergeRequestApprovals.editApprovalRule(projectId, approvalRuleId, rule.name, rule.approvalsRequired, {
524
- applies_to_all_protected_branches: rule.appliesToAllProtectedBranches,
525
- group_ids: rule.groupIds,
526
- protected_branch_ids: rule.protectedBranchIds,
527
- user_ids: rule.userIds,
528
- usernames: rule.usernames
529
- })];
530
- case 1:
531
- approvalRule = _a.sent();
532
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.approvalRule(approvalRule)];
533
- }
534
- });
535
- });
536
- };
537
- GitLabApiClient.prototype.getProtectedBranches = function (projectId) {
538
- return __awaiter(this, void 0, void 0, function () {
539
- var branches;
540
- return __generator(this, function (_a) {
541
- switch (_a.label) {
542
- case 0: return [4 /*yield*/, this.client.ProtectedBranches.all(projectId)];
543
- case 1:
544
- branches = _a.sent();
545
- return [2 /*return*/, branches.map(GitLabMapper_1.GitLabMapper.protectedBranch)];
546
- }
547
- });
548
- });
549
- };
550
- GitLabApiClient = __decorate([
551
- (0, inversify_1.injectable)(),
552
- __param(0, (0, inversify_1.inject)(types_1.MISC.GitLabConfig)),
553
- __metadata("design:paramtypes", [Object])
554
- ], GitLabApiClient);
555
- return GitLabApiClient;
556
- }());
557
- 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, updatedAfter, 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
+ updatedAfter = new Date();
78
+ updatedAfter.setMonth(updatedAfter.getMonth() - 3);
79
+ return [4 /*yield*/, this.client.MergeRequests.all({
80
+ milestone: milestone,
81
+ updatedAfter: updatedAfter.toISOString(),
82
+ scope: 'all'
83
+ })];
84
+ case 1:
85
+ mergeRequests = _a.sent();
86
+ return [2 /*return*/, mergeRequests.map(GitLabMapper_1.GitLabMapper.mergeRequest)];
87
+ }
88
+ });
89
+ });
90
+ };
91
+ GitLabApiClient.prototype.getProjectsByIds = function (projectIds) {
92
+ return __awaiter(this, void 0, void 0, function () {
93
+ var promises, projects;
94
+ var _this = this;
95
+ return __generator(this, function (_a) {
96
+ switch (_a.label) {
97
+ case 0:
98
+ promises = projectIds.map(function (p) { return _this.client.Projects.show(p); });
99
+ return [4 /*yield*/, Promise.all(promises)];
100
+ case 1:
101
+ projects = _a.sent();
102
+ return [2 /*return*/, projects.map(GitLabMapper_1.GitLabMapper.project)];
103
+ }
104
+ });
105
+ });
106
+ };
107
+ GitLabApiClient.prototype.getAllProjects = function () {
108
+ return __awaiter(this, void 0, void 0, function () {
109
+ var projects;
110
+ return __generator(this, function (_a) {
111
+ switch (_a.label) {
112
+ case 0: return [4 /*yield*/, this.client.Projects.all()];
113
+ case 1:
114
+ projects = _a.sent();
115
+ return [2 /*return*/, projects.map(GitLabMapper_1.GitLabMapper.project)];
116
+ }
117
+ });
118
+ });
119
+ };
120
+ GitLabApiClient.prototype.getAllGroupProjects = function (groupId) {
121
+ return __awaiter(this, void 0, void 0, function () {
122
+ var projects;
123
+ return __generator(this, function (_a) {
124
+ switch (_a.label) {
125
+ case 0: return [4 /*yield*/, this.client.Groups.projects(groupId, {
126
+ archived: false,
127
+ with_shared: false,
128
+ include_subgroups: true,
129
+ })];
130
+ case 1:
131
+ projects = _a.sent();
132
+ return [2 /*return*/, projects.map(GitLabMapper_1.GitLabMapper.project)];
133
+ }
134
+ });
135
+ });
136
+ };
137
+ GitLabApiClient.prototype.getLatestTags = function (projectId) {
138
+ return __awaiter(this, void 0, void 0, function () {
139
+ var tags;
140
+ return __generator(this, function (_a) {
141
+ switch (_a.label) {
142
+ case 0: return [4 /*yield*/, this.client.Tags.all(projectId, { maxPages: 1, perPage: 20 })];
143
+ case 1:
144
+ tags = _a.sent();
145
+ return [2 /*return*/, tags.map(GitLabMapper_1.GitLabMapper.tag)];
146
+ }
147
+ });
148
+ });
149
+ };
150
+ GitLabApiClient.prototype.getTag = function (projectId, tagName) {
151
+ return __awaiter(this, void 0, void 0, function () {
152
+ var tag, _a;
153
+ return __generator(this, function (_b) {
154
+ switch (_b.label) {
155
+ case 0:
156
+ _b.trys.push([0, 2, , 3]);
157
+ return [4 /*yield*/, this.client.Tags.show(projectId, tagName)];
158
+ case 1:
159
+ tag = _b.sent();
160
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.tag(tag)];
161
+ case 2:
162
+ _a = _b.sent();
163
+ return [2 /*return*/, null];
164
+ case 3: return [2 /*return*/];
165
+ }
166
+ });
167
+ });
168
+ };
169
+ GitLabApiClient.prototype.createTag = function (projectId, tagName, sha) {
170
+ return __awaiter(this, void 0, void 0, function () {
171
+ var tag;
172
+ return __generator(this, function (_a) {
173
+ switch (_a.label) {
174
+ case 0: return [4 /*yield*/, this.client.Tags.create(projectId, tagName, sha)];
175
+ case 1:
176
+ tag = _a.sent();
177
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.tag(tag)];
178
+ }
179
+ });
180
+ });
181
+ };
182
+ GitLabApiClient.prototype.createRelease = function (projectId, release) {
183
+ return __awaiter(this, void 0, void 0, function () {
184
+ var newRelease;
185
+ return __generator(this, function (_a) {
186
+ switch (_a.label) {
187
+ case 0: return [4 /*yield*/, this.client.Releases.create(projectId, {
188
+ id: projectId,
189
+ name: release.name,
190
+ tag_name: release.tag,
191
+ description: release.description,
192
+ ref: release.ref
193
+ })];
194
+ case 1:
195
+ newRelease = _a.sent();
196
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.release(newRelease)];
197
+ }
198
+ });
199
+ });
200
+ };
201
+ GitLabApiClient.prototype.getCommitsForRelease = function (projectId, dateSince) {
202
+ return __awaiter(this, void 0, void 0, function () {
203
+ var commits;
204
+ return __generator(this, function (_a) {
205
+ switch (_a.label) {
206
+ case 0: return [4 /*yield*/, this.client.Commits.all(projectId, {
207
+ ref_name: 'dev',
208
+ since: dateSince,
209
+ /**
210
+ * This allows us to get merge commits of MRs being accepted
211
+ */
212
+ first_parent: true
213
+ })];
214
+ case 1:
215
+ commits = _a.sent();
216
+ return [2 /*return*/, commits.map(GitLabMapper_1.GitLabMapper.commit)];
217
+ }
218
+ });
219
+ });
220
+ };
221
+ GitLabApiClient.prototype.getBranch = function (projectId, branchName) {
222
+ return __awaiter(this, void 0, void 0, function () {
223
+ var branch, _a;
224
+ return __generator(this, function (_b) {
225
+ switch (_b.label) {
226
+ case 0:
227
+ _b.trys.push([0, 2, , 3]);
228
+ return [4 /*yield*/, this.client.Branches.show(projectId, branchName)];
229
+ case 1:
230
+ branch = _b.sent();
231
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.branch(branch)];
232
+ case 2:
233
+ _a = _b.sent();
234
+ return [2 /*return*/, null];
235
+ case 3: return [2 /*return*/];
236
+ }
237
+ });
238
+ });
239
+ };
240
+ GitLabApiClient.prototype.createBranch = function (projectId, branchName, branchFrom) {
241
+ return __awaiter(this, void 0, void 0, function () {
242
+ var newBranch;
243
+ return __generator(this, function (_a) {
244
+ switch (_a.label) {
245
+ case 0: return [4 /*yield*/, this.client.Branches.create(projectId, branchName, branchFrom)];
246
+ case 1:
247
+ newBranch = _a.sent();
248
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.branch(newBranch)];
249
+ }
250
+ });
251
+ });
252
+ };
253
+ GitLabApiClient.prototype.cherryPick = function (projectId, sha, branchName) {
254
+ return __awaiter(this, void 0, void 0, function () {
255
+ return __generator(this, function (_a) {
256
+ switch (_a.label) {
257
+ case 0: return [4 /*yield*/, this.client.Commits.cherryPick(projectId, sha, branchName)];
258
+ case 1:
259
+ _a.sent();
260
+ return [2 /*return*/];
261
+ }
262
+ });
263
+ });
264
+ };
265
+ GitLabApiClient.prototype.getMergeRequest = function (projectId, sourceBranch, targetBranch, state) {
266
+ return __awaiter(this, void 0, void 0, function () {
267
+ var opts, mergeRequests, mergeRequest;
268
+ return __generator(this, function (_a) {
269
+ switch (_a.label) {
270
+ case 0:
271
+ opts = {
272
+ projectId: projectId,
273
+ sourceBranch: sourceBranch,
274
+ targetBranch: targetBranch
275
+ };
276
+ /**
277
+ * We only care about open MRs, this allows us to close any MR and run the CLI again if needed
278
+ */
279
+ if (state)
280
+ opts.state = state;
281
+ return [4 /*yield*/, this.client.MergeRequests.all(opts)];
282
+ case 1:
283
+ mergeRequests = _a.sent();
284
+ mergeRequest = mergeRequests[0];
285
+ if (!mergeRequest)
286
+ return [2 /*return*/, null];
287
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(mergeRequest)];
288
+ }
289
+ });
290
+ });
291
+ };
292
+ GitLabApiClient.prototype.getMergeRequestById = function (projectId, mergeRequestId) {
293
+ return __awaiter(this, void 0, void 0, function () {
294
+ var mergeRequest;
295
+ return __generator(this, function (_a) {
296
+ switch (_a.label) {
297
+ case 0: return [4 /*yield*/, this.client.MergeRequests.show(projectId, mergeRequestId)];
298
+ case 1:
299
+ mergeRequest = _a.sent();
300
+ if (!mergeRequest)
301
+ return [2 /*return*/, null];
302
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(mergeRequest)];
303
+ }
304
+ });
305
+ });
306
+ };
307
+ GitLabApiClient.prototype.getReleaseMergeRequest = function (projectId, milestone) {
308
+ return __awaiter(this, void 0, void 0, function () {
309
+ var mergeRequests, releaseMR;
310
+ return __generator(this, function (_a) {
311
+ switch (_a.label) {
312
+ case 0: return [4 /*yield*/, this.client.MergeRequests.all({
313
+ projectId: projectId,
314
+ targetBranch: 'master',
315
+ /**
316
+ * We only care about open MRs, this allows us to close any MR and run the CLI again if needed
317
+ */
318
+ state: 'opened',
319
+ milestone: milestone
320
+ })];
321
+ case 1:
322
+ mergeRequests = _a.sent();
323
+ releaseMR = mergeRequests[0];
324
+ if (!releaseMR)
325
+ return [2 /*return*/, null];
326
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(releaseMR)];
327
+ }
328
+ });
329
+ });
330
+ };
331
+ GitLabApiClient.prototype.createMergeRequest = function (projectId, sourceBranch, targetBranch, title, description, milestone) {
332
+ return __awaiter(this, void 0, void 0, function () {
333
+ var mergeRequest;
334
+ return __generator(this, function (_a) {
335
+ switch (_a.label) {
336
+ case 0: return [4 /*yield*/, this.client.MergeRequests.create(projectId, sourceBranch, targetBranch, title, {
337
+ description: description,
338
+ milestoneId: milestone.id,
339
+ assigneeId: GitLabMemberIds_1.GitLabMemberIds.SHIP_IT
340
+ })];
341
+ case 1:
342
+ mergeRequest = _a.sent();
343
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(mergeRequest)];
344
+ }
345
+ });
346
+ });
347
+ };
348
+ GitLabApiClient.prototype.AcceptMergeRequest = function (projectId, mergerequestIId) {
349
+ return __awaiter(this, void 0, void 0, function () {
350
+ var mergeRequest;
351
+ return __generator(this, function (_a) {
352
+ switch (_a.label) {
353
+ case 0: return [4 /*yield*/, this.client.MergeRequests.accept(projectId, mergerequestIId)];
354
+ case 1:
355
+ mergeRequest = _a.sent();
356
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(mergeRequest)];
357
+ }
358
+ });
359
+ });
360
+ };
361
+ GitLabApiClient.prototype.getFile = function (projectId, filePath, branchName) {
362
+ return __awaiter(this, void 0, void 0, function () {
363
+ var file, _a;
364
+ return __generator(this, function (_b) {
365
+ switch (_b.label) {
366
+ case 0:
367
+ _b.trys.push([0, 2, , 3]);
368
+ return [4 /*yield*/, this.client.RepositoryFiles.show(projectId, filePath, branchName)];
369
+ case 1:
370
+ file = _b.sent();
371
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.file(file)];
372
+ case 2:
373
+ _a = _b.sent();
374
+ return [2 /*return*/, null];
375
+ case 3: return [2 /*return*/];
376
+ }
377
+ });
378
+ });
379
+ };
380
+ GitLabApiClient.prototype.updateFile = function (projectId, filePath, branchName, content, commitMessage) {
381
+ return __awaiter(this, void 0, void 0, function () {
382
+ return __generator(this, function (_a) {
383
+ switch (_a.label) {
384
+ case 0: return [4 /*yield*/, this.client.RepositoryFiles.edit(projectId, filePath, branchName, content, commitMessage)];
385
+ case 1:
386
+ _a.sent();
387
+ return [2 /*return*/];
388
+ }
389
+ });
390
+ });
391
+ };
392
+ GitLabApiClient.prototype.commit = function (projectId, branchName, files, commitMessage) {
393
+ return __awaiter(this, void 0, void 0, function () {
394
+ return __generator(this, function (_a) {
395
+ switch (_a.label) {
396
+ case 0: return [4 /*yield*/, this.client.Commits.create(projectId, branchName, commitMessage, files.map(function (f) { return ({
397
+ action: 'update',
398
+ filePath: f.filePath,
399
+ content: f.content
400
+ }); }))];
401
+ case 1:
402
+ _a.sent();
403
+ return [2 /*return*/];
404
+ }
405
+ });
406
+ });
407
+ };
408
+ GitLabApiClient.prototype.getMilestone = function (milestoneName, projectId) {
409
+ return __awaiter(this, void 0, void 0, function () {
410
+ var groupMilestones, milestone, projectMilestones;
411
+ return __generator(this, function (_a) {
412
+ switch (_a.label) {
413
+ case 0: return [4 /*yield*/, this.client.GroupMilestones.all(GroupIds_1.GroupIds.CLICKVIEW)];
414
+ case 1:
415
+ groupMilestones = _a.sent();
416
+ milestone = groupMilestones.find(function (milestone) { return milestone.title === milestoneName; });
417
+ if (milestone)
418
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.milestone(milestone)];
419
+ if (!projectId)
420
+ return [2 /*return*/, null];
421
+ return [4 /*yield*/, this.client.ProjectMilestones.all(projectId)];
422
+ case 2:
423
+ projectMilestones = _a.sent();
424
+ milestone = projectMilestones.find(function (milestone) { return milestone.title === milestoneName; });
425
+ if (!milestone)
426
+ return [2 /*return*/, null];
427
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.milestone(milestone)];
428
+ }
429
+ });
430
+ });
431
+ };
432
+ GitLabApiClient.prototype.updateMilestone = function (projectId, mergeRequestId, newMilestoneId) {
433
+ return __awaiter(this, void 0, void 0, function () {
434
+ var updated;
435
+ return __generator(this, function (_a) {
436
+ switch (_a.label) {
437
+ case 0: return [4 /*yield*/, this.client.MergeRequests.edit(projectId, mergeRequestId, {
438
+ milestoneId: newMilestoneId,
439
+ })];
440
+ case 1:
441
+ updated = _a.sent();
442
+ if (!updated)
443
+ return [2 /*return*/, null];
444
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.milestone(updated.milestone)];
445
+ }
446
+ });
447
+ });
448
+ };
449
+ GitLabApiClient.prototype.getLabels = function (projectId) {
450
+ return __awaiter(this, void 0, void 0, function () {
451
+ var labels;
452
+ return __generator(this, function (_a) {
453
+ switch (_a.label) {
454
+ case 0: return [4 /*yield*/, this.client.Labels.all(projectId)];
455
+ case 1:
456
+ labels = _a.sent();
457
+ return [2 /*return*/, labels.map(GitLabMapper_1.GitLabMapper.label)];
458
+ }
459
+ });
460
+ });
461
+ };
462
+ GitLabApiClient.prototype.getApprovalRuleConfiguration = function (projectId) {
463
+ return __awaiter(this, void 0, void 0, function () {
464
+ var configuration;
465
+ return __generator(this, function (_a) {
466
+ switch (_a.label) {
467
+ case 0: return [4 /*yield*/, this.client.MergeRequestApprovals.configuration(projectId)];
468
+ case 1:
469
+ configuration = _a.sent();
470
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.approvalRuleConfiguration(configuration)];
471
+ }
472
+ });
473
+ });
474
+ };
475
+ GitLabApiClient.prototype.updateApprovalRuleConfiguration = function (projectId, configuration) {
476
+ return __awaiter(this, void 0, void 0, function () {
477
+ var mapping, response;
478
+ return __generator(this, function (_a) {
479
+ switch (_a.label) {
480
+ case 0:
481
+ mapping = GitLabMapper_1.GitLabMapper.reverseApprovalRuleConfiguration(configuration);
482
+ return [4 /*yield*/, this.client.MergeRequestApprovals.editConfiguration(projectId, mapping)];
483
+ case 1:
484
+ response = _a.sent();
485
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.approvalRuleConfiguration(response)];
486
+ }
487
+ });
488
+ });
489
+ };
490
+ GitLabApiClient.prototype.getApprovalRules = function (projectId) {
491
+ return __awaiter(this, void 0, void 0, function () {
492
+ var approvalRules;
493
+ return __generator(this, function (_a) {
494
+ switch (_a.label) {
495
+ case 0: return [4 /*yield*/, this.client.MergeRequestApprovals.approvalRules(projectId)];
496
+ case 1:
497
+ approvalRules = _a.sent();
498
+ return [2 /*return*/, approvalRules.map(GitLabMapper_1.GitLabMapper.approvalRule)];
499
+ }
500
+ });
501
+ });
502
+ };
503
+ GitLabApiClient.prototype.createApprovalRule = function (projectId, rule) {
504
+ return __awaiter(this, void 0, void 0, function () {
505
+ var approvalRule;
506
+ return __generator(this, function (_a) {
507
+ switch (_a.label) {
508
+ case 0: return [4 /*yield*/, this.client.MergeRequestApprovals.addApprovalRule(projectId, rule.name, rule.approvalsRequired, {
509
+ applies_to_all_protected_branches: rule.appliesToAllProtectedBranches,
510
+ group_ids: rule.groupIds,
511
+ protected_branch_ids: rule.protectedBranchIds,
512
+ user_ids: rule.userIds,
513
+ usernames: rule.usernames
514
+ })];
515
+ case 1:
516
+ approvalRule = _a.sent();
517
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.approvalRule(approvalRule)];
518
+ }
519
+ });
520
+ });
521
+ };
522
+ GitLabApiClient.prototype.updateApprovalRule = function (projectId, approvalRuleId, rule) {
523
+ return __awaiter(this, void 0, void 0, function () {
524
+ var approvalRule;
525
+ return __generator(this, function (_a) {
526
+ switch (_a.label) {
527
+ case 0: return [4 /*yield*/, this.client.MergeRequestApprovals.editApprovalRule(projectId, approvalRuleId, rule.name, rule.approvalsRequired, {
528
+ applies_to_all_protected_branches: rule.appliesToAllProtectedBranches,
529
+ group_ids: rule.groupIds,
530
+ protected_branch_ids: rule.protectedBranchIds,
531
+ user_ids: rule.userIds,
532
+ usernames: rule.usernames
533
+ })];
534
+ case 1:
535
+ approvalRule = _a.sent();
536
+ return [2 /*return*/, GitLabMapper_1.GitLabMapper.approvalRule(approvalRule)];
537
+ }
538
+ });
539
+ });
540
+ };
541
+ GitLabApiClient.prototype.getProtectedBranches = function (projectId) {
542
+ return __awaiter(this, void 0, void 0, function () {
543
+ var branches;
544
+ return __generator(this, function (_a) {
545
+ switch (_a.label) {
546
+ case 0: return [4 /*yield*/, this.client.ProtectedBranches.all(projectId)];
547
+ case 1:
548
+ branches = _a.sent();
549
+ return [2 /*return*/, branches.map(GitLabMapper_1.GitLabMapper.protectedBranch)];
550
+ }
551
+ });
552
+ });
553
+ };
554
+ GitLabApiClient = __decorate([
555
+ (0, inversify_1.injectable)(),
556
+ __param(0, (0, inversify_1.inject)(types_1.MISC.GitLabConfig)),
557
+ __metadata("design:paramtypes", [Object])
558
+ ], GitLabApiClient);
559
+ return GitLabApiClient;
560
+ }());
561
+ exports.GitLabApiClient = GitLabApiClient;