@clickview/ship-it 0.0.38 → 0.0.40
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.
- package/lib/src/api-clients/git-lab/GitLabApiClient.js +118 -0
- package/lib/src/api-clients/git-lab/GitLabMapper.js +40 -0
- package/lib/src/commands/ConfigureProjectsCommand.js +84 -0
- package/lib/src/commands/ReleaseCommand.js +13 -6
- package/lib/src/commands/StatusCommand.js +7 -2
- package/lib/src/commands/index.js +1 -0
- package/lib/src/constants/CommandTypeMapping.js +2 -1
- package/lib/src/constants/ProjectNames.js +1 -0
- package/lib/src/constants/TeamCityBuildIDs.js +1 -0
- package/lib/src/interfaces/command-options/ConfigureProjectsOptions.js +2 -0
- package/lib/src/interfaces/command-options/index.js +1 -0
- package/lib/src/interfaces/models/ApprovalRule.js +2 -0
- package/lib/src/interfaces/models/ApprovalRuleConfiguration.js +2 -0
- package/lib/src/interfaces/models/CreateApprovalRuleRequest.js +2 -0
- package/lib/src/interfaces/models/Group.js +2 -0
- package/lib/src/interfaces/models/ProtectedBranch.js +2 -0
- package/lib/src/interfaces/models/index.js +6 -0
- package/lib/src/inversify.config.js +5 -0
- package/lib/src/services/GitLabService.js +40 -6
- package/lib/src/startup/SetupCommands.js +12 -0
- package/lib/src/tasks/BumpPackagesTask.js +44 -91
- package/lib/src/tasks/CreateBranchTask.js +1 -1
- package/lib/src/tasks/InstallPackagesTask.js +8 -0
- package/lib/src/tasks/TagMasterTask.js +14 -11
- package/lib/src/tasks/configure-projects/AddApprovalRulesTask.js +182 -0
- package/lib/src/tasks/configure-projects/CreateToolingBranchTask.js +136 -0
- package/lib/src/tasks/configure-projects/EnsureApprovalRulesTask.js +106 -0
- package/lib/src/tasks/configure-projects/index.js +18 -0
- package/lib/src/tasks/configure-projects/primitives/BaseConfigureProjectsTask.js +98 -0
- package/lib/src/tasks/index.js +1 -0
- package/lib/src/types.js +6 -2
- package/package.json +1 -1
|
@@ -64,27 +64,20 @@ var BumpPackagesTask = /** @class */ (function () {
|
|
|
64
64
|
function BumpPackagesTask(service) {
|
|
65
65
|
this.isReleaseBranch = false;
|
|
66
66
|
this.isHotfixBranch = false;
|
|
67
|
-
this.isInPreRelease = false;
|
|
68
67
|
this.service = service;
|
|
69
68
|
}
|
|
70
69
|
BumpPackagesTask.prototype.run = function (options) {
|
|
71
70
|
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
-
var
|
|
73
|
-
return __generator(this, function (
|
|
74
|
-
switch (
|
|
71
|
+
var branch, isValid, commitFiles, _i, commitFiles_1, file, newJsonFile;
|
|
72
|
+
return __generator(this, function (_a) {
|
|
73
|
+
switch (_a.label) {
|
|
75
74
|
case 0:
|
|
76
75
|
utils_1.Logger.logTask('Bumping clickview npm package versions');
|
|
77
76
|
this.isReleaseBranch = RELEASE_BRANCH_REGEX.test(options.branchName);
|
|
78
77
|
this.isHotfixBranch = HOTFIX_BRANCH_REGEX.test(options.branchName);
|
|
79
|
-
_a = this;
|
|
80
|
-
return [4 /*yield*/, this.getIsInPrerelease(options.branchName)];
|
|
81
|
-
case 1:
|
|
82
|
-
_a.isInPreRelease = _b.sent();
|
|
83
|
-
if (this.isInPreRelease)
|
|
84
|
-
utils_1.Logger.logTask('Detected that monorepo is currently in a pre-release state');
|
|
85
78
|
return [4 /*yield*/, this.service.getBranch(utils_1.ProjectIds.MONOREPO_PROJECT_ID, options.branchName)];
|
|
86
|
-
case
|
|
87
|
-
branch =
|
|
79
|
+
case 1:
|
|
80
|
+
branch = _a.sent();
|
|
88
81
|
if (!branch) {
|
|
89
82
|
utils_1.Logger.logError("Branch with name ".concat(options.branchName, " was not be found."));
|
|
90
83
|
return [2 /*return*/, false];
|
|
@@ -103,8 +96,8 @@ var BumpPackagesTask = /** @class */ (function () {
|
|
|
103
96
|
}
|
|
104
97
|
utils_1.Logger.logInfo('Committing new versions...');
|
|
105
98
|
return [4 /*yield*/, this.service.commit(utils_1.ProjectIds.MONOREPO_PROJECT_ID, options.branchName, 'Bump package versions', commitFiles)];
|
|
106
|
-
case
|
|
107
|
-
|
|
99
|
+
case 2:
|
|
100
|
+
_a.sent();
|
|
108
101
|
utils_1.Logger.logSuccess('Successfully committed updated version numbers.');
|
|
109
102
|
return [2 /*return*/, true];
|
|
110
103
|
}
|
|
@@ -174,98 +167,58 @@ var BumpPackagesTask = /** @class */ (function () {
|
|
|
174
167
|
}
|
|
175
168
|
return commitFiles;
|
|
176
169
|
};
|
|
177
|
-
BumpPackagesTask.prototype.getNextVersion = function (
|
|
170
|
+
BumpPackagesTask.prototype.getNextVersion = function (currentVersion, options) {
|
|
178
171
|
if (options.preId)
|
|
179
|
-
return this.getNextPrereleaseVersion(
|
|
180
|
-
return this.getNextReleaseVersion(
|
|
172
|
+
return this.getNextPrereleaseVersion(currentVersion, options);
|
|
173
|
+
return this.getNextReleaseVersion(currentVersion);
|
|
181
174
|
};
|
|
182
|
-
BumpPackagesTask.prototype.getNextPrereleaseVersion = function (
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (this.isInPreRelease) {
|
|
190
|
-
if (options.preId === 'dev') {
|
|
191
|
-
if (DEV_VERSION_REGEX.test(version)) {
|
|
192
|
-
var _a = version.split('-dev.'), mainVersion = _a[0], currentPreId = _a[1];
|
|
193
|
-
return "".concat(mainVersion, "-dev.").concat(Number(currentPreId) + 1);
|
|
194
|
-
}
|
|
195
|
-
return "".concat(utils_1.Versions.getNextVersion(version, 'patch'), "-dev.0");
|
|
196
|
-
}
|
|
197
|
-
if (options.preId === 'rc') {
|
|
198
|
-
if (RC_VERSION_REGEX.test(version)) {
|
|
199
|
-
var _b = version.split('-rc.'), mainVersion = _b[0], currentPreId = _b[1];
|
|
200
|
-
return "".concat(mainVersion, "-rc.").concat(Number(currentPreId) + 1);
|
|
201
|
-
}
|
|
202
|
-
if (this.isReleaseBranch)
|
|
203
|
-
return "".concat(utils_1.Versions.getNextVersion(version, 'minor'), "-rc.0");
|
|
204
|
-
if (this.isHotfixBranch)
|
|
205
|
-
return "".concat(utils_1.Versions.getNextVersion(version, 'patch'), "-rc.0");
|
|
175
|
+
BumpPackagesTask.prototype.getNextPrereleaseVersion = function (currentVersion, options) {
|
|
176
|
+
if (options.preId === 'dev') {
|
|
177
|
+
// If version is already a dev version, increment the preId
|
|
178
|
+
// Example: 1.0.0-dev.5 -> 1.0.0-dev.6
|
|
179
|
+
if (DEV_VERSION_REGEX.test(currentVersion)) {
|
|
180
|
+
var _a = currentVersion.split('-dev.'), mainVersion = _a[0], currentPreId = _a[1];
|
|
181
|
+
return "".concat(mainVersion, "-dev.").concat(Number(currentPreId) + 1);
|
|
206
182
|
}
|
|
207
|
-
//
|
|
208
|
-
|
|
183
|
+
// Bump the patch version and add the dev preId
|
|
184
|
+
// Example: 1.0.0 -> 1.0.1-dev.0
|
|
185
|
+
return "".concat(utils_1.Versions.getNextVersion(currentVersion, 'patch'), "-dev.0");
|
|
209
186
|
}
|
|
210
|
-
/**
|
|
211
|
-
* The code below runs if we are not currently in a prerelease state,
|
|
212
|
-
* and we want to bump to a prerelease version.
|
|
213
|
-
*
|
|
214
|
-
* Example: 1.0.0 -> 1.0.1-dev.0 / 1.0.0 -> 1.1.0-rc.0
|
|
215
|
-
*/
|
|
216
|
-
if (options.preId === 'dev')
|
|
217
|
-
return "".concat(utils_1.Versions.getNextVersion(version, 'patch'), "-dev.0");
|
|
218
187
|
if (options.preId === 'rc') {
|
|
188
|
+
// If version is already an rc version, increment the preId
|
|
189
|
+
// Example: 1.0.0-rc.5 -> 1.0.0-rc.6
|
|
190
|
+
if (RC_VERSION_REGEX.test(currentVersion)) {
|
|
191
|
+
var _b = currentVersion.split('-rc.'), mainVersion = _b[0], currentPreId = _b[1];
|
|
192
|
+
return "".concat(mainVersion, "-rc.").concat(Number(currentPreId) + 1);
|
|
193
|
+
}
|
|
194
|
+
// For release branches, bump the minor version and add the rc preId
|
|
195
|
+
// Example: 1.0.0 -> 1.1.0-rc.0
|
|
219
196
|
if (this.isReleaseBranch)
|
|
220
|
-
return "".concat(utils_1.Versions.getNextVersion(
|
|
197
|
+
return "".concat(utils_1.Versions.getNextVersion(currentVersion, 'minor'), "-rc.0");
|
|
198
|
+
// For hotfix branches, bump the patch version and add the rc preId
|
|
199
|
+
// Example: 1.0.0 -> 1.0.1-rc.0
|
|
221
200
|
if (this.isHotfixBranch)
|
|
222
|
-
return "".concat(utils_1.Versions.getNextVersion(
|
|
201
|
+
return "".concat(utils_1.Versions.getNextVersion(currentVersion, 'patch'), "-rc.0");
|
|
223
202
|
}
|
|
224
203
|
// Should never run
|
|
225
|
-
return
|
|
204
|
+
return currentVersion;
|
|
226
205
|
};
|
|
227
|
-
BumpPackagesTask.prototype.getNextReleaseVersion = function (
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
return
|
|
206
|
+
BumpPackagesTask.prototype.getNextReleaseVersion = function (currentVersion) {
|
|
207
|
+
// Example: 1.0.1-dev.0 -> 1.0.1
|
|
208
|
+
if (DEV_VERSION_REGEX.test(currentVersion)) {
|
|
209
|
+
return currentVersion.split('-')[0];
|
|
210
|
+
}
|
|
211
|
+
// Example: 1.0.1-rc.5 -> 1.0.1
|
|
212
|
+
if (RC_VERSION_REGEX.test(currentVersion)) {
|
|
213
|
+
return currentVersion.split('-')[0];
|
|
231
214
|
}
|
|
232
215
|
// Example: 1.0.0 -> 1.1.0
|
|
233
216
|
if (this.isReleaseBranch)
|
|
234
|
-
return utils_1.Versions.getNextVersion(
|
|
217
|
+
return utils_1.Versions.getNextVersion(currentVersion, 'minor');
|
|
235
218
|
// Example: 1.0.0 -> 1.0.1
|
|
236
219
|
if (this.isHotfixBranch)
|
|
237
|
-
return utils_1.Versions.getNextVersion(
|
|
238
|
-
return
|
|
239
|
-
};
|
|
240
|
-
BumpPackagesTask.prototype.getIsInPrerelease = function (branchName) {
|
|
241
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
242
|
-
var _i, MONOREPO_PACKAGE_JSON_FILES_1, file, text, json;
|
|
243
|
-
return __generator(this, function (_a) {
|
|
244
|
-
switch (_a.label) {
|
|
245
|
-
case 0:
|
|
246
|
-
_i = 0, MONOREPO_PACKAGE_JSON_FILES_1 = MonorepoPackageJsonFiles_1.MONOREPO_PACKAGE_JSON_FILES;
|
|
247
|
-
_a.label = 1;
|
|
248
|
-
case 1:
|
|
249
|
-
if (!(_i < MONOREPO_PACKAGE_JSON_FILES_1.length)) return [3 /*break*/, 4];
|
|
250
|
-
file = MONOREPO_PACKAGE_JSON_FILES_1[_i];
|
|
251
|
-
if (!file.includes('projects'))
|
|
252
|
-
return [3 /*break*/, 3];
|
|
253
|
-
return [4 /*yield*/, this.getFileText(utils_1.ProjectIds.MONOREPO_PROJECT_ID, branchName, file)];
|
|
254
|
-
case 2:
|
|
255
|
-
text = _a.sent();
|
|
256
|
-
json = JSON.parse(text);
|
|
257
|
-
if (RC_VERSION_REGEX.test(json.version))
|
|
258
|
-
return [2 /*return*/, true];
|
|
259
|
-
if (DEV_VERSION_REGEX.test(json.version))
|
|
260
|
-
return [2 /*return*/, true];
|
|
261
|
-
_a.label = 3;
|
|
262
|
-
case 3:
|
|
263
|
-
_i++;
|
|
264
|
-
return [3 /*break*/, 1];
|
|
265
|
-
case 4: return [2 /*return*/, false];
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
});
|
|
220
|
+
return utils_1.Versions.getNextVersion(currentVersion, 'patch');
|
|
221
|
+
return currentVersion;
|
|
269
222
|
};
|
|
270
223
|
BumpPackagesTask = __decorate([
|
|
271
224
|
(0, inversify_1.injectable)(),
|
|
@@ -81,7 +81,7 @@ var CreateBranchTask = /** @class */ (function () {
|
|
|
81
81
|
return [3 /*break*/, 5];
|
|
82
82
|
}
|
|
83
83
|
branchFrom = options.version === 'patch' ? 'master' : 'dev';
|
|
84
|
-
return [4 /*yield*/, this.service.createBranch(project, branchFrom, branchName
|
|
84
|
+
return [4 /*yield*/, this.service.createBranch(project, branchFrom, branchName)];
|
|
85
85
|
case 4:
|
|
86
86
|
_b.sent();
|
|
87
87
|
utils_1.Logger.logMessage("[".concat(project.title, "]: [").concat(branchName, "] Has been created"));
|
|
@@ -96,6 +96,14 @@ var InstallPackagesTask = /** @class */ (function () {
|
|
|
96
96
|
}
|
|
97
97
|
if (!(_options.targetBranchName && _options.monorepoBranchName && _options.projectIds)) return [3 /*break*/, 8];
|
|
98
98
|
targetBranch = _options.targetBranchName;
|
|
99
|
+
if (targetBranch.startsWith('release') && !_options.monorepoBranchName.startsWith('release')) {
|
|
100
|
+
utils_1.Logger.logError('Attempting to target release with non release branch.');
|
|
101
|
+
return [2 /*return*/, false];
|
|
102
|
+
}
|
|
103
|
+
if (targetBranch.startsWith('hotfix') && !_options.monorepoBranchName.startsWith('hotfix')) {
|
|
104
|
+
utils_1.Logger.logError('Attempting to target hotfix with non hotfix branch.');
|
|
105
|
+
return [2 /*return*/, false];
|
|
106
|
+
}
|
|
99
107
|
if (_options.projectIds.length > 1) {
|
|
100
108
|
utils_1.Logger.logError("Too many projects given! Maximum 1 project allowed but got ".concat(_options.projectIds.length));
|
|
101
109
|
return [2 /*return*/, false];
|
|
@@ -62,7 +62,7 @@ var TagMasterTask = /** @class */ (function () {
|
|
|
62
62
|
}
|
|
63
63
|
TagMasterTask.prototype.run = function (options) {
|
|
64
64
|
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
-
var projects, cont, logMessageSlack, _i, projects_1, project, _a, branchName, nextVersion,
|
|
65
|
+
var projects, cont, logMessageSlack, _i, projects_1, project, _a, branchName, nextVersion, existingTag, mergeRequest, _b, threadLabel, statusCleanMessage;
|
|
66
66
|
return __generator(this, function (_c) {
|
|
67
67
|
switch (_c.label) {
|
|
68
68
|
case 0:
|
|
@@ -80,19 +80,19 @@ var TagMasterTask = /** @class */ (function () {
|
|
|
80
80
|
return [4 /*yield*/, this.service.getNextBranchInfo(project.id, options.version)];
|
|
81
81
|
case 3:
|
|
82
82
|
_a = _c.sent(), branchName = _a.branchName, nextVersion = _a.nextVersion;
|
|
83
|
-
return [4 /*yield*/, this.service.
|
|
83
|
+
return [4 /*yield*/, this.service.getTag(project.id, nextVersion)];
|
|
84
84
|
case 4:
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
Logger_1.Logger.
|
|
85
|
+
existingTag = _c.sent();
|
|
86
|
+
if (existingTag) {
|
|
87
|
+
Logger_1.Logger.logWarning("[".concat(project.title, "]: [").concat(existingTag.name, "] tag already exists"));
|
|
88
88
|
cont = false;
|
|
89
89
|
return [3 /*break*/, 8];
|
|
90
90
|
}
|
|
91
|
-
return [4 /*yield*/, this.service.
|
|
91
|
+
return [4 /*yield*/, this.service.getMergeRequest(project.id, branchName)];
|
|
92
92
|
case 5:
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
Logger_1.Logger.
|
|
93
|
+
mergeRequest = _c.sent();
|
|
94
|
+
if (!(mergeRequest === null || mergeRequest === void 0 ? void 0 : mergeRequest.mergeCommit)) {
|
|
95
|
+
Logger_1.Logger.logError("[".concat(project.title, "]: [").concat(branchName, "] has not been merged"));
|
|
96
96
|
cont = false;
|
|
97
97
|
return [3 /*break*/, 8];
|
|
98
98
|
}
|
|
@@ -115,7 +115,7 @@ var TagMasterTask = /** @class */ (function () {
|
|
|
115
115
|
return [3 /*break*/, 2];
|
|
116
116
|
case 9:
|
|
117
117
|
if (!(options.slackNotifier && logMessageSlack !== '')) return [3 /*break*/, 11];
|
|
118
|
-
threadLabel = "".concat(options.milestone, " merge
|
|
118
|
+
threadLabel = "".concat(options.milestone, " merge issues found when merging master into dev.");
|
|
119
119
|
statusCleanMessage = 'No projects require manual merging.';
|
|
120
120
|
return [4 /*yield*/, this.slackService.sendSlackStatusMessage({
|
|
121
121
|
emailList: [],
|
|
@@ -143,7 +143,7 @@ var TagMasterTask = /** @class */ (function () {
|
|
|
143
143
|
case 1:
|
|
144
144
|
mergeRequest = _a.sent();
|
|
145
145
|
// Add delay to give time before we merge created MR
|
|
146
|
-
return [4 /*yield*/, delay(
|
|
146
|
+
return [4 /*yield*/, delay(10000)];
|
|
147
147
|
case 2:
|
|
148
148
|
// Add delay to give time before we merge created MR
|
|
149
149
|
_a.sent();
|
|
@@ -168,6 +168,9 @@ var TagMasterTask = /** @class */ (function () {
|
|
|
168
168
|
}
|
|
169
169
|
else {
|
|
170
170
|
Logger_1.Logger.logError("Could not merge master into dev.");
|
|
171
|
+
logMessageSlack += "[".concat(project.title, "]: Requires manual merging. An issue was found when trying to merge master into dev.\n");
|
|
172
|
+
logMessageSlack += " - ".concat(updatedMergeRequest.url, "\n");
|
|
173
|
+
return [2 /*return*/, logMessageSlack];
|
|
171
174
|
}
|
|
172
175
|
return [2 /*return*/, logMessageSlack];
|
|
173
176
|
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
29
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
30
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
31
|
+
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;
|
|
32
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
33
|
+
};
|
|
34
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
35
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
36
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
37
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
38
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
39
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
40
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
44
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
45
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
46
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
47
|
+
function step(op) {
|
|
48
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
49
|
+
while (_) try {
|
|
50
|
+
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;
|
|
51
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
52
|
+
switch (op[0]) {
|
|
53
|
+
case 0: case 1: t = op; break;
|
|
54
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
55
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
56
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
57
|
+
default:
|
|
58
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
59
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
60
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
61
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
62
|
+
if (t[2]) _.ops.pop();
|
|
63
|
+
_.trys.pop(); continue;
|
|
64
|
+
}
|
|
65
|
+
op = body.call(thisArg, _);
|
|
66
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
67
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
71
|
+
exports.AddApprovalRulesTask = exports.APPROVAL_RULE_NAME = void 0;
|
|
72
|
+
require("reflect-metadata");
|
|
73
|
+
var inversify_1 = require("inversify");
|
|
74
|
+
var utils_1 = require("../../utils");
|
|
75
|
+
var BaseConfigureProjectsTask_1 = require("./primitives/BaseConfigureProjectsTask");
|
|
76
|
+
var APPROVAL_RULE_CONFIGURATION = {
|
|
77
|
+
mergeRequestsAuthorApproval: false,
|
|
78
|
+
disableOverridingApproversPerMergeRequest: false,
|
|
79
|
+
mergeRequestsDisableCommittersApproval: false,
|
|
80
|
+
requirePasswordToApprove: false,
|
|
81
|
+
resetApprovalsOnPush: true
|
|
82
|
+
};
|
|
83
|
+
exports.APPROVAL_RULE_NAME = 'ClickView Group';
|
|
84
|
+
var CLICKVIEW_GROUP_ID = 1069;
|
|
85
|
+
var NEW_APPROVAL_RULE = {
|
|
86
|
+
name: exports.APPROVAL_RULE_NAME,
|
|
87
|
+
approvalsRequired: 1,
|
|
88
|
+
appliesToAllProtectedBranches: false,
|
|
89
|
+
groupIds: [CLICKVIEW_GROUP_ID],
|
|
90
|
+
// The task will fetch "master" and use it's id in this lookup
|
|
91
|
+
protectedBranchIds: []
|
|
92
|
+
};
|
|
93
|
+
var AddApprovalRulesTask = /** @class */ (function (_super) {
|
|
94
|
+
__extends(AddApprovalRulesTask, _super);
|
|
95
|
+
function AddApprovalRulesTask() {
|
|
96
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
97
|
+
}
|
|
98
|
+
AddApprovalRulesTask.prototype.run = function (options) {
|
|
99
|
+
var _a;
|
|
100
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
101
|
+
var projectIds, _i, projectIds_1, projectId;
|
|
102
|
+
return __generator(this, function (_b) {
|
|
103
|
+
switch (_b.label) {
|
|
104
|
+
case 0:
|
|
105
|
+
if (!options.projectIds && !options.allProjects) {
|
|
106
|
+
utils_1.Logger.logError('No --projectIds provided and --allProjects option was not selected.');
|
|
107
|
+
return [2 /*return*/, false];
|
|
108
|
+
}
|
|
109
|
+
if (options.allProjects && ((_a = options.projectIds) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
110
|
+
utils_1.Logger.logError('Cannot specify --projectIds and --allProjects option.');
|
|
111
|
+
return [2 /*return*/, false];
|
|
112
|
+
}
|
|
113
|
+
return [4 /*yield*/, this.getProjectIds(options)];
|
|
114
|
+
case 1:
|
|
115
|
+
projectIds = _b.sent();
|
|
116
|
+
utils_1.Logger.logTask('Adding approval rules');
|
|
117
|
+
_i = 0, projectIds_1 = projectIds;
|
|
118
|
+
_b.label = 2;
|
|
119
|
+
case 2:
|
|
120
|
+
if (!(_i < projectIds_1.length)) return [3 /*break*/, 5];
|
|
121
|
+
projectId = projectIds_1[_i];
|
|
122
|
+
return [4 /*yield*/, this.runProject(projectId)];
|
|
123
|
+
case 3:
|
|
124
|
+
if (!(_b.sent()))
|
|
125
|
+
return [2 /*return*/, false];
|
|
126
|
+
_b.label = 4;
|
|
127
|
+
case 4:
|
|
128
|
+
_i++;
|
|
129
|
+
return [3 /*break*/, 2];
|
|
130
|
+
case 5: return [2 /*return*/, true];
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
AddApprovalRulesTask.prototype.runProject = function (projectId) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
137
|
+
var project, protectedBranches, masterBranch, approvalRules, approvalRule;
|
|
138
|
+
return __generator(this, function (_a) {
|
|
139
|
+
switch (_a.label) {
|
|
140
|
+
case 0: return [4 /*yield*/, this.service.getProject(+projectId)];
|
|
141
|
+
case 1:
|
|
142
|
+
project = _a.sent();
|
|
143
|
+
if (!project) {
|
|
144
|
+
utils_1.Logger.logError("Could not fetch projectId: ".concat(projectId));
|
|
145
|
+
return [2 /*return*/, false];
|
|
146
|
+
}
|
|
147
|
+
return [4 /*yield*/, this.service.getProtectedBranches(projectId)];
|
|
148
|
+
case 2:
|
|
149
|
+
protectedBranches = _a.sent();
|
|
150
|
+
masterBranch = protectedBranches === null || protectedBranches === void 0 ? void 0 : protectedBranches.find(function (b) { return b.name === 'master'; });
|
|
151
|
+
if (!masterBranch) {
|
|
152
|
+
utils_1.Logger.logError("Could not find protected master branch for projectId: ".concat(projectId, "."));
|
|
153
|
+
return [2 /*return*/, false];
|
|
154
|
+
}
|
|
155
|
+
return [4 /*yield*/, this.service.getApprovalRules(projectId)];
|
|
156
|
+
case 3:
|
|
157
|
+
approvalRules = _a.sent();
|
|
158
|
+
approvalRule = approvalRules === null || approvalRules === void 0 ? void 0 : approvalRules.find(function (r) { return r.name === exports.APPROVAL_RULE_NAME; });
|
|
159
|
+
if (!!approvalRule) return [3 /*break*/, 5];
|
|
160
|
+
return [4 /*yield*/, this.service.createApprovalRule(projectId, __assign(__assign({}, NEW_APPROVAL_RULE), { protectedBranchIds: [masterBranch.id] }))];
|
|
161
|
+
case 4:
|
|
162
|
+
_a.sent();
|
|
163
|
+
return [3 /*break*/, 7];
|
|
164
|
+
case 5: return [4 /*yield*/, this.service.updateApprovalRule(projectId, approvalRule.id, __assign(__assign({}, NEW_APPROVAL_RULE), { protectedBranchIds: [masterBranch.id] }))];
|
|
165
|
+
case 6:
|
|
166
|
+
_a.sent();
|
|
167
|
+
_a.label = 7;
|
|
168
|
+
case 7: return [4 /*yield*/, this.service.updateApprovalRuleConfiguration(projectId, APPROVAL_RULE_CONFIGURATION)];
|
|
169
|
+
case 8:
|
|
170
|
+
_a.sent();
|
|
171
|
+
utils_1.Logger.logSuccess("Successfully added approval rules to: ".concat(project.title));
|
|
172
|
+
return [2 /*return*/, true];
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
AddApprovalRulesTask = __decorate([
|
|
178
|
+
(0, inversify_1.injectable)()
|
|
179
|
+
], AddApprovalRulesTask);
|
|
180
|
+
return AddApprovalRulesTask;
|
|
181
|
+
}(BaseConfigureProjectsTask_1.BaseConfigureProjectsTask));
|
|
182
|
+
exports.AddApprovalRulesTask = AddApprovalRulesTask;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
+
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;
|
|
21
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
+
};
|
|
23
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
24
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
25
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
26
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
27
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
28
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
33
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
34
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
35
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
36
|
+
function step(op) {
|
|
37
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
38
|
+
while (_) try {
|
|
39
|
+
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;
|
|
40
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
41
|
+
switch (op[0]) {
|
|
42
|
+
case 0: case 1: t = op; break;
|
|
43
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
44
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
45
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
46
|
+
default:
|
|
47
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
48
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
49
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
50
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
51
|
+
if (t[2]) _.ops.pop();
|
|
52
|
+
_.trys.pop(); continue;
|
|
53
|
+
}
|
|
54
|
+
op = body.call(thisArg, _);
|
|
55
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
56
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
60
|
+
exports.CreateToolingBranchTask = void 0;
|
|
61
|
+
require("reflect-metadata");
|
|
62
|
+
var inversify_1 = require("inversify");
|
|
63
|
+
var utils_1 = require("../../utils");
|
|
64
|
+
var BaseConfigureProjectsTask_1 = require("./primitives/BaseConfigureProjectsTask");
|
|
65
|
+
var TOOLING_BRANCH_NAME = 'tooling';
|
|
66
|
+
var CreateToolingBranchTask = /** @class */ (function (_super) {
|
|
67
|
+
__extends(CreateToolingBranchTask, _super);
|
|
68
|
+
function CreateToolingBranchTask() {
|
|
69
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
70
|
+
}
|
|
71
|
+
CreateToolingBranchTask.prototype.run = function (options) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
+
var projectIds, _i, projectIds_1, projectId;
|
|
74
|
+
return __generator(this, function (_a) {
|
|
75
|
+
switch (_a.label) {
|
|
76
|
+
case 0: return [4 /*yield*/, this.getProjectIds(options)];
|
|
77
|
+
case 1:
|
|
78
|
+
projectIds = _a.sent();
|
|
79
|
+
utils_1.Logger.logTask('Adding "tooling" branch to all projects');
|
|
80
|
+
_i = 0, projectIds_1 = projectIds;
|
|
81
|
+
_a.label = 2;
|
|
82
|
+
case 2:
|
|
83
|
+
if (!(_i < projectIds_1.length)) return [3 /*break*/, 5];
|
|
84
|
+
projectId = projectIds_1[_i];
|
|
85
|
+
return [4 /*yield*/, this.runProject(projectId)];
|
|
86
|
+
case 3:
|
|
87
|
+
if (!(_a.sent()))
|
|
88
|
+
return [2 /*return*/, false];
|
|
89
|
+
_a.label = 4;
|
|
90
|
+
case 4:
|
|
91
|
+
_i++;
|
|
92
|
+
return [3 /*break*/, 2];
|
|
93
|
+
case 5: return [2 /*return*/, true];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
CreateToolingBranchTask.prototype.runProject = function (projectId) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
100
|
+
var project, toolingBranch, masterBranch;
|
|
101
|
+
return __generator(this, function (_a) {
|
|
102
|
+
switch (_a.label) {
|
|
103
|
+
case 0: return [4 /*yield*/, this.service.getProject(+projectId)];
|
|
104
|
+
case 1:
|
|
105
|
+
project = _a.sent();
|
|
106
|
+
if (!project) {
|
|
107
|
+
utils_1.Logger.logError("Could not fetch projectId: ".concat(projectId));
|
|
108
|
+
return [2 /*return*/, false];
|
|
109
|
+
}
|
|
110
|
+
return [4 /*yield*/, this.service.getBranch(projectId, TOOLING_BRANCH_NAME)];
|
|
111
|
+
case 2:
|
|
112
|
+
toolingBranch = _a.sent();
|
|
113
|
+
if (toolingBranch)
|
|
114
|
+
return [2 /*return*/, true];
|
|
115
|
+
return [4 /*yield*/, this.service.getBranch(projectId, 'master')];
|
|
116
|
+
case 3:
|
|
117
|
+
masterBranch = _a.sent();
|
|
118
|
+
if (!masterBranch) {
|
|
119
|
+
utils_1.Logger.logError("Could not find master branch to branch from for projectId: ".concat(projectId, "."));
|
|
120
|
+
return [2 /*return*/, false];
|
|
121
|
+
}
|
|
122
|
+
return [4 /*yield*/, this.service.createBranch(project, masterBranch.name, TOOLING_BRANCH_NAME)];
|
|
123
|
+
case 4:
|
|
124
|
+
_a.sent();
|
|
125
|
+
utils_1.Logger.logSuccess("Successfully added a \"tooling\" branch to project: ".concat(project.title));
|
|
126
|
+
return [2 /*return*/, true];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
CreateToolingBranchTask = __decorate([
|
|
132
|
+
(0, inversify_1.injectable)()
|
|
133
|
+
], CreateToolingBranchTask);
|
|
134
|
+
return CreateToolingBranchTask;
|
|
135
|
+
}(BaseConfigureProjectsTask_1.BaseConfigureProjectsTask));
|
|
136
|
+
exports.CreateToolingBranchTask = CreateToolingBranchTask;
|