@clickview/ship-it 0.0.2-dev.2 → 0.0.2

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 (47) hide show
  1. package/lib/src/api-clients/GitLabApiClient.js +1 -1
  2. package/lib/src/api-clients/index.js +1 -1
  3. package/lib/src/commands/BumpPackagesCommand.js +4 -12
  4. package/lib/src/commands/CreateBranchCommand.js +8 -8
  5. package/lib/src/commands/CreateMergeRequestCommand.js +10 -10
  6. package/lib/src/commands/CreateReleaseNotesCommand.js +4 -4
  7. package/lib/src/commands/ReleaseCommand.js +14 -14
  8. package/lib/src/commands/StatusCommand.js +2 -2
  9. package/lib/src/commands/VersionCommand.js +2 -2
  10. package/lib/src/commands/index.js +0 -1
  11. package/lib/src/index.js +85 -2
  12. package/lib/src/interfaces/index.js +1 -2
  13. package/lib/src/inversify.config.js +0 -3
  14. package/lib/src/services/GitLabService.js +33 -60
  15. package/lib/src/tasks/BumpPackagesTask.js +239 -102
  16. package/lib/src/tasks/BumpVersionTxtTask.js +26 -13
  17. package/lib/src/tasks/CreateBranchTask.js +32 -17
  18. package/lib/src/tasks/CreateMergeRequestTask.js +36 -21
  19. package/lib/src/tasks/CreateReleaseNotesTask.js +6 -2
  20. package/lib/src/tasks/ValidateCommitsTask.js +14 -6
  21. package/lib/src/tasks/ValidateDescriptionsTask.js +8 -4
  22. package/lib/src/tasks/ValidateTask.js +6 -5
  23. package/lib/src/tasks/VersionTask.js +20 -7
  24. package/lib/src/tasks/index.js +0 -2
  25. package/lib/src/types.js +1 -4
  26. package/lib/src/utils/Descriptions.js +4 -5
  27. package/lib/src/utils/ProjectIds.js +2 -6
  28. package/package.json +22 -22
  29. package/lib/src/api-clients/git-lab/GitLabApiClient.js +0 -285
  30. package/lib/src/api-clients/git-lab/GitLabMapper.js +0 -51
  31. package/lib/src/commands/CommitPackageVersionsCommand.js +0 -78
  32. package/lib/src/commands/InstallPackagesCommand.js +0 -78
  33. package/lib/src/constants/CommandTypeMapping.js +0 -14
  34. package/lib/src/constants/MonorepoPackageJsonFiles.js +0 -13
  35. package/lib/src/constants/index.js +0 -18
  36. package/lib/src/errors/ShipItError.js +0 -32
  37. package/lib/src/errors/index.js +0 -17
  38. package/lib/src/interfaces/VersionType.js +0 -2
  39. package/lib/src/interfaces/command-options/BumpPackagesCommandOptions.js +0 -2
  40. package/lib/src/interfaces/command-options/CommitPackageVersionsCommandOptions.js +0 -2
  41. package/lib/src/interfaces/command-options/MilestoneCommandOptions.js +0 -2
  42. package/lib/src/interfaces/command-options/index.js +0 -18
  43. package/lib/src/startup/AddMilestoneCommand.js +0 -75
  44. package/lib/src/startup/SetupCommands.js +0 -66
  45. package/lib/src/tasks/CommitLocalPackagesTask.js +0 -137
  46. package/lib/src/tasks/CommitPackageVersionsTask.js +0 -111
  47. package/lib/src/tasks/InstallPackagesTask.js +0 -317
@@ -61,7 +61,7 @@ var services_1 = require("../services");
61
61
  var utils_1 = require("../utils");
62
62
  var CreateReleaseNotesTask = /** @class */ (function () {
63
63
  function CreateReleaseNotesTask(service) {
64
- this.service = service;
64
+ this._service = service;
65
65
  }
66
66
  CreateReleaseNotesTask.prototype.run = function (options) {
67
67
  return __awaiter(this, void 0, void 0, function () {
@@ -70,9 +70,13 @@ var CreateReleaseNotesTask = /** @class */ (function () {
70
70
  switch (_a.label) {
71
71
  case 0:
72
72
  utils_1.Logger.logTask('Creating release notes');
73
- return [4 /*yield*/, this.service.getProjects(options)];
73
+ return [4 /*yield*/, this._service.getProjects(options)];
74
74
  case 1:
75
75
  projects = _a.sent();
76
+ if (!projects.length) {
77
+ utils_1.Logger.logError("No projects could be found with the specified options");
78
+ return [2 /*return*/, false];
79
+ }
76
80
  combinedDescription = '';
77
81
  utils_1.Logger.logMessage('Created files');
78
82
  _i = 0, projects_1 = projects;
@@ -56,28 +56,36 @@ var services_1 = require("../services");
56
56
  var utils_1 = require("../utils");
57
57
  var ValidateCommitsTask = /** @class */ (function () {
58
58
  function ValidateCommitsTask(service) {
59
- this.service = service;
59
+ this._service = service;
60
60
  }
61
61
  ValidateCommitsTask.prototype.run = function (options) {
62
62
  return __awaiter(this, void 0, void 0, function () {
63
- var projects, cont, _i, projects_1, project, tag, devCommits, shouldCherryPick;
63
+ var projects, cont, _i, projects_1, project, currentVersionTag, devCommits, shouldCherryPick;
64
64
  return __generator(this, function (_a) {
65
65
  switch (_a.label) {
66
66
  case 0:
67
67
  utils_1.Logger.logTask('Validating dev commits');
68
- return [4 /*yield*/, this.service.getProjects(options)];
68
+ return [4 /*yield*/, this._service.getProjects(options)];
69
69
  case 1:
70
70
  projects = _a.sent();
71
+ if (!projects.length) {
72
+ utils_1.Logger.logError("No projects could be found with the specified options");
73
+ return [2 /*return*/, false];
74
+ }
71
75
  cont = true;
72
76
  _i = 0, projects_1 = projects;
73
77
  _a.label = 2;
74
78
  case 2:
75
79
  if (!(_i < projects_1.length)) return [3 /*break*/, 6];
76
80
  project = projects_1[_i];
77
- return [4 /*yield*/, this.service.getNextBranchInfo(project.id, options.version)];
81
+ return [4 /*yield*/, this._service.getCurrentVersionTag(project.id)];
78
82
  case 3:
79
- tag = (_a.sent()).tag;
80
- return [4 /*yield*/, this.service.getDevCommitsSince(project.id, tag.target)];
83
+ currentVersionTag = _a.sent();
84
+ if (!currentVersionTag) {
85
+ utils_1.Logger.logError("Could not find the next version for: ".concat(project.title));
86
+ return [2 /*return*/, false];
87
+ }
88
+ return [4 /*yield*/, this._service.getDevCommitsSince(project.id, currentVersionTag.target)];
81
89
  case 4:
82
90
  devCommits = _a.sent();
83
91
  shouldCherryPick = utils_1.Commits.shouldCherryPick(project, devCommits);
@@ -56,11 +56,11 @@ require("reflect-metadata");
56
56
  var inversify_1 = require("inversify");
57
57
  var lodash_1 = __importDefault(require("lodash"));
58
58
  var types_1 = require("../types");
59
- var services_1 = require("../services");
59
+ var GitLabService_1 = require("../services/GitLabService");
60
60
  var utils_1 = require("../utils");
61
61
  var ValidateDescriptionsTask = /** @class */ (function () {
62
62
  function ValidateDescriptionsTask(service) {
63
- this.service = service;
63
+ this._service = service;
64
64
  }
65
65
  ValidateDescriptionsTask.prototype.run = function (options) {
66
66
  return __awaiter(this, void 0, void 0, function () {
@@ -69,9 +69,13 @@ var ValidateDescriptionsTask = /** @class */ (function () {
69
69
  switch (_e.label) {
70
70
  case 0:
71
71
  utils_1.Logger.logTask('Validating descriptions');
72
- return [4 /*yield*/, this.service.getProjects(options)];
72
+ return [4 /*yield*/, this._service.getProjects(options)];
73
73
  case 1:
74
74
  projects = _e.sent();
75
+ if (!projects.length) {
76
+ utils_1.Logger.logError("No projects could be found with the specified options");
77
+ return [2 /*return*/, false];
78
+ }
75
79
  cont = true;
76
80
  for (_i = 0, projects_1 = projects; _i < projects_1.length; _i++) {
77
81
  project = projects_1[_i];
@@ -107,7 +111,7 @@ var ValidateDescriptionsTask = /** @class */ (function () {
107
111
  ValidateDescriptionsTask = __decorate([
108
112
  (0, inversify_1.injectable)(),
109
113
  __param(0, (0, inversify_1.inject)(types_1.SERVICES.GitLabService)),
110
- __metadata("design:paramtypes", [services_1.GitLabService])
114
+ __metadata("design:paramtypes", [GitLabService_1.GitLabService])
111
115
  ], ValidateDescriptionsTask);
112
116
  return ValidateDescriptionsTask;
113
117
  }());
@@ -71,7 +71,7 @@ var services_1 = require("../services");
71
71
  var utils_1 = require("../utils");
72
72
  var ValidateTask = /** @class */ (function () {
73
73
  function ValidateTask(service) {
74
- this.service = service;
74
+ this._service = service;
75
75
  }
76
76
  ValidateTask.prototype.run = function (options) {
77
77
  return __awaiter(this, void 0, void 0, function () {
@@ -80,9 +80,13 @@ var ValidateTask = /** @class */ (function () {
80
80
  switch (_a.label) {
81
81
  case 0:
82
82
  utils_1.Logger.logTask('Validating the release');
83
- return [4 /*yield*/, this.service.getProjects(options)];
83
+ return [4 /*yield*/, this._service.getProjects(options)];
84
84
  case 1:
85
85
  projects = _a.sent();
86
+ if (!projects.length) {
87
+ utils_1.Logger.logError("No projects could be found with the specified options");
88
+ return [2 /*return*/, false];
89
+ }
86
90
  utils_1.Logger.logMessage("Found ".concat(projects.length, " projects that need to be released"));
87
91
  cont = true;
88
92
  _loop_1 = function (project) {
@@ -92,9 +96,6 @@ var ValidateTask = /** @class */ (function () {
92
96
  return __assign(__assign({}, prev), (_a = {}, _a[current] = groupedMRs[current].length, _a));
93
97
  }, {});
94
98
  var ready = !count.opened || count.opened === 0;
95
- /**
96
- * Any MRs that are not targeting dev should not have a milestone
97
- */
98
99
  var nonDevMrs = project.mergeRequests.filter(function (mr) { return mr.targetBranch !== 'dev'; });
99
100
  if (nonDevMrs.length)
100
101
  ready = false;
@@ -56,34 +56,47 @@ var services_1 = require("../services");
56
56
  var utils_1 = require("../utils");
57
57
  var VersionTask = /** @class */ (function () {
58
58
  function VersionTask(service) {
59
- this.service = service;
59
+ this._service = service;
60
60
  }
61
61
  VersionTask.prototype.run = function (options) {
62
62
  return __awaiter(this, void 0, void 0, function () {
63
- var projects, _i, projects_1, project, tag, nextVersion;
63
+ var projects, cont, _i, projects_1, project, currentVersionTag, nextVersion;
64
64
  return __generator(this, function (_a) {
65
65
  switch (_a.label) {
66
66
  case 0:
67
67
  utils_1.Logger.logTask('Calculating versions');
68
- return [4 /*yield*/, this.service.getProjects(options)];
68
+ return [4 /*yield*/, this._service.getProjects(options)];
69
69
  case 1:
70
70
  projects = _a.sent();
71
+ if (!projects.length) {
72
+ utils_1.Logger.logError("No projects could be found with the specified options");
73
+ return [2 /*return*/, false];
74
+ }
75
+ cont = true;
71
76
  utils_1.Logger.logMessage('Versions:');
72
77
  _i = 0, projects_1 = projects;
73
78
  _a.label = 2;
74
79
  case 2:
75
80
  if (!(_i < projects_1.length)) return [3 /*break*/, 5];
76
81
  project = projects_1[_i];
77
- return [4 /*yield*/, this.service.getNextBranchInfo(project.id, options.version)];
82
+ return [4 /*yield*/, this._service.getCurrentVersionTag(project.id)];
78
83
  case 3:
79
- tag = (_a.sent()).tag;
80
- nextVersion = utils_1.Versions.getNextVersion(tag.name, options.version);
84
+ currentVersionTag = _a.sent();
85
+ if (currentVersionTag === null) {
86
+ utils_1.Logger.logError("[NOT FOUND]: ".concat(project.title));
87
+ cont = false;
88
+ return [3 /*break*/, 4];
89
+ }
90
+ nextVersion = utils_1.Versions.getNextVersion(currentVersionTag.name, options.version);
81
91
  utils_1.Logger.logMessage("[".concat(nextVersion, "]: ").concat(project.title));
82
92
  _a.label = 4;
83
93
  case 4:
84
94
  _i++;
85
95
  return [3 /*break*/, 2];
86
- case 5: return [2 /*return*/, true];
96
+ case 5:
97
+ if (!cont)
98
+ utils_1.Logger.logError('\nCould not calculate versions for all projects');
99
+ return [2 /*return*/, cont];
87
100
  }
88
101
  });
89
102
  });
@@ -16,11 +16,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./BumpPackagesTask"), exports);
18
18
  __exportStar(require("./BumpVersionTxtTask"), exports);
19
- __exportStar(require("./CommitPackageVersionsTask"), exports);
20
19
  __exportStar(require("./CreateBranchTask"), exports);
21
20
  __exportStar(require("./CreateMergeRequestTask"), exports);
22
21
  __exportStar(require("./CreateReleaseNotesTask"), exports);
23
- __exportStar(require("./InstallPackagesTask"), exports);
24
22
  __exportStar(require("./ValidateCommitsTask"), exports);
25
23
  __exportStar(require("./ValidateDescriptionsTask"), exports);
26
24
  __exportStar(require("./ValidateTask"), exports);
package/lib/src/types.js CHANGED
@@ -19,9 +19,7 @@ exports.TASKS = {
19
19
  CreateMergeRequestTask: Symbol.for('CreateMergeRequestTask'),
20
20
  ValidateDescriptionsTask: Symbol.for('ValidateDescriptionsTask'),
21
21
  CreateReleaseNotesTask: Symbol.for('CreateReleaseNotesTask'),
22
- InstallPackagesTask: Symbol.for('InstallPackagesTask'),
23
- BumpPackagesTask: Symbol.for('BumpPackagesTask'),
24
- CommitPackageVersionsTask: Symbol.for('CommitPackageVersionsTask')
22
+ BumpPackagesTask: Symbol.for('BumpPackagesTask')
25
23
  };
26
24
  exports.COMMANDS = {
27
25
  StatusCommand: Symbol.for('StatusCommand'),
@@ -30,6 +28,5 @@ exports.COMMANDS = {
30
28
  CreateBranchCommand: Symbol.for('CreateBranchCommand'),
31
29
  CreateMergeRequestCommand: Symbol.for('CreateMergeRequestCommand'),
32
30
  CreateReleaseNotesCommand: Symbol.for('CreateReleaseNotesCommand'),
33
- InstallPackagesCommand: Symbol.for('InstallPackagesCommand'),
34
31
  BumpPackagesCommand: Symbol.for('BumpPackagesCommand')
35
32
  };
@@ -19,15 +19,14 @@ var VALID_MONOREPO_HEADINGS = {
19
19
  'styles': true,
20
20
  'player': true,
21
21
  'reports': true,
22
- 'analytics': true,
22
+ 'analytis': true,
23
23
  'tooling': true,
24
24
  'testing': true,
25
25
  'dependencies': true,
26
- 'notes': true,
27
- 'monorepo': true
26
+ 'notes': true
28
27
  };
29
28
  function toObject(lines, headingPrefix) {
30
- var obj = {};
29
+ var obj = [];
31
30
  var currentHeading = 'Other';
32
31
  for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
33
32
  var line = lines_1[_i];
@@ -117,7 +116,7 @@ exports.Descriptions = {
117
116
  var descriptionObjs = mergeRequests
118
117
  .filter(function (mr) { return mr.status === 'merged'; })
119
118
  .map(function (mr) { return toObject(mr.description.split('\n'), '#'); });
120
- var combinedObj = {};
119
+ var combinedObj = [];
121
120
  var _loop_2 = function (descriptionObj) {
122
121
  Object.keys(descriptionObj).forEach(function (key) {
123
122
  if (!combinedObj[key])
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
+ // TODO: Eventually this should allow us to map project names to project ids
2
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
5
  };
5
6
  Object.defineProperty(exports, "__esModule", { value: true });
6
7
  exports.ProjectIds = void 0;
7
8
  var lodash_1 = __importDefault(require("lodash"));
8
- var errors_1 = require("../errors");
9
9
  var PROJECT_NAMES = {
10
10
  monorepo: '789',
11
11
  online: '109',
@@ -16,10 +16,6 @@ var PROJECT_NAMES = {
16
16
  };
17
17
  exports.ProjectIds = {
18
18
  MONOREPO_PROJECT_ID: '798',
19
- /**
20
- * This allows project names to be passed into the CLI.
21
- * For example `ship-it release -m S2 -p lite`
22
- */
23
19
  getProjectIds: function (projects) {
24
20
  var projectIds = [];
25
21
  for (var _i = 0, projects_1 = projects; _i < projects_1.length; _i++) {
@@ -30,7 +26,7 @@ exports.ProjectIds = {
30
26
  }
31
27
  var mappedId = PROJECT_NAMES[project.toLowerCase()];
32
28
  if (!mappedId)
33
- throw new errors_1.ShipItError("Could not find project id mapping for ".concat(project));
29
+ throw new Error("Could not find project id mapping for ".concat(project));
34
30
  projectIds.push(mappedId);
35
31
  }
36
32
  return projectIds;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clickview/ship-it",
3
- "version": "0.0.2-dev.2",
3
+ "version": "0.0.2",
4
4
  "description": "Release Manager",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
@@ -18,28 +18,28 @@
18
18
  "author": "Joshua Taylor, Shale Kuzmanovski",
19
19
  "license": "ISC",
20
20
  "dependencies": {
21
- "@gitbeaker/node": "35.6.0",
22
- "chalk": "4.1.2",
23
- "commander": "9.1.0",
24
- "fs-extra": "10.0.1",
25
- "inversify": "6.0.1",
26
- "lodash": "4.17.21",
27
- "reflect-metadata": "0.1.13",
28
- "semver": "7.3.5"
21
+ "@gitbeaker/node": "^35.6.0",
22
+ "chalk": "^4.1.2",
23
+ "commander": "^9.1.0",
24
+ "fs-extra": "^10.0.1",
25
+ "inversify": "^6.0.1",
26
+ "lodash": "^4.17.21",
27
+ "reflect-metadata": "^0.1.13",
28
+ "semver": "^7.3.5"
29
29
  },
30
30
  "devDependencies": {
31
- "@clickview/eslint-config": "1.0.3",
32
- "@types/fs-extra": "9.0.13",
33
- "@types/lodash": "4.14.181",
34
- "@types/node": "17.0.23",
35
- "@types/semver": "7.3.9",
36
- "@typescript-eslint/eslint-plugin": "5.17.0",
37
- "@typescript-eslint/parser": "5.17.0",
38
- "eslint": "8.12.0",
39
- "eslint-plugin-react-hooks": "4.4.0",
40
- "ts-node": "10.7.0",
41
- "tsc-alias": "1.6.6",
42
- "tsconfig-paths": "3.14.1",
43
- "typescript": "4.6.3"
31
+ "@clickview/eslint-config": "^1.0.3",
32
+ "@types/fs-extra": "^9.0.13",
33
+ "@types/lodash": "^4.14.181",
34
+ "@types/node": "^17.0.23",
35
+ "@types/semver": "^7.3.9",
36
+ "@typescript-eslint/eslint-plugin": "^5.17.0",
37
+ "@typescript-eslint/parser": "^5.17.0",
38
+ "eslint": "^8.12.0",
39
+ "eslint-plugin-react-hooks": "^4.4.0",
40
+ "ts-node": "^10.7.0",
41
+ "tsc-alias": "^1.6.6",
42
+ "tsconfig-paths": "^3.14.1",
43
+ "typescript": "^4.6.3"
44
44
  }
45
45
  }
@@ -1,285 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- 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;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
- var __generator = (this && this.__generator) || function (thisArg, body) {
24
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
25
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
26
- function verb(n) { return function (v) { return step([n, v]); }; }
27
- function step(op) {
28
- if (f) throw new TypeError("Generator is already executing.");
29
- while (_) try {
30
- 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;
31
- if (y = 0, t) op = [op[0] & 2, t.value];
32
- switch (op[0]) {
33
- case 0: case 1: t = op; break;
34
- case 4: _.label++; return { value: op[1], done: false };
35
- case 5: _.label++; y = op[1]; op = [0]; continue;
36
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
37
- default:
38
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
39
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
40
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
41
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
42
- if (t[2]) _.ops.pop();
43
- _.trys.pop(); continue;
44
- }
45
- op = body.call(thisArg, _);
46
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
47
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
- }
49
- };
50
- Object.defineProperty(exports, "__esModule", { value: true });
51
- exports.GitLabApiClient = void 0;
52
- require("reflect-metadata");
53
- var inversify_1 = require("inversify");
54
- var node_1 = require("@gitbeaker/node");
55
- var types_1 = require("../../types");
56
- var errors_1 = require("../../errors");
57
- var GitLabMapper_1 = require("./GitLabMapper");
58
- var GitLabApiClient = /** @class */ (function () {
59
- function GitLabApiClient(config) {
60
- this.config = config;
61
- this.client = new node_1.Gitlab({
62
- token: this.config.accessToken,
63
- host: this.config.url
64
- });
65
- }
66
- GitLabApiClient.prototype.getMergeRequests = function (options) {
67
- return __awaiter(this, void 0, void 0, function () {
68
- var milestone, projectIds, mergeRequests;
69
- return __generator(this, function (_a) {
70
- switch (_a.label) {
71
- case 0:
72
- milestone = options.milestone, projectIds = options.projectIds;
73
- if (!milestone && !(projectIds === null || projectIds === void 0 ? void 0 : projectIds.length))
74
- throw new errors_1.ShipItError('Must specify one of the following: Milestone or ProjectIds');
75
- return [4 /*yield*/, this.client.MergeRequests.all({
76
- milestone: milestone,
77
- scope: 'all'
78
- })];
79
- case 1:
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
- return [2 /*return*/, mergeRequests.map(GitLabMapper_1.GitLabMapper.mergeRequest)];
90
- }
91
- });
92
- });
93
- };
94
- GitLabApiClient.prototype.getProjectsByIds = function (projectIds) {
95
- return __awaiter(this, void 0, void 0, function () {
96
- var promises, projects;
97
- var _this = this;
98
- return __generator(this, function (_a) {
99
- switch (_a.label) {
100
- case 0:
101
- promises = projectIds.map(function (p) { return _this.client.Projects.show(p); });
102
- return [4 /*yield*/, Promise.all(promises)];
103
- case 1:
104
- projects = _a.sent();
105
- return [2 /*return*/, projects.map(GitLabMapper_1.GitLabMapper.project)];
106
- }
107
- });
108
- });
109
- };
110
- GitLabApiClient.prototype.getLatestTags = function (projectId) {
111
- return __awaiter(this, void 0, void 0, function () {
112
- var tags;
113
- return __generator(this, function (_a) {
114
- switch (_a.label) {
115
- case 0: return [4 /*yield*/, this.client.Tags.all(projectId, { maxPages: 1, perPage: 20 })];
116
- case 1:
117
- tags = _a.sent();
118
- if (!tags.length)
119
- throw new errors_1.ShipItError("Project ".concat(projectId, " does not have any tags"));
120
- return [2 /*return*/, tags.map(GitLabMapper_1.GitLabMapper.tag)];
121
- }
122
- });
123
- });
124
- };
125
- GitLabApiClient.prototype.getCommitsSince = function (projectId, branchName, sinceSha) {
126
- return __awaiter(this, void 0, void 0, function () {
127
- var commit, commits;
128
- return __generator(this, function (_a) {
129
- switch (_a.label) {
130
- case 0: return [4 /*yield*/, this.client.Commits.show(projectId, sinceSha)];
131
- case 1:
132
- commit = _a.sent();
133
- return [4 /*yield*/, this.client.Commits.all(projectId, {
134
- ref_name: branchName,
135
- since: commit.committed_date,
136
- /**
137
- * This allows us to get merge commits of MRs being accepted
138
- */
139
- first_parent: true
140
- })];
141
- case 2:
142
- commits = _a.sent();
143
- return [2 /*return*/, commits.map(GitLabMapper_1.GitLabMapper.commit)];
144
- }
145
- });
146
- });
147
- };
148
- GitLabApiClient.prototype.getBranch = function (projectId, branchName) {
149
- return __awaiter(this, void 0, void 0, function () {
150
- var branch, _a;
151
- return __generator(this, function (_b) {
152
- switch (_b.label) {
153
- case 0:
154
- _b.trys.push([0, 2, , 3]);
155
- return [4 /*yield*/, this.client.Branches.show(projectId, branchName)];
156
- case 1:
157
- branch = _b.sent();
158
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.branch(branch)];
159
- case 2:
160
- _a = _b.sent();
161
- return [2 /*return*/, null];
162
- case 3: return [2 /*return*/];
163
- }
164
- });
165
- });
166
- };
167
- GitLabApiClient.prototype.createBranch = function (projectId, branchName, branchFrom) {
168
- return __awaiter(this, void 0, void 0, function () {
169
- var newBranch;
170
- return __generator(this, function (_a) {
171
- switch (_a.label) {
172
- case 0: return [4 /*yield*/, this.client.Branches.create(projectId, branchName, branchFrom)];
173
- case 1:
174
- newBranch = _a.sent();
175
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.branch(newBranch)];
176
- }
177
- });
178
- });
179
- };
180
- GitLabApiClient.prototype.cherryPick = function (projectId, sha, branchName) {
181
- return __awaiter(this, void 0, void 0, function () {
182
- return __generator(this, function (_a) {
183
- switch (_a.label) {
184
- case 0: return [4 /*yield*/, this.client.Commits.cherryPick(projectId, sha, branchName)];
185
- case 1:
186
- _a.sent();
187
- return [2 /*return*/];
188
- }
189
- });
190
- });
191
- };
192
- GitLabApiClient.prototype.getMergeRequest = function (projectId, sourceBranch, targetBranch) {
193
- return __awaiter(this, void 0, void 0, function () {
194
- var mergeRequests, mergeRequest;
195
- return __generator(this, function (_a) {
196
- switch (_a.label) {
197
- case 0: return [4 /*yield*/, this.client.MergeRequests.all({
198
- projectId: projectId,
199
- sourceBranch: sourceBranch,
200
- targetBranch: targetBranch,
201
- /**
202
- * We only care about open MRs, this allows us to close any MR and run the CLI again if needed
203
- */
204
- state: 'opened'
205
- })];
206
- case 1:
207
- mergeRequests = _a.sent();
208
- mergeRequest = mergeRequests[0];
209
- if (!mergeRequest)
210
- return [2 /*return*/, null];
211
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(mergeRequest)];
212
- }
213
- });
214
- });
215
- };
216
- GitLabApiClient.prototype.createMergeRequest = function (projectId, sourceBranch, targetBranch, title, description) {
217
- return __awaiter(this, void 0, void 0, function () {
218
- var mergeRequest;
219
- return __generator(this, function (_a) {
220
- switch (_a.label) {
221
- case 0: return [4 /*yield*/, this.client.MergeRequests.create(projectId, sourceBranch, targetBranch, title, {
222
- description: description
223
- })];
224
- case 1:
225
- mergeRequest = _a.sent();
226
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.mergeRequest(mergeRequest)];
227
- }
228
- });
229
- });
230
- };
231
- GitLabApiClient.prototype.getFile = function (projectId, filePath, branchName) {
232
- return __awaiter(this, void 0, void 0, function () {
233
- var file, _a;
234
- return __generator(this, function (_b) {
235
- switch (_b.label) {
236
- case 0:
237
- _b.trys.push([0, 2, , 3]);
238
- return [4 /*yield*/, this.client.RepositoryFiles.show(projectId, filePath, branchName)];
239
- case 1:
240
- file = _b.sent();
241
- return [2 /*return*/, GitLabMapper_1.GitLabMapper.file(file)];
242
- case 2:
243
- _a = _b.sent();
244
- return [2 /*return*/, null];
245
- case 3: return [2 /*return*/];
246
- }
247
- });
248
- });
249
- };
250
- GitLabApiClient.prototype.updateFile = function (projectId, filePath, branchName, content, commitMessage) {
251
- return __awaiter(this, void 0, void 0, function () {
252
- return __generator(this, function (_a) {
253
- switch (_a.label) {
254
- case 0: return [4 /*yield*/, this.client.RepositoryFiles.edit(projectId, filePath, branchName, content, commitMessage)];
255
- case 1:
256
- _a.sent();
257
- return [2 /*return*/];
258
- }
259
- });
260
- });
261
- };
262
- GitLabApiClient.prototype.commit = function (projectId, branchName, files, commitMessage) {
263
- return __awaiter(this, void 0, void 0, function () {
264
- return __generator(this, function (_a) {
265
- switch (_a.label) {
266
- case 0: return [4 /*yield*/, this.client.Commits.create(projectId, branchName, commitMessage, files.map(function (f) { return ({
267
- action: 'update',
268
- filePath: f.filePath,
269
- content: f.content
270
- }); }))];
271
- case 1:
272
- _a.sent();
273
- return [2 /*return*/];
274
- }
275
- });
276
- });
277
- };
278
- GitLabApiClient = __decorate([
279
- (0, inversify_1.injectable)(),
280
- __param(0, (0, inversify_1.inject)(types_1.MISC.GitLabConfig)),
281
- __metadata("design:paramtypes", [Object])
282
- ], GitLabApiClient);
283
- return GitLabApiClient;
284
- }());
285
- exports.GitLabApiClient = GitLabApiClient;