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

Fix resolution comment length bug when migrating Secret Scanning alerts

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

Problem

When migrating secret scanning alerts with gh gei migrate-secret-alerts, if the new comment format [@resolverName] originalComment exceeds 270 characters, the GitHub API call fails with an error about comment length limits.

This was introduced in PR #1337 which added the resolver name prefix to resolution comments, but didn't account for the 270 character limit.

Solution

Added length validation before using the prefixed comment format:

  • If [@resolverName] originalComment is < 270 characters: use the prefixed format (preserves existing behavior)
  • If [@resolverName] originalComment is >= 270 characters: fall back to using only the original comment

This ensures migration completes successfully while preserving the most important content when length limits are exceeded.

Changes

  • SecretScanningAlertService.cs: Added comment length check with fallback logic
  • SecretScanningAlertServiceTests.cs: Added test cases for both scenarios:
    • Update_With_Long_Comment_Uses_Original_Comment_Only - verifies fallback behavior
    • Update_With_Short_Comment_Uses_Prefixed_Comment - ensures existing behavior preserved

Example

// Before: Always used prefixed format, could fail on long comments
var targetResolutionComment = $"[@{resolverName}] {originalComment}";

// After: Length-aware with fallback
var prefixedComment = $"[@{resolverName}] {originalComment}";
var targetResolutionComment = prefixedComment.Length < 270 
    ? prefixedComment 
    : originalComment ?? string.Empty;

All existing tests pass. The fix is minimal and preserves all existing functionality while gracefully handling the edge case.

Fixes #1348.

[!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:

  • 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)

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

@dylan-smith I suggest we implement the other option. If new comment = concat original author + original comment has length > 270, trim the new content to the acceptable length (<=270). In practice these migrations are commonly provided as service and executed by a central team therefore preserving the original author (and therefore trail) gives better confidence to customers.

theztefan avatar Jun 12 '25 07:06 theztefan

The build gave this error: /Users/runner/work/gh-gei/gh-gei/src/Octoshift/Services/SecretScanningAlertService.cs(84,66): warning IDE0057: Substring can be simplified

Make sure you run dotnet format src/OctoshiftCLI.sln before every commit.

dylan-smith avatar Jun 26 '25 14:06 dylan-smith

The build gave this error: /Users/runner/work/gh-gei/gh-gei/src/Octoshift/Services/SecretScanningAlertService.cs(84,66): warning IDE0057: Substring can be simplified

...

Fixed the IDE0057 warning by running dotnet format which simplified the Substring call to use modern C# range syntax. The build now completes without warnings. Commit: 8f06e3a

Copilot avatar Jun 26 '25 14:06 Copilot

Unit Test Results

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

Results for commit 53551377.

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

github-actions[bot] avatar Jul 03 '25 15:07 github-actions[bot]

Add a bullet point to RELEASENOTES.md describing the change to our users

dylan-smith avatar Jul 07 '25 16:07 dylan-smith

Add a bullet point to RELEASENOTES.md describing the change to our users

Added a bullet point to RELEASENOTES.md describing the Secret Scanning alert comment length fix for users. Commit: cfea4ab

Copilot avatar Jul 07 '25 16:07 Copilot

Code Coverage

Package Line Rate Branch Rate Complexity Health
Octoshift 87% 76% 1439 βœ”
bbs2gh 82% 76% 669 βœ”
gei 81% 73% 596 βœ”
ado2gh 84% 78% 618 βœ”
Summary 84% (7269 / 8607) 76% (1708 / 2258) 3322 βœ”

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