8000 Migrate GitHub importer to aboutcode pipeline by keshav-space · Pull Request #1584 · aboutcode-org/vulnerablecode · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Migrate GitHub importer to aboutcode pipeline #1584

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

Merged
merged 4 commits into from
Sep 27, 2024
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
4 changes: 2 additions & 2 deletions vulnerabilities/importers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from vulnerabilities.importers import epss
from vulnerabilities.importers import fireeye
from vulnerabilities.importers import gentoo
from vulnerabilities.importers import github
from vulnerabilities.importers import github_osv
from vulnerabilities.importers import istio
from vulnerabilities.importers import mozilla
Expand All @@ -38,14 +37,14 @@
from vulnerabilities.importers import vulnrichment
from vulnerabilities.importers import xen
from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipeline
from vulnerabilities.pipelines import github_importer
from vulnerabilities.pipelines import gitlab_importer
from vulnerabilities.pipelines import nginx_importer
from vulnerabilities.pipelines import npm_importer
from vulnerabilities.pipelines import pypa_importer

IMPORTERS_REGISTRY = [
nvd.NVDImporter,
github.GitHubAPIImporter,
pysec.PyPIImporter,
alpine_linux.AlpineImporter,
openssl.OpensslImporter,
Expand Down Expand Up @@ -78,6 +77,7 @@
npm_importer.NpmImporterPipeline,
nginx_importer.NginxImporterPipeline,
gitlab_importer.GitLabImporterPipeline,
github_importer.GitHubAPIImporterPipeline,
]

IMPORTERS_REGISTRY = {
Expand Down
4 changes: 2 additions & 2 deletions vulnerabilities/improvers/valid_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from vulnerabilities.importers.debian import DebianImporter
from vulnerabilities.importers.debian_oval import DebianOvalImporter
from vulnerabilities.importers.elixir_security import ElixirSecurityImporter
from vulnerabilities.importers.github import GitHubAPIImporter
from vulnerabilities.importers.github_osv import GithubOSVImporter
from vulnerabilities.importers.istio import IstioImporter
from vulnerabilities.importers.oss_fuzz import OSSFuzzImporter
Expand All @@ -42,6 +41,7 @@
from vulnerabilities.improver import Inference
from vulnerabilities.models import Advisory
from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipeline
from vulnerabilities.pipelines.github_importer import GitHubAPIImporterPipeline
from vulnerabilities.pipelines.gitlab_importer import GitLabImporterPipeline
from vulnerabilities.pipelines.nginx_importer import NginxImporterPipeline
from vulnerabilities.pipelines.npm_importer import NpmImporterPipeline
Expand Down Expand Up @@ -371,7 +371,7 @@ class GitLabBasicImprover(ValidVersionImprover):


class GitHubBasicImprover(ValidVersionImprover):
importer = GitHubAPIImporter
importer = GitHubAPIImporterPipeline
ignorable_versions = frozenset(
[
"0.1-bulbasaur",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 4.2.15 on 2024-09-27 14:31

from django.db import migrations

"""
Update the created_by field on Advisory from the old qualified_name
to the new pipeline_id.
"""


def update_created_by(apps, schema_editor):
from vulnerabilities.pipelines.github_importer import GitHubAPIImporterPipeline

Advisory = apps.get_model("vulnerabilities", "Advisory")
Advisory.objects.filter(created_by="vulnerabilities.importers.github.GitHubAPIImporter").update(
created_by=GitHubAPIImporterPipeline.pipeline_id
)



def reverse_update_created_by(apps, schema_editor):
from vulnerabilities.pipelines.github_importer import GitHubAPIImporterPipeline

Advisory = apps.get_model("vulnerabilities", "Advisory")
Advisory.objects.filter(created_by=GitHubAPIImporterPipeline.pipeline_id).update(
created_by="vulnerabilities.importers.github.GitHubAPIImporter"
)


class Migration(migrations.Migration):

dependencies = [
("vulnerabilities", "0066_update_gitlab_advisory_created_by"),
]

operations = [
migrations.RunPython(update_created_by, reverse_code=reverse_update_created_by),
]
7 changes: 6 additions & 1 deletion vulnerabilities/pipelines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ def advisories_count(self) -> int:

def collect_and_store_advisories(self):
collected_advisory_count = 0
progress = LoopProgress(total_iterations=self.advisories_count(), logger=self.log)
estimated_advisory_count = self.advisories_count()

if estimated_advisory_count > 0:
self.log(f"Collecting {estimated_advisory_count:,d} advisories")

progress = LoopProgress(total_iterations=estimated_advisory_count, logger=self.log)
for advisory in progress.iter(self.collect_advisories()):
if _obj := insert_advisory(
advisory=advisory,
Expand Down
Loading
Loading
0