Skip to content

Commit

Permalink
Merge pull request #1223 from github/1094-last-one
Browse files Browse the repository at this point in the history
Implement `target-api-url` for `generate-script` commands
  • Loading branch information
brianaj authored Feb 9, 2024
2 parents b932e62 + 54158a7 commit 1ab43a4
Show file tree
Hide file tree
Showing 20 changed files with 161 additions and 49 deletions.
2 changes: 1 addition & 1 deletion RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- Add `--target-api-url` to `gh ado2gh migrate-repo`, `gh bbs2gh migrate-repo`, and `gh gei migrate-org` to support newer GitHub migration paths.
- Add `--target-api-url` to commonly used commands to support newer GitHub migration paths.
- Fixed `gh ado2gh rewire-pipeline` command for ADO Team Projects with more than 10,000 Build Definitions.
2 changes: 1 addition & 1 deletion src/Octoshift/Commands/CreateTeam/CreateTeamCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public CreateTeamCommandBase() : base(name: "create-team", description: "Creates
{
Description = "Personal access token of the GitHub target. Overrides GH_PAT environment variable."
};
public Option<string> TargetApiUrl { get; } = new("--target-api-url")
public virtual Option<string> TargetApiUrl { get; } = new("--target-api-url")
{
Description = "The URL of the target API, if not migrating to github.com. Defaults to https://api.github.com"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public GenerateMannequinCsvCommandBase() : base(
{
Description = "Personal access token of the GitHub target. Overrides GH_PAT environment variable."
};
public Option<string> TargetApiUrl { get; } = new("--target-api-url")
public virtual Option<string> TargetApiUrl { get; } = new("--target-api-url")
{
Description = "The URL of the target API, if not migrating to github.com. Defaults to https://api.github.com"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public GrantMigratorRoleCommandBase() : base(
IsRequired = false,
Description = "The URL of the GitHub Enterprise Server instance, if migrating from GHES. Supports granting access for exports. Can only configure one of --ghes-api-url or --target-api-url at a time."
};
public Option<string> TargetApiUrl { get; } = new("--target-api-url")
public virtual Option<string> TargetApiUrl { get; } = new("--target-api-url")
{
IsRequired = false,
Description = "The URL of the target API, if not migrating to github.com. Defaults to https://api.github.com. Can only configure one of --ghes-api-url or --target-api-url at a time."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public ReclaimMannequinCommandBase() : base(
Description = "Reclaim mannequins immediately without sending an invitation to the user. Only available for Enterprise Managed Users (EMU) organizations. Warning: this is irreversible!"
};

public Option<string> TargetApiUrl { get; } = new("--target-api-url")
public virtual Option<string> TargetApiUrl { get; } = new("--target-api-url")
{
Description = "The URL of the target API, if not migrating to github.com. Defaults to https://api.github.com"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,34 @@ public async Task SequentialScript_Single_Repo_No_Options()
_scriptOutput.Should().Be(expected);
}

[Fact]
public async Task SequentialScript_Single_Repo_With_TargetApiUrl()
{
// Arrange
_mockAdoInspector.Setup(m => m.GetRepoCount()).ReturnsAsync(1);
_mockAdoInspector.Setup(m => m.GetOrgs()).ReturnsAsync(ADO_ORGS);
_mockAdoInspector.Setup(m => m.GetTeamProjects(ADO_ORG)).ReturnsAsync(ADO_TEAM_PROJECTS);
_mockAdoInspector.Setup(m => m.GetRepos(ADO_ORG, ADO_TEAM_PROJECT)).ReturnsAsync(ADO_REPOS);
var targetApiUrl = "https://foo.com/api/v3";

// Act
var args = new GenerateScriptCommandArgs
{
GithubOrg = GITHUB_ORG,
AdoOrg = ADO_ORG,
Sequential = true,
Output = new FileInfo("unit-test-output"),
TargetApiUrl = targetApiUrl
};
await _handler.Handle(args);

_scriptOutput = TrimNonExecutableLines(_scriptOutput);
var expected = $"Exec {{ gh ado2gh migrate-repo --target-api-url \"{targetApiUrl}\" --ado-org \"{ADO_ORG}\" --ado-team-project \"{ADO_TEAM_PROJECT}\" --ado-repo \"{FOO_REPO}\" --github-org \"{GITHUB_ORG}\" --github-repo \"{ADO_TEAM_PROJECT}-{FOO_REPO}\" --target-repo-visibility private }}";

// Assert
_scriptOutput.Should().Be(expected);
}

[Fact]
public async Task SequentialScript_Single_Repo_AdoServer()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void Should_Have_Options()
var command = new GenerateScriptCommand();
command.Should().NotBeNull();
command.Name.Should().Be("generate-script");
command.Options.Count.Should().Be(17);
command.Options.Count.Should().Be(18);

TestHelpers.VerifyCommandOption(command.Options, "github-org", true);
TestHelpers.VerifyCommandOption(command.Options, "ado-org", false);
Expand All @@ -57,6 +57,7 @@ public void Should_Have_Options()
TestHelpers.VerifyCommandOption(command.Options, "rewire-pipelines", false);
TestHelpers.VerifyCommandOption(command.Options, "all", false);
TestHelpers.VerifyCommandOption(command.Options, "repo-list", false);
TestHelpers.VerifyCommandOption(command.Options, "target-api-url", false);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,41 @@ public async Task One_Repo_With_Smb()
_mockFileSystemProvider.Verify(m => m.WriteAllTextAsync(It.IsAny<string>(), It.Is<string>(script => script.Contains(migrateRepoCommand))));
}

[Fact]
public async Task One_Repo_With_Smb_And_TargetApiUrl()
{
// Arrange
_mockBbsApi.Setup(m => m.GetProjects()).ReturnsAsync(new[]
{
(Id: 1, Key: BBS_FOO_PROJECT_KEY, Name: BBS_FOO_PROJECT_NAME),
});
_mockBbsApi.Setup(m => m.GetRepos(BBS_FOO_PROJECT_KEY)).ReturnsAsync(new[]
{
(Id: 1, Slug: BBS_FOO_REPO_1_SLUG, Name: BBS_FOO_REPO_1_NAME),
});
var targetApiUrl = "https://foo.com/api/v3";
var migrateRepoCommand = $"Exec {{ gh bbs2gh migrate-repo --target-api-url \"{targetApiUrl}\" --bbs-server-url \"{BBS_SERVER_URL}\" --bbs-username \"{BBS_USERNAME}\" --bbs-shared-home \"{BBS_SHARED_HOME}\" --bbs-project \"{BBS_FOO_PROJECT_KEY}\" --bbs-repo \"{BBS_FOO_REPO_1_SLUG}\" --smb-user \"{SMB_USER}\" --smb-domain {SMB_DOMAIN} --github-org \"{GITHUB_ORG}\" --github-repo \"{BBS_FOO_PROJECT_KEY}-{BBS_FOO_REPO_1_SLUG}\" --verbose --target-repo-visibility private }}";

// Act
var args = new GenerateScriptCommandArgs
{
BbsServerUrl = BBS_SERVER_URL,
GithubOrg = GITHUB_ORG,
BbsUsername = BBS_USERNAME,
BbsPassword = BBS_PASSWORD,
BbsSharedHome = BBS_SHARED_HOME,
SmbUser = SMB_USER,
SmbDomain = SMB_DOMAIN,
Output = new FileInfo(OUTPUT),
Verbose = true,
TargetApiUrl = targetApiUrl
};
await _handler.Handle(args);

// Assert
_mockFileSystemProvider.Verify(m => m.WriteAllTextAsync(It.IsAny<string>(), It.Is<string>(script => script.Contains(migrateRepoCommand))));
}

[Fact]
public async Task One_Repo_With_Smb_And_Archive_Download_Host()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void Should_Have_Options()
{
_command.Should().NotBeNull();
_command.Name.Should().Be("generate-script");
_command.Options.Count.Should().Be(19);
_command.Options.Count.Should().Be(20);

TestHelpers.VerifyCommandOption(_command.Options, "bbs-server-url", true);
TestHelpers.VerifyCommandOption(_command.Options, "github-org", true);
Expand All @@ -57,6 +57,7 @@ public void Should_Have_Options()
TestHelpers.VerifyCommandOption(_command.Options, "aws-region", false);
TestHelpers.VerifyCommandOption(_command.Options, "keep-archive", false);
TestHelpers.VerifyCommandOption(_command.Options, "no-ssl-verify", false);
TestHelpers.VerifyCommandOption(_command.Options, "target-api-url", false);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,33 @@ public async Task Sequential_Github_Single_Repo()
_script.Should().Be(expected);
}

[Fact]
public async Task Sequential_Github_Single_Repo_With_TargetApiUrl()
{
// Arrange
_mockGithubApi
.Setup(m => m.GetRepos(SOURCE_ORG))
.ReturnsAsync(new[] { (REPO, "private") });
var targetApiUrl = "https://foo.com/api/v3";
var expected = $"Exec {{ gh gei migrate-repo --target-api-url \"{targetApiUrl}\" --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --target-repo-visibility private }}";

// Act
var args = new GenerateScriptCommandArgs
{
GithubSourceOrg = SOURCE_ORG,
GithubTargetOrg = TARGET_ORG,
Output = new FileInfo("unit-test-output"),
Sequential = true,
TargetApiUrl = targetApiUrl
};
await _handler.Handle(args);

_script = TrimNonExecutableLines(_script);

// Assert
_script.Should().Be(expected);
}

[Fact]
public async Task Sequential_Github_Multiple_Repos()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void Should_Have_Options()
var command = new GenerateScriptCommand();
command.Should().NotBeNull();
command.Name.Should().Be("generate-script");
command.Options.Count.Should().Be(14);
command.Options.Count.Should().Be(15);

TestHelpers.VerifyCommandOption(command.Options, "github-source-org", true);
TestHelpers.VerifyCommandOption(command.Options, "github-target-org", true);
Expand All @@ -55,6 +55,7 @@ public void Should_Have_Options()
TestHelpers.VerifyCommandOption(command.Options, "aws-bucket-name", false);
TestHelpers.VerifyCommandOption(command.Options, "aws-region", false);
TestHelpers.VerifyCommandOption(command.Options, "keep-archive", false);
TestHelpers.VerifyCommandOption(command.Options, "target-api-url", false);
}

[Fact]
Expand Down
5 changes: 5 additions & 0 deletions src/ado2gh/Commands/GenerateScript/GenerateScriptCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public GenerateScriptCommand() : base(
"Note: Expects ADO_PAT env variable or --ado-pat option to be set.")
{
AddOption(GithubOrg);
AddOption(TargetApiUrl);
AddOption(AdoOrg);
AddOption(AdoTeamProject);
AddOption(AdoServerUrl);
Expand Down Expand Up @@ -91,6 +92,10 @@ public GenerateScriptCommand() : base(
{
Description = "Path to a csv file that contains a list of repos to generate a script for. The CSV file should be generated using the inventory-report command."
};
public Option<string> TargetApiUrl { get; } = new("--target-api-url")
{
Description = "The URL of the target API, if not migrating to github.com. Defaults to https://api.github.com"
};

public override GenerateScriptCommandHandler BuildHandler(GenerateScriptCommandArgs args, IServiceProvider sp)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public class GenerateScriptCommandArgs : CommandArgs
public bool RewirePipelines { get; set; }
public bool All { get; set; }
public FileInfo RepoList { get; set; }
public string TargetApiUrl { get; set; }
}
}
Loading

0 comments on commit 1ab43a4

Please sign in to comment.