@clickview/ship-it 0.0.12 → 0.0.13
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 +10 -13
- package/lib/src/api-clients/git-lab/GitLabMapper.js +2 -1
- package/lib/src/services/GitLabService.js +9 -27
- package/lib/src/tasks/BumpVersionTxtTask.js +1 -1
- package/lib/src/tasks/ValidateCommitsTask.js +21 -15
- package/lib/src/utils/Commits.js +29 -21
- package/package.json +1 -1
|
@@ -165,23 +165,20 @@ var GitLabApiClient = /** @class */ (function () {
|
|
|
165
165
|
});
|
|
166
166
|
});
|
|
167
167
|
};
|
|
168
|
-
GitLabApiClient.prototype.
|
|
168
|
+
GitLabApiClient.prototype.getCommitsForRelease = function (projectId, dateSince) {
|
|
169
169
|
return __awaiter(this, void 0, void 0, function () {
|
|
170
|
-
var
|
|
170
|
+
var commits;
|
|
171
171
|
return __generator(this, function (_a) {
|
|
172
172
|
switch (_a.label) {
|
|
173
|
-
case 0: return [4 /*yield*/, this.client.Commits.
|
|
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) {
|
|
@@ -205,30 +205,12 @@ var GitLabService = /** @class */ (function () {
|
|
|
205
205
|
});
|
|
206
206
|
});
|
|
207
207
|
};
|
|
208
|
-
GitLabService.prototype.
|
|
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.
|
|
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.
|
|
397
|
+
GitLabService.prototype.getCurrentMinorVersionTag = function (projectId) {
|
|
416
398
|
return __awaiter(this, void 0, void 0, function () {
|
|
417
|
-
var tags, tagNames, sortedTagNames,
|
|
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
|
-
|
|
430
|
-
currentTag = tags.find(function (t) { return t.name ===
|
|
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.
|
|
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 [
|
|
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;
|
|
@@ -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,
|
|
64
|
-
return __generator(this, function (
|
|
65
|
-
switch (
|
|
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 =
|
|
71
|
+
projects = _d.sent();
|
|
71
72
|
cont = true;
|
|
72
73
|
_i = 0, projects_1 = projects;
|
|
73
|
-
|
|
74
|
+
_d.label = 2;
|
|
74
75
|
case 2:
|
|
75
|
-
if (!(_i < projects_1.length)) return [3 /*break*/,
|
|
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
|
-
|
|
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*/,
|
|
86
|
-
|
|
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
|
-
|
|
89
|
-
|
|
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
|
-
|
|
95
|
-
case
|
|
100
|
+
_d.label = 6;
|
|
101
|
+
case 6:
|
|
96
102
|
_i++;
|
|
97
103
|
return [3 /*break*/, 2];
|
|
98
|
-
case
|
|
104
|
+
case 7:
|
|
99
105
|
if (cont)
|
|
100
106
|
utils_1.Logger.logSuccess('No projects require cherrypicking');
|
|
101
107
|
return [2 /*return*/, cont];
|
package/lib/src/utils/Commits.js
CHANGED
|
@@ -13,31 +13,39 @@ 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
|
-
|
|
22
|
-
|
|
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
|
|
26
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return
|
|
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
|
+
return !mergeRequestLookup[commit.id];
|
|
42
|
+
});
|
|
43
|
+
if (invalidCommits.length) {
|
|
44
|
+
return {
|
|
45
|
+
shouldCherryPick: true,
|
|
46
|
+
invalidCommits: invalidCommits
|
|
47
|
+
};
|
|
40
48
|
}
|
|
41
|
-
return false;
|
|
49
|
+
return { shouldCherryPick: false, invalidCommits: [] };
|
|
42
50
|
}
|
|
43
51
|
};
|