Compare commits

...

67 Commits
v1.0 ... v1.1.7

Author SHA1 Message Date
Jonas Bushart
fe269d550e Update cargo-audit to 0.17.6 2023-05-12 22:05:27 +02:00
Jonas Bushart
b6da146557 Merge pull request #27 from actions-rust-lang/pre-commit-ci-update-config 2023-05-08 22:21:23 +02:00
pre-commit-ci[bot]
e661f5f79f [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/asottile/pyupgrade: v3.3.2 → v3.4.0](https://github.com/asottile/pyupgrade/compare/v3.3.2...v3.4.0)
- [github.com/python-jsonschema/check-jsonschema: 0.22.0 → 0.23.0](https://github.com/python-jsonschema/check-jsonschema/compare/0.22.0...0.23.0)
2023-05-08 19:32:55 +00:00
Jonas Bushart
6c5b44595d Merge pull request #26 from actions-rust-lang/pre-commit-ci-update-config
[pre-commit.ci] pre-commit autoupdate
2023-05-01 23:08:15 +02:00
pre-commit-ci[bot]
b4f705152a [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/asottile/pyupgrade: v3.3.1 → v3.3.2](https://github.com/asottile/pyupgrade/compare/v3.3.1...v3.3.2)
2023-05-01 19:24:23 +00:00
Jonas Bushart
38e4be49ce Merge pull request #25 from actions-rust-lang/pre-commit-ci-update-config
[pre-commit.ci] pre-commit autoupdate
2023-04-11 06:01:20 +03:00
pre-commit-ci[bot]
c93937eff7 [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/pre-commit/mirrors-mypy: v1.1.1 → v1.2.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.1.1...v1.2.0)
2023-04-10 19:18:55 +00:00
Jonas Bushart
b890df83b8 Merge pull request #24 from actions-rust-lang/pre-commit-ci-update-config 2023-04-03 22:12:59 +02:00
pre-commit-ci[bot]
8d89530feb [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/psf/black: 23.1.0 → 23.3.0](https://github.com/psf/black/compare/23.1.0...23.3.0)
2023-04-03 19:54:37 +00:00
Jonas Bushart
7e63792ca8 Update cargo-audit to 0.17.5 2023-03-24 20:14:05 +01:00
Jonas Bushart
229220ba5c Merge pull request #23 from actions-rust-lang/pre-commit-ci-update-config 2023-03-13 21:59:19 +01:00
pre-commit-ci[bot]
0fd4d6ceb9 [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/pre-commit/mirrors-mypy: v1.0.1 → v1.1.1](https://github.com/pre-commit/mirrors-mypy/compare/v1.0.1...v1.1.1)
- [github.com/python-jsonschema/check-jsonschema: 0.21.0 → 0.22.0](https://github.com/python-jsonschema/check-jsonschema/compare/0.21.0...0.22.0)
2023-03-13 19:27:32 +00:00
Jonas Bushart
26cc152162 Merge pull request #22 from actions-rust-lang/pre-commit-ci-update-config 2023-02-20 20:16:44 +01:00
pre-commit-ci[bot]
839e077185 [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/pre-commit/mirrors-mypy: v1.0.0 → v1.0.1](https://github.com/pre-commit/mirrors-mypy/compare/v1.0.0...v1.0.1)
2023-02-20 19:03:41 +00:00
Jonas Bushart
a4304b40f7 Check the syntax of GitHub Actions and Workflows files 2023-02-13 20:17:27 +01:00
Jonas Bushart
de4a880f36 Merge pull request #21 from actions-rust-lang/pre-commit-ci-update-config 2023-02-13 20:15:08 +01:00
pre-commit-ci[bot]
60557a6189 [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/pre-commit/mirrors-mypy: v0.991 → v1.0.0](https://github.com/pre-commit/mirrors-mypy/compare/v0.991...v1.0.0)
2023-02-13 19:09:15 +00:00
Jonas Bushart
fc8955c20d Merge pull request #20 from actions-rust-lang/pre-commit-ci-update-config 2023-02-06 21:01:58 +01:00
pre-commit-ci[bot]
5e0c395775 [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/psf/black: 22.12.0 → 23.1.0](https://github.com/psf/black/compare/22.12.0...23.1.0)
2023-02-06 19:35:04 +00:00
Jonas Bushart
362dc829f3 Merge pull request #19 from actions-rust-lang/pre-commit-ci-update-config
[pre-commit.ci] pre-commit autoupdate
2023-01-30 21:12:36 +01:00
pre-commit-ci[bot]
ea1aefd179 [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/PyCQA/isort: 5.11.4 → 5.12.0](https://github.com/PyCQA/isort/compare/5.11.4...5.12.0)
2023-01-30 19:23:47 +00:00
Jonas Bushart
0d6847edc7 Merge pull request #18 from actions-rust-lang/pre-commit-ci-update-config 2022-12-26 20:33:51 +01:00
pre-commit-ci[bot]
058839aa82 [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/PyCQA/isort: v5.11.3 → 5.11.4](https://github.com/PyCQA/isort/compare/v5.11.3...5.11.4)
2022-12-26 18:55:00 +00:00
Jonas Bushart
165ccb4a64 Prepare new version to fix duplicate issues for yanked crates 2022-12-22 23:09:27 +01:00
Jonas Bushart
623cff7dbe Fix finding of existing issues, since the issue title format was expanded
Issues for yanked crates start with "Crate ... v..." not with
"RUSTSEC-". So the filter on the existing issues list was too strict,
not detecting the issue for yanked crates. This causes duplicate issues.
2022-12-22 22:44:56 +01:00
Jonas Bushart
2406ebfa1e Prepare new version v1.1.4
Closes #17
2022-12-22 22:00:04 +01:00
Jonas Bushart
bbbc43cd45 Add icon to markdown summary for yanked crates 2022-12-22 21:51:32 +01:00
Jonas Bushart
44f419d83a Handle that the advisory field is optional
If missing show a message that the crate is yanked
2022-12-22 21:42:26 +01:00
Jonas Bushart
bf3d0bcece Add some debug statements
This should make future debugging requests easier, since the cargo audit
command and the resulting JSON are directly accessible.
2022-12-22 21:33:06 +01:00
Jonas Bushart
cf4c31eba1 Merge pull request #16 from actions-rust-lang/pre-commit-ci-update-config 2022-12-19 19:43:10 +01:00
pre-commit-ci[bot]
13b59a5eab [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/PyCQA/isort: 5.10.1 → v5.11.3](https://github.com/PyCQA/isort/compare/5.10.1...v5.11.3)
2022-12-19 18:33:35 +00:00
Jonas Bushart
502e7e5028 Merge pull request #15 from actions-rust-lang/pre-commit-ci-update-config
[pre-commit.ci] pre-commit autoupdate
2022-12-12 20:01:18 +01:00
pre-commit-ci[bot]
8ee9b53721 [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/psf/black: 22.10.0 → 22.12.0](https://github.com/psf/black/compare/22.10.0...22.12.0)
- [github.com/asottile/pyupgrade: v3.3.0 → v3.3.1](https://github.com/asottile/pyupgrade/compare/v3.3.0...v3.3.1)
2022-12-12 18:48:16 +00:00
Jonas Bushart
2c37721442 Add timeout arguments to network functions
This fixes a pylint warning
2022-12-05 22:22:46 +00:00
Jonas Bushart
65677fab72 Release version with caching fixes 2022-12-05 22:04:42 +00:00
Jonas Bushart
8de7e6de94 Remove duplicate bin/ 2022-12-05 21:00:24 +00:00
Jonas Bushart
a1194263c1 Fix the path for cache action 2022-12-05 20:06:33 +00:00
Jonas Bushart
88907a355a Merge pull request #14 from actions-rust-lang/pre-commit-ci-update-config 2022-12-05 19:45:55 +01:00
pre-commit-ci[bot]
568294585d [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/asottile/pyupgrade: v3.2.2 → v3.3.0](https://github.com/asottile/pyupgrade/compare/v3.2.2...v3.3.0)
2022-12-05 18:31:12 +00:00
Jonas Bushart
ec48ef0b45 Merge pull request #13 from actions-rust-lang/pre-commit-ci-update-config 2022-11-28 21:14:03 +01:00
pre-commit-ci[bot]
b8f4057e9c [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/pre-commit/pre-commit-hooks: v4.3.0 → v4.4.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.3.0...v4.4.0)
2022-11-28 19:00:41 +00:00
Jonas Bushart
92881e10cb Merge pull request #12 from actions-rust-lang/pre-commit-ci-update-config 2022-11-21 20:17:04 +01:00
pre-commit-ci[bot]
ece2fac1af [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/pre-commit/mirrors-mypy: v0.990 → v0.991](https://github.com/pre-commit/mirrors-mypy/compare/v0.990...v0.991)
2022-11-21 18:16:37 +00:00
Jonas Bushart
16d3c44a77 Merge pull request #11 from actions-rust-lang/pre-commit-ci-update-config 2022-11-14 19:34:37 +01:00
pre-commit-ci[bot]
3164ded2e4 [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/asottile/pyupgrade: v3.2.0 → v3.2.2](https://github.com/asottile/pyupgrade/compare/v3.2.0...v3.2.2)
- [github.com/pre-commit/mirrors-mypy: v0.982 → v0.990](https://github.com/pre-commit/mirrors-mypy/compare/v0.982...v0.990)
2022-11-14 18:23:14 +00:00
Jonas Bushart
34b262c4ff Bump cargo-audit to 0.17.4 2022-11-09 18:14:33 +01:00
Jonas Bushart
585ac71b19 Merge pull request #10 from actions-rust-lang/pre-commit-ci-update-config 2022-10-31 21:51:12 +01:00
pre-commit-ci[bot]
ef659d2397 [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/asottile/pyupgrade: v3.1.0 → v3.2.0](https://github.com/asottile/pyupgrade/compare/v3.1.0...v3.2.0)
2022-10-31 18:25:48 +00:00
Jonas Bushart
919e90c805 Merge pull request #9 from actions-rust-lang/pre-commit-ci-update-config 2022-10-17 21:07:45 +02:00
pre-commit-ci[bot]
a7fc2f648c [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/asottile/pyupgrade: v3.0.0 → v3.1.0](https://github.com/asottile/pyupgrade/compare/v3.0.0...v3.1.0)
2022-10-17 18:17:22 +00:00
Jonas Bushart
5172a3ea85 Switch from set-output to $GITHUB_OUTPUT
https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
2022-10-13 20:57:51 +02:00
Jonas Bushart
330429446f Merge pull request #8 from actions-rust-lang/pre-commit-ci-update-config 2022-10-10 21:18:28 +02:00
pre-commit-ci[bot]
c2cbc39d10 [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/psf/black: 22.8.0 → 22.10.0](https://github.com/psf/black/compare/22.8.0...22.10.0)
- [github.com/asottile/pyupgrade: v2.38.2 → v3.0.0](https://github.com/asottile/pyupgrade/compare/v2.38.2...v3.0.0)
- [github.com/pre-commit/mirrors-mypy: v0.981 → v0.982](https://github.com/pre-commit/mirrors-mypy/compare/v0.981...v0.982)
2022-10-10 18:32:56 +00:00
Jonas Bushart
74931db5cd Merge pull request #7 from actions-rust-lang/pre-commit-ci-update-config 2022-10-03 20:28:23 +02:00
pre-commit-ci[bot]
5d7f19dca3 [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/pre-commit/mirrors-mypy: v0.971 → v0.981](https://github.com/pre-commit/mirrors-mypy/compare/v0.971...v0.981)
2022-10-03 18:06:24 +00:00
Jonas Bushart
5145399af2 Merge pull request #6 from actions-rust-lang/pre-commit-ci-update-config 2022-09-26 20:26:57 +02:00
pre-commit-ci[bot]
bef751aae3 [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/asottile/pyupgrade: v2.38.0 → v2.38.2](https://github.com/asottile/pyupgrade/compare/v2.38.0...v2.38.2)
2022-09-26 18:15:28 +00:00
Jonas Bushart
f62ab55884 Merge pull request #5 from actions-rust-lang/pre-commit-ci-update-config
[pre-commit.ci] pre-commit autoupdate
2022-09-19 21:56:36 +02:00
pre-commit-ci[bot]
71ed029bec [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/asottile/pyupgrade: v2.37.3 → v2.38.0](https://github.com/asottile/pyupgrade/compare/v2.37.3...v2.38.0)
2022-09-19 18:17:15 +00:00
Jonas Bushart
90988942a7 Merge pull request #4 from actions-rust-lang/pre-commit-ci-update-config
[pre-commit.ci] pre-commit autoupdate
2022-09-06 12:49:18 +02:00
pre-commit-ci[bot]
ac36165976 [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/psf/black: 22.6.0 → 22.8.0](https://github.com/psf/black/compare/22.6.0...22.8.0)
2022-09-05 18:14:32 +00:00
Jonas Bushart
59b495571e Better example workflow
Include more trigger condition in the example workflow.
2022-08-15 15:50:35 +02:00
Jonas Bushart
64aafa27ea Prevent GitHub from autolinking usernames 2022-08-14 16:29:35 +00:00
Jonas Bushart
b49c8648ab Update Action name and description 2022-08-14 16:22:39 +00:00
Jonas Bushart
2f313e5d05 Better explain informational_warnings and how cargo audit handles them
Setting denyWarnings will pass that flag to cargo audit.

Closes #3
2022-08-14 16:21:03 +00:00
Jonas Bushart
037e5da0c0 Present aliases to the Rustsec IDs
The overview table will now show aliases and related advisories.

Closes #1
2022-08-14 16:14:05 +00:00
Jonas Bushart
bc29d560db Slight description tweak 2022-08-09 23:13:11 +02:00
6 changed files with 265 additions and 56 deletions

View File

@@ -19,7 +19,7 @@ jobs:
- name: Get version from tag
id: tag_name
run: |
echo ::set-output name=current_version::${GITHUB_REF#refs/tags/}
echo "current_version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
shell: bash
- name: Create and push tags
run: |

View File

@@ -1,10 +1,10 @@
repos:
- repo: https://github.com/psf/black
rev: 22.6.0
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-ast
- id: check-case-conflict
@@ -14,19 +14,25 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
# https://github.com/psf/black/blob/main/docs/guides/using_black_with_other_tools.md
hooks:
- id: isort
args: ["--profile=black"]
- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
rev: v3.4.0
hooks:
- id: pyupgrade
args: ["--py37-plus"]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
rev: v1.2.0
hooks:
- id: mypy
additional_dependencies:
- types-requests
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.23.0
hooks:
- id: check-dependabot
- id: check-github-actions
- id: check-github-workflows

View File

@@ -7,9 +7,61 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [1.1.7] - 2023-05-12
* Update `cargo-audit` to 0.17.6
## [1.1.6] - 2023-03-24
* Update `cargo-audit` to 0.17.5
## [1.1.5] - 2022-12-22
* Fix duplicate issues for yanked crates.
The previous version introduced a bug where existing issues were not properly detected.
This only affected issues for yanked crates.
Now duplicate issues will no longer be created.
## [1.1.4] - 2022-12-22
* Handle warnings without any associated advisory.
This occurs for yanked crates, where the `advisory` field is `null` in the JSON output.
Now a message is shown that the crate and version is yanked.
## [1.1.3] - 2022-12-05
* Fix the path to the cargo installation directory to fix caching.
## [1.1.2] - 2022-11-09
### Changed
* Update `cargo-audit` to 0.17.4 which fixes checking for yanked crates.
## [1.1.1] - 2022-10-13
### Changed
* Switch from set-output to $GITHUB_OUTPUT to avoid warning
https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
## [1.1.0] - 2022-08-14
### Added
* Present aliases for the RustSec ID and related advisories in the overview table (#1).
### Changed
* Setting `denyWarnings` will now pass `--deny warnings` to cargo audit.
## [1.0.1] - 2022-08-09
Create proper release tags.
### Added
* Create proper release tags.
## [1.0.0] - 2022-08-09

View File

@@ -13,10 +13,18 @@ name: "Audit Dependencies"
on:
push:
paths:
# Run if workflow changes
- '.github/workflows/audit.yml'
# Run on changed dependencies
- '**/Cargo.toml'
- '**/Cargo.lock'
# Run if the configuration file changes
- '**/audit.toml'
# Rerun periodicly to pick up new advisories
schedule:
- cron: '0 0 * * *'
# Run manually
workflow_dispatch:
permissions: read-all
@@ -38,6 +46,9 @@ jobs:
All inputs are optional.
Consider adding a [`audit.toml` configuration file] to your repository for further configurations.
cargo audit supports multiple warning types, such as unsound code or yanked crates.
Configuration is only possible via the `informational_warnings` parameter in the configuration file ([#318](https://github.com/rustsec/rustsec/issues/318)).
Setting `denyWarnings` to true will also enable these warnings, but each warning is upgraded to an error.
| Name | Description | Default |
| -------------- | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------ |

View File

@@ -1,6 +1,6 @@
name: Audit Rust Dependencies
name: cargo audit your Rust Dependencies
description: |
Audit Rust dependencies for vulnerabilities or outdated dependencies.
Audit Rust dependencies with cargo audit and the RustSec Advisory DB
branding:
icon: "shield"
color: "red"
@@ -26,19 +26,23 @@ inputs:
runs:
using: composite
steps:
- name: Identify cargo installation directory
run: echo "cargohome=${CARGO_HOME:-$HOME/.cargo}" >> $GITHUB_OUTPUT
shell: bash
id: cargo-home
- uses: actions/cache@v3
id: cache
with:
path: |
${{ env.CARGO_HOME }}/.cargo/bin/cargo-audit*
${{ env.CARGO_HOME }}/.cargo/.crates.toml
${{ env.CARGO_HOME }}/.cargo/.crates2.json
key: cargo-audit-v0.17.0
${{ steps.cargo-home.outputs.cargohome }}/bin/cargo-audit*
${{ steps.cargo-home.outputs.cargohome }}/.crates.toml
${{ steps.cargo-home.outputs.cargohome }}/.crates2.json
key: cargo-audit-v0.17.6
- name: Install cargo-audit
if: steps.cache.outputs.cache-hit != 'true'
# Update both this version number and the cache key
run: cargo install cargo-audit --vers 0.17.0
run: cargo install cargo-audit --vers 0.17.6 --no-default-features
shell: bash
- run: |

220
audit.py
View File

@@ -11,6 +11,15 @@ import requests
# https://github.com/alstr/todo-to-issue-action/blob/25c80e9c4999d107bec208af49974d329da26370/main.py
# Originally licensed under MIT license
# Timeout in seconds for requests methods
TIMEOUT = 30
def debug(message: str) -> None:
"""Print a debug message to the GitHub Action log"""
newline = "\n"
print(f"""::debug::{message.replace(newline, " ")}""")
class Issue:
"""Basic Issue model for collecting the necessary info to send to GitHub."""
@@ -21,7 +30,7 @@ class Issue:
labels: List[str],
assignees: List[str],
body: str,
rustsec_id: str,
rustsec_id: str, # Should be the start of the title
) -> None:
self.title = title
self.labels = labels
@@ -59,58 +68,160 @@ class Entry:
self.entry_type = entry_type
self.warning_type = warning_type
def _entry_table(self) -> str:
advisory = self.entry["advisory"]
def id(self) -> str:
"""
Return the ID of the entry.
"""
if self.warning_type is None:
warning = ""
# IMPORTANT: Coordinate this value with the `_get_existing_issues` method below.
# Any value returned here must also be present in the filtering there, since the id will be used in the issue title.
advisory = self.entry.get("advisory", None)
if advisory:
return advisory["id"]
else:
warning = f"\n| Warning | {self.warning_type} |"
unaffected = " OR ".join(self.entry["versions"]["unaffected"])
if unaffected != "":
unaffected = f"\n| Unaffected Versions | `{unaffected}` |"
patched = " OR ".join(self.entry["versions"]["patched"])
if patched == "":
patched = "n/a"
return f"Crate {self.entry['package']['name']} {self.entry['package']['version']}"
def _entry_table(self) -> str:
advisory = self.entry.get("advisory", None)
if advisory:
table = []
table.append(("Details", ""))
table.append(("---", "---"))
table.append(("Package", f"`{advisory['package']}`"))
table.append(("Version", f"`{self.entry['package']['version']}`"))
if self.warning_type is not None:
table.append(("Warning", str(self.warning_type)))
table.append(("URL", advisory["url"]))
table.append(
(
"Patched Versions",
" OR ".join(self.entry["versions"]["patched"])
if len(self.entry["versions"]["patched"]) > 0
else "n/a",
)
)
if len(self.entry["versions"]["unaffected"]) > 0:
table.append(
(
"Unaffected Versions",
" OR ".join(self.entry["versions"]["unaffected"]),
)
)
if len(advisory["aliases"]) > 0:
table.append(
(
"Aliases",
", ".join(
Entry._md_autolink_advisory_id(advisory_id)
for advisory_id in advisory["aliases"]
),
)
)
if len(advisory["related"]) > 0:
table.append(
(
"Related Advisories",
", ".join(
Entry._md_autolink_advisory_id(advisory_id)
for advisory_id in advisory["related"]
),
)
)
table_parts = []
for row in table:
table_parts.append("| ")
table_parts.append(row[0])
table_parts.append(" | ")
table_parts.append(row[1])
table_parts.append(" |\n")
return "".join(table_parts)
else:
patched = f"`{patched}`"
table = f"""| Details | |
| --- | --- |
| Package | `{advisory['package']}` |
| Version | `{self.entry['package']['version']}` |{warning}
| URL | <{advisory['url']}> |
| Patched Versions | {patched} |{unaffected}
# There is no advisory.
# This occurs when a yanked version is detected.
name = self.entry["package"]["name"]
return f"""{self.id()} is yanked.
Switch to a different version of `{name}` to resolve this issue.
"""
return table
@classmethod
def _md_autolink_advisory_id(cls, advisory_id: str) -> str:
"""
If a supported advisory format, such as GHSA- is detected, return a markdown link.
Otherwise return the ID as text.
"""
if advisory_id.startswith("GHSA-"):
return f"[{advisory_id}](https://github.com/advisories/{advisory_id})"
if advisory_id.startswith("CVE-"):
return f"[{advisory_id}](https://nvd.nist.gov/vuln/detail/{advisory_id})"
if advisory_id.startswith("RUSTSEC-"):
return f"[{advisory_id}](https://rustsec.org/advisories/{advisory_id})"
return advisory_id
def format_as_markdown(self) -> str:
advisory = self.entry["advisory"]
advisory = self.entry.get("advisory", None)
entry_table = self._entry_table()
md = f"""## {self.entry_type.icon()} {advisory['id']}: {advisory['title']}
if advisory:
entry_table = self._entry_table()
# Replace the @ with a ZWJ to avoid triggering markdown autolinks
# Otherwise GitHub will interpret the @ as a mention
description = advisory["description"].replace("@", "@\u200d")
md = f"""## {self.entry_type.icon()} {advisory['id']}: {advisory['title']}
{entry_table}
{advisory['description']}
{description}
"""
return md
else:
# There is no advisory.
# This occurs when a yanked version is detected.
name = self.entry["package"]["name"]
return f"""## {self.entry_type.icon()} {self.id()} is yanked.
Switch to a different version of `{name}` to resolve this issue.
"""
return md
def format_as_issue(self, labels: List[str], assignees: List[str]) -> Issue:
advisory = self.entry["advisory"]
advisory = self.entry.get("advisory", None)
entry_table = self._entry_table()
if advisory:
entry_table = self._entry_table()
title = f"{advisory['id']}: {advisory['title']}"
body = f"""{entry_table}
title = f"{self.id()}: {advisory['title']}"
body = f"""{entry_table}
{advisory['description']}"""
return Issue(
title=title,
labels=labels,
assignees=assignees,
body=body,
rustsec_id=advisory["id"],
)
return Issue(
title=title,
labels=labels,
assignees=assignees,
body=body,
rustsec_id=self.id(),
)
else:
# There is no advisory.
# This occurs when a yanked version is detected.
name = self.entry["package"]["name"]
title = f"{self.id()} is yanked"
body = (
f"""Switch to a different version of `{name}` to resolve this issue."""
)
return Issue(
title=title,
labels=labels,
assignees=assignees,
body=body,
rustsec_id=self.id(),
)
class GitHubClient:
@@ -131,6 +242,10 @@ class GitHubClient:
# Retrieve the existing repo issues now so we can easily check them later.
self._get_existing_issues()
debug("Existing issues:")
for issue in self.existing_issues:
debug(f"* {issue['title']}")
def _get_existing_issues(self, page: int = 1) -> None:
"""Populate the existing issues list."""
params: Dict[str, Union[str, int]] = {
@@ -138,16 +253,17 @@ class GitHubClient:
"page": page,
"state": "open",
}
debug(f"Fetching existing issues from GitHub: {page=}")
list_issues_request = requests.get(
self.issues_url, headers=self.issue_headers, params=params
self.issues_url, headers=self.issue_headers, params=params, timeout=TIMEOUT
)
print(f"DBG: {list_issues_request.status_code=}")
if list_issues_request.status_code == 200:
self.existing_issues.extend(
[
issue
for issue in list_issues_request.json()
if issue["title"].startswith("RUSTSEC-")
or issue["title"].startswith("Crate ")
]
)
links = list_issues_request.links
@@ -157,6 +273,7 @@ class GitHubClient:
def create_issue(self, issue: Issue) -> Optional[int]:
"""Create a dict containing the issue details and send it to GitHub."""
title = issue.title
debug(f"Creating issue: {title=}")
# Check if the current issue already exists - if so, skip it.
# The below is a simple and imperfect check based on the issue title.
@@ -175,9 +292,14 @@ class GitHubClient:
existing_issue["url"],
headers=self.issue_headers,
data=json.dumps(body),
timeout=TIMEOUT,
)
return update_request.status_code
debug(
f"""No existing issue found for "{issue.rustsec_id}". Creating new issue."""
)
new_issue_body = {"title": title, "body": issue.body, "labels": issue.labels}
# We need to check if any assignees/milestone specified exist, otherwise issue creation will fail.
@@ -185,7 +307,9 @@ class GitHubClient:
for assignee in issue.assignees:
assignee_url = f"{self.repos_url}{self.repo}/assignees/{assignee}"
assignee_request = requests.get(
url=assignee_url, headers=self.issue_headers
url=assignee_url,
headers=self.issue_headers,
timeout=TIMEOUT,
)
if assignee_request.status_code == 204:
valid_assignees.append(assignee)
@@ -197,6 +321,7 @@ class GitHubClient:
url=self.issues_url,
headers=self.issue_headers,
data=json.dumps(new_issue_body),
timeout=TIMEOUT,
)
return new_issue_request.status_code
@@ -204,7 +329,10 @@ class GitHubClient:
def close_issue(self, issue: Dict[str, Any]) -> int:
body = {"state": "closed"}
close_request = requests.patch(
issue["url"], headers=self.issue_headers, data=json.dumps(body)
issue["url"],
headers=self.issue_headers,
data=json.dumps(body),
timeout=TIMEOUT,
)
return close_request.status_code
@@ -261,12 +389,20 @@ def run() -> None:
ignore_args.append("--ignore")
ignore_args.append(ign)
extra_args = []
if os.environ["INPUT_DENY_WARNINGS"] == "true":
extra_args.append("--deny")
extra_args.append("warnings")
audit_cmd = ["cargo", "audit", "--json"] + extra_args + ignore_args
debug(f"Running command: {audit_cmd}")
completed = subprocess.run(
["cargo", "audit", "--json"] + ignore_args,
audit_cmd,
capture_output=True,
text=True,
check=False,
)
debug(f"Command output: {completed.stdout}")
data = json.loads(completed.stdout)
summary = create_summary(data)
@@ -300,7 +436,7 @@ def run() -> None:
num_existing_issues = len(gh_client.existing_issues)
for entry in entries:
for ex_issue in gh_client.existing_issues:
if ex_issue["title"].startswith(entry.entry["advisory"]["id"]):
if ex_issue["title"].startswith(entry.id()):
gh_client.existing_issues.remove(ex_issue)
num_old_issues = len(gh_client.existing_issues)
print(