Skip to content

Commit

Permalink
fix(dashboard): undefined currentValue (#15917)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel-Ladzaretti committed Jun 7, 2022
1 parent d40a8a9 commit ea8ab7c
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 1 deletion.
42 changes: 42 additions & 0 deletions lib/workers/repository/__fixtures__/package-files-digest.json
@@ -0,0 +1,42 @@
{
"dockerfile": [
{
"packageFile": "ver-and-digest/Dockerfile",
"deps": [
{
"depName": "ubuntu",
"currentValue": "18.04",
"currentDigest": "sha256:a7ed45c4a95fbe19f9c5fb9d1ca58b2431b2a4984754be2f50ccec99d9428b79"
}
]
},
{
"packageFile": "no-ver-no-digest/Dockerfile",
"deps": [
{
"depName": "ubuntu",
"replaceString": "ubuntu",
"skipReason": "invalid-value"
}
]
},
{
"packageFile": "ver-only/Dockerfile",
"deps": [
{
"depName": "ubuntu",
"currentValue": "20.04"
}
]
},
{
"packageFile": "digest-only/Dockerfile",
"deps": [
{
"depName": "ubuntu",
"currentDigest": "sha256:06b5d30fabc1fc574f2ecab87375692299d45f8f190d9b71f512deb494114e1f"
}
]
}
]
}
Expand Up @@ -319,6 +319,46 @@ None detected
"
`;

exports[`workers/repository/dependency-dashboard ensureDependencyDashboard() checks detected dependencies section single base branch repo shows different combinations of version+digest for a given dependency 1`] = `
"This issue provides visibility into Renovate updates and their statuses. [Learn more](https://docs.renovatebot.com/key-concepts/dashboard/)
This repository currently has no open or pending branches.
## Detected dependencies
<details><summary>dockerfile</summary>
<blockquote>
<details><summary>ver-and-digest/Dockerfile</summary>
- \`ubuntu 18.04@sha256:a7ed45c4a95fbe19f9c5fb9d1ca58b2431b2a4984754be2f50ccec99d9428b79\`
</details>
<details><summary>no-ver-no-digest/Dockerfile</summary>
- \`ubuntu no version found\`
</details>
<details><summary>ver-only/Dockerfile</summary>
- \`ubuntu 20.04\`
</details>
<details><summary>digest-only/Dockerfile</summary>
- \`ubuntu sha256:06b5d30fabc1fc574f2ecab87375692299d45f8f190d9b71f512deb494114e1f\`
</details>
</blockquote>
</details>
"
`;

exports[`workers/repository/dependency-dashboard ensureDependencyDashboard() contains logged problems 1`] = `
"This issue provides visibility into Renovate updates and their statuses. [Learn more](https://docs.renovatebot.com/key-concepts/dashboard/)
Expand Down
14 changes: 14 additions & 0 deletions lib/workers/repository/dependency-dashboard.spec.ts
Expand Up @@ -558,6 +558,9 @@ describe('workers/repository/dependency-dashboard', () => {

describe('checks detected dependencies section', () => {
const packageFiles = Fixtures.getJson('./package-files.json');
const packageFilesWithDigest = Fixtures.getJson(
'./package-files-digest.json'
);
let config: RenovateConfig;

beforeAll(() => {
Expand Down Expand Up @@ -608,6 +611,17 @@ describe('workers/repository/dependency-dashboard', () => {
// same with dry run
await dryRun(branches, platform);
});

it('shows different combinations of version+digest for a given dependency', async () => {
const branches: BranchConfig[] = [];
PackageFiles.add('main', packageFilesWithDigest);
await dependencyDashboard.ensureDependencyDashboard(config, branches);
expect(platform.ensureIssue).toHaveBeenCalledTimes(1);
expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot();

// same with dry run
await dryRun(branches, platform);
});
});

describe('multi base branch repo', () => {
Expand Down
11 changes: 10 additions & 1 deletion lib/workers/repository/package-files.ts
Expand Up @@ -46,12 +46,21 @@ export class PackageFiles {
deps += pad ? '</blockquote>\n</details>\n\n' : '';
continue;
}

const placeHolder = `no version found`;

for (const manager of managers) {
deps += `<details><summary>${manager}</summary>\n<blockquote>\n\n`;
for (const packageFile of packageFiles[manager]) {
deps += `<details><summary>${packageFile.packageFile}</summary>\n\n`;
for (const dep of packageFile.deps) {
deps += ` - \`${dep.depName} ${dep.currentValue}\`\n`;
const ver = dep.currentValue;
const digest = dep.currentDigest;
const version =
ver && digest
? `${ver}@${digest}`
: `${digest ?? ver ?? placeHolder}`;
deps += ` - \`${dep.depName} ${version}\`\n`;
}
deps += '\n</details>\n\n';
}
Expand Down

0 comments on commit ea8ab7c

Please sign in to comment.