@clickview/ship-it 0.0.4 → 0.0.5-rc.1

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.
@@ -78,14 +78,6 @@ var GitLabApiClient = /** @class */ (function () {
78
78
  })];
79
79
  case 1:
80
80
  mergeRequests = _a.sent();
81
- /**
82
- * Filter out only projectIds we care about
83
- */
84
- if (projectIds === null || projectIds === void 0 ? void 0 : projectIds.length) {
85
- mergeRequests = mergeRequests.filter(function (mr) {
86
- return projectIds.some(function (p) { return mr.project_id.toString() === p.toString(); });
87
- });
88
- }
89
81
  return [2 /*return*/, mergeRequests.map(GitLabMapper_1.GitLabMapper.mergeRequest)];
90
82
  }
91
83
  });
@@ -241,20 +233,23 @@ var GitLabApiClient = /** @class */ (function () {
241
233
  });
242
234
  });
243
235
  };
244
- GitLabApiClient.prototype.getMergeRequest = function (projectId, sourceBranch, targetBranch) {
236
+ GitLabApiClient.prototype.getMergeRequest = function (projectId, sourceBranch, targetBranch, state) {
245
237
  return __awaiter(this, void 0, void 0, function () {
246
- var mergeRequests, mergeRequest;
238
+ var opts, mergeRequests, mergeRequest;
247
239
  return __generator(this, function (_a) {
248
240
  switch (_a.label) {
249
- case 0: return [4 /*yield*/, this.client.MergeRequests.all({
241
+ case 0:
242
+ opts = {
250
243
  projectId: projectId,
251
244
  sourceBranch: sourceBranch,
252
- targetBranch: targetBranch,
253
- /**
254
- * We only care about open MRs, this allows us to close any MR and run the CLI again if needed
255
- */
256
- state: 'opened'
257
- })];
245
+ targetBranch: targetBranch
246
+ };
247
+ /**
248
+ * We only care about open MRs, this allows us to close any MR and run the CLI again if needed
249
+ */
250
+ if (state)
251
+ opts.state = state;
252
+ return [4 /*yield*/, this.client.MergeRequests.all(opts)];
258
253
  case 1:
259
254
  mergeRequests = _a.sent();
260
255
  mergeRequest = mergeRequests[0];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -19,6 +19,7 @@ __exportStar(require("./command-options"), exports);
19
19
  __exportStar(require("./models"), exports);
20
20
  __exportStar(require("./view-models"), exports);
21
21
  __exportStar(require("./Config"), exports);
22
+ __exportStar(require("./MergeRequestState"), exports);
22
23
  __exportStar(require("./ShipItCommand"), exports);
23
24
  __exportStar(require("./ShipItTask"), exports);
24
25
  __exportStar(require("./VersionType"), exports);
@@ -82,40 +82,51 @@ var GitLabService = /** @class */ (function () {
82
82
  this.apiClient = apiClient;
83
83
  }
84
84
  GitLabService.prototype.getProjects = function (options) {
85
+ var _a;
85
86
  return __awaiter(this, void 0, void 0, function () {
86
87
  var allMergeRequests, mergeRequests, projectIds, projects, mappedProjects, _i, mappedProjects_1, mappedProject, extraProjects;
87
- return __generator(this, function (_a) {
88
- switch (_a.label) {
88
+ return __generator(this, function (_b) {
89
+ switch (_b.label) {
89
90
  case 0:
90
91
  if (this.projects)
91
92
  return [2 /*return*/, this.projects];
92
93
  return [4 /*yield*/, this.apiClient.getMergeRequests(options)];
93
94
  case 1:
94
- allMergeRequests = _a.sent();
95
+ allMergeRequests = _b.sent();
95
96
  mergeRequests = allMergeRequests.filter(function (mr) { return mr.targetBranch !== 'master'; });
96
97
  if (!(mergeRequests === null || mergeRequests === void 0 ? void 0 : mergeRequests.length))
97
98
  throw new errors_1.ShipItError('Could not find any merge requests for the specified options');
98
99
  projectIds = lodash_1.default.uniqBy(mergeRequests, function (m) { return m.projectId; }).map(function (m) { return m.projectId; });
99
100
  return [4 /*yield*/, this.apiClient.getProjectsByIds(projectIds)];
100
101
  case 2:
101
- projects = _a.sent();
102
+ projects = _b.sent();
102
103
  if (!(projects === null || projects === void 0 ? void 0 : projects.length) || projects.length !== projectIds.length)
103
104
  throw new errors_1.ShipItError('Could not find all projects for the found merge requests');
104
105
  mappedProjects = projects.map(function (p) { return (__assign(__assign({}, p), { mergeRequests: mergeRequests.filter(function (mr) { return mr.projectId === p.id; }) })); });
105
106
  _i = 0, mappedProjects_1 = mappedProjects;
106
- _a.label = 3;
107
+ _b.label = 3;
107
108
  case 3:
108
109
  if (!(_i < mappedProjects_1.length)) return [3 /*break*/, 6];
109
110
  mappedProject = mappedProjects_1[_i];
110
111
  return [4 /*yield*/, this.getExtraProjects(mappedProject, projectIds)];
111
112
  case 4:
112
- extraProjects = _a.sent();
113
+ extraProjects = _b.sent();
113
114
  Array.prototype.push.apply(mappedProjects, extraProjects.map(function (p) { return (__assign(__assign({}, p), { mergeRequests: [] })); }));
114
- _a.label = 5;
115
+ _b.label = 5;
115
116
  case 5:
116
117
  _i++;
117
118
  return [3 /*break*/, 3];
118
- case 6: return [2 /*return*/, (this.projects = mappedProjects)];
119
+ case 6:
120
+ /**
121
+ * We need to filter our relevant projects after we've added extra projects via tags
122
+ */
123
+ if ((_a = options.projectIds) === null || _a === void 0 ? void 0 : _a.length) {
124
+ mappedProjects = mappedProjects.filter(function (p) {
125
+ var _a;
126
+ return (_a = options.projectIds) === null || _a === void 0 ? void 0 : _a.some(function (pid) { return p.id.toString() === pid; });
127
+ });
128
+ }
129
+ return [2 /*return*/, (this.projects = mappedProjects)];
119
130
  }
120
131
  });
121
132
  });
@@ -254,8 +265,8 @@ var GitLabService = /** @class */ (function () {
254
265
  });
255
266
  });
256
267
  };
257
- GitLabService.prototype.getMergeRequest = function (projectId, branchName) {
258
- return this.apiClient.getMergeRequest(projectId, branchName, 'master');
268
+ GitLabService.prototype.getMergeRequest = function (projectId, branchName, state) {
269
+ return this.apiClient.getMergeRequest(projectId, branchName, 'master', state);
259
270
  };
260
271
  GitLabService.prototype.getMergeRequestById = function (projectId, mergeRequestId) {
261
272
  if (isNaN(+mergeRequestId))
@@ -299,7 +310,7 @@ var GitLabService = /** @class */ (function () {
299
310
  var mergeRequest;
300
311
  return __generator(this, function (_c) {
301
312
  switch (_c.label) {
302
- case 0: return [4 /*yield*/, this.getMergeRequest(projectId, branchName)];
313
+ case 0: return [4 /*yield*/, this.getMergeRequest(projectId, branchName, 'opened')];
303
314
  case 1:
304
315
  mergeRequest = _c.sent();
305
316
  if (!mergeRequest)
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -39,10 +50,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
50
  exports.processMilestoneCommandOptions = exports.getAddMilestoneCommand = void 0;
40
51
  var utils_1 = require("../utils");
41
52
  function processOptions(options) {
42
- var opts = {
43
- milestone: options.milestone,
44
- version: 'minor'
45
- };
53
+ var opts = __assign(__assign({}, options), { version: 'minor' });
46
54
  if (options.projectIds)
47
55
  opts.projectIds = utils_1.ProjectIds.getProjectIds(options.projectIds);
48
56
  if (options.hotfix && options.major)
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -46,12 +35,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
36
  }
48
37
  };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
38
  Object.defineProperty(exports, "__esModule", { value: true });
53
39
  exports.setupCommands = void 0;
54
- var lodash_1 = __importDefault(require("lodash"));
55
40
  var AddMilestoneCommand_1 = require("./AddMilestoneCommand");
56
41
  var GetAction_1 = require("./GetAction");
57
42
  function setupCommands(program, container) {
@@ -77,7 +62,7 @@ function setupCommands(program, container) {
77
62
  return __generator(this, function (_a) {
78
63
  switch (_a.label) {
79
64
  case 0:
80
- options = __assign(__assign({}, (0, AddMilestoneCommand_1.processMilestoneCommandOptions)(lodash_1.default.omit(opts, 'triggerMonorepoBuild'))), { triggerMonorepoBuild: !!opts.triggerMonorepoBuild });
65
+ options = (0, AddMilestoneCommand_1.processMilestoneCommandOptions)(opts);
81
66
  return [4 /*yield*/, getAction('release')(options)];
82
67
  case 1:
83
68
  _a.sent();
@@ -95,7 +80,19 @@ function setupCommands(program, container) {
95
80
  .option('-m, --milestone <milestone>')
96
81
  .option('-b, --monorepoBranchName <monorepoBranchName>')
97
82
  .option('-p, --projectIds <projectIds...>')
98
- .action(getAction('install-packages'));
83
+ .action(function (opts) { return __awaiter(_this, void 0, void 0, function () {
84
+ var options;
85
+ return __generator(this, function (_a) {
86
+ switch (_a.label) {
87
+ case 0:
88
+ options = (0, AddMilestoneCommand_1.processMilestoneCommandOptions)(opts);
89
+ return [4 /*yield*/, getAction('install-packages')(options)];
90
+ case 1:
91
+ _a.sent();
92
+ return [2 /*return*/];
93
+ }
94
+ });
95
+ }); });
99
96
  program.command('validate-mr')
100
97
  .description('Validate a merge request in a single project, ensuring it has a milestone and valid description')
101
98
  .option('-p, --projectId <projectId>')
@@ -106,12 +103,18 @@ function setupCommands(program, container) {
106
103
  .option('-m, --milestone <milestone>')
107
104
  .option('--monorepoBranchName <monorepoBranchName>')
108
105
  .option('-p, --projectIds <projectIds...>')
109
- .action(getAction('start-consuming-project-builds'));
110
- program.command('start-consuming-project-builds')
111
- .description('Trigger TeamCity builds in all consuming projects that are a part of a milestone')
112
- .option('-m, --milestone <milestone>')
113
- .option('--monorepoBranchName <monorepoBranchName>')
114
- .option('-p, --projectIds <projectIds...>')
115
- .action(getAction('start-consuming-project-builds'));
106
+ .action(function (opts) { return __awaiter(_this, void 0, void 0, function () {
107
+ var options;
108
+ return __generator(this, function (_a) {
109
+ switch (_a.label) {
110
+ case 0:
111
+ options = (0, AddMilestoneCommand_1.processMilestoneCommandOptions)(opts);
112
+ return [4 /*yield*/, getAction('start-consuming-project-builds')(options)];
113
+ case 1:
114
+ _a.sent();
115
+ return [2 /*return*/];
116
+ }
117
+ });
118
+ }); });
116
119
  }
117
120
  exports.setupCommands = setupCommands;
@@ -80,7 +80,7 @@ var CreateMergeRequestTask = /** @class */ (function () {
80
80
  utils_1.Logger.logError("[".concat(project.title, "]: [").concat(branchName, "] does not exist"));
81
81
  return [3 /*break*/, 6];
82
82
  }
83
- return [4 /*yield*/, this.service.getMergeRequest(project.id, branchName)];
83
+ return [4 /*yield*/, this.service.getMergeRequest(project.id, branchName, 'opened')];
84
84
  case 4:
85
85
  mergeRequest = _b.sent();
86
86
  if (mergeRequest) {
@@ -225,6 +225,8 @@ var InstallPackagesTask = /** @class */ (function () {
225
225
  switch (_a.label) {
226
226
  case 0:
227
227
  rootDir = ROOT_DIRECTORIES[project.id];
228
+ if (!rootDir)
229
+ return [2 /*return*/, false];
228
230
  return [4 /*yield*/, this.getFileText(project.id, branchName, "".concat(rootDir, "/package.json"))];
229
231
  case 1:
230
232
  packageJson = _a.sent();
@@ -62,7 +62,7 @@ var StartConsumingProjectBuildsTask = /** @class */ (function () {
62
62
  }
63
63
  StartConsumingProjectBuildsTask.prototype.run = function (_options) {
64
64
  return __awaiter(this, void 0, void 0, function () {
65
- var milestone, options, projects, consumingProjects, projectBuildMap, _i, consumingProjects_1, project, branchName, build, totalBuilds, project;
65
+ var milestone, options, projects, consumingProjects, projectBuildMap, _i, consumingProjects_1, project, branchName, buildId, build, totalBuilds, project;
66
66
  return __generator(this, function (_a) {
67
67
  switch (_a.label) {
68
68
  case 0:
@@ -81,7 +81,7 @@ var StartConsumingProjectBuildsTask = /** @class */ (function () {
81
81
  case 2:
82
82
  if (!milestone)
83
83
  return [2 /*return*/, false];
84
- utils_1.Logger.logInfo("Found milestone \"".concat(milestone, "\". Proceeding to install packages in consuming projects..."));
84
+ utils_1.Logger.logInfo("Found milestone \"".concat(milestone, "\". Proceeding to run builds for consuming projects..."));
85
85
  options = {
86
86
  version: _options.version,
87
87
  projectIds: _options.projectIds,
@@ -108,7 +108,12 @@ var StartConsumingProjectBuildsTask = /** @class */ (function () {
108
108
  utils_1.Logger.logWarning("Release branch in project \"".concat(project.title, "\" with milestone \"").concat(options.milestone, "\" was not found. Skipping project..."));
109
109
  return [3 /*break*/, 7];
110
110
  }
111
- return [4 /*yield*/, this.teamCityService.startBuild(TeamCityBuildIDs_1.TeamCityBuildIds[project.id.toString()], branchName)];
111
+ buildId = TeamCityBuildIDs_1.TeamCityBuildIds[project.id.toString()];
112
+ if (!buildId) {
113
+ utils_1.Logger.logWarning("Skipping build for ".concat(project.title, " as no Team City build ID has been specified"));
114
+ return [3 /*break*/, 7];
115
+ }
116
+ return [4 /*yield*/, this.teamCityService.startBuild(buildId, branchName)];
112
117
  case 6:
113
118
  build = _a.sent();
114
119
  projectBuildMap[project.title] = build;
@@ -94,7 +94,7 @@ var TagMasterTask = /** @class */ (function () {
94
94
  return [3 /*break*/, 7];
95
95
  }
96
96
  return [4 /*yield*/, this.service.createRelease(project.id, {
97
- name: "".concat(options.milestone, " Release"),
97
+ name: nextVersion,
98
98
  tag: nextVersion,
99
99
  description: mergeRequest.description,
100
100
  ref: mergeRequest.mergeCommit,
@@ -7,7 +7,8 @@ var VALID_HEADINGS = {
7
7
  'customer changes': true,
8
8
  'code changes': true,
9
9
  'testing': true,
10
- 'notes': true
10
+ 'notes': true,
11
+ 'other': true
11
12
  };
12
13
  var VALID_MONOREPO_HEADINGS = {
13
14
  'common': true,
@@ -24,11 +25,12 @@ var VALID_MONOREPO_HEADINGS = {
24
25
  'testing': true,
25
26
  'dependencies': true,
26
27
  'notes': true,
27
- 'monorepo': true
28
+ 'monorepo': true,
29
+ 'before release': true
28
30
  };
29
31
  function toObject(lines, headingPrefix) {
30
32
  var obj = {};
31
- var currentHeading = 'Other';
33
+ var currentHeading = 'other';
32
34
  for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
33
35
  var line = lines_1[_i];
34
36
  // Skip empty lines
@@ -55,8 +57,9 @@ function toObject(lines, headingPrefix) {
55
57
  return obj;
56
58
  }
57
59
  exports.Descriptions = {
58
- isDescriptionValid: function (description, headingPrefix) {
60
+ isDescriptionValid: function (description, headingPrefix, checkForTesting) {
59
61
  if (headingPrefix === void 0) { headingPrefix = '#'; }
62
+ if (checkForTesting === void 0) { checkForTesting = true; }
60
63
  if (!description.trim())
61
64
  return false;
62
65
  var obj = toObject(description.split('\n'), headingPrefix);
@@ -65,7 +68,7 @@ exports.Descriptions = {
65
68
  return false;
66
69
  if (keys.some(function (k) { return !VALID_HEADINGS[k]; }))
67
70
  return false;
68
- if (obj['testing'] === undefined)
71
+ if (checkForTesting && obj['testing'] === undefined)
69
72
  return false;
70
73
  return true;
71
74
  },
@@ -78,12 +81,13 @@ exports.Descriptions = {
78
81
  return false;
79
82
  if (keys.some(function (k) { return !VALID_MONOREPO_HEADINGS[k]; }))
80
83
  return false;
81
- if (!obj['testing'])
84
+ if (obj['testing'] === undefined)
82
85
  return false;
83
86
  var isValid = Object.keys(obj).every(function (key) {
84
- if (key !== 'dependencies' && key !== 'testing')
87
+ if (key === 'dependencies' || key === 'testing')
85
88
  return true;
86
- return exports.Descriptions.isDescriptionValid(obj[key], '##');
89
+ var subValid = exports.Descriptions.isDescriptionValid(obj[key], '##', false);
90
+ return subValid;
87
91
  });
88
92
  return isValid;
89
93
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clickview/ship-it",
3
- "version": "0.0.4",
3
+ "version": "0.0.5-rc.1",
4
4
  "description": "Release Manager",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {