From c7aa57eaa91adebf1341cb630cd35cb8015b2489 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Tue, 6 Apr 2021 03:19:59 +0900 Subject: [PATCH] feat: improve PR body (#368) --- dist/index.js | 28 ++++++++++++++++------ lib/__tests__/buildPullRequestBody.test.js | 19 +++++++++++---- lib/buildPullRequestBody.js | 26 +++++++++++++++----- lib/updateNpm.js | 2 +- 4 files changed, 57 insertions(+), 18 deletions(-) diff --git a/dist/index.js b/dist/index.js index bceb3dee..13052f90 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2116,7 +2116,7 @@ module.exports = async function updateNpm(version) { // eslint-disable-next-line dot-notation -- Prevent TS4111 await exec("sudo", ["chown", "-R", `${process.env["USER"]}:`, `${process.env["HOME"]}/.config`]); - return actualVersion; + return actualVersion.trim(); }; @@ -8521,9 +8521,14 @@ module.exports = function buildPullRequestBody(report, npmVersion) { header.push("|:--------|:-------:|:------:|:-------|"); const lines = []; + lines.push( + `This pull request fixes vulnerabilities of the packages via npm [${npmVersion}](https://github.com/npm/cli/releases/tag/v${npmVersion}).` + ); + if (report.updated.length > 0) { lines.push(""); - lines.push(`### Updated (${report.updated.length})`); + lines.push("
"); + lines.push(`Updated (${report.updated.length})`); lines.push(""); lines.push(...header); @@ -8541,32 +8546,41 @@ module.exports = function buildPullRequestBody(report, npmVersion) { ) ); }); + + lines.push(""); + lines.push("
"); } + if (report.added.length > 0) { lines.push(""); - lines.push(`### Added (${report.added.length})`); + lines.push("
"); + lines.push(`Added (${report.added.length})`); lines.push(""); lines.push(...header); report.added.forEach(({ name, version }) => { lines.push(buildTableRow(npmPackage(name), versionLabel(version), repoLink(name), EMPTY)); }); + lines.push(""); + lines.push("
"); } + if (report.removed.length > 0) { lines.push(""); - lines.push(`### Removed (${report.removed.length})`); + lines.push("
"); + lines.push(`Removed (${report.removed.length})`); lines.push(""); lines.push(...header); report.removed.forEach(({ name, version }) => { lines.push(buildTableRow(npmPackage(name), versionLabel(version), repoLink(name), EMPTY)); }); + lines.push(""); + lines.push("
"); } lines.push(""); lines.push("***"); lines.push(""); - lines.push( - `This pull request is created by [${PACKAGE_NAME}](${PACKAGE_URL}) via npm ${npmVersion}.` - ); + lines.push(`Created by [${PACKAGE_NAME}](${PACKAGE_URL})`); return lines.join("\n").trim(); }; diff --git a/lib/__tests__/buildPullRequestBody.test.js b/lib/__tests__/buildPullRequestBody.test.js index c6b487f7..d27a748a 100644 --- a/lib/__tests__/buildPullRequestBody.test.js +++ b/lib/__tests__/buildPullRequestBody.test.js @@ -4,28 +4,39 @@ const report = require("./fixtures/report.json"); test("buildPullRequestBody()", () => { expect(buildPullRequestBody(report, "7.7.0")).toBe( ` -### Updated (2) +This pull request fixes vulnerabilities of the packages via npm [7.7.0](https://github.com/npm/cli/releases/tag/v7.7.0). + +
+Updated (2) | Package | Version | Source | Detail | |:--------|:-------:|:------:|:-------| | [minimist](https://npm.im/minimist) | \`1.2.1\` → \`1.2.4\` | [github](https://github.com/substack/minimist) | - | | [mocha](https://npm.im/mocha) | \`1.3.0\` → \`1.4.3\` | [github](https://github.com/mochajs/mocha) | **[Low]** Prototype Pollution ([ref](https://npmjs.com/advisories/1179)) | -### Added (1) +
+ +
+Added (1) | Package | Version | Source | Detail | |:--------|:-------:|:------:|:-------| | [xo](https://npm.im/xo) | \`0.1.1\` | - | - | -### Removed (1) +
+ +
+Removed (1) | Package | Version | Source | Detail | |:--------|:-------:|:------:|:-------| | [@gitlab/ui](https://npm.im/@gitlab/ui) | \`1.2.3\` | [gitlab](https://gitlab.com/gitlab-org/gitlab-ui) | - | +
+ *** -This pull request is created by [ybiquitous/npm-audit-fix-action](https://github.com/ybiquitous/npm-audit-fix-action) via npm 7.7.0. +Created by [ybiquitous/npm-audit-fix-action](https://github.com/ybiquitous/npm-audit-fix-action) `.trim() ); }); diff --git a/lib/buildPullRequestBody.js b/lib/buildPullRequestBody.js index 05867d40..e3c64482 100644 --- a/lib/buildPullRequestBody.js +++ b/lib/buildPullRequestBody.js @@ -38,9 +38,14 @@ module.exports = function buildPullRequestBody(report, npmVersion) { header.push("|:--------|:-------:|:------:|:-------|"); const lines = []; + lines.push( + `This pull request fixes vulnerabilities of the packages via npm [${npmVersion}](https://github.com/npm/cli/releases/tag/v${npmVersion}).` + ); + if (report.updated.length > 0) { lines.push(""); - lines.push(`### Updated (${report.updated.length})`); + lines.push("
"); + lines.push(`Updated (${report.updated.length})`); lines.push(""); lines.push(...header); @@ -58,32 +63,41 @@ module.exports = function buildPullRequestBody(report, npmVersion) { ) ); }); + + lines.push(""); + lines.push("
"); } + if (report.added.length > 0) { lines.push(""); - lines.push(`### Added (${report.added.length})`); + lines.push("
"); + lines.push(`Added (${report.added.length})`); lines.push(""); lines.push(...header); report.added.forEach(({ name, version }) => { lines.push(buildTableRow(npmPackage(name), versionLabel(version), repoLink(name), EMPTY)); }); + lines.push(""); + lines.push("
"); } + if (report.removed.length > 0) { lines.push(""); - lines.push(`### Removed (${report.removed.length})`); + lines.push("
"); + lines.push(`Removed (${report.removed.length})`); lines.push(""); lines.push(...header); report.removed.forEach(({ name, version }) => { lines.push(buildTableRow(npmPackage(name), versionLabel(version), repoLink(name), EMPTY)); }); + lines.push(""); + lines.push("
"); } lines.push(""); lines.push("***"); lines.push(""); - lines.push( - `This pull request is created by [${PACKAGE_NAME}](${PACKAGE_URL}) via npm ${npmVersion}.` - ); + lines.push(`Created by [${PACKAGE_NAME}](${PACKAGE_URL})`); return lines.join("\n").trim(); }; diff --git a/lib/updateNpm.js b/lib/updateNpm.js index 2800f992..51d3b841 100644 --- a/lib/updateNpm.js +++ b/lib/updateNpm.js @@ -20,5 +20,5 @@ module.exports = async function updateNpm(version) { // eslint-disable-next-line dot-notation -- Prevent TS4111 await exec("sudo", ["chown", "-R", `${process.env["USER"]}:`, `${process.env["HOME"]}/.config`]); - return actualVersion; + return actualVersion.trim(); };