gh-gei icon indicating copy to clipboard operation
gh-gei copied to clipboard

Add Dependabot Alert Dismissal migration support to GEI

Open Copilot opened this issue 6 months ago β€’ 4 comments

This PR adds support for migrating Dependabot alert dismissals in the GitHub Enterprise Importer (GEI), addressing the need to preserve dismissed Dependabot alerts and their dismissal reasons when migrating repositories.

New Features

CLI Command

  • gh gei migrate-dependabot-alerts - New command to migrate Dependabot alert states and dismissal information
  • Supports all standard GEI options: source/target org/repo, API URLs, PATs, dry-run mode, verbose logging
  • Follows the same pattern as existing migrate-code-scanning-alerts and migrate-secret-alerts commands

Alert Matching Strategy

The implementation uses a robust two-tier matching approach:

  1. Primary: Match by GHSA ID + package name + manifest path
  2. Fallback: Match by CVE ID + package name + manifest path

This ensures reliable alert matching even when security advisory IDs differ between source and target instances.

Supported Dismissal Reasons

Preserves all standard Dependabot dismissal reasons:

  • false_positive - Alert is not actually vulnerable
  • inaccurate - Alert is not accurate
  • not_used - Vulnerable code is not used
  • no_bandwidth - No time to fix right now
  • tolerable_risk - Risk is acceptable

State Migration

  • Migrates open and dismissed states (skips fixed as it's automatically managed)
  • Preserves dismissal comments and timestamps
  • Comprehensive error handling and logging
  • Dry-run mode for testing without making changes

Implementation Details

Core Components

  • Models: DependabotAlert, DependabotAlertDependency, DependabotAlertSecurityAdvisory, DependabotAlertSecurityVulnerability
  • State Management: DependabotAlertState with validation for states and dismissal reasons
  • Service: DependabotAlertService handles the migration logic
  • API Integration: GitHub API methods for retrieving and updating Dependabot alerts
  • Factory: DependabotAlertServiceFactory for dependency injection

Error Handling

  • Validates alert states and dismissal reasons
  • Throws exception if alerts cannot be matched (prevents partial migrations)
  • Comprehensive logging of success, skipped, and failed operations
  • Graceful handling of non-migratable alert states

Testing

Added 15 comprehensive tests covering:

  • DependabotAlertService: 8 tests for core migration logic
  • GitHub API integration: 6 tests for API methods and data parsing
  • Command interface: 3 tests for CLI argument handling

All existing tests continue to pass (903 total tests).

Example Usage

# Migrate Dependabot alerts with dry-run
gh gei migrate-dependabot-alerts \
  --source-org myorg \
  --source-repo myrepo \
  --target-org neworg \
  --target-repo newrepo \
  --dry-run

# Migrate between GitHub instances
gh gei migrate-dependabot-alerts \
  --source-org myorg \
  --source-repo myrepo \
  --target-org neworg \
  --target-repo newrepo \
  --ghes-api-url https://github.mycompany.com/api/v3 \
  --github-source-pat $SOURCE_PAT \
  --github-target-pat $TARGET_PAT

This resolves the issue for organizations with large numbers of dismissed Dependabot alerts who need to preserve their security review decisions during repository migrations.

Fixes #1286.

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.github.com
    • Triggering command: /home/REDACTED/work/gh-gei/gh-gei/src/gei/bin/Debug/net8.0/gei migrate-dependabot-alerts --dry-run --source-org test-org --source-repo test-repo --target-org test-org --target-repo test-repo --github-source-pat dummy --github-target-pat dummy (dns block)
  • http://www.microsoft.com:80/pkiops/crl/Microsoft%20Identity%20Verification%20Root%20Certificate%20Authority%202020.crl
    • Triggering command: dotnet build src/OctoshiftCLI.sln (http block)
  • http://www.microsoft.com:80/pkiops/crl/Microsoft%20Public%20RSA%20Timestamping%20CA%202020.crl
    • Triggering command: dotnet build src/OctoshiftCLI.sln (http block)
  • www.githubstatus.com
    • Triggering command: /home/REDACTED/work/gh-gei/gh-gei/src/gei/bin/Debug/net8.0/gei --help (dns block)
    • Triggering command: /home/REDACTED/work/gh-gei/gh-gei/src/gei/bin/Debug/net8.0/gei migrate-dependabot-alerts --help (dns block)
    • Triggering command: /home/REDACTED/work/gh-gei/gh-gei/src/gei/bin/Debug/net8.0/gei migrate-dependabot-alerts --dry-run --source-org test-org --source-repo test-repo --target-org test-org --target-repo test-repo --github-source-pat dummy --github-target-pat dummy (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


πŸ’‘ You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Jun 07 '25 04:06 Copilot

Unit Test Results

  1 files    1 suites   21s ⏱️ 914 tests 914 βœ…β€ƒ0 πŸ’€β€ƒ0 ❌ 915 runsβ€Šβ€ƒ915 βœ…β€ƒ0 πŸ’€β€ƒ0 ❌

Results for commit 0d858757.

:recycle: This comment has been updated with latest results.

github-actions[bot] avatar Jun 11 '25 02:06 github-actions[bot]

dotnet format is returning a number of errors/warnings which need to be fixed up to pass the build

dylan-smith avatar Jun 11 '25 06:06 dylan-smith

dotnet format is returning a number of errors/warnings which need to be fixed up to pass the build

Fixed the formatting issues. The problem was missing final newlines in the newly added Dependabot Alert files - applied dotnet format to add the required newlines and fix other formatting issues. Commit 3d315b1.

Copilot avatar Jun 11 '25 06:06 Copilot

Code Coverage

Package Line Rate Branch Rate Complexity Health
Octoshift 88% 76% 1550 βœ”
bbs2gh 82% 76% 669 βœ”
gei 80% 70% 646 βœ”
ado2gh 84% 78% 618 βœ”
Summary 85% (7510 / 8885) 75% (1781 / 2368) 3483 βœ”

github-actions[bot] avatar Jul 08 '25 04:07 github-actions[bot]