@clickview/ship-it 0.0.12 → 0.0.14

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.
@@ -165,23 +165,20 @@ var GitLabApiClient = /** @class */ (function () {
165
165
  });
166
166
  });
167
167
  };
168
- GitLabApiClient.prototype.getCommitsSince = function (projectId, branchName, sinceSha) {
168
+ GitLabApiClient.prototype.getCommitsForRelease = function (projectId, dateSince) {
169
169
  return __awaiter(this, void 0, void 0, function () {
170
- var commit, commits;
170
+ var commits;
171
171
  return __generator(this, function (_a) {
172
172
  switch (_a.label) {
173
- case 0: return [4 /*yield*/, this.client.Commits.show(projectId, sinceSha)];
173
+ case 0: return [4 /*yield*/, this.client.Commits.all(projectId, {
174
+ ref_name: 'dev',
175
+ since: dateSince,
176
+ /**
177
+ * This allows us to get merge commits of MRs being accepted
178
+ */
179
+ first_parent: true
180
+ })];
174
181
  case 1:
175
- commit = _a.sent();
176
- return [4 /*yield*/, this.client.Commits.all(projectId, {
177
- ref_name: branchName,
178
- since: commit.committed_date,
179
- /**
180
- * This allows us to get merge commits of MRs being accepted
181
- */
182
- first_parent: true
183
- })];
184
- case 2:
185
182
  commits = _a.sent();
186
183
  return [2 /*return*/, commits.map(GitLabMapper_1.GitLabMapper.commit)];
187
184
  }
@@ -17,7 +17,8 @@ exports.GitLabMapper = {
17
17
  targetBranch: m.target_branch,
18
18
  sourceBranch: m.source_branch,
19
19
  milestone: exports.GitLabMapper.milestone(m.milestone),
20
- labels: m.labels
20
+ labels: m.labels,
21
+ dateCreated: m.created_at
21
22
  };
22
23
  },
23
24
  project: function (p) {
@@ -10,4 +10,5 @@ exports.TeamCityBuildIds = (_a = {},
10
10
  _a[constants_1.PROJECT_NAMES.frontend.cloud] = 'ClickViewCloud_BuildAndPackageDocker',
11
11
  _a[constants_1.PROJECT_NAMES.frontend.reports] = 'Web_AnalyticsWeb_BuildAndPackageDocker',
12
12
  _a[constants_1.PROJECT_NAMES.frontend.lite] = 'ClickViewLiteWeb_BuildAndPackageDocker',
13
+ _a[constants_1.PROJECT_NAMES.backend.auth] = 'auth_web_B',
13
14
  _a);
@@ -205,30 +205,12 @@ var GitLabService = /** @class */ (function () {
205
205
  });
206
206
  });
207
207
  };
208
- GitLabService.prototype.getDevCommitsSince = function (projectId, sinceSha) {
208
+ GitLabService.prototype.getCommitsForRelease = function (projectId, dateSince) {
209
209
  return __awaiter(this, void 0, void 0, function () {
210
- var commits, mergeCommitIndex;
211
210
  return __generator(this, function (_a) {
212
211
  switch (_a.label) {
213
- case 0: return [4 /*yield*/, this.apiClient.getCommitsSince(projectId, 'dev', sinceSha)];
214
- case 1:
215
- commits = _a.sent();
216
- mergeCommitIndex = commits.findIndex(function (commit) {
217
- var title = commit.title.toLowerCase();
218
- return title.includes('merge') &&
219
- title.includes('master') &&
220
- title.includes('dev');
221
- });
222
- if (mergeCommitIndex > -1)
223
- commits.splice(mergeCommitIndex, 1);
224
- /**
225
- * This is commented out right now because of a problem with the logic of this approach of validating MRs.
226
- * We need to find a way to fetch all commits that will be included in this release. Leaving this commented
227
- * until we figure that out - Sha
228
- */
229
- // if (!commits?.length)
230
- // throw new ShipItError(`Could not find any commits in dev for projectId: ${projectId} since ${sinceSha}`);
231
- return [2 /*return*/, commits];
212
+ case 0: return [4 /*yield*/, this.apiClient.getCommitsForRelease(projectId, dateSince)];
213
+ case 1: return [2 /*return*/, _a.sent()];
232
214
  }
233
215
  });
234
216
  });
@@ -412,9 +394,9 @@ var GitLabService = /** @class */ (function () {
412
394
  * We use the latest valid semver tag in master to determine what the current version
413
395
  * of a project is
414
396
  */
415
- GitLabService.prototype.getCurrentVersionTag = function (projectId) {
397
+ GitLabService.prototype.getCurrentMinorVersionTag = function (projectId) {
416
398
  return __awaiter(this, void 0, void 0, function () {
417
- var tags, tagNames, sortedTagNames, currentVersion, currentTag;
399
+ var tags, tagNames, sortedTagNames, latestMinorVersion, currentTag;
418
400
  return __generator(this, function (_a) {
419
401
  switch (_a.label) {
420
402
  case 0: return [4 /*yield*/, this.apiClient.getLatestTags(projectId)];
@@ -425,9 +407,9 @@ var GitLabService = /** @class */ (function () {
425
407
  tagNames = tags.map(function (t) { return t.name; }).filter(function (t) { return semver_1.default.valid(t); });
426
408
  if (!tagNames.length)
427
409
  return [2 /*return*/, null];
428
- sortedTagNames = semver_1.default.sort(tagNames);
429
- currentVersion = lodash_1.default.last(sortedTagNames);
430
- currentTag = tags.find(function (t) { return t.name === currentVersion; });
410
+ sortedTagNames = semver_1.default.sort(tagNames).reverse();
411
+ latestMinorVersion = sortedTagNames.find(function (tag) { return tag.endsWith('.0'); });
412
+ currentTag = tags.find(function (t) { return t.name === latestMinorVersion; });
431
413
  if (!currentTag)
432
414
  return [2 /*return*/, null];
433
415
  return [2 /*return*/, currentTag];
@@ -453,7 +435,7 @@ var GitLabService = /** @class */ (function () {
453
435
  var tag, nextVersion, branchName, branch;
454
436
  return __generator(this, function (_a) {
455
437
  switch (_a.label) {
456
- case 0: return [4 /*yield*/, this.getCurrentVersionTag(projectId)];
438
+ case 0: return [4 /*yield*/, this.getCurrentMinorVersionTag(projectId)];
457
439
  case 1:
458
440
  tag = _a.sent();
459
441
  if (!tag)
@@ -75,7 +75,7 @@ var BumpVersionTxtTask = /** @class */ (function () {
75
75
  if (!(_i < projects_1.length)) return [3 /*break*/, 6];
76
76
  project = projects_1[_i];
77
77
  if (this.skip(project.id))
78
- return [2 /*return*/, false];
78
+ return [3 /*break*/, 5];
79
79
  return [4 /*yield*/, this.service.getNextBranchInfo(project.id, options.version)];
80
80
  case 3:
81
81
  _a = _b.sent(), nextVersion = _a.nextVersion, branchName = _a.branchName;
@@ -71,7 +71,9 @@ var ROOT_DIRECTORIES = {
71
71
  // Online
72
72
  109: 'src/ClickView.Web.Online.Pages',
73
73
  // Reports
74
- 970: 'src/ClickView.Analytics.Web'
74
+ 970: 'src/ClickView.Analytics.Web',
75
+ // Auth
76
+ 54: 'src/ClickView.Auth'
75
77
  };
76
78
  var InstallPackagesTask = /** @class */ (function () {
77
79
  function InstallPackagesTask(service) {
@@ -59,43 +59,49 @@ var ValidateCommitsTask = /** @class */ (function () {
59
59
  this.service = service;
60
60
  }
61
61
  ValidateCommitsTask.prototype.run = function (options) {
62
+ var _a;
62
63
  return __awaiter(this, void 0, void 0, function () {
63
- var projects, cont, _i, projects_1, project, _a, branch, tag, devCommits, shouldCherryPick;
64
- return __generator(this, function (_b) {
65
- switch (_b.label) {
64
+ var projects, cont, _i, projects_1, project, _b, branch, tag, previousReleaseBranchName, previousReleaseMergeRequest, devCommits, _c, shouldCherryPick, invalidCommits;
65
+ return __generator(this, function (_d) {
66
+ switch (_d.label) {
66
67
  case 0:
67
68
  utils_1.Logger.logTask('Validating dev commits');
68
69
  return [4 /*yield*/, this.service.getProjects(options)];
69
70
  case 1:
70
- projects = _b.sent();
71
+ projects = _d.sent();
71
72
  cont = true;
72
73
  _i = 0, projects_1 = projects;
73
- _b.label = 2;
74
+ _d.label = 2;
74
75
  case 2:
75
- if (!(_i < projects_1.length)) return [3 /*break*/, 6];
76
+ if (!(_i < projects_1.length)) return [3 /*break*/, 7];
76
77
  project = projects_1[_i];
77
78
  return [4 /*yield*/, this.service.getNextBranchInfo(project.id, options.version)];
78
79
  case 3:
79
- _a = _b.sent(), branch = _a.branch, tag = _a.tag;
80
+ _b = _d.sent(), branch = _b.branch, tag = _b.tag;
80
81
  /**
81
82
  * If the release branch already exists, this can be skipped as this
82
83
  * validation is only required when creating a new release
83
84
  */
84
85
  if (branch)
85
- return [3 /*break*/, 5];
86
- return [4 /*yield*/, this.service.getDevCommitsSince(project.id, tag.target)];
86
+ return [3 /*break*/, 6];
87
+ previousReleaseBranchName = utils_1.BranchNames.getRelease(tag.name);
88
+ return [4 /*yield*/, this.service.getMergeRequest(project.id, previousReleaseBranchName)];
87
89
  case 4:
88
- devCommits = _b.sent();
89
- shouldCherryPick = utils_1.Commits.shouldCherryPick(project, devCommits);
90
+ previousReleaseMergeRequest = _d.sent();
91
+ return [4 /*yield*/, this.service.getCommitsForRelease(project.id, (_a = previousReleaseMergeRequest === null || previousReleaseMergeRequest === void 0 ? void 0 : previousReleaseMergeRequest.dateCreated) !== null && _a !== void 0 ? _a : '')];
92
+ case 5:
93
+ devCommits = _d.sent();
94
+ _c = utils_1.Commits.shouldCherryPick(project, devCommits), shouldCherryPick = _c.shouldCherryPick, invalidCommits = _c.invalidCommits;
90
95
  if (shouldCherryPick) {
91
- utils_1.Logger.logError("[".concat(project.title, "]: Requires cherrypicking"));
96
+ utils_1.Logger.logError("[".concat(project.title, "]: Requires cherrypicking. These are the merge commits that either have the wrong milestone, or no milestone:"));
97
+ invalidCommits.forEach(function (commit) { return utils_1.Logger.logError("- ".concat(commit.id)); });
92
98
  cont = false;
93
99
  }
94
- _b.label = 5;
95
- case 5:
100
+ _d.label = 6;
101
+ case 6:
96
102
  _i++;
97
103
  return [3 /*break*/, 2];
98
- case 6:
104
+ case 7:
99
105
  if (cont)
100
106
  utils_1.Logger.logSuccess('No projects require cherrypicking');
101
107
  return [2 /*return*/, cont];
@@ -13,31 +13,41 @@ var __assign = (this && this.__assign) || function () {
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.Commits = void 0;
15
15
  exports.Commits = {
16
- /**
17
- * Returns true if dev contains commits that are merge commits from a milestone
18
- * that is beyond the current release milestone
19
- */
20
16
  shouldCherryPick: function (project, commits) {
21
- var _a;
22
- var commitKeys = project.mergeRequests.reduce(function (prev, current) {
17
+ /**
18
+ * Build a lookup table of every merge request with the milestone we passed.
19
+ */
20
+ var mergeRequestLookup = project.mergeRequests.reduce(function (acc, current) {
23
21
  var _a;
24
22
  if (!current.mergeCommit)
25
- return prev;
26
- return __assign(__assign({}, prev), (_a = {}, _a[current.mergeCommit] = true, _a));
23
+ return acc;
24
+ if (current.sourceBranch === 'master')
25
+ return acc;
26
+ return __assign(__assign({}, acc), (_a = {}, _a[current.mergeCommit] = current, _a));
27
27
  }, {});
28
- for (var _i = 0, commits_1 = commits; _i < commits_1.length; _i++) {
29
- var commit = commits_1[_i];
30
- if (!commitKeys[commit.id]) {
31
- /**
32
- * Commits straight to dev will have 1 parentId, however
33
- * merge commits that are potentially targeting another milestone
34
- * will have at least 2 parent Ids.
35
- */
36
- if (((_a = commit.parentIds) === null || _a === void 0 ? void 0 : _a.length) === 1)
37
- continue;
38
- return true;
39
- }
28
+ /**
29
+ * Loop through every single commit since the last release was created.
30
+ * Any commit that has more than 1 parent Id is a merge commit.
31
+ *
32
+ * Every single merge commit should have a corresponding merge request in the lookup table.
33
+ * If a merge commit does not have a corresponding merge request, it means that the merge request has the wrong milestone.
34
+ */
35
+ var invalidCommits = commits.filter(function (commit) {
36
+ var _a;
37
+ if (!commit.parentIds || ((_a = commit.parentIds) === null || _a === void 0 ? void 0 : _a.length) < 2)
38
+ return false;
39
+ if (commit.title.toLowerCase().includes('merge') && commit.title.includes('master') && commit.title.includes('dev'))
40
+ return false;
41
+ if (commit.title === 'Merge remote-tracking branch \'origin/dev\' into dev')
42
+ return false;
43
+ return !mergeRequestLookup[commit.id];
44
+ });
45
+ if (invalidCommits.length) {
46
+ return {
47
+ shouldCherryPick: true,
48
+ invalidCommits: invalidCommits
49
+ };
40
50
  }
41
- return false;
51
+ return { shouldCherryPick: false, invalidCommits: [] };
42
52
  }
43
53
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clickview/ship-it",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "Release Manager",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {