Skip to content

Refresh GitHub git archive URLs if they have expired#1439

Merged
dpmex4527 merged 7 commits intomainfrom
dpmex4527/refresh-archive-urls-if-expired
Oct 22, 2025
Merged

Refresh GitHub git archive URLs if they have expired#1439
dpmex4527 merged 7 commits intomainfrom
dpmex4527/refresh-archive-urls-if-expired

Conversation

@dpmex4527
Copy link
Copy Markdown
Member

@dpmex4527 dpmex4527 commented Oct 10, 2025

This PR fixes an issue when sometimes for GitHub migrations the metadata export takes a long time and it causes the gitArchiveUrl that was generated right before starting with the metadata export to expire. What we now do is check to see if the git archive URL expires (by catching 403 errors for migrations backed by Azure/S3 or 404 errors when backed by GHES local storage) and if so, re-fresh the download URL to allow the download to continue.

  • 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 AI review requested due to automatic review settings October 10, 2025 19:54
@dpmex4527 dpmex4527 changed the title Refresh archive URLs if they have expired Refresh GitHub git archive URLs if they have expired Oct 10, 2025
@dpmex4527 dpmex4527 marked this pull request as draft October 10, 2025 19:54
Copy link
Copy Markdown
Contributor

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 adds retry logic for expired archive URLs during GitHub migrations. When download URLs expire (indicated by 403 errors), the system now regenerates fresh URLs and retries the download operation.

  • Implements automatic retry logic for both git and metadata archive downloads when 403 errors occur
  • Adds comprehensive test coverage for retry scenarios including individual and combined archive failures

Reviewed Changes

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

File Description
src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs Added try-catch blocks around archive downloads to handle 403 errors and regenerate fresh URLs
src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs Added three test methods covering git archive retry, metadata archive retry, and both archives retry scenarios

@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 10, 2025

Unit Test Results

  1 files    1 suites   10m 24s ⏱️
948 tests 948 ✅ 0 💤 0 ❌
949 runs  949 ✅ 0 💤 0 ❌

Results for commit c418f8b.

♻️ This comment has been updated with latest results.

- Check error against exception status code
@dpmex4527 dpmex4527 force-pushed the dpmex4527/refresh-archive-urls-if-expired branch from c56d8be to fb2205b Compare October 11, 2025 05:57
@dpmex4527 dpmex4527 self-assigned this Oct 14, 2025
- Gracefully handle empty results when fetching IDP groups
- Add tests
@dpmex4527 dpmex4527 marked this pull request as ready for review October 21, 2025 19:17
Copy link
Copy Markdown
Collaborator

@synthead synthead left a comment

Choose a reason for hiding this comment

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

Awesome work here!! This will be very helpful when customers enqueue a lot of migrations!

Comment on lines +1852 to +1861
// Assert
// Verify that GetArchiveMigrationUrl was called twice for git archive (once during generation, once during retry)
_mockSourceGithubApi.Verify(x => x.GetArchiveMigrationUrl(SOURCE_ORG, GIT_ARCHIVE_ID), Times.Exactly(2));

// Verify that DownloadToFile was called twice for git archive (original URL failed, fresh URL succeeded)
_mockHttpDownloadService.Verify(x => x.DownloadToFile(GIT_ARCHIVE_URL, GIT_ARCHIVE_FILE_PATH), Times.Once);
_mockHttpDownloadService.Verify(x => x.DownloadToFile(freshGitArchiveUrl, GIT_ARCHIVE_FILE_PATH), Times.Once);

// Verify metadata archive was only downloaded once (no retry needed)
_mockHttpDownloadService.Verify(x => x.DownloadToFile(METADATA_ARCHIVE_URL, METADATA_ARCHIVE_FILE_PATH), Times.Once);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice!

@synthead
Copy link
Copy Markdown
Collaborator

Oh also, one more idea you might entertain is using theories, like so:

[Theory]
[InlineData("https://e2e-bbs-linux-1.westus2.cloudapp.azure.com", true, ArchiveUploadOption.AzureStorage)]
[InlineData("https://e2e-bbs-linux-1.westus2.cloudapp.azure.com", true, ArchiveUploadOption.AwsS3)]
[InlineData("https://e2e-bbs-linux-1.westus2.cloudapp.azure.com", true, ArchiveUploadOption.GithubStorage)]
public async Task Basic(string bbsServer, bool useSshForArchiveDownload, ArchiveUploadOption uploadOption)
{

They work a lot like RSpec's shared examples. Since there's a lot of overlap between the metadata and Git archive URL tests, you might be able to say "this URL returns a 403 first", and pass a URL into your mocks. This could possibly clean up your tests in a DRY way, but keep an eye out for making them too complex with abstractions, too 👍

@github-actions
Copy link
Copy Markdown

Code Coverage

Package Line Rate Branch Rate Complexity Health
ado2gh 72% 70% 712
Octoshift 83% 72% 1714
bbs2gh 83% 77% 653
gei 81% 72% 574
Summary 80% (7692 / 9555) 73% (1810 / 2491) 3653

@dpmex4527 dpmex4527 merged commit 3010627 into main Oct 22, 2025
79 of 86 checks passed
@dpmex4527 dpmex4527 deleted the dpmex4527/refresh-archive-urls-if-expired branch October 22, 2025 00:54
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.

4 participants