MCPcopy Create free account
hub / github.com/aboutcode-org/vulnerablecode / get_patches_bulk

Function get_patches_bulk

vulnerabilities/api_v3.py:474–525  ·  view source on GitHub ↗

Get introduced and fixed patches

(package_ids, advisory_ids)

Source from the content-addressed store, hash-verified

472
473
474def get_patches_bulk(package_ids, advisory_ids):
475 """Get introduced and fixed patches"""
476
477 base_qs = ImpactedPackageAffecting.objects.filter(
478 package_id__in=package_ids,
479 impacted_package__advisory_id__in=advisory_ids,
480 impacted_package__advisory__is_latest=True,
481 impacted_package__advisory___all_impacts_unfurled_at__isnull=False,
482 )
483
484 introduced_rows = base_qs.filter(
485 impacted_package__introduced_by_package_commit_patches__isnull=False
486 ).values(
487 "package_id",
488 "impacted_package__advisory_id",
489 commit_hash=F("impacted_package__introduced_by_package_commit_patches__commit_hash"),
490 vcs_url=F("impacted_package__introduced_by_package_commit_patches__vcs_url"),
491 )
492
493 fixed_rows = base_qs.filter(
494 impacted_package__fixed_by_package_commit_patches__isnull=False
495 ).values(
496 "package_id",
497 "impacted_package__advisory_id",
498 commit_hash=F("impacted_package__fixed_by_package_commit_patches__commit_hash"),
499 vcs_url=F("impacted_package__fixed_by_package_commit_patches__vcs_url"),
500 )
501
502 introduced_patches_map = defaultdict(list)
503 fixed_patches_map = defaultdict(list)
504
505 for row in introduced_rows:
506 if row["commit_hash"] or row["vcs_url"]:
507 key = (row["package_id"], row["impacted_package__advisory_id"])
508 introduced_patches_map[key].append(
509 {
510 "commit_hash": row["commit_hash"],
511 "vcs_url": row["vcs_url"],
512 }
513 )
514
515 for row in fixed_rows:
516 if row["commit_hash"] or row["vcs_url"]:
517 key = (row["package_id"], row["impacted_package__advisory_id"])
518 fixed_patches_map[key].append(
519 {
520 "commit_hash": row["commit_hash"],
521 "vcs_url": row["vcs_url"],
522 }
523 )
524
525 return introduced_patches_map, fixed_patches_map
526
527
528def build_patch_set_map(patches_map, advisory_ids_by_set):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected