Skip to content

Commit 468d557

Browse files
authored
Merge branch 'main' into patch-1
2 parents 1b3398c + f9ee191 commit 468d557

File tree

16 files changed

+379
-33
lines changed

16 files changed

+379
-33
lines changed

LATEST-VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.14.0
1+
v1.15.1

releasenotes/v1.15.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Improve resilience of `gh gei migrate-repo` and `gh bb2gh migrate-repo` commands when uploading migration archives to GitHub owned storage.

releasenotes/v1.15.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Adjusting the release version so we can go to 1.15.1

releasenotes/v1.9.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- `gh gei migrate-secret-alerts` copies the resolver name from the original alert to the resolution comment of the matching target alert. The comment follows this format: `[@actorname] original comment`.

src/Octoshift/Models/GithubSecretScanningAlert.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class GithubSecretScanningAlert
77
public string ResolutionComment { get; set; }
88
public string SecretType { get; set; }
99
public string Secret { get; set; }
10+
public string ResolverName { get; set; }
1011
}
1112

1213
public class GithubSecretScanningAlertLocation

src/Octoshift/Services/ArchiveUploader.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ public class ArchiveUploader
1515
private readonly GithubClient _client;
1616
private readonly OctoLogger _log;
1717
internal int _streamSizeLimit = 100 * 1024 * 1024; // 100 MiB
18+
private readonly RetryPolicy _retryPolicy;
1819

1920
private const string BASE_URL = "https://uploads.github.com";
2021

21-
public ArchiveUploader(GithubClient client, OctoLogger log)
22+
public ArchiveUploader(GithubClient client, OctoLogger log, RetryPolicy retryPolicy)
2223
{
2324
_client = client;
2425
_log = log;
26+
_retryPolicy = retryPolicy;
2527
}
2628
public virtual async Task<string> Upload(Stream archiveContent, string archiveName, string orgDatabaseId)
2729
{
@@ -48,7 +50,7 @@ public virtual async Task<string> Upload(Stream archiveContent, string archiveNa
4850
{
4951
var url = $"{BASE_URL}/organizations/{orgDatabaseId.EscapeDataString()}/gei/archive?name={archiveName.EscapeDataString()}";
5052

51-
response = await _client.PostAsync(url, streamContent);
53+
response = await _retryPolicy.Retry(async () => await _client.PostAsync(url, streamContent));
5254
var data = JObject.Parse(response);
5355
return (string)data["uri"];
5456
}
@@ -101,7 +103,7 @@ private async Task<IEnumerable<KeyValuePair<string, IEnumerable<string>>>> Start
101103

102104
try
103105
{
104-
var (responseContent, headers) = await _client.PostWithFullResponseAsync(uploadUrl, body);
106+
var (_, headers) = await _retryPolicy.Retry(async () => await _client.PostWithFullResponseAsync(uploadUrl, body));
105107
return headers.ToList();
106108
}
107109
catch (Exception ex)
@@ -119,7 +121,7 @@ private async Task<Uri> UploadPart(byte[] body, int bytesRead, string nextUrl, i
119121
try
120122
{
121123
// Make the PATCH request and retrieve headers
122-
var (_, headers) = await _client.PatchWithFullResponseAsync(nextUrl, content);
124+
var (_, headers) = await _retryPolicy.Retry(async () => await _client.PatchWithFullResponseAsync(nextUrl, content));
123125

124126
// Retrieve the next URL from the response headers
125127
return GetNextUrl(headers.ToList());
@@ -134,7 +136,7 @@ private async Task CompleteUpload(string lastUrl)
134136
{
135137
try
136138
{
137-
await _client.PutAsync(lastUrl, "");
139+
await _retryPolicy.Retry(async () => await _client.PutAsync(lastUrl, ""));
138140
_log.LogInformation("Finished uploading archive");
139141
}
140142
catch (Exception ex)

src/Octoshift/Services/GithubApi.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,9 @@ private static GithubSecretScanningAlert BuildSecretScanningAlert(JToken secretA
11821182
ResolutionComment = (string)secretAlert["resolution_comment"],
11831183
SecretType = (string)secretAlert["secret_type"],
11841184
Secret = (string)secretAlert["secret"],
1185+
ResolverName = secretAlert["resolved_by"]?.Type != JTokenType.Null
1186+
? (string)secretAlert["resolved_by"]["login"]
1187+
: null
11851188
};
11861189

11871190
private static GithubSecretScanningAlertLocation BuildSecretScanningAlertLocation(JToken alertLocation)

src/Octoshift/Services/SecretScanningAlertService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ public virtual async Task MigrateSecretScanningAlerts(string sourceOrg, string s
7474

7575
_log.LogInformation($" updating target alert:{targetAlert.Alert.Number} to state:{sourceAlert.Alert.State} and resolution:{sourceAlert.Alert.Resolution}");
7676

77+
var targetResolutionComment = $"[@{sourceAlert.Alert.ResolverName}] {sourceAlert.Alert.ResolutionComment}";
78+
7779
await _targetGithubApi.UpdateSecretScanningAlert(targetOrg, targetRepo, targetAlert.Alert.Number, sourceAlert.Alert.State,
78-
sourceAlert.Alert.Resolution, sourceAlert.Alert.ResolutionComment);
79-
_log.LogSuccess($" target alert successfully updated to {sourceAlert.Alert.Resolution}.");
80+
sourceAlert.Alert.Resolution, targetResolutionComment);
81+
_log.LogSuccess($" target alert successfully updated to {sourceAlert.Alert.Resolution} with comment {targetResolutionComment}.");
8082
}
8183
else
8284
{

src/OctoshiftCLI.IntegrationTests/BbsToGithub.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public BbsToGithub(ITestOutputHelper output)
5959

6060
_targetGithubHttpClient = new HttpClient();
6161
_targetGithubClient = new GithubClient(_logger, _targetGithubHttpClient, new VersionChecker(_versionClient, _logger), new RetryPolicy(_logger), new DateTimeProvider(), targetGithubToken);
62-
_archiveUploader = new ArchiveUploader(_targetGithubClient, _logger);
62+
var retryPolicy = new RetryPolicy(_logger);
63+
_archiveUploader = new ArchiveUploader(_targetGithubClient, _logger, retryPolicy);
6364
_targetGithubApi = new GithubApi(_targetGithubClient, "https://api.github.com", new RetryPolicy(_logger), _archiveUploader);
6465

6566
_blobServiceClient = new BlobServiceClient(_azureStorageConnectionString);

src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public GhesToGithub(ITestOutputHelper output)
4747
};
4848

4949
_versionClient = new HttpClient();
50-
_archiveUploader = new ArchiveUploader(_targetGithubClient, logger);
50+
var retryPolicy = new RetryPolicy(logger);
51+
_archiveUploader = new ArchiveUploader(_targetGithubClient, logger, retryPolicy);
5152

5253
_sourceGithubHttpClient = new HttpClient();
5354
_sourceGithubClient = new GithubClient(logger, _sourceGithubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger), new DateTimeProvider(), sourceGithubToken);

0 commit comments

Comments
 (0)