@clickview/ship-it 0.0.40 → 0.0.42-dev.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 (125) hide show
  1. package/Dockerfile +33 -33
  2. package/README.md +48 -48
  3. package/config.json +19 -19
  4. package/dist/I3/I3 Notes Audit.csv +127 -0
  5. package/dist/J1/J1 Notes Audit.csv +38 -0
  6. package/dist/J2/J2 Notes Audit.csv +52 -0
  7. package/dist/L1/L1 Notes Audit.csv +139 -0
  8. package/lib/config.json +20 -20
  9. package/lib/src/api-clients/git-lab/GitLabApiClient.js +564 -557
  10. package/lib/src/api-clients/git-lab/GitLabMapper.js +122 -122
  11. package/lib/src/api-clients/index.js +20 -20
  12. package/lib/src/api-clients/slack/SlackApiClient.js +206 -206
  13. package/lib/src/api-clients/team-city/TeamCityApiClient.js +100 -100
  14. package/lib/src/api-clients/trello/TrelloApiClient.js +145 -145
  15. package/lib/src/commands/BumpPackagesCommand.js +76 -76
  16. package/lib/src/commands/ConfigureProjectsCommand.js +84 -84
  17. package/lib/src/commands/CreateBranchCommand.js +100 -100
  18. package/lib/src/commands/CreateMergeRequestCommand.js +107 -107
  19. package/lib/src/commands/CreateNotesAuditCommand.js +84 -84
  20. package/lib/src/commands/CreateReleaseNotesCommand.js +95 -95
  21. package/lib/src/commands/CreateTrelloCardsCommand.js +76 -77
  22. package/lib/src/commands/InstallPackagesCommand.js +76 -76
  23. package/lib/src/commands/ListProjectsCommand.js +76 -76
  24. package/lib/src/commands/ReleaseCommand.js +136 -136
  25. package/lib/src/commands/StartProjectBuildsCommand.js +76 -76
  26. package/lib/src/commands/StatusCommand.js +93 -93
  27. package/lib/src/commands/TagMasterCommand.js +76 -76
  28. package/lib/src/commands/ValidateMergeRequestCommand.js +76 -76
  29. package/lib/src/commands/VersionCommand.js +76 -76
  30. package/lib/src/commands/index.js +31 -31
  31. package/lib/src/constants/CommandTypeMapping.js +21 -21
  32. package/lib/src/constants/GitLabMemberIds.js +6 -6
  33. package/lib/src/constants/MonorepoPackageJsonFiles.js +41 -41
  34. package/lib/src/constants/MonorepoProjectNames.js +16 -16
  35. package/lib/src/constants/ProjectNames.js +69 -69
  36. package/lib/src/constants/SlackUserEmailList.js +13 -13
  37. package/lib/src/constants/TeamCityBuildIDs.js +46 -46
  38. package/lib/src/constants/index.js +19 -19
  39. package/lib/src/errors/ShipItError.js +32 -32
  40. package/lib/src/errors/index.js +17 -17
  41. package/lib/src/index.js +18 -18
  42. package/lib/src/interfaces/Config.js +2 -2
  43. package/lib/src/interfaces/MergeRequestState.js +2 -2
  44. package/lib/src/interfaces/ProjectNames.js +2 -2
  45. package/lib/src/interfaces/ShipItCommand.js +2 -2
  46. package/lib/src/interfaces/ShipItTask.js +2 -2
  47. package/lib/src/interfaces/VersionType.js +2 -2
  48. package/lib/src/interfaces/command-cli-options/DockerMilestoneCommandCliOptions.js +2 -0
  49. package/lib/src/interfaces/command-cli-options/MilestoneCommandCliOptions.js +2 -2
  50. package/lib/src/interfaces/command-cli-options/ReleaseCommandCliOptions.js +2 -2
  51. package/lib/src/interfaces/command-cli-options/StatusCommandCliOptions.js +2 -2
  52. package/lib/src/interfaces/command-cli-options/index.js +19 -19
  53. package/lib/src/interfaces/command-options/BaseCommandOptions.js +2 -2
  54. package/lib/src/interfaces/command-options/BumpPackagesCommandOptions.js +2 -2
  55. package/lib/src/interfaces/command-options/ConfigureProjectsOptions.js +2 -2
  56. package/lib/src/interfaces/command-options/DockerMilestoneCommandOptions.js +2 -2
  57. package/lib/src/interfaces/command-options/MilestoneCommandOptions.js +2 -2
  58. package/lib/src/interfaces/command-options/ReleaseCommandOptions.js +2 -2
  59. package/lib/src/interfaces/command-options/StatusCommandOptions.js +2 -2
  60. package/lib/src/interfaces/command-options/ValidateMRCommandOptions.js +2 -2
  61. package/lib/src/interfaces/command-options/index.js +23 -23
  62. package/lib/src/interfaces/index.js +26 -26
  63. package/lib/src/interfaces/models/ApprovalRule.js +2 -2
  64. package/lib/src/interfaces/models/ApprovalRuleConfiguration.js +2 -2
  65. package/lib/src/interfaces/models/Branch.js +2 -2
  66. package/lib/src/interfaces/models/Commit.js +2 -2
  67. package/lib/src/interfaces/models/CommitFile.js +2 -2
  68. package/lib/src/interfaces/models/CreateApprovalRuleRequest.js +2 -2
  69. package/lib/src/interfaces/models/File.js +2 -2
  70. package/lib/src/interfaces/models/Group.js +2 -2
  71. package/lib/src/interfaces/models/Label.js +2 -2
  72. package/lib/src/interfaces/models/MergeRequest.js +2 -2
  73. package/lib/src/interfaces/models/Milestone.js +2 -2
  74. package/lib/src/interfaces/models/Project.js +2 -2
  75. package/lib/src/interfaces/models/ProjectConfig.js +9 -9
  76. package/lib/src/interfaces/models/ProtectedBranch.js +2 -2
  77. package/lib/src/interfaces/models/Release.js +2 -2
  78. package/lib/src/interfaces/models/Tag.js +2 -2
  79. package/lib/src/interfaces/models/index.js +32 -32
  80. package/lib/src/interfaces/view-models/MilestoneProject.js +2 -2
  81. package/lib/src/interfaces/view-models/index.js +17 -17
  82. package/lib/src/inversify.config.js +79 -79
  83. package/lib/src/services/GitLabService.js +553 -544
  84. package/lib/src/services/SlackService.js +142 -142
  85. package/lib/src/services/TeamCityService.js +37 -37
  86. package/lib/src/services/TrelloService.js +84 -84
  87. package/lib/src/services/index.js +20 -20
  88. package/lib/src/startup/AddMilestoneCommand.js +88 -96
  89. package/lib/src/startup/GetAction.js +68 -68
  90. package/lib/src/startup/SetupCommands.js +191 -180
  91. package/lib/src/tasks/BumpPackagesTask.js +230 -230
  92. package/lib/src/tasks/BumpVersionTxtTask.js +110 -110
  93. package/lib/src/tasks/CommitPackageVersionsTask.js +116 -0
  94. package/lib/src/tasks/CreateBranchTask.js +104 -104
  95. package/lib/src/tasks/CreateMergeRequestTask.js +126 -118
  96. package/lib/src/tasks/CreateNotesAuditTask.js +140 -140
  97. package/lib/src/tasks/CreateReleaseNotesTask.js +144 -144
  98. package/lib/src/tasks/InstallPackagesTask.js +409 -415
  99. package/lib/src/tasks/ListProjectsTask.js +87 -87
  100. package/lib/src/tasks/PopulateTrelloBoardTask.js +140 -140
  101. package/lib/src/tasks/StartMonorepoBuildTask.js +109 -109
  102. package/lib/src/tasks/StartProjectBuildsTask.js +164 -170
  103. package/lib/src/tasks/TagMasterTask.js +196 -189
  104. package/lib/src/tasks/ValidateCommitsTask.js +210 -143
  105. package/lib/src/tasks/ValidateDescriptionsTask.js +178 -178
  106. package/lib/src/tasks/ValidateMergeRequestTask.js +115 -115
  107. package/lib/src/tasks/ValidateTask.js +419 -419
  108. package/lib/src/tasks/VersionTask.js +98 -98
  109. package/lib/src/tasks/configure-projects/AddApprovalRulesTask.js +199 -182
  110. package/lib/src/tasks/configure-projects/CreateToolingBranchTask.js +138 -136
  111. package/lib/src/tasks/configure-projects/EnsureApprovalRulesTask.js +106 -106
  112. package/lib/src/tasks/configure-projects/index.js +18 -18
  113. package/lib/src/tasks/configure-projects/primitives/BaseConfigureProjectsTask.js +98 -98
  114. package/lib/src/tasks/index.js +34 -34
  115. package/lib/src/types.js +60 -60
  116. package/lib/src/utils/BranchNames.js +11 -11
  117. package/lib/src/utils/Commits.js +82 -55
  118. package/lib/src/utils/Csv.js +54 -54
  119. package/lib/src/utils/Descriptions.js +274 -274
  120. package/lib/src/utils/GroupIds.js +6 -6
  121. package/lib/src/utils/Logger.js +62 -62
  122. package/lib/src/utils/ProjectIds.js +48 -47
  123. package/lib/src/utils/Versions.js +20 -20
  124. package/lib/src/utils/index.js +22 -22
  125. package/package.json +50 -50
@@ -1,54 +1,54 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.CsvFile = void 0;
18
- var format_1 = require("@fast-csv/format");
19
- var fs_extra_1 = __importDefault(require("fs-extra"));
20
- var CsvFile = /** @class */ (function () {
21
- function CsvFile(opts) {
22
- this.headers = opts.headers;
23
- this.path = opts.path;
24
- this.writeOpts = { headers: this.headers, includeEndRowDelimiter: true };
25
- }
26
- CsvFile.write = function (stream, rows, options) {
27
- return new Promise(function (res, rej) {
28
- (0, format_1.writeToStream)(stream, rows, options)
29
- .on('error', function (err) { return rej(err); })
30
- .on('finish', function () { return res(); });
31
- });
32
- };
33
- CsvFile.prototype.create = function (rows) {
34
- return CsvFile.write(fs_extra_1.default.createWriteStream(this.path), rows, __assign({}, this.writeOpts));
35
- };
36
- CsvFile.prototype.append = function (rows) {
37
- return CsvFile.write(fs_extra_1.default.createWriteStream(this.path, { flags: 'a' }), rows, __assign(__assign({}, this.writeOpts), {
38
- // dont write the headers when appending
39
- writeHeaders: false }));
40
- };
41
- CsvFile.prototype.read = function () {
42
- var _this = this;
43
- return new Promise(function (res, rej) {
44
- fs_extra_1.default.readFile(_this.path, function (err, contents) {
45
- if (err) {
46
- return rej(err);
47
- }
48
- return res(contents);
49
- });
50
- });
51
- };
52
- return CsvFile;
53
- }());
54
- exports.CsvFile = CsvFile;
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 __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.CsvFile = void 0;
18
+ var format_1 = require("@fast-csv/format");
19
+ var fs_extra_1 = __importDefault(require("fs-extra"));
20
+ var CsvFile = /** @class */ (function () {
21
+ function CsvFile(opts) {
22
+ this.headers = opts.headers;
23
+ this.path = opts.path;
24
+ this.writeOpts = { headers: this.headers, includeEndRowDelimiter: true };
25
+ }
26
+ CsvFile.write = function (stream, rows, options) {
27
+ return new Promise(function (res, rej) {
28
+ (0, format_1.writeToStream)(stream, rows, options)
29
+ .on('error', function (err) { return rej(err); })
30
+ .on('finish', function () { return res(); });
31
+ });
32
+ };
33
+ CsvFile.prototype.create = function (rows) {
34
+ return CsvFile.write(fs_extra_1.default.createWriteStream(this.path), rows, __assign({}, this.writeOpts));
35
+ };
36
+ CsvFile.prototype.append = function (rows) {
37
+ return CsvFile.write(fs_extra_1.default.createWriteStream(this.path, { flags: 'a' }), rows, __assign(__assign({}, this.writeOpts), {
38
+ // dont write the headers when appending
39
+ writeHeaders: false }));
40
+ };
41
+ CsvFile.prototype.read = function () {
42
+ var _this = this;
43
+ return new Promise(function (res, rej) {
44
+ fs_extra_1.default.readFile(_this.path, function (err, contents) {
45
+ if (err) {
46
+ return rej(err);
47
+ }
48
+ return res(contents);
49
+ });
50
+ });
51
+ };
52
+ return CsvFile;
53
+ }());
54
+ exports.CsvFile = CsvFile;
@@ -1,274 +1,274 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Descriptions = void 0;
4
- var Headings = {
5
- BeforeRelease: 'Before release',
6
- Dependencies: 'Dependencies',
7
- CodeChanges: 'Code changes',
8
- CustomerChanges: 'Customer changes',
9
- Testing: 'Testing',
10
- Notes: 'Notes'
11
- };
12
- var BASE_VALID_HEADINGS = [
13
- Headings.BeforeRelease,
14
- Headings.Dependencies,
15
- Headings.Testing,
16
- Headings.Notes
17
- ];
18
- var PROJECT_VALID_HEADINGS = BASE_VALID_HEADINGS.concat([
19
- Headings.CustomerChanges,
20
- Headings.CodeChanges
21
- ]);
22
- var PROJECT_REQUIRED_HEADINGS = [
23
- Headings.Testing
24
- ];
25
- var HEADING_ORDER = [
26
- Headings.BeforeRelease,
27
- Headings.Dependencies,
28
- Headings.CustomerChanges,
29
- Headings.CodeChanges,
30
- '*',
31
- Headings.Testing,
32
- Headings.Notes,
33
- ];
34
- function headingTransformer(heading) {
35
- // Fix casing of known headings
36
- var lowerHeading = heading.toLowerCase();
37
- for (var i = 0; i < PROJECT_VALID_HEADINGS.length; i++) {
38
- if (PROJECT_VALID_HEADINGS[i].toLowerCase() === lowerHeading)
39
- return PROJECT_VALID_HEADINGS[i];
40
- }
41
- // No transform
42
- return heading;
43
- }
44
- function toObject(lines, headingPrefix) {
45
- var obj = {};
46
- var currentHeading = 'other';
47
- for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
48
- var line = lines_1[_i];
49
- // Skip empty lines
50
- if (!line.trim() || line === '/n')
51
- continue;
52
- if (line.startsWith(headingPrefix + ' ')) {
53
- // TODO: Potentially add heading transforms to capture multiple variants
54
- currentHeading = headingTransformer(line.replace(headingPrefix, '').trim());
55
- continue;
56
- }
57
- if (!obj[currentHeading])
58
- obj[currentHeading] = '';
59
- /**
60
- * Our images need an extra line return so they don't get squished against our dot points
61
- */
62
- if (line.startsWith('!'))
63
- obj[currentHeading] += '\n';
64
- /**
65
- * Skip the line if the dev is opting out by adding n/a
66
- */
67
- if (line.toLowerCase().trim() !== 'n/a')
68
- obj[currentHeading] += line + '\n';
69
- }
70
- return obj;
71
- }
72
- /**
73
- * I can't read this code but it came from here and it works: https://stackoverflow.com/a/63457487/14258157
74
- * - Josh
75
- */
76
- function orderDescriptionHeadings(headings) {
77
- // Get the index of our wildcard where we put all the other headings into
78
- var starIndex = HEADING_ORDER.indexOf('*');
79
- if (starIndex === -1)
80
- starIndex = HEADING_ORDER.length;
81
- return headings.sort(function (a, b) {
82
- var aIndex = HEADING_ORDER.indexOf(a);
83
- var bIndex = HEADING_ORDER.indexOf(b);
84
- // Do normal sort logic if both are missing from heading order
85
- if (aIndex === -1 && bIndex === -1) {
86
- if (a < b)
87
- return -1;
88
- if (a > b)
89
- return 1;
90
- return 0;
91
- }
92
- if (aIndex === -1)
93
- aIndex = starIndex;
94
- if (bIndex === -1)
95
- bIndex = starIndex;
96
- return aIndex - bIndex;
97
- });
98
- }
99
- exports.Descriptions = {
100
- validate: function (description, projectConfig) {
101
- var validHeadings;
102
- // If we are a monorepo, add in the valid sub project headings
103
- if (projectConfig.monorepo.enabled) {
104
- var subProjects = projectConfig.monorepo.validSubProjects;
105
- validHeadings = BASE_VALID_HEADINGS.concat(subProjects);
106
- }
107
- else {
108
- validHeadings = PROJECT_VALID_HEADINGS;
109
- }
110
- // Parse description
111
- var obj = toObject(description.split('\n'), '#');
112
- var errors = this.validateProject(obj, {
113
- validSections: validHeadings,
114
- requiredSections: PROJECT_REQUIRED_HEADINGS
115
- });
116
- if (!projectConfig.monorepo.enabled)
117
- return errors;
118
- var _loop_1 = function (subProject) {
119
- // Ignore known headings
120
- if (PROJECT_VALID_HEADINGS.indexOf(subProject) !== -1)
121
- return "continue";
122
- var subObj = toObject(obj[subProject].split('\n'), '##');
123
- var subErrors = this_1.validateProject(subObj, {
124
- validSections: PROJECT_VALID_HEADINGS,
125
- requiredSections: []
126
- });
127
- errors = errors.concat(subErrors.map(function (x) { return "[".concat(subProject, "] ") + x; }));
128
- };
129
- var this_1 = this;
130
- // If monorepo we need to check the sub projects are valid
131
- for (var subProject in obj) {
132
- _loop_1(subProject);
133
- }
134
- return errors;
135
- },
136
- validateProject: function (parsedDescription, options) {
137
- // Parse description
138
- var headings = Object.keys(parsedDescription);
139
- // Must have at least one heading
140
- if (headings.length < 1)
141
- return ['Must have at least one section'];
142
- var errors = [];
143
- // Ensure all the headings are valid
144
- for (var _i = 0, headings_1 = headings; _i < headings_1.length; _i++) {
145
- var heading = headings_1[_i];
146
- if (options.validSections.indexOf(heading) === -1)
147
- errors.push("Invalid section: ".concat(heading));
148
- }
149
- // Ensure we have all required headings
150
- for (var _a = 0, _b = options.requiredSections; _a < _b.length; _a++) {
151
- var requiredSection = _b[_a];
152
- if (parsedDescription[requiredSection] === undefined)
153
- errors.push("Missing section: ".concat(requiredSection));
154
- }
155
- return errors;
156
- },
157
- getCombinedDescription: function (mergeRequests, headingPrefix) {
158
- if (headingPrefix === void 0) { headingPrefix = '#'; }
159
- var descriptionObjs = mergeRequests
160
- .filter(function (mr) { return mr.status === 'merged'; })
161
- .map(function (mr) { return toObject(mr.description.split('\n'), headingPrefix); });
162
- var obj = {};
163
- var _loop_2 = function (descriptionObj) {
164
- Object.keys(descriptionObj).forEach(function (key) {
165
- if (!obj[key])
166
- obj[key] = '';
167
- obj[key] += descriptionObj[key] + '\n';
168
- });
169
- };
170
- for (var _i = 0, descriptionObjs_1 = descriptionObjs; _i < descriptionObjs_1.length; _i++) {
171
- var descriptionObj = descriptionObjs_1[_i];
172
- _loop_2(descriptionObj);
173
- }
174
- var description = '';
175
- var orderedHeadings = orderDescriptionHeadings(Object.keys(obj));
176
- orderedHeadings.forEach(function (key) {
177
- if (key === Headings.Notes)
178
- return;
179
- if (!obj[key])
180
- return;
181
- description += '\n' + headingPrefix + ' ' + key + '\n';
182
- description += obj[key];
183
- });
184
- return description;
185
- },
186
- getDescriptionSection: function (heading, mergeRequest) {
187
- var descriptionObj = toObject(mergeRequest.description.split('\n'), '#');
188
- var obj = {};
189
- Object.keys(descriptionObj).forEach(function (key) {
190
- if (!obj[key])
191
- obj[key] = '';
192
- obj[key] += descriptionObj[key] + '\n';
193
- });
194
- return obj[Headings[heading]];
195
- },
196
- // TODO: This isn't readable, it needs to be refactored
197
- getMonorepoCombinedDescription: function (mergeRequests) {
198
- // Get an object where H1s are properties
199
- var descriptionObjs = mergeRequests
200
- .filter(function (mr) { return mr.status === 'merged'; })
201
- .map(function (mr) { return toObject(mr.description.split('\n'), '#'); });
202
- var combinedObj = {};
203
- var _loop_3 = function (descriptionObj) {
204
- Object.keys(descriptionObj).forEach(function (key) {
205
- if (!combinedObj[key])
206
- combinedObj[key] = {};
207
- var combinedSubObj = toObject(descriptionObj[key].split('\n'), '##');
208
- var orderedHeadings = orderDescriptionHeadings(Object.keys(combinedSubObj));
209
- orderedHeadings.forEach(function (subKey) {
210
- if (!combinedObj[key][subKey])
211
- combinedObj[key][subKey] = '';
212
- combinedObj[key][subKey] += combinedSubObj[subKey];
213
- });
214
- });
215
- };
216
- // For each property in each MR object, calculate it's H2 heading objects
217
- for (var _i = 0, descriptionObjs_2 = descriptionObjs; _i < descriptionObjs_2.length; _i++) {
218
- var descriptionObj = descriptionObjs_2[_i];
219
- _loop_3(descriptionObj);
220
- }
221
- var orderedHeadings = orderDescriptionHeadings(Object.keys(combinedObj));
222
- // Build our description
223
- var description = '';
224
- orderedHeadings.forEach(function (key) {
225
- if (key === Headings.Notes)
226
- return;
227
- description += '\n# ' + key + '\n';
228
- Object.keys(combinedObj[key]).forEach(function (subKey) {
229
- if (key !== Headings.Dependencies && key !== Headings.Testing)
230
- description += '\n## ' + subKey + '\n';
231
- description += combinedObj[key][subKey];
232
- });
233
- });
234
- return description;
235
- },
236
- getMonorepoDescriptionSection: function (subHeading, mergeRequest) {
237
- var descriptionObj = toObject(mergeRequest.description.split('\n'), '#');
238
- var obj = {};
239
- Object.keys(descriptionObj).forEach(function (key) {
240
- if (!obj[key])
241
- obj[key] = {};
242
- var combinedSubObj = toObject(descriptionObj[key].split('\n'), '##');
243
- Object.keys(combinedSubObj).forEach(function (subKey) {
244
- if (!obj[key][subKey])
245
- obj[key][subKey] = '';
246
- obj[key][subKey] += combinedSubObj[subKey];
247
- });
248
- });
249
- // Build our description
250
- var description = '';
251
- Object.keys(obj).forEach(function (key) {
252
- if (key === Headings.Notes)
253
- return;
254
- Object.keys(obj[key]).forEach(function (subKey) {
255
- if (subKey !== Headings[subHeading])
256
- return;
257
- description += '\n# ' + key + '\n';
258
- description += obj[key][subKey];
259
- });
260
- });
261
- return description;
262
- },
263
- bumpHeadings: function (description) {
264
- var lines = description.split('\n');
265
- var bumpedDescription = '';
266
- lines.forEach(function (line) {
267
- if (line.startsWith('#'))
268
- bumpedDescription += '#' + line + '\n';
269
- else
270
- bumpedDescription += line + '\n';
271
- });
272
- return bumpedDescription;
273
- }
274
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Descriptions = void 0;
4
+ var Headings = {
5
+ BeforeRelease: 'Before release',
6
+ Dependencies: 'Dependencies',
7
+ CodeChanges: 'Code changes',
8
+ CustomerChanges: 'Customer changes',
9
+ Testing: 'Testing',
10
+ Notes: 'Notes'
11
+ };
12
+ var BASE_VALID_HEADINGS = [
13
+ Headings.BeforeRelease,
14
+ Headings.Dependencies,
15
+ Headings.Testing,
16
+ Headings.Notes
17
+ ];
18
+ var PROJECT_VALID_HEADINGS = BASE_VALID_HEADINGS.concat([
19
+ Headings.CustomerChanges,
20
+ Headings.CodeChanges
21
+ ]);
22
+ var PROJECT_REQUIRED_HEADINGS = [
23
+ Headings.Testing
24
+ ];
25
+ var HEADING_ORDER = [
26
+ Headings.BeforeRelease,
27
+ Headings.Dependencies,
28
+ Headings.CustomerChanges,
29
+ Headings.CodeChanges,
30
+ '*',
31
+ Headings.Testing,
32
+ Headings.Notes,
33
+ ];
34
+ function headingTransformer(heading) {
35
+ // Fix casing of known headings
36
+ var lowerHeading = heading.toLowerCase();
37
+ for (var i = 0; i < PROJECT_VALID_HEADINGS.length; i++) {
38
+ if (PROJECT_VALID_HEADINGS[i].toLowerCase() === lowerHeading)
39
+ return PROJECT_VALID_HEADINGS[i];
40
+ }
41
+ // No transform
42
+ return heading;
43
+ }
44
+ function toObject(lines, headingPrefix) {
45
+ var obj = {};
46
+ var currentHeading = 'other';
47
+ for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
48
+ var line = lines_1[_i];
49
+ // Skip empty lines
50
+ if (!line.trim() || line === '/n')
51
+ continue;
52
+ if (line.startsWith(headingPrefix + ' ')) {
53
+ // TODO: Potentially add heading transforms to capture multiple variants
54
+ currentHeading = headingTransformer(line.replace(headingPrefix, '').trim());
55
+ continue;
56
+ }
57
+ if (!obj[currentHeading])
58
+ obj[currentHeading] = '';
59
+ /**
60
+ * Our images need an extra line return so they don't get squished against our dot points
61
+ */
62
+ if (line.startsWith('!'))
63
+ obj[currentHeading] += '\n';
64
+ /**
65
+ * Skip the line if the dev is opting out by adding n/a
66
+ */
67
+ if (line.toLowerCase().trim() !== 'n/a')
68
+ obj[currentHeading] += line + '\n';
69
+ }
70
+ return obj;
71
+ }
72
+ /**
73
+ * I can't read this code but it came from here and it works: https://stackoverflow.com/a/63457487/14258157
74
+ * - Josh
75
+ */
76
+ function orderDescriptionHeadings(headings) {
77
+ // Get the index of our wildcard where we put all the other headings into
78
+ var starIndex = HEADING_ORDER.indexOf('*');
79
+ if (starIndex === -1)
80
+ starIndex = HEADING_ORDER.length;
81
+ return headings.sort(function (a, b) {
82
+ var aIndex = HEADING_ORDER.indexOf(a);
83
+ var bIndex = HEADING_ORDER.indexOf(b);
84
+ // Do normal sort logic if both are missing from heading order
85
+ if (aIndex === -1 && bIndex === -1) {
86
+ if (a < b)
87
+ return -1;
88
+ if (a > b)
89
+ return 1;
90
+ return 0;
91
+ }
92
+ if (aIndex === -1)
93
+ aIndex = starIndex;
94
+ if (bIndex === -1)
95
+ bIndex = starIndex;
96
+ return aIndex - bIndex;
97
+ });
98
+ }
99
+ exports.Descriptions = {
100
+ validate: function (description, projectConfig) {
101
+ var validHeadings;
102
+ // If we are a monorepo, add in the valid sub project headings
103
+ if (projectConfig.monorepo.enabled) {
104
+ var subProjects = projectConfig.monorepo.validSubProjects;
105
+ validHeadings = BASE_VALID_HEADINGS.concat(subProjects);
106
+ }
107
+ else {
108
+ validHeadings = PROJECT_VALID_HEADINGS;
109
+ }
110
+ // Parse description
111
+ var obj = toObject(description.split('\n'), '#');
112
+ var errors = this.validateProject(obj, {
113
+ validSections: validHeadings,
114
+ requiredSections: PROJECT_REQUIRED_HEADINGS
115
+ });
116
+ if (!projectConfig.monorepo.enabled)
117
+ return errors;
118
+ var _loop_1 = function (subProject) {
119
+ // Ignore known headings
120
+ if (PROJECT_VALID_HEADINGS.indexOf(subProject) !== -1)
121
+ return "continue";
122
+ var subObj = toObject(obj[subProject].split('\n'), '##');
123
+ var subErrors = this_1.validateProject(subObj, {
124
+ validSections: PROJECT_VALID_HEADINGS,
125
+ requiredSections: []
126
+ });
127
+ errors = errors.concat(subErrors.map(function (x) { return "[".concat(subProject, "] ") + x; }));
128
+ };
129
+ var this_1 = this;
130
+ // If monorepo we need to check the sub projects are valid
131
+ for (var subProject in obj) {
132
+ _loop_1(subProject);
133
+ }
134
+ return errors;
135
+ },
136
+ validateProject: function (parsedDescription, options) {
137
+ // Parse description
138
+ var headings = Object.keys(parsedDescription);
139
+ // Must have at least one heading
140
+ if (headings.length < 1)
141
+ return ['Must have at least one section'];
142
+ var errors = [];
143
+ // Ensure all the headings are valid
144
+ for (var _i = 0, headings_1 = headings; _i < headings_1.length; _i++) {
145
+ var heading = headings_1[_i];
146
+ if (options.validSections.indexOf(heading) === -1)
147
+ errors.push("Invalid section: ".concat(heading));
148
+ }
149
+ // Ensure we have all required headings
150
+ for (var _a = 0, _b = options.requiredSections; _a < _b.length; _a++) {
151
+ var requiredSection = _b[_a];
152
+ if (parsedDescription[requiredSection] === undefined)
153
+ errors.push("Missing section: ".concat(requiredSection));
154
+ }
155
+ return errors;
156
+ },
157
+ getCombinedDescription: function (mergeRequests, headingPrefix) {
158
+ if (headingPrefix === void 0) { headingPrefix = '#'; }
159
+ var descriptionObjs = mergeRequests
160
+ .filter(function (mr) { return mr.status === 'merged'; })
161
+ .map(function (mr) { return toObject(mr.description.split('\n'), headingPrefix); });
162
+ var obj = {};
163
+ var _loop_2 = function (descriptionObj) {
164
+ Object.keys(descriptionObj).forEach(function (key) {
165
+ if (!obj[key])
166
+ obj[key] = '';
167
+ obj[key] += descriptionObj[key] + '\n';
168
+ });
169
+ };
170
+ for (var _i = 0, descriptionObjs_1 = descriptionObjs; _i < descriptionObjs_1.length; _i++) {
171
+ var descriptionObj = descriptionObjs_1[_i];
172
+ _loop_2(descriptionObj);
173
+ }
174
+ var description = '';
175
+ var orderedHeadings = orderDescriptionHeadings(Object.keys(obj));
176
+ orderedHeadings.forEach(function (key) {
177
+ if (key === Headings.Notes)
178
+ return;
179
+ if (!obj[key])
180
+ return;
181
+ description += '\n' + headingPrefix + ' ' + key + '\n';
182
+ description += obj[key];
183
+ });
184
+ return description;
185
+ },
186
+ getDescriptionSection: function (heading, mergeRequest) {
187
+ var descriptionObj = toObject(mergeRequest.description.split('\n'), '#');
188
+ var obj = {};
189
+ Object.keys(descriptionObj).forEach(function (key) {
190
+ if (!obj[key])
191
+ obj[key] = '';
192
+ obj[key] += descriptionObj[key] + '\n';
193
+ });
194
+ return obj[Headings[heading]];
195
+ },
196
+ // TODO: This isn't readable, it needs to be refactored
197
+ getMonorepoCombinedDescription: function (mergeRequests) {
198
+ // Get an object where H1s are properties
199
+ var descriptionObjs = mergeRequests
200
+ .filter(function (mr) { return mr.status === 'merged'; })
201
+ .map(function (mr) { return toObject(mr.description.split('\n'), '#'); });
202
+ var combinedObj = {};
203
+ var _loop_3 = function (descriptionObj) {
204
+ Object.keys(descriptionObj).forEach(function (key) {
205
+ if (!combinedObj[key])
206
+ combinedObj[key] = {};
207
+ var combinedSubObj = toObject(descriptionObj[key].split('\n'), '##');
208
+ var orderedHeadings = orderDescriptionHeadings(Object.keys(combinedSubObj));
209
+ orderedHeadings.forEach(function (subKey) {
210
+ if (!combinedObj[key][subKey])
211
+ combinedObj[key][subKey] = '';
212
+ combinedObj[key][subKey] += combinedSubObj[subKey];
213
+ });
214
+ });
215
+ };
216
+ // For each property in each MR object, calculate it's H2 heading objects
217
+ for (var _i = 0, descriptionObjs_2 = descriptionObjs; _i < descriptionObjs_2.length; _i++) {
218
+ var descriptionObj = descriptionObjs_2[_i];
219
+ _loop_3(descriptionObj);
220
+ }
221
+ var orderedHeadings = orderDescriptionHeadings(Object.keys(combinedObj));
222
+ // Build our description
223
+ var description = '';
224
+ orderedHeadings.forEach(function (key) {
225
+ if (key === Headings.Notes)
226
+ return;
227
+ description += '\n# ' + key + '\n';
228
+ Object.keys(combinedObj[key]).forEach(function (subKey) {
229
+ if (key !== Headings.Dependencies && key !== Headings.Testing)
230
+ description += '\n## ' + subKey + '\n';
231
+ description += combinedObj[key][subKey];
232
+ });
233
+ });
234
+ return description;
235
+ },
236
+ getMonorepoDescriptionSection: function (subHeading, mergeRequest) {
237
+ var descriptionObj = toObject(mergeRequest.description.split('\n'), '#');
238
+ var obj = {};
239
+ Object.keys(descriptionObj).forEach(function (key) {
240
+ if (!obj[key])
241
+ obj[key] = {};
242
+ var combinedSubObj = toObject(descriptionObj[key].split('\n'), '##');
243
+ Object.keys(combinedSubObj).forEach(function (subKey) {
244
+ if (!obj[key][subKey])
245
+ obj[key][subKey] = '';
246
+ obj[key][subKey] += combinedSubObj[subKey];
247
+ });
248
+ });
249
+ // Build our description
250
+ var description = '';
251
+ Object.keys(obj).forEach(function (key) {
252
+ if (key === Headings.Notes)
253
+ return;
254
+ Object.keys(obj[key]).forEach(function (subKey) {
255
+ if (subKey !== Headings[subHeading])
256
+ return;
257
+ description += '\n# ' + key + '\n';
258
+ description += obj[key][subKey];
259
+ });
260
+ });
261
+ return description;
262
+ },
263
+ bumpHeadings: function (description) {
264
+ var lines = description.split('\n');
265
+ var bumpedDescription = '';
266
+ lines.forEach(function (line) {
267
+ if (line.startsWith('#'))
268
+ bumpedDescription += '#' + line + '\n';
269
+ else
270
+ bumpedDescription += line + '\n';
271
+ });
272
+ return bumpedDescription;
273
+ }
274
+ };