Skip to content

Commit

Permalink
Merge pull request #27 from gruntwork-io/fix-missing-breaking-version
Browse files Browse the repository at this point in the history
Fix undefined error when theres no next breaking version
  • Loading branch information
marinalimeira authored Sep 6, 2023
2 parents 3dd5920 + e866a9d commit af0b1c9
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 29 deletions.
68 changes: 42 additions & 26 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ exports.prepareKeyValueMessage = exports.issueFileCommand = void 0;
/* eslint-disable @typescript-eslint/no-explicit-any */
const fs = __importStar(__nccwpck_require__(7147));
const os = __importStar(__nccwpck_require__(2037));
const uuid_1 = __nccwpck_require__(1866);
const uuid_1 = __nccwpck_require__(8974);
const utils_1 = __nccwpck_require__(5278);
function issueFileCommand(command, message) {
const filePath = process.env[`GITHUB_${command}`];
Expand Down Expand Up @@ -994,7 +994,7 @@ exports.toCommandProperties = toCommandProperties;

/***/ }),

/***/ 1866:
/***/ 8974:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";
Expand Down Expand Up @@ -13583,10 +13583,15 @@ function pullRequestTitle(dependency, workingDir) {
}
return title;
}
function pullRequestReleaseNotesBreakingVersion(nextBreakingVersion) {
if (!!nextBreakingVersion) {
return `([Release notes for ${nextBreakingVersion.version}](${nextBreakingVersion.release_notes_url}))`;
}
return "";
}
function pullRequestBodyUpdatedModules(modules) {
// TODO do not show patches applied if count = 0
return modules.map(module => (` - Previous version: \`${module.previous_version}\`
- Updated version: \`${module.updated_version}\` ([Release notes for ${module.next_breaking_version.version}](${module.next_breaking_version.release_notes_url}))
- Updated version: \`${module.updated_version}\` ${pullRequestReleaseNotesBreakingVersion(module.next_breaking_version)}
- Patches applied: ${module.patches_applied.count}`)).join("\n");
}
function pullRequestBodySuccessfulUpdates(updatedModules) {
Expand Down Expand Up @@ -13797,6 +13802,29 @@ async function run() {
exports.run = run;


/***/ }),

/***/ 6144:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";

var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core_1 = __importDefault(__nccwpck_require__(2186));
const action_1 = __nccwpck_require__(7672);
(async () => {
try {
await (0, action_1.run)();
}
catch (e) {
core_1.default.setFailed(`Action failed with "${e}"`);
}
})();


/***/ }),

/***/ 2877:
Expand Down Expand Up @@ -20246,7 +20274,7 @@ var int = __nccwpck_require__(3019);
var schema = __nccwpck_require__(27);
var schema$1 = __nccwpck_require__(4545);
var binary = __nccwpck_require__(5724);
var omap = __nccwpck_require__(8974);
var omap = __nccwpck_require__(644);
var pairs = __nccwpck_require__(9841);
var schema$2 = __nccwpck_require__(5389);
var set = __nccwpck_require__(7847);
Expand Down Expand Up @@ -20579,7 +20607,7 @@ exports.intOct = intOct;

/***/ }),

/***/ 8974:
/***/ 644:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";
Expand Down Expand Up @@ -20767,7 +20795,7 @@ var binary = __nccwpck_require__(5724);
var bool = __nccwpck_require__(2631);
var float = __nccwpck_require__(8035);
var int = __nccwpck_require__(9503);
var omap = __nccwpck_require__(8974);
var omap = __nccwpck_require__(644);
var pairs = __nccwpck_require__(9841);
var set = __nccwpck_require__(7847);
var timestamp = __nccwpck_require__(1156);
Expand Down Expand Up @@ -22410,24 +22438,12 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"]
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
(() => {
"use strict";
var exports = __webpack_exports__;

Object.defineProperty(exports, "__esModule", ({ value: true }));
const action_1 = __nccwpck_require__(7672);
(async () => {
// try {
await (0, action_1.run)();
// } catch (e) {
// core.setFailed(`Action failed with "${e}"`);
// }
})();

})();

module.exports = __webpack_exports__;
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module is referenced by other modules so it can't be inlined
/******/ var __webpack_exports__ = __nccwpck_require__(6144);
/******/ module.exports = __webpack_exports__;
/******/
/******/ })()
;
14 changes: 11 additions & 3 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,19 @@ export interface PatchesApplied {
count: number;
}

function pullRequestReleaseNotesBreakingVersion(nextBreakingVersion: NextBreakingVersion): string {
if (!!nextBreakingVersion) {
return `([Release notes for ${nextBreakingVersion.version}](${nextBreakingVersion.release_notes_url}))`
}

return "";
}

function pullRequestBodyUpdatedModules(modules: UpdatedModule[]): string {
// TODO do not show patches applied if count = 0
return modules.map(module => (` - Previous version: \`${module.previous_version}\`
- Updated version: \`${module.updated_version}\` ([Release notes for ${module.next_breaking_version.version}](${module.next_breaking_version.release_notes_url}))
- Patches applied: ${module.patches_applied.count}`)).join("\n");
- Updated version: \`${module.updated_version}\` ${pullRequestReleaseNotesBreakingVersion(module.next_breaking_version)}
- Patches applied: ${module.patches_applied.count}`
)).join("\n");
}

function pullRequestBodySuccessfulUpdates(updatedModules: SuccessfulUpdate[]): string {
Expand Down
49 changes: 49 additions & 0 deletions tests/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,55 @@ successful_updates:
## Steps to review
1. Check the proposed changes to the \`terraform\` and/or \`terragrunt\` configuration files.
1. Validate the changes in the infrastructure by running \`terraform/terragrunt plan\`.
1. Upon approval, proceed with deploying the infrastructure changes."
`);
});
test("parses patcher's output when updating two files", () => {
const patcherRawOutput = ` successful_updates:
- file_path: dev/us-east-1/_regional/service-quotas/terragrunt.hcl
updated_modules:
- repo: terraform-aws-utilities
module: request-quota-increase
previous_version: v0.9.2
updated_version: v0.9.4
patches_applied:
count: 0`;
const result = pullRequestBody(patcherRawOutput, "gruntwork-io/terraform-aws-utilities/request-quota-increase");
expect(result).toMatchInlineSnapshot(`
":robot: This is an automated pull request opened by [Patcher](https://docs.gruntwork.io/patcher/).
## Description
Updated the \`gruntwork-io/terraform-aws-utilities/request-quota-increase\` dependency.
### Updated files
- \`dev/us-east-1/_regional/service-quotas/terragrunt.hcl\`
- Previous version: \`v0.9.2\`
- Updated version: \`v0.9.4\`
- Patches applied: 0
<details>
<summary>Raw output from \`patcher update\`</summary>
\`\`\`yaml
successful_updates:
- file_path: dev/us-east-1/_regional/service-quotas/terragrunt.hcl
updated_modules:
- repo: terraform-aws-utilities
module: request-quota-increase
previous_version: v0.9.2
updated_version: v0.9.4
patches_applied:
count: 0
\`\`\`
</details>
## Steps to review
1. Check the proposed changes to the \`terraform\` and/or \`terragrunt\` configuration files.
1. Validate the changes in the infrastructure by running \`terraform/terragrunt plan\`.
1. Upon approval, proceed with deploying the infrastructure changes."
Expand Down

0 comments on commit af0b1c9

Please sign in to comment.