-
Notifications
You must be signed in to change notification settings - Fork 88
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
Add support for migrating secret scanning resolution comments #1241
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
|
||
- Add support for migrating secret scanning alert resolution comments |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2507,6 +2507,7 @@ public async Task GetSecretScanningAlertsData() | |
""resolution"": null, | ||
""resolved_by"": null, | ||
""resolved_at"": null, | ||
""resolution_comment"": null, | ||
""push_protection_bypassed"": false, | ||
""push_protection_bypassed_by"": null, | ||
""push_protection_bypassed_at"": null | ||
|
@@ -2540,6 +2541,7 @@ public async Task GetSecretScanningAlertsData() | |
""site_admin"": true | ||
}}, | ||
""resolved_at"": ""2022-04-05T20:57:03"", | ||
""resolution_comment"": null, | ||
""push_protection_bypassed"": false, | ||
""push_protection_bypassed_by"": null, | ||
""push_protection_bypassed_at"": null | ||
|
@@ -2561,6 +2563,7 @@ public async Task GetSecretScanningAlertsData() | |
""resolution"": null, | ||
""resolved_by"": null, | ||
""resolved_at"": null, | ||
""resolution_comment"": null, | ||
""push_protection_bypassed"": false, | ||
""push_protection_bypassed_by"": null, | ||
""push_protection_bypassed_at"": null | ||
|
@@ -2601,6 +2604,7 @@ public async Task GetSecretScanningAlertsData() | |
""site_admin"": true | ||
}}, | ||
""resolved_at"": ""2022-08-15T13:53:42Z"", | ||
""resolution_comment"": null, | ||
""push_protection_bypassed"": false, | ||
""push_protection_bypassed_by"": null, | ||
""push_protection_bypassed_at"": null | ||
|
@@ -2740,6 +2744,7 @@ private void AssertSecretScanningData(GithubSecretScanningAlert actual, JToken e | |
actual.State.Should().Be((string)expectedData["state"]); | ||
actual.SecretType.Should().Be((string)expectedData["secret_type"]); | ||
actual.Resolution.Should().Be((string)expectedData["resolution"]); | ||
actual.ResolutionComment.Should().Be((string)expectedData["resolution_comment"]); | ||
actual.Secret.Should().Be((string)expectedData["secret"]); | ||
} | ||
|
||
|
@@ -2750,16 +2755,18 @@ public async Task UpdateSecretScanningAlert_Calls_The_Right_Endpoint_With_Payloa | |
const int alertNumber = 100; | ||
const string alertState = "resolved"; | ||
const string alertResolution = "wont_fix"; | ||
const string alertResolutionComment = "Risk has been accepted"; | ||
|
||
var url = $"https://api.github.com/repos/{GITHUB_ORG}/{GITHUB_REPO}/secret-scanning/alerts/{alertNumber}"; | ||
var payload = new | ||
{ | ||
state = alertState, | ||
resolution = alertResolution | ||
resolution = alertResolution, | ||
resolution_comment = alertResolutionComment | ||
}; | ||
|
||
// Act | ||
await _githubApi.UpdateSecretScanningAlert(GITHUB_ORG, GITHUB_REPO, alertNumber, alertState, alertResolution); | ||
await _githubApi.UpdateSecretScanningAlert(GITHUB_ORG, GITHUB_REPO, alertNumber, alertState, alertResolution, alertResolutionComment); | ||
|
||
// Assert | ||
_githubClientMock.Verify(m => m.PatchAsync(url, It.Is<object>(x => x.ToJson() == payload.ToJson()), null)); | ||
|
@@ -2782,6 +2789,30 @@ public async Task UpdateSecretScanningAlert_Calls_The_Right_Endpoint_With_Payloa | |
_githubClientMock.Verify(m => m.PatchAsync(url, It.Is<object>(x => x.ToJson() == payload.ToJson()), null)); | ||
} | ||
|
||
|
||
[Fact] | ||
public async Task UpdateSecretScanningAlert_Replaces_Null_Resolution_Comment_With_Empty_String() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on my earlier comment we probably won't need this test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. As per previous comment, happy to do a separate pull request to align both code scanning and secret scanning, or do the changes in this one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have opened #1248 and added your suggestions there. Thanks again! |
||
{ | ||
// Arrange | ||
const int alertNumber = 100; | ||
const string alertState = "resolved"; | ||
const string alertResolution = "wont_fix"; | ||
|
||
var url = $"https://api.github.com/repos/{GITHUB_ORG}/{GITHUB_REPO}/secret-scanning/alerts/{alertNumber}"; | ||
var payload = new | ||
{ | ||
state = alertState, | ||
resolution = alertResolution, | ||
resolution_comment = string.Empty | ||
}; | ||
|
||
// Act | ||
await _githubApi.UpdateSecretScanningAlert(GITHUB_ORG, GITHUB_REPO, alertNumber, alertState, alertResolution); | ||
|
||
// Assert | ||
_githubClientMock.Verify(m => m.PatchAsync(url, It.Is<object>(x => x.ToJson() == payload.ToJson()), null)); | ||
} | ||
|
||
[Fact] | ||
public async Task GetDefaultBranch_Returns_Default_Branch_Field() | ||
{ | ||
|
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.
Why is it being set to empty string? If nothing is passed it makes sense for the default to be
null
.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.
Hello, thanks for the comments.
Added it that way to align with what is done for the dismissedComment for code scanning alerts (cf. https://github.com/github/gh-gei/blob/main/src/Octoshift/Services/GithubApi.cs#L933 )
Your suggestion makes sense though, so would you prefer me to do that in a separate pull request to align both changes, or change both it in this pull request?
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.
👋 ok got it. So I guess as you said the other one needs to be changed too. I think it's better to do that one in a separate PR.
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.
Understood. I have opened #1248 and added your suggestions there. Thanks again!