-
Notifications
You must be signed in to change notification settings - Fork 92
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
Secret Scanning Alerts migration - update to new location types #1306
base: main
Are you sure you want to change the base?
Secret Scanning Alerts migration - update to new location types #1306
Conversation
Unit Test Results856 tests 856 ✅ 20s ⏱️ Results for commit 5b07255. ♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I am not super familiar with secret scanning, the code changes looks good my main concern is there is a bit of a logic changes do we have enough unit test coverage?
@@ -1 +1 @@ | |||
|
|||
- Updated Secret Scanning Alerts migration command to match on all location types. Now includes: issues, pull requests, issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Updated Secret Scanning Alerts migration command to match on all location types. Now includes: issues, pull requests, issues. | |
- Updated Secret Scanning Alerts migration (`gh gei migrate-secret-alerts`) command to match on all location types. Now includes: issues, pull requests, issues. |
//"discussion_title" => sourceLocation.DiscussionTitleUrl == targetLocation.DiscussionTitleUrl, | ||
//"discussion_body" => sourceLocation.DiscussionBodyUrl == targetLocation.DiscussionBodyUrl, | ||
//"discussion_comment" => sourceLocation.DiscussionCommentUrl == targetLocation.DiscussionCommentUrl, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the commented code
//"discussion_title" => sourceLocation.DiscussionTitleUrl == targetLocation.DiscussionTitleUrl, | |
//"discussion_body" => sourceLocation.DiscussionBodyUrl == targetLocation.DiscussionBodyUrl, | |
//"discussion_comment" => sourceLocation.DiscussionCommentUrl == targetLocation.DiscussionCommentUrl, |
// and value List of AlertWithLocations | ||
// This method is used to get alerts from both source and target repositories | ||
private async Task<Dictionary<(string SecretType, string Secret), List<AlertWithLocations>>> | ||
GetAlertsWithLocationsDict(GithubApi api, string org, string repo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: not a biggie but generally speaking adding a returned type suffix is discouraged in method and variable names so I would still use the previous name.
foreach (var sourceKey in sourceAlertsDict.Keys) | ||
{ | ||
_log.LogInformation($"Processing source secret {alert.Alert.Number}"); | ||
|
||
if (SecretScanningAlert.IsOpen(alert.Alert.State)) | ||
foreach (var sourceAlert in sourceAlertsDict[sourceKey]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: These two foreach
statements can be combined into one:
foreach (var kvp in sourceAlertsDict)
{
// if you wish to use the variable names, I wish C# supported deconstruction syntax in foreach loops!
var sourceKey = kvp.Key;
var sourceAlert = kvp.Value;
}
PR implements #1305
ThirdPartyNotices.txt
(if applicable)Summary of code changes
src/Octoshift/Models/GithubSecretScanningAlert.cs
GithubSecretScanningAlert
to include resolution commentGithubSecretScanningAlertLocation
to include types of location and related infosrc/Octoshift/Services/GithubApi.cs
to work with new model definitionresolution_comment
when updating alertsrc/Octoshift/Services/SecretScanningAlertService.cs
in regards to matching the locations of alerts criteria to include the new location types; and the algorithm for matching alerts between source and target repositories.Instead of iterating thru all alerts in a list to match an alert from source and target we now use dictionary for the lookup. We use this lookup to match all locations on all alerts; The criteria for matching alerts follows the similar structure as before but included couple of guards/pre-flight checks to further speed up the matching process. Performance optimization has benefits when migrating repositories with big number of alerts.