Skip to content

Commit

Permalink
feat: improve PR body (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous authored Apr 5, 2021
1 parent 35cc9be commit c7aa57e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 18 deletions.
28 changes: 21 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};


Expand Down Expand Up @@ -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("<details open>");
lines.push(`<summary><strong>Updated (${report.updated.length})</strong></summary>`);
lines.push("");
lines.push(...header);

Expand All @@ -8541,32 +8546,41 @@ module.exports = function buildPullRequestBody(report, npmVersion) {
)
);
});

lines.push("");
lines.push("</details>");
}

if (report.added.length > 0) {
lines.push("");
lines.push(`### Added (${report.added.length})`);
lines.push("<details open>");
lines.push(`<summary><strong>Added (${report.added.length})</strong></summary>`);
lines.push("");
lines.push(...header);
report.added.forEach(({ name, version }) => {
lines.push(buildTableRow(npmPackage(name), versionLabel(version), repoLink(name), EMPTY));
});
lines.push("");
lines.push("</details>");
}

if (report.removed.length > 0) {
lines.push("");
lines.push(`### Removed (${report.removed.length})`);
lines.push("<details open>");
lines.push(`<summary><strong>Removed (${report.removed.length})</strong></summary>`);
lines.push("");
lines.push(...header);
report.removed.forEach(({ name, version }) => {
lines.push(buildTableRow(npmPackage(name), versionLabel(version), repoLink(name), EMPTY));
});
lines.push("");
lines.push("</details>");
}

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();
};
Expand Down
19 changes: 15 additions & 4 deletions lib/__tests__/buildPullRequestBody.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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).
<details open>
<summary><strong>Updated (2)</strong></summary>
| 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)
</details>
<details open>
<summary><strong>Added (1)</strong></summary>
| Package | Version | Source | Detail |
|:--------|:-------:|:------:|:-------|
| [xo](https://npm.im/xo) | \`0.1.1\` | - | - |
### Removed (1)
</details>
<details open>
<summary><strong>Removed (1)</strong></summary>
| Package | Version | Source | Detail |
|:--------|:-------:|:------:|:-------|
| [@gitlab/ui](https://npm.im/@gitlab/ui) | \`1.2.3\` | [gitlab](https://gitlab.com/gitlab-org/gitlab-ui) | - |
</details>
***
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()
);
});
26 changes: 20 additions & 6 deletions lib/buildPullRequestBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("<details open>");
lines.push(`<summary><strong>Updated (${report.updated.length})</strong></summary>`);
lines.push("");
lines.push(...header);

Expand All @@ -58,32 +63,41 @@ module.exports = function buildPullRequestBody(report, npmVersion) {
)
);
});

lines.push("");
lines.push("</details>");
}

if (report.added.length > 0) {
lines.push("");
lines.push(`### Added (${report.added.length})`);
lines.push("<details open>");
lines.push(`<summary><strong>Added (${report.added.length})</strong></summary>`);
lines.push("");
lines.push(...header);
report.added.forEach(({ name, version }) => {
lines.push(buildTableRow(npmPackage(name), versionLabel(version), repoLink(name), EMPTY));
});
lines.push("");
lines.push("</details>");
}

if (report.removed.length > 0) {
lines.push("");
lines.push(`### Removed (${report.removed.length})`);
lines.push("<details open>");
lines.push(`<summary><strong>Removed (${report.removed.length})</strong></summary>`);
lines.push("");
lines.push(...header);
report.removed.forEach(({ name, version }) => {
lines.push(buildTableRow(npmPackage(name), versionLabel(version), repoLink(name), EMPTY));
});
lines.push("");
lines.push("</details>");
}

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();
};
2 changes: 1 addition & 1 deletion lib/updateNpm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

0 comments on commit c7aa57e

Please sign in to comment.