@clickview/ship-it 0.0.42-dev.1 → 0.0.42

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