-
-
Notifications
You must be signed in to change notification settings - Fork 237
Add GitHub OSV Live V2 Importer Pipeline #1977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
* Add GitHub OSV Live V2 Importer * Add tests for the GitHub OSV Live V2 Importer * Tested functionally using the Live Evaluation API in #1969 Signed-off-by: Michael Ehab Mikhail <[email protected]>
Signed-off-by: Michael Ehab Mikhail <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaelehab Nice work! Just a few nits for your consideration.
if resp.status_code != 200: | ||
return [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if resp.status_code != 200: | |
return [] | |
response.raise_for_status() |
date_str = adv.get("published") or adv.get("modified") | ||
|
||
if date_str: | ||
from datetime import datetime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep all imports at the top, unless it’s a heavy library that is only used once. In that case, a local import is acceptable.
from datetime import datetime | |
except Exception: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use specific exceptions for clarity and safety
return purl.name | ||
|
||
|
||
def fetch_github_osv_advisories_for_purl(purl: PackageURL): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple and concise
def fetch_github_osv_advisories_for_purl(purl: PackageURL): | |
def fetch_osv_advisories(purl: PackageURL): |
pkg = {"ecosystem": ecosystem, "name": _osv_package_name(purl)} | ||
# Query by package to get all advisories for that package; we filter GHSA below. | ||
body = {"package": pkg} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkg = {"ecosystem": ecosystem, "name": _osv_package_name(purl)} | |
# Query by package to get all advisories for that package; we filter GHSA below. | |
body = {"package": pkg} | |
body = {"package": {"ecosystem": ecosystem, "name": _osv_package_name(purl)}} |
|
||
for adv in self.advisories: | ||
adv_id = adv.get("id") | ||
advisory_url = build_github_repo_advisory_url(adv, adv_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use consistent naming: choose either full names or abbreviations, but stay consistent
advisory_url = build_github_repo_advisory_url(adv, adv_id) | |
adv_url = build_github_repo_advisory_url(adv, adv_id) |
} | ||
|
||
|
||
def build_github_repo_advisory_url(adv: dict, adv_id: Optional[str]) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some unit tests for the function build_github_repo_advisory_url
.
from datetime import datetime | ||
|
||
try: | ||
dt = datetime.fromisoformat(date_str.replace("Z", "+00:00")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try using dateparser
? I think it can simplify the logic there.
Add GitHub OSV Live V2 Importer
Add tests for the GitHub OSV Live V2 Importer
Tested functionally using the Live Evaluation API in Add Live Evaluation API endpoint and PyPa live pipeline importer #1969