@clickview/ship-it 0.0.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.
Files changed (49) hide show
  1. package/README.md +1 -0
  2. package/lib/src/api-clients/GitLabApiClient.js +342 -0
  3. package/lib/src/api-clients/index.js +17 -0
  4. package/lib/src/commands/BumpPackagesCommand.js +78 -0
  5. package/lib/src/commands/CreateBranchCommand.js +102 -0
  6. package/lib/src/commands/CreateMergeRequestCommand.js +109 -0
  7. package/lib/src/commands/CreateReleaseNotesCommand.js +86 -0
  8. package/lib/src/commands/ReleaseCommand.js +122 -0
  9. package/lib/src/commands/StatusCommand.js +78 -0
  10. package/lib/src/commands/VersionCommand.js +78 -0
  11. package/lib/src/commands/index.js +23 -0
  12. package/lib/src/index.js +101 -0
  13. package/lib/src/interfaces/Config.js +2 -0
  14. package/lib/src/interfaces/ShipItCommand.js +2 -0
  15. package/lib/src/interfaces/ShipItOptions.js +2 -0
  16. package/lib/src/interfaces/ShipItTask.js +2 -0
  17. package/lib/src/interfaces/index.js +22 -0
  18. package/lib/src/interfaces/models/Branch.js +2 -0
  19. package/lib/src/interfaces/models/Commit.js +2 -0
  20. package/lib/src/interfaces/models/CommitFile.js +2 -0
  21. package/lib/src/interfaces/models/File.js +2 -0
  22. package/lib/src/interfaces/models/MergeRequest.js +2 -0
  23. package/lib/src/interfaces/models/Project.js +2 -0
  24. package/lib/src/interfaces/models/Tag.js +2 -0
  25. package/lib/src/interfaces/models/index.js +23 -0
  26. package/lib/src/interfaces/view-models/MilestoneProject.js +2 -0
  27. package/lib/src/interfaces/view-models/index.js +17 -0
  28. package/lib/src/inversify.config.js +48 -0
  29. package/lib/src/services/GitLabService.js +252 -0
  30. package/lib/src/services/index.js +17 -0
  31. package/lib/src/tasks/BumpPackagesTask.js +353 -0
  32. package/lib/src/tasks/BumpVersionTxtTask.js +115 -0
  33. package/lib/src/tasks/CreateBranchTask.js +119 -0
  34. package/lib/src/tasks/CreateMergeRequestTask.js +130 -0
  35. package/lib/src/tasks/CreateReleaseNotesTask.js +124 -0
  36. package/lib/src/tasks/ValidateCommitsTask.js +115 -0
  37. package/lib/src/tasks/ValidateDescriptionsTask.js +118 -0
  38. package/lib/src/tasks/ValidateTask.js +167 -0
  39. package/lib/src/tasks/VersionTask.js +111 -0
  40. package/lib/src/tasks/index.js +25 -0
  41. package/lib/src/types.js +32 -0
  42. package/lib/src/utils/BranchNames.js +11 -0
  43. package/lib/src/utils/Commits.js +33 -0
  44. package/lib/src/utils/Descriptions.js +162 -0
  45. package/lib/src/utils/Logger.js +62 -0
  46. package/lib/src/utils/ProjectIds.js +34 -0
  47. package/lib/src/utils/Versions.js +20 -0
  48. package/lib/src/utils/index.js +22 -0
  49. package/package.json +45 -0
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createContainer = void 0;
4
+ var inversify_1 = require("inversify");
5
+ var api_clients_1 = require("./api-clients");
6
+ var services_1 = require("./services");
7
+ var commands_1 = require("./commands");
8
+ var tasks_1 = require("./tasks");
9
+ var types_1 = require("./types");
10
+ function createContainer(config) {
11
+ var container = new inversify_1.Container();
12
+ /**
13
+ * Misc
14
+ */
15
+ container.bind(types_1.MISC.GitLabConfig).toConstantValue(config.gitLab);
16
+ /**
17
+ * Clients
18
+ */
19
+ container.bind(types_1.API_CLIENTS.GitLabApiClient).to(api_clients_1.GitLabApiClient);
20
+ /**
21
+ * Services
22
+ */
23
+ container.bind(types_1.SERVICES.GitLabService).to(services_1.GitLabService).inSingletonScope();
24
+ /**
25
+ * Tasks
26
+ */
27
+ container.bind(types_1.TASKS.ValidateTask).to(tasks_1.ValidateTask);
28
+ container.bind(types_1.TASKS.VersionTask).to(tasks_1.VersionTask);
29
+ container.bind(types_1.TASKS.CreateBranchTask).to(tasks_1.CreateBranchTask);
30
+ container.bind(types_1.TASKS.ValidateCommitsTask).to(tasks_1.ValidateCommitsTask);
31
+ container.bind(types_1.TASKS.BumpVersionTxtTask).to(tasks_1.BumpVersionTxtTask);
32
+ container.bind(types_1.TASKS.CreateMergeRequestTask).to(tasks_1.CreateMergeRequestTask);
33
+ container.bind(types_1.TASKS.ValidateDescriptionsTask).to(tasks_1.ValidateDescriptionsTask);
34
+ container.bind(types_1.TASKS.CreateReleaseNotesTask).to(tasks_1.CreateReleaseNotesTask);
35
+ container.bind(types_1.TASKS.BumpPackagesTask).to(tasks_1.BumpPackagesTask);
36
+ /**
37
+ * Commands
38
+ */
39
+ container.bind(types_1.COMMANDS.StatusCommand).to(commands_1.StatusCommand);
40
+ container.bind(types_1.COMMANDS.VersionCommand).to(commands_1.VersionCommand);
41
+ container.bind(types_1.COMMANDS.CreateBranchCommand).to(commands_1.CreateBranchCommand);
42
+ container.bind(types_1.COMMANDS.CreateMergeRequestCommand).to(commands_1.CreateMergeRequestCommand);
43
+ container.bind(types_1.COMMANDS.ReleaseCommand).to(commands_1.ReleaseCommand);
44
+ container.bind(types_1.COMMANDS.CreateReleaseNotesCommand).to(commands_1.CreateReleaseNotesCommand);
45
+ container.bind(types_1.COMMANDS.BumpPackagesCommand).to(commands_1.BumpPackagesCommand);
46
+ return container;
47
+ }
48
+ exports.createContainer = createContainer;
@@ -0,0 +1,252 @@
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
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
14
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
16
+ 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;
17
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
18
+ };
19
+ var __metadata = (this && this.__metadata) || function (k, v) {
20
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
21
+ };
22
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
23
+ return function (target, key) { decorator(target, key, paramIndex); }
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (_) try {
41
+ 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;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ var __importDefault = (this && this.__importDefault) || function (mod) {
62
+ return (mod && mod.__esModule) ? mod : { "default": mod };
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.GitLabService = void 0;
66
+ require("reflect-metadata");
67
+ var inversify_1 = require("inversify");
68
+ var lodash_1 = __importDefault(require("lodash"));
69
+ var semver_1 = __importDefault(require("semver"));
70
+ var types_1 = require("../types");
71
+ var api_clients_1 = require("../api-clients");
72
+ var GitLabService = /** @class */ (function () {
73
+ function GitLabService(apiClient) {
74
+ this._apiClient = apiClient;
75
+ }
76
+ GitLabService.prototype.getProjects = function (options) {
77
+ return __awaiter(this, void 0, void 0, function () {
78
+ var mergeRequests, projectIds, projects;
79
+ return __generator(this, function (_a) {
80
+ switch (_a.label) {
81
+ case 0:
82
+ if (this._projects)
83
+ return [2 /*return*/, this._projects];
84
+ return [4 /*yield*/, this._apiClient.getMergeRequests(options)];
85
+ case 1:
86
+ mergeRequests = _a.sent();
87
+ if (!(mergeRequests === null || mergeRequests === void 0 ? void 0 : mergeRequests.length))
88
+ throw new Error('Could not find any merge requests for the specified options');
89
+ projectIds = lodash_1.default.uniqBy(mergeRequests, function (m) { return m.projectId; }).map(function (m) { return m.projectId; });
90
+ return [4 /*yield*/, this._apiClient.getProjectsByIds(projectIds)];
91
+ case 2:
92
+ projects = _a.sent();
93
+ if (!(projects === null || projects === void 0 ? void 0 : projects.length) || projects.length !== projectIds.length)
94
+ throw new Error('Could not find all projects for the found merge requests');
95
+ return [2 /*return*/, (this._projects = projects.map(function (p) { return (__assign(__assign({}, p), { mergeRequests: mergeRequests.filter(function (mr) { return mr.projectId === p.id; }) })); }))];
96
+ }
97
+ });
98
+ });
99
+ };
100
+ GitLabService.prototype.getDevCommitsSince = function (projectId, sinceSha) {
101
+ return __awaiter(this, void 0, void 0, function () {
102
+ var commits, lastDevCommit, title;
103
+ return __generator(this, function (_a) {
104
+ switch (_a.label) {
105
+ case 0: return [4 /*yield*/, this._apiClient.getCommitsSince(projectId, 'dev', sinceSha)];
106
+ case 1:
107
+ commits = _a.sent();
108
+ lastDevCommit = lodash_1.default.last(commits);
109
+ title = lastDevCommit === null || lastDevCommit === void 0 ? void 0 : lastDevCommit.title.toLowerCase();
110
+ if ((title === null || title === void 0 ? void 0 : title.includes('merge')) &&
111
+ (title === null || title === void 0 ? void 0 : title.includes('master')) &&
112
+ (title === null || title === void 0 ? void 0 : title.includes('dev'))) {
113
+ commits.pop();
114
+ }
115
+ if (!(commits === null || commits === void 0 ? void 0 : commits.length))
116
+ throw new Error("Could not find any commits in dev for projectId: ".concat(projectId, " since ").concat(sinceSha));
117
+ return [2 /*return*/, commits];
118
+ }
119
+ });
120
+ });
121
+ };
122
+ GitLabService.prototype.getBranch = function (projectId, branchName) {
123
+ return __awaiter(this, void 0, void 0, function () {
124
+ return __generator(this, function (_a) {
125
+ switch (_a.label) {
126
+ case 0: return [4 /*yield*/, this._apiClient.getBranch(projectId, branchName)];
127
+ case 1: return [2 /*return*/, _a.sent()];
128
+ }
129
+ });
130
+ });
131
+ };
132
+ GitLabService.prototype.createBranch = function (project, branchFrom, branchName, cherryPick) {
133
+ return __awaiter(this, void 0, void 0, function () {
134
+ var newBranch_1, i, mr, newBranch;
135
+ return __generator(this, function (_a) {
136
+ switch (_a.label) {
137
+ case 0:
138
+ if (!cherryPick) return [3 /*break*/, 6];
139
+ return [4 /*yield*/, this._apiClient.createBranch(project.id, branchName, 'master')];
140
+ case 1:
141
+ newBranch_1 = _a.sent();
142
+ if (!newBranch_1)
143
+ throw new Error("Failed to create branch from master for projectId: ".concat(project.id));
144
+ i = 0;
145
+ _a.label = 2;
146
+ case 2:
147
+ if (!(i < project.mergeRequests.length)) return [3 /*break*/, 5];
148
+ mr = project.mergeRequests[i];
149
+ if (!mr.mergeCommit)
150
+ throw new Error("Could not find the merge commit sha for MR: ".concat(mr.title, " in projectId: ").concat(project.id));
151
+ return [4 /*yield*/, this._apiClient.cherryPick(project.id, mr.mergeCommit, branchName)];
152
+ case 3:
153
+ _a.sent();
154
+ _a.label = 4;
155
+ case 4:
156
+ i++;
157
+ return [3 /*break*/, 2];
158
+ case 5: return [2 /*return*/, newBranch_1];
159
+ case 6: return [4 /*yield*/, this._apiClient.createBranch(project.id, branchName, branchFrom)];
160
+ case 7:
161
+ newBranch = _a.sent();
162
+ if (!newBranch)
163
+ throw new Error("Failed to create branch from master for projectId: ".concat(project.id));
164
+ return [2 /*return*/, newBranch];
165
+ }
166
+ });
167
+ });
168
+ };
169
+ GitLabService.prototype.getMergeRequest = function (projectId, branchName) {
170
+ return this._apiClient.getMergeRequest(projectId, branchName, 'master');
171
+ };
172
+ GitLabService.prototype.createMergeRequest = function (projectId, branchName, description) {
173
+ return this._apiClient.createMergeRequest(projectId, branchName, 'master', branchName, description);
174
+ };
175
+ GitLabService.prototype.bumpVersionTxt = function (projectId, branchName, newVersion) {
176
+ return __awaiter(this, void 0, void 0, function () {
177
+ var versionTxt, buff, text;
178
+ return __generator(this, function (_a) {
179
+ switch (_a.label) {
180
+ case 0: return [4 /*yield*/, this._apiClient.getFile(projectId, 'version.txt', branchName)];
181
+ case 1:
182
+ versionTxt = _a.sent();
183
+ if (!versionTxt)
184
+ return [2 /*return*/, false];
185
+ buff = Buffer.from(versionTxt.content, 'base64');
186
+ text = buff.toString('utf-8');
187
+ if (text === newVersion)
188
+ return [2 /*return*/, false];
189
+ return [4 /*yield*/, this._apiClient.updateFile(projectId, 'version.txt', branchName, newVersion, 'Bumping version.txt')];
190
+ case 2:
191
+ _a.sent();
192
+ return [2 /*return*/, true];
193
+ }
194
+ });
195
+ });
196
+ };
197
+ GitLabService.prototype.getFile = function (projectId, branchName, file) {
198
+ return __awaiter(this, void 0, void 0, function () {
199
+ return __generator(this, function (_a) {
200
+ switch (_a.label) {
201
+ case 0: return [4 /*yield*/, this._apiClient.getFile(projectId, file, branchName)];
202
+ case 1: return [2 /*return*/, _a.sent()];
203
+ }
204
+ });
205
+ });
206
+ };
207
+ GitLabService.prototype.updateFile = function (projectId, filePath, branchName, content, commit) {
208
+ return this._apiClient.updateFile(projectId, filePath, branchName, content, commit);
209
+ };
210
+ GitLabService.prototype.commit = function (projectId, branchName, commitMessage, files) {
211
+ return __awaiter(this, void 0, void 0, function () {
212
+ return __generator(this, function (_a) {
213
+ switch (_a.label) {
214
+ case 0: return [4 /*yield*/, this._apiClient.commit(projectId, branchName, files, commitMessage)];
215
+ case 1:
216
+ _a.sent();
217
+ return [2 /*return*/];
218
+ }
219
+ });
220
+ });
221
+ };
222
+ GitLabService.prototype.getCurrentVersionTag = function (projectId) {
223
+ return __awaiter(this, void 0, void 0, function () {
224
+ var tags, tagNames, sortedTagNames, currentVersion, currentTag;
225
+ return __generator(this, function (_a) {
226
+ switch (_a.label) {
227
+ case 0: return [4 /*yield*/, this._apiClient.getLatestTags(projectId)];
228
+ case 1:
229
+ tags = _a.sent();
230
+ if (!(tags === null || tags === void 0 ? void 0 : tags.length))
231
+ return [2 /*return*/, null];
232
+ tagNames = tags.map(function (t) { return t.name; }).filter(function (t) { return semver_1.default.valid(t); });
233
+ if (!tagNames.length)
234
+ return [2 /*return*/, null];
235
+ sortedTagNames = semver_1.default.sort(tagNames);
236
+ currentVersion = lodash_1.default.last(sortedTagNames);
237
+ currentTag = tags.find(function (t) { return t.name === currentVersion; });
238
+ if (!currentTag)
239
+ return [2 /*return*/, null];
240
+ return [2 /*return*/, currentTag];
241
+ }
242
+ });
243
+ });
244
+ };
245
+ GitLabService = __decorate([
246
+ (0, inversify_1.injectable)(),
247
+ __param(0, (0, inversify_1.inject)(types_1.API_CLIENTS.GitLabApiClient)),
248
+ __metadata("design:paramtypes", [api_clients_1.GitLabApiClient])
249
+ ], GitLabService);
250
+ return GitLabService;
251
+ }());
252
+ exports.GitLabService = GitLabService;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./GitLabService"), exports);