From 9cd866144cb79e22fc9eb85fa912b25551f3d3aa Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Mon, 2 Oct 2023 12:44:53 +0100 Subject: [PATCH 1/2] In `bbs2gh migrate-repo` and `gei migrate-repo`, create the migration source before starting the export This reworks `bbs2gh migrate-repo` and `gei migrate-repo` to create the migration source before running the export from the migration origin. This change will allow us to deduce a rough estimate of how long exports take on GitHub Enterprise Server and Bitbucket Server. --- .../MigrateRepo/MigrateRepoCommandHandler.cs | 29 +++++++++++------ .../MigrateRepo/MigrateRepoCommandHandler.cs | 32 +++++++++++-------- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/bbs2gh/Commands/MigrateRepo/MigrateRepoCommandHandler.cs b/src/bbs2gh/Commands/MigrateRepo/MigrateRepoCommandHandler.cs index af6738927..99d8a834f 100644 --- a/src/bbs2gh/Commands/MigrateRepo/MigrateRepoCommandHandler.cs +++ b/src/bbs2gh/Commands/MigrateRepo/MigrateRepoCommandHandler.cs @@ -53,6 +53,7 @@ public async Task Handle(MigrateRepoCommandArgs args) ValidateOptions(args); var exportId = 0L; + var migrationSourceId = ""; if (args.ShouldImportArchive()) { @@ -62,6 +63,8 @@ public async Task Handle(MigrateRepoCommandArgs args) { throw new OctoshiftCliException($"A repository called {args.GithubOrg}/{args.GithubRepo} already exists"); } + + migrationSourceId = await CreateMigrationSource(args); } if (args.ShouldGenerateArchive()) @@ -99,7 +102,7 @@ public async Task Handle(MigrateRepoCommandArgs args) if (args.ShouldImportArchive()) { - await ImportArchive(args, args.ArchiveUrl); + await ImportArchive(args, migrationSourceId, args.ArchiveUrl); } } @@ -190,22 +193,16 @@ private async Task UploadArchiveToAws(string bucketName, string archiveP return archiveBlobUrl; } - private async Task ImportArchive(MigrateRepoCommandArgs args, string archiveUrl = null) + private async Task CreateMigrationSource(MigrateRepoCommandArgs args) { - _log.LogInformation("Importing Archive..."); - - archiveUrl ??= args.ArchiveUrl; - - var bbsRepoUrl = GetBbsRepoUrl(args); + _log.LogInformation("Creating Migration Source..."); args.GithubPat ??= _environmentVariableProvider.TargetGithubPersonalAccessToken(); var githubOrgId = await _githubApi.GetOrganizationId(args.GithubOrg); - string migrationSourceId; - try { - migrationSourceId = await _githubApi.CreateBbsMigrationSource(githubOrgId); + return await _githubApi.CreateBbsMigrationSource(githubOrgId); } catch (OctoshiftCliException ex) when (ex.Message.Contains("not have the correct permissions to execute")) { @@ -213,6 +210,18 @@ private async Task ImportArchive(MigrateRepoCommandArgs args, string archiveUrl var message = $"{ex.Message}{insufficientPermissionsMessage}"; throw new OctoshiftCliException(message, ex); } + } + + private async Task ImportArchive(MigrateRepoCommandArgs args, string migrationSourceId, string archiveUrl = null) + { + _log.LogInformation("Importing Archive..."); + + archiveUrl ??= args.ArchiveUrl; + + var bbsRepoUrl = GetBbsRepoUrl(args); + + args.GithubPat ??= _environmentVariableProvider.TargetGithubPersonalAccessToken(); + var githubOrgId = await _githubApi.GetOrganizationId(args.GithubOrg); string migrationId; diff --git a/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs b/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs index cf6e3c3f2..df4bc1ce2 100644 --- a/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs +++ b/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs @@ -85,7 +85,25 @@ public async Task Handle(MigrateRepoCommandArgs args) { throw new OctoshiftCliException($"The target org \"{args.GithubTargetOrg}\" does not exist."); } + } + + string migrationSourceId; + + var githubOrgId = await _targetGithubApi.GetOrganizationId(args.GithubTargetOrg); + + try + { + migrationSourceId = await _targetGithubApi.CreateGhecMigrationSource(githubOrgId); + } + catch (OctoshiftCliException ex) when (ex.Message.Contains("not have the correct permissions to execute")) + { + var insufficientPermissionsMessage = InsufficientPermissionsMessageGenerator.Generate(args.GithubTargetOrg); + var message = $"{ex.Message}{insufficientPermissionsMessage}"; + throw new OctoshiftCliException(message, ex); + } + if (args.GhesApiUrl.HasValue()) + { (args.GitArchiveUrl, args.MetadataArchiveUrl) = await GenerateAndUploadArchive( args.GithubSourceOrg, args.SourceRepo, @@ -102,24 +120,10 @@ public async Task Handle(MigrateRepoCommandArgs args) } } - var githubOrgId = await _targetGithubApi.GetOrganizationId(args.GithubTargetOrg); var sourceRepoUrl = GetSourceRepoUrl(args); var sourceToken = GetSourceToken(args); var targetToken = args.GithubTargetPat ?? _environmentVariableProvider.TargetGithubPersonalAccessToken(); - string migrationSourceId; - - try - { - migrationSourceId = await _targetGithubApi.CreateGhecMigrationSource(githubOrgId); - } - catch (OctoshiftCliException ex) when (ex.Message.Contains("not have the correct permissions to execute")) - { - var insufficientPermissionsMessage = InsufficientPermissionsMessageGenerator.Generate(args.GithubTargetOrg); - var message = $"{ex.Message}{insufficientPermissionsMessage}"; - throw new OctoshiftCliException(message, ex); - } - string migrationId; try From 6e584ec549fbb252f6b02bf27af62116c244248c Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Fri, 6 Oct 2023 12:45:12 +0100 Subject: [PATCH 2/2] Update release notes --- RELEASENOTES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 8b1378917..88da814d6 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1 +1 @@ - +- When running migrations with `gh bbs2gh` and migrations from GitHub Enterprise Server with `gh gei`, create the migration source before starting the export