Skip to content

Migrate generic and AI-detected secret scanning alerts (fixes #1595) - #1613

Open
SAIKARTHIKGOTURI wants to merge 2 commits into
github:mainfrom
SAIKARTHIKGOTURI:saikarthikgoturi-migrate-generic-secret-alerts
Open

SAIKARTHIKGOTURI wants to merge 2 commits into
github:mainfrom
SAIKARTHIKGOTURI:saikarthikgoturi-migrate-generic-secret-alerts

Conversation

@SAIKARTHIKGOTURI

@SAIKARTHIKGOTURI SAIKARTHIKGOTURI commented Sep 17, 2026

Copy link
Copy Markdown

What

migrate-secret-alerts only migrated default (provider) + custom secret scanning alerts. Generic patterns (e.g. rsa_private_key, connection strings) and the AI-detected password pattern were silently skipped, so those alerts stayed open on the target even when resolved on the source.

Why

GET /repos/{org}/{repo}/secret-scanning/alerts returns only default/custom patterns unless non-default secret types are requested explicitly via secret_type. exclude_secret_types does not surface them either, so the non-default types must be enumerated.

How

  • Added a documented NonDefaultSecretTypes list (10 generic slugs + password) with doc links and a "last verified" date.
  • GetSecretScanningAlertsForRepository now makes a second call with &secret_type=<joined list> and merges results with a DistinctBy(Number) safety net.
  • Graceful degradation on older GitHub Enterprise Server targets: some of these secret types are version-gated on GHES, and requesting an unsupported slug makes the list API return an HTTP 422 "Validation Failed" (unsupported) for the whole request rather than omitting that slug. Only the non-default call is wrapped: on that specific 422 it logs a warning and continues migrating the default/custom alerts. The default/custom call always runs first and its result is never lost, and all other failures (auth, 5xx, unrelated 422s, network) still propagate.
  • Added unit tests covering generic + AI-detected alerts, deduplication of an alert present in both responses, the 422 graceful-degradation path (default alerts preserved, warning logged), and propagation of non-422 errors. Updated existing tests.

Supersedes #1596 (adds the missing AI-detected password type, the 422 compatibility handling, tests, dedup guard, and docs).

Testing

  • dotnet build src/OctoshiftCLI.sln — succeeds.
  • dotnet test --filter FullyQualifiedName~SecretScanning — 38/38 pass.

Fixes #1595


  • Did you write/update appropriate tests
  • Release notes updated (if appropriate)
  • Appropriate logging output
  • Issue linked
  • Docs updated (or issue created) — no docs change needed; behavior of migrate-secret-alerts is unchanged from the user's perspective (it now simply migrates more of the existing alert types)
  • New package licenses are added to ThirdPartyNotices.txt (if applicable) — N/A, no new dependencies

Fixes github#1595. The secret-scanning list-alerts endpoint returns only
default (provider) and custom pattern alerts unless non-default secret
types are requested explicitly. GetSecretScanningAlertsForRepository now
performs a second call filtered by the generic and AI-detected secret
type slugs and merges the results (de-duplicated by alert number) so
those alerts are migrated too.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 17, 2026 16:46
@github-actions

github-actions Bot commented Sep 17, 2026

Copy link
Copy Markdown

Unit Test Results

    1 files      1 suites   23s ⏱️
1 179 tests 1 179 ✅ 0 💤 0 ❌
1 180 runs  1 180 ✅ 0 💤 0 ❌

Results for commit 1a25503.

♻️ This comment has been updated with latest results.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unsupported secret types can cause migrations against older GHES versions to fail.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Extends secret-alert migration to include generic and AI-detected patterns.

Changes:

  • Fetches and deduplicates non-default alerts.
  • Adds unit coverage and release notes.
File summaries
File Description
src/OctoshiftCLI.Tests/Octoshift/Services/GithubApiTests.cs Tests non-default alert retrieval.
src/Octoshift/Services/GithubApi.cs Fetches generic and AI-detected alerts.
RELEASENOTES.md Documents the migration fix.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Octoshift/Services/GithubApi.cs Outdated
Comment thread src/OctoshiftCLI.Tests/Octoshift/Services/GithubApiTests.cs
Address Copilot review feedback on PR github#1613:

- GetSecretScanningAlertsForRepository now wraps only the non-default
  (secret_type-filtered) call and degrades gracefully on the HTTP 422
  'Validation Failed' (unsupported) response older GHES targets return
  when a requested generic/AI-detected secret type is not available. The
  default/custom call still runs first and its result always survives;
  all other failures continue to propagate. A warning is logged via an
  optional OctoLogger now passed through GithubApiFactory.
- Corrected the comments that wrongly claimed unsupported slugs return no
  rows (they cause a 422, handled above).
- Reworked the merge test so the same alert number appears in both
  responses, proving DistinctBy(Number) actually dedups.
- Added tests for the 422 graceful-degradation path (default alerts kept,
  warning logged) and for a non-422 error still propagating.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Code Coverage

Package Line Rate Branch Rate Complexity Health
ado2gh 71% 70% 749
Octoshift 81% 70% 2047
gei 81% 74% 688
gl2gh 77% 70% 417
bbs2gh 83% 78% 668
Summary 79% (9056 / 11447) 72% (2317 / 3219) 4569

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The compatibility path can suppress unrelated validation errors and repeatedly retries an expected non-transient response.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (1)

src/Octoshift/Services/GithubApi.cs:1051

  • This method queries both source and target repositories (SecretScanningAlertService.cs:31-32), so an older source can also reach this handler. Calling it “the target” then misidentifies which side skipped alerts; use role-neutral wording unless the caller supplies the repository role.
            _log?.LogWarning(
                "The target does not support one or more of the generic or AI-detected secret scanning types, " +
                "so alerts of those types will not be migrated. This is expected on older GitHub Enterprise Server " +
                "versions where some of these secret types are not available.");
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Balanced

{
nonDefaultAlerts = await _client.GetAllAsync(nonDefaultUrl).ToListAsync();
}
catch (HttpRequestException ex) when (ex.StatusCode == HttpStatusCode.UnprocessableEntity && ex.Message.Contains("secret_type"))
var nonDefaultAlerts = new List<JToken>();
try
{
nonDefaultAlerts = await _client.GetAllAsync(nonDefaultUrl).ToListAsync();
@SAIKARTHIKGOTURI

Copy link
Copy Markdown
Author

@brianaj, can you please look into this ? this problem is being faced by many users and fix to this will be really helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

migrate-secret-alerts does not take into account secrets of the generic kind

2 participants