Skip to content

Conversation

synthead
Copy link
Collaborator

@synthead synthead commented Jun 26, 2025

Closes https://github.ghe.com/github/octoshift/issues/10765!

This PR consumes the new JSON response from the PUT "complete" request for the multipart upload flow when uploading archives to GitHub-owned storage for GEI!

This is an example of a response from the PUT response:

{
  "guid": "363b2659-b8a3-4878-bfff-eed4bcb54d35",
  "node_id": "MA_kgDaACQzNjNiMjY1OS1iOGEzLTQ4NzgtYmZmZi1lZWQ0YmNiNTRkMzU",
  "name": "git-archive.tar.gz",
  "size": 33287,
  "uri": "gei://archive/363b2659-b8a3-4878-bfff-eed4bcb54d35",
  "created_at": "2024-11-13T12:35:45.761-08:00"
}

With the changes in this PR, the JSON body ☝️ is consumed, and the GEI URI doesn't need to be interpolated anymore:

// 3. Complete the upload
await CompleteUpload(nextUrl.ToString());
return $"gei://archive/{guid}";

Here's an example of these changes at work:

[2025-06-25 18:13:03] [INFO] Uploading archive 2025-06-25_18-10-22-74170-git_archive.tar.gz to GitHub Storage
[2025-06-25 18:13:03] [INFO] Starting archive upload into GitHub owned storage: 2025-06-25_18-10-22-74170-git_archive.tar.gz...
[2025-06-25 18:13:03] [INFO] Uploading part 1/11...
[2025-06-25 18:13:06] [INFO] Uploading part 2/11...
[2025-06-25 18:13:11] [INFO] Uploading part 3/11...
[2025-06-25 18:13:15] [INFO] Uploading part 4/11...
[2025-06-25 18:13:20] [INFO] Uploading part 5/11...
[2025-06-25 18:13:25] [INFO] Uploading part 6/11...
[2025-06-25 18:13:31] [INFO] Uploading part 7/11...
[2025-06-25 18:13:36] [INFO] Uploading part 8/11...
[2025-06-25 18:13:41] [INFO] Uploading part 9/11...
[2025-06-25 18:13:45] [INFO] Uploading part 10/11...
[2025-06-25 18:13:50] [INFO] Uploading part 11/11...
[2025-06-25 18:13:55] [INFO] Finished uploading archive
[2025-06-25 18:13:55] [INFO] Upload complete
[2025-06-25 18:13:56] [INFO] Uploading archive 2025-06-25_18-10-22-74171-metadata_archive.tar.gz to GitHub Storage
[2025-06-25 18:13:56] [INFO] Upload complete
[2025-06-25 18:13:56] [INFO] Archives uploaded to blob storage, now starting migration...
  • Did you write/update appropriate tests
  • Release notes updated (if appropriate)
  • Appropriate logging output
  • Issue linked
  • Docs updated (or issue created)
  • New package licenses are added to ThirdPartyNotices.txt (if applicable)

@Copilot Copilot AI review requested due to automatic review settings June 26, 2025 01:21
Copilot

This comment was marked as outdated.

@synthead synthead requested a review from a team June 26, 2025 01:24
@synthead synthead self-assigned this Jun 26, 2025
Copy link

github-actions bot commented Jun 26, 2025

Unit Test Results

  1 files    1 suites   21s ⏱️
901 tests 901 ✅ 0 💤 0 ❌
902 runs  902 ✅ 0 💤 0 ❌

Results for commit 3dca950.

♻️ This comment has been updated with latest results.

@Copilot Copilot AI review requested due to automatic review settings August 4, 2025 22:14
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the multipart upload flow for GEI archives to consume the URI directly from the PUT response instead of interpolating it from the GUID. The changes implement parsing of a JSON response that contains metadata including the gei://archive/{guid} URI.

  • Modifies the CompleteUpload method to parse JSON response and extract the URI
  • Updates all test cases to mock the new JSON response format
  • Removes the dependency on parsing GUID from query parameters and manual URI construction

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Octoshift/Services/ArchiveUploader.cs Updates CompleteUpload to parse JSON response and return URI directly
src/OctoshiftCLI.Tests/Octoshift/Services/ArchiveUploadersTests.cs Updates test mocks to return JSON response and adds Newtonsoft.Json.Linq import


return $"gei://archive/{guid}";
return geiUri.ToString();
Copy link
Preview

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

The variable geiUri is a Uri object, but calling ToString() on it is redundant since the method return type is string. This should return geiUri.ToString() or change the return type to Uri and return geiUri directly.

Copilot uses AI. Check for mistakes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This suggestion produces this error:

error CS0029: Cannot implicitly convert type 'System.Uri' to 'string' [src/Octoshift/Octoshift.csproj]

_log.LogInformation("Finished uploading archive");

return new Uri((string)responseData["uri"]);
Copy link
Preview

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

The cast to (string) could throw an exception if the 'uri' field is null or not a string. Consider using responseData["uri"]?.ToString() or add null checking to provide a more helpful error message if the expected field is missing.

Suggested change
return new Uri((string)responseData["uri"]);
var uriString = responseData["uri"]?.ToString();
if (string.IsNullOrWhiteSpace(uriString))
{
throw new OctoshiftCliException("The response from the server did not contain a valid 'uri' field.");
}
return new Uri(uriString);

Copilot uses AI. Check for mistakes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

With our API, it's not possible for a 201 to be returned from uploads and not have a URI in the response.

Copy link

github-actions bot commented Aug 5, 2025

Code Coverage

Package Line Rate Branch Rate Complexity Health
gei 80% 72% 574
bbs2gh 83% 77% 653
ado2gh 83% 77% 613
Octoshift 87% 76% 1479
Summary 85% (7281 / 8589) 76% (1712 / 2252) 3319

Copy link
Member

@dpmex4527 dpmex4527 left a comment

Choose a reason for hiding this comment

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

LGTM!

@synthead synthead merged commit fd4e079 into main Aug 5, 2025
52 of 53 checks passed
@synthead synthead deleted the consume-gei-uri-in-multipart-response branch August 5, 2025 20:38
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.

3 participants