Skip to content

Commit 35b7b53

Browse files
committed
Release v1.2.0
1 parent d6b76c8 commit 35b7b53

File tree

7 files changed

+75
-67
lines changed

7 files changed

+75
-67
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [1.2.0]
8+
## [1.2.0] - 2020-05-07
99

1010
### Fixed
1111

12-
- Do not fail check if no critical vulnerabilities were found when executed for a fork repository (closes #104)
12+
- Compatibility with latest `cargo-audit == 0.12` JSON output (#115)
13+
- Do not fail check if no critical vulnerabilities were found when executed for a fork repository (closes #104)
1314

1415
## [1.1.0]
1516

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rust-audit-check",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"private": false,
55
"description": "Security audit for security vulnerabilities",
66
"main": "lib/main.js",

src/interfaces.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface Report {
88
database: DatabaseInfo;
99
lockfile: LockfileInfo;
1010
vulnerabilities: VulnerabilitiesInfo;
11-
warnings: Warning[];
11+
warnings: Warning[] | { [key: string]: Warning[] };
1212
}
1313

1414
export interface DatabaseInfo {
@@ -47,23 +47,7 @@ export interface Package {
4747
}
4848

4949
export interface Warning {
50-
kind: Kind;
51-
package: Package;
52-
}
53-
54-
// TypeScript types system is weird :(
55-
export interface Kind {
56-
unmaintained?: KindUnmaintained;
57-
informational?: KindInformational;
58-
yanked?: KindYanked;
59-
}
60-
61-
export interface KindUnmaintained {
62-
advisory: Advisory;
63-
}
64-
65-
export interface KindInformational {
50+
kind: 'unmaintained' | 'informational' | 'yanked' | string;
6651
advisory: Advisory;
52+
package: Package;
6753
}
68-
69-
export interface KindYanked {} // eslint-disable-line @typescript-eslint/no-empty-interface

src/main.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,22 @@ export async function run(actionInput: input.Input): Promise<void> {
5353
shouldReport = true;
5454
}
5555

56-
if (report.warnings.length === 0) {
56+
// In `cargo-audit < 0.12` report contained an array of `Warning`.
57+
// In `cargo-audit >= 0.12` it is a JSON object,
58+
// where key is a warning type, and value is an array of `Warning` of that type.
59+
let warnings: Array<interfaces.Warning> = [];
60+
if (Array.isArray(report.warnings)) {
61+
warnings = report.warnings;
62+
} else {
63+
for (const items of Object.values(report.warnings)) {
64+
warnings = warnings.concat(items);
65+
}
66+
}
67+
68+
if (warnings.length === 0) {
5769
core.info('No warnings were found');
5870
} else {
59-
core.warning(`${report.warnings.length} warnings found!`);
71+
core.warning(`${warnings.length} warnings found!`);
6072
shouldReport = true;
6173
}
6274

@@ -72,12 +84,12 @@ export async function run(actionInput: input.Input): Promise<void> {
7284
core.debug(
7385
'Action was triggered on a schedule event, creating an Issues report',
7486
);
75-
await reporter.reportIssues(client, advisories, report.warnings);
87+
await reporter.reportIssues(client, advisories, warnings);
7688
} else {
7789
core.debug(
7890
`Action was triggered on a ${github.context.eventName} event, creating a Check report`,
7991
);
80-
await reporter.reportCheck(client, advisories, report.warnings);
92+
await reporter.reportCheck(client, advisories, warnings);
8193
}
8294
}
8395

src/reporter.ts

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,32 @@ function makeReport(
2626
): string {
2727
const preparedWarnings: Array<templates.ReportWarning> = [];
2828
for (const warning of warnings) {
29-
// TODO: Is there any better way?
30-
if ('unmaintained' in warning.kind) {
31-
preparedWarnings.push({
32-
advisory: warning.kind.unmaintained!.advisory, // eslint-disable-line @typescript-eslint/no-non-null-assertion
33-
package: warning.package,
34-
});
35-
} else if ('informational' in warning.kind) {
36-
preparedWarnings.push({
37-
advisory: warning.kind.informational!.advisory, // eslint-disable-line @typescript-eslint/no-non-null-assertion
38-
package: warning.package,
39-
});
40-
} else if ('yanked' in warning.kind) {
41-
preparedWarnings.push({
42-
package: warning.package,
43-
});
44-
} else {
45-
core.warning(
46-
`Unknown warning kind ${warning.kind} found, please, file a bug`,
47-
);
48-
continue;
29+
switch (warning.kind) {
30+
case 'unmaintained':
31+
preparedWarnings.push({
32+
advisory: warning.advisory,
33+
package: warning.package,
34+
});
35+
break;
36+
37+
case 'informational':
38+
preparedWarnings.push({
39+
advisory: warning.advisory,
40+
package: warning.package,
41+
});
42+
break;
43+
44+
case 'yanked':
45+
preparedWarnings.push({
46+
package: warning.package,
47+
});
48+
break;
49+
50+
default:
51+
core.warning(
52+
`Unknown warning kind ${warning.kind} found, please, file a bug`,
53+
);
54+
break;
4955
}
5056
}
5157

@@ -85,11 +91,15 @@ function getStats(
8591
}
8692

8793
for (const warning of warnings) {
88-
if (warning.kind.unmaintained) {
89-
unmaintained += 1;
90-
} else {
91-
// Both yanked and informational types of kind
92-
other += 1;
94+
switch (warning.kind) {
95+
case 'unmaintained':
96+
unmaintained += 1;
97+
break;
98+
99+
default:
100+
// Both yanked and informational types of kind
101+
other += 1;
102+
break;
93103
}
94104
}
95105

@@ -243,20 +253,21 @@ export async function reportIssues(
243253

244254
for (const warning of warnings) {
245255
let advisory: interfaces.Advisory;
246-
if ('unmaintained' in warning.kind) {
247-
advisory = warning.kind.unmaintained!.advisory; // eslint-disable-line @typescript-eslint/no-non-null-assertion
248-
} else if ('informational' in warning.kind) {
249-
advisory = warning.kind.informational!.advisory; // eslint-disable-line @typescript-eslint/no-non-null-assertion
250-
} else if ('yanked' in warning.kind) {
251-
core.warning(
252-
`Crate ${warning.package.name} was yanked, but no issue will be reported about it`,
253-
);
254-
continue;
255-
} else {
256-
core.warning(
257-
`Unknown warning kind ${warning.kind} found, please, file a bug`,
258-
);
259-
continue;
256+
switch (warning.kind) {
257+
case 'unmaintained':
258+
case 'informational':
259+
advisory = warning.advisory;
260+
break;
261+
case 'yanked':
262+
core.warning(
263+
`Crate ${warning.package.name} was yanked, but no issue will be reported about it`,
264+
);
265+
continue;
266+
default:
267+
core.warning(
268+
`Unknown warning kind ${warning.kind} found, please, file a bug`,
269+
);
270+
continue;
260271
}
261272

262273
const reported = await alreadyReported(client, advisory.id);

0 commit comments

Comments
 (0)