Skip to content

Commit

Permalink
feat: add version to npmjs.com link (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous authored Apr 5, 2021
1 parent 7c502cc commit 50e55a3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
14 changes: 10 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8503,8 +8503,10 @@ const EMPTY = "-";
module.exports = function buildPullRequestBody(report, npmVersion) {
/**
* @param {string} name
* @param {string} version
*/
const npmPackage = (name) => `[${name}](https://npm.im/${name})`;
const npmPackage = (name, version) =>
`[${name}](https://www.npmjs.com/package/${name}/v/${version})`;

/**
* @param {...string} items
Expand Down Expand Up @@ -8549,7 +8551,7 @@ module.exports = function buildPullRequestBody(report, npmVersion) {
}
lines.push(
buildTableRow(
npmPackage(name),
npmPackage(name, version),
`${versionLabel(previousVersion)}${versionLabel(version)}`,
repoLink(name),
extra
Expand All @@ -8568,7 +8570,9 @@ module.exports = function buildPullRequestBody(report, npmVersion) {
lines.push("");
lines.push(...header);
report.added.forEach(({ name, version }) => {
lines.push(buildTableRow(npmPackage(name), versionLabel(version), repoLink(name), EMPTY));
lines.push(
buildTableRow(npmPackage(name, version), versionLabel(version), repoLink(name), EMPTY)
);
});
lines.push("");
lines.push("</details>");
Expand All @@ -8581,7 +8585,9 @@ module.exports = function buildPullRequestBody(report, npmVersion) {
lines.push("");
lines.push(...header);
report.removed.forEach(({ name, version }) => {
lines.push(buildTableRow(npmPackage(name), versionLabel(version), repoLink(name), EMPTY));
lines.push(
buildTableRow(npmPackage(name, version), versionLabel(version), repoLink(name), EMPTY)
);
});
lines.push("");
lines.push("</details>");
Expand Down
8 changes: 4 additions & 4 deletions lib/__tests__/buildPullRequestBody.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ This pull request fixes the vulnerable packages via npm [7.7.0](https://github.c
| 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)) |
| [minimist](https://www.npmjs.com/package/minimist/v/1.2.4) | \`1.2.1\` → \`1.2.4\` | [github](https://github.com/substack/minimist) | - |
| [mocha](https://www.npmjs.com/package/mocha/v/1.4.3) | \`1.3.0\` → \`1.4.3\` | [github](https://github.com/mochajs/mocha) | **[Low]** Prototype Pollution ([ref](https://npmjs.com/advisories/1179)) |
</details>
Expand All @@ -21,7 +21,7 @@ This pull request fixes the vulnerable packages via npm [7.7.0](https://github.c
| Package | Version | Source | Detail |
|:--------|:-------:|:------:|:-------|
| [xo](https://npm.im/xo) | \`0.1.1\` | - | - |
| [xo](https://www.npmjs.com/package/xo/v/0.38.0) | \`0.38.0\` | - | - |
</details>
Expand All @@ -30,7 +30,7 @@ This pull request fixes the vulnerable packages via npm [7.7.0](https://github.c
| Package | Version | Source | Detail |
|:--------|:-------:|:------:|:-------|
| [@gitlab/ui](https://npm.im/@gitlab/ui) | \`1.2.3\` | [gitlab](https://gitlab.com/gitlab-org/gitlab-ui) | - |
| [@gitlab/ui](https://www.npmjs.com/package/@gitlab/ui/v/29.2.0) | \`29.2.0\` | [gitlab](https://gitlab.com/gitlab-org/gitlab-ui) | - |
</details>
Expand Down
4 changes: 2 additions & 2 deletions lib/__tests__/fixtures/report.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"added": [{ "name": "xo", "version": "0.1.1" }],
"removed": [{ "name": "@gitlab/ui", "version": "1.2.3" }],
"added": [{ "name": "xo", "version": "0.38.0" }],
"removed": [{ "name": "@gitlab/ui", "version": "29.2.0" }],
"updated": [
{
"name": "minimist",
Expand Down
14 changes: 10 additions & 4 deletions lib/buildPullRequestBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ const EMPTY = "-";
module.exports = function buildPullRequestBody(report, npmVersion) {
/**
* @param {string} name
* @param {string} version
*/
const npmPackage = (name) => `[${name}](https://npm.im/${name})`;
const npmPackage = (name, version) =>
`[${name}](https://www.npmjs.com/package/${name}/v/${version})`;

/**
* @param {...string} items
Expand Down Expand Up @@ -56,7 +58,7 @@ module.exports = function buildPullRequestBody(report, npmVersion) {
}
lines.push(
buildTableRow(
npmPackage(name),
npmPackage(name, version),
`${versionLabel(previousVersion)}${versionLabel(version)}`,
repoLink(name),
extra
Expand All @@ -75,7 +77,9 @@ module.exports = function buildPullRequestBody(report, npmVersion) {
lines.push("");
lines.push(...header);
report.added.forEach(({ name, version }) => {
lines.push(buildTableRow(npmPackage(name), versionLabel(version), repoLink(name), EMPTY));
lines.push(
buildTableRow(npmPackage(name, version), versionLabel(version), repoLink(name), EMPTY)
);
});
lines.push("");
lines.push("</details>");
Expand All @@ -88,7 +92,9 @@ module.exports = function buildPullRequestBody(report, npmVersion) {
lines.push("");
lines.push(...header);
report.removed.forEach(({ name, version }) => {
lines.push(buildTableRow(npmPackage(name), versionLabel(version), repoLink(name), EMPTY));
lines.push(
buildTableRow(npmPackage(name, version), versionLabel(version), repoLink(name), EMPTY)
);
});
lines.push("");
lines.push("</details>");
Expand Down

0 comments on commit 50e55a3

Please sign in to comment.