Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "drupal-advisory-database"
requires-python = ">= 3.13"

[tool.poetry.dependencies]
colorama = "^0.4.6"
jsonschema = "^4.23.0"
markdownify = "^1.1.0"
mypy = "^1.15.0"
Expand All @@ -12,6 +13,7 @@ ruff = "~0.14.0"
semver = "^3.0.4"
types-jsonschema = "^4.23.0.20241208"
types-requests = "^2.32.0.20250328"
types-colorama = "^0.4.15.20240311"

[tool.poetry]
package-mode = false
Expand Down
17 changes: 12 additions & 5 deletions scripts/generate_osv_advisories.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import requests
import semver
from helpers import text_is
from markdownify import markdownify

from typings import drupal, osv
Expand Down Expand Up @@ -350,10 +351,13 @@ def patch_advisory(sa_id: str, sa_advisory: drupal.Advisory) -> bool:

if before == sa_advisory['field_affected_versions']:
sa_advisory['field_affected_versions'] = after
print(' \\- patched affected versions')
print(' \\- ' + text_is.success('patched affected versions'))
return True
print(
f' \\- skipped patching as affected version is now "{sa_advisory["field_affected_versions"]}"'
' \\- '
+ text_is.warning(
f'skipped patching as affected version is now "{sa_advisory["field_affected_versions"]}"'
)
)
return False

Expand All @@ -375,14 +379,14 @@ def build_osv_advisory(
# we expect that the downloader has excluded PSA type entries, but
# we still guard against them here just in case one slips through
if sa_advisory['field_is_psa'] == '1':
print(' \\- skipping as it is a psa? (this should not happen)')
print(' \\-' + text_is.error('skipping as it is a psa? (this should not happen)'))
return None

# there's not really much we can do if there isn't an affected version
# todo: since build_affected_ranges throws if this isn't present, it might
# make more sense to use that, with a custom exception class
if sa_advisory['field_affected_versions'] is None:
print(' \\- skipping as we do not have any affected versions')
print(' \\- ' + text_is.notice('skipping as we do not have any affected versions'))
return None

osv_advisory: osv.Vulnerability = {
Expand Down Expand Up @@ -461,7 +465,10 @@ def generate_osv_advisories() -> None:
os.makedirs(f'advisories/{name}', exist_ok=True)
if is_existing_advisory_ahead(name, sa_id, osv_advisory['modified']):
print(
' \\- error: current modified date is ahead of the proposed modified date (is your cache up to date?)'
' \\- '
+ text_is.error(
'error: current modified date is ahead of the proposed modified date (is your cache up to date?)'
)
)
exit(1)

Expand Down
Empty file added scripts/helpers/__init__.py
Empty file.
19 changes: 19 additions & 0 deletions scripts/helpers/text_is.py
Comment thread
Unifex marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from colorama import Fore, Style, just_fix_windows_console

just_fix_windows_console()
Comment thread
Unifex marked this conversation as resolved.


def notice(message: str) -> str:
return f'{Fore.YELLOW}{Style.DIM}{message}{Style.RESET_ALL}'


def success(message: str) -> str:
return f'{Fore.GREEN}{message}{Style.RESET_ALL}'


def warning(message: str) -> str:
return f'{Fore.YELLOW}{message}{Style.RESET_ALL}'


def error(message: str) -> str:
return f'{Fore.RED}{message}{Style.RESET_ALL}'