Properly migrate forks by passing BBS repo URL to GEI#1002
Conversation
- Upcoming backend changes will allow customers to select which repo to migrate if migrating a fork based on the --bbs-project and --bbs-repo flags passed in. The cli will craft the full repo url that contains the necessary context so that the backend correctly choose which repo to migrate in an export archive as Bitbucket Server always includes the full fork network in export archives that are generated. - This solves the "Multiple Repsitories in archive" error and also solves the problem where a customer wants to migrate a source but octoshift incorrectly picks the parent repo git data. - Update tests
timrogers
left a comment
There was a problem hiding this comment.
LGTM
(but do get a review from an engineer first 😊 !)
|
We support calling |
That's a great point! For what it's worth, I'm happy to introduce a breaking change at this point in the private beta, as it will enable us to make migrations more reliable and avoid surprises. |
…as arguments - Update tests to address NullReference exceptions
|
👋 @timrogers @dylan-smith thanks for the feedback! I'm 👍 in making the |
|
I've opened #1004 to track making the |
synthead
left a comment
There was a problem hiding this comment.
This looks awesome! Quick and straight-forward 😄
I left a suggestion to remove the "not used" values for the fields that are now optional! Feel free to make these changes, or file a tech debit issue for them and ship this PR as-is. I left a LGTM on this review so you can make a choice 👍
| bbsRepoUrl, // source repository URL | ||
| orgId, | ||
| repo, | ||
| "not-used", // source access token |
There was a problem hiding this comment.
The access token and metadata URL fields are optional in the GraphQL API now! I know that these fields are mostly unrelated to your changes, but it would be great to switch them to null while you're here! If you'd like, you are also welcome to file a tech debt issue for this suggestion instead and ship this PR without this suggestion 👍
The biggest lift would be to remove the ! in the query in the GithubApi to for accessToken indicate that they're optional:
gh-gei/src/Octoshift/Services/GithubApi.cs
Line 294 in cff1488
There are various places in tests where we build a query, and we'll also want to remove the !. This should be a simple find-and-replace. Here's an example:
Then, for the BBS tests, we'd want to remove the "not used" variables:
gh-gei/src/OctoshiftCLI.Tests/Octoshift/Services/GithubApiTests.cs
Lines 877 to 878 in b709e7b
For the metadataArchiveUrl and accessToken values here...
gh-gei/src/OctoshiftCLI.Tests/Octoshift/Services/GithubApiTests.cs
Lines 934 to 935 in b709e7b
...we'll simply turn this into a hard-coded, nulled string. There's a good example of that here:
There was a problem hiding this comment.
I made these changes (with below diff) but now getting null reference exceptions. Any idea on how to best resolve that?
@dpmex4527 ➜ /workspaces/gh-gei (bbs-send-repo-url-for-selecting-fork-support) $ git diff
diff --git a/src/Octoshift/Services/GithubApi.cs b/src/Octoshift/Services/GithubApi.cs
index 323d543..ea0fe65 100644
--- a/src/Octoshift/Services/GithubApi.cs
+++ b/src/Octoshift/Services/GithubApi.cs
@@ -291,7 +291,7 @@ public class GithubApi
$continueOnError: Boolean!,
$gitArchiveUrl: String,
$metadataArchiveUrl: String,
- $accessToken: String!,
+ $accessToken: String,
$githubPat: String,
$skipReleases: Boolean,
$targetRepoVisibility: String,
diff --git a/src/OctoshiftCLI.Tests/Octoshift/Services/GithubApiTests.cs b/src/OctoshiftCLI.Tests/Octoshift/Services/GithubApiTests.cs
index 76665b1..e447bc2 100644
--- a/src/OctoshiftCLI.Tests/Octoshift/Services/GithubApiTests.cs
+++ b/src/OctoshiftCLI.Tests/Octoshift/Services/GithubApiTests.cs
@@ -778,7 +778,7 @@ public class GithubApiTests
$continueOnError: Boolean!,
$gitArchiveUrl: String,
$metadataArchiveUrl: String,
- $accessToken: String!,
+ $accessToken: String,
$githubPat: String,
$skipReleases: Boolean,
$targetRepoVisibility: String,
@@ -874,9 +874,6 @@ public class GithubApiTests
const string gitArchiveUrl = "GIT_ARCHIVE_URL";
const string targetToken = "TARGET_TOKEN";
- const string unusedSourceToken = "not-used";
- const string unusedMetadataArchiveUrl = "https://not-used";
-
const string query = @"
mutation startRepositoryMigration(
$sourceId: ID!,
@@ -886,7 +883,7 @@ public class GithubApiTests
$continueOnError: Boolean!,
$gitArchiveUrl: String,
$metadataArchiveUrl: String,
- $accessToken: String!,
+ $accessToken: String,
$githubPat: String,
$skipReleases: Boolean,
$targetRepoVisibility: String,
@@ -931,8 +928,8 @@ public class GithubApiTests
repositoryName = GITHUB_REPO,
continueOnError = true,
gitArchiveUrl,
- metadataArchiveUrl = unusedMetadataArchiveUrl,
- accessToken = unusedSourceToken,
+ metadataArchiveUrl = (string)null,
+ accessToken = (string)null,
githubPat = targetToken,
skipReleases = false,
targetRepoVisibility = (string)null,
@dpmex4527 ➜ /workspaces/gh-gei (bbs-send-repo-url-for-selecting-fork-support) $ dotnet test src/OctoshiftCLI.Tests/OctoshiftCLI.Tests.csproj --no-build --verbosity normal
Build started 5/25/2023 8:20:16 PM.
Test run for /workspaces/gh-gei/src/OctoshiftCLI.Tests/bin/Debug/net6.0/OctoshiftCLI.Tests.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.3.2 (x64)
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Unexpected response when retrieving User ID
{"invalid":{"PublicAlias":{"value":"foo-user-id"}}}
Description:
Adds a team to a repo with a specific role/permission
Note: Expects GH_PAT env variable or --github-pat option to be set.
Usage:
add-team-to-repo [options]
Options:
--github-org <github-org> (REQUIRED)
--github-repo <github-repo> (REQUIRED)
--team <team> (REQUIRED)
--role <admin|maintain|pull|push|triage> (REQUIRED) The only valid values are: pull, push, admin, maintain, triage. For more details see https://docs.github.com/en/rest/reference/teams#add-or-update-team-repository-permissions, custom repository roles are not currently supported.
--github-pat <github-pat>
--verbose
--version Show version information
-?, -h, --help Show help and usage information
[xUnit.net 00:00:01.46] OctoshiftCLI.Tests.Octoshift.Services.GithubApiTests.StartBbsMigration_Returns_New_Repository_Migration_Id [FAIL]
Failed OctoshiftCLI.Tests.Octoshift.Services.GithubApiTests.StartBbsMigration_Returns_New_Repository_Migration_Id [11 ms]
Error Message:
System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
at OctoshiftCLI.Services.GithubApi.StartMigration(String migrationSourceId, String sourceRepoUrl, String orgId, String repo, String sourceToken, String targetToken, String gitArchiveUrl, String metadataArchiveUrl, Boolean skipReleases, String targetRepoVisibility, Boolean lockSource) in /workspaces/gh-gei/src/Octoshift/Services/GithubApi.cs:line 352
at OctoshiftCLI.Services.GithubApi.StartBbsMigration(String migrationSourceId, String bbsRepoUrl, String orgId, String repo, String targetToken, String archiveUrl, String targetRepoVisibility) in /workspaces/gh-gei/src/Octoshift/Services/GithubApi.cs:line 428
at OctoshiftCLI.Tests.Octoshift.Services.GithubApiTests.StartBbsMigration_Returns_New_Repository_Migration_Id() in /workspaces/gh-gei/src/OctoshiftCLI.Tests/Octoshift/Services/GithubApiTests.cs:line 965
--- End of stack trace from previous location ---
Failed! - Failed: 1, Passed: 777, Skipped: 0, Total: 778, Duration: 7 s - /workspaces/gh-gei/src/OctoshiftCLI.Tests/bin/Debug/net6.0/OctoshiftCLI.Tests.dll (net6.0)
Build FAILED.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:09.33
There was a problem hiding this comment.
You know, I was working on this myself to help you resolve these test failures, and it turned out to be quite a bit more work than I expected 😄 Let's hold off on this for now and remove the "not used" parameters in a follow-up PR 👍
There was a problem hiding this comment.
Sounds good. I've added this as a cleanup task in #1004
synthead
left a comment
There was a problem hiding this comment.
Sorry to make a "request changes" review after approving your PR 😅 I just saw that this PR doesn't have coverage for the backward-compatible BBS repo URL functionality that this PR introduces. Could we add a few tests for it?
Co-authored-by: Maxwell Pray <synthead@github.com>
src/OctoshiftCLI.Tests/bbs2gh/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs
Outdated
Show resolved
Hide resolved
src/OctoshiftCLI.Tests/bbs2gh/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs
Outdated
Show resolved
Hide resolved
- Test passes without it
…CommandHandlerTests.cs Co-authored-by: Dylan Smith <dylanfromwinnipeg@gmail.com>
…//github.com/github/gh-gei into bbs-send-repo-url-for-selecting-fork-support
|
release notes? |
Added in 8d5d503. Let me know if wording sounds good or if it needs updates. |
| private string GetBbsRepoUrl(MigrateRepoCommandArgs args) | ||
| { | ||
| return !args.BbsServerUrl.HasValue() || !args.BbsProject.HasValue() || !args.BbsRepo.HasValue() | ||
| ? "https://not-used" | ||
| : $"{args.BbsServerUrl.TrimEnd('/')}/projects/{args.BbsProject}/repos/{args.BbsRepo}/browse"; | ||
| } |
There was a problem hiding this comment.
Since we're sticking with a ternary as opposed to a guard (thanks dotnet format 😄), I think this reads a little better without "not" operators and inverting the logic:
| private string GetBbsRepoUrl(MigrateRepoCommandArgs args) | |
| { | |
| return !args.BbsServerUrl.HasValue() || !args.BbsProject.HasValue() || !args.BbsRepo.HasValue() | |
| ? "https://not-used" | |
| : $"{args.BbsServerUrl.TrimEnd('/')}/projects/{args.BbsProject}/repos/{args.BbsRepo}/browse"; | |
| } | |
| private string GetBbsRepoUrl(MigrateRepoCommandArgs args) | |
| { | |
| return args.BbsServerUrl.HasValue() && args.BbsProject.HasValue() && args.BbsRepo.HasValue() | |
| ? $"{args.BbsServerUrl.TrimEnd('/')}/projects/{args.BbsProject}/repos/{args.BbsRepo}/browse" | |
| : "https://not-used" | |
| } |
There was a problem hiding this comment.
FYI there's also .IsNullOrWhitespace() which is the opposite of .HasValue()
| bbsRepoUrl, // source repository URL | ||
| orgId, | ||
| repo, | ||
| "not-used", // source access token |
There was a problem hiding this comment.
You know, I was working on this myself to help you resolve these test failures, and it turned out to be quite a bit more work than I expected 😄 Let's hold off on this for now and remove the "not used" parameters in a follow-up PR 👍
- Refactor ternary expression to make it read better
synthead
left a comment
There was a problem hiding this comment.
One small suggestion in the release notes, then we're good to 🚢!
Co-authored-by: Maxwell Pray <synthead@github.com>
This PR updates the value passed in the
sourceRepositoryUrlfield when starting a repository migration in GEI to include the full BBS repo URL and is constructed using the values from the--bbs-server-url,--bbs-project, and--bbs-repocli args. This change is being made, alongside upcoming GEI changes in the backend, to allow customers to properly migrate repositories that either are currently forks or used to be a fork but the parent repo was deleted.The Bitbucket Server export API documentation states that when a fork is selected for export, all repos that are part of the fork network will be included in the export archive, which includes the parent repo and any other child forks of the parent repo. This resulted in a few error scenarios such as when a migration would fail with the
Multiple repositories found in archiveerror or if the migration succeeded but instead of migrating the fork git data, the parent git data was picked instead.This is my first contribution to the CLI so looking forward to any feedback!
ThirdPartyNotices.txt(if applicable)