Skip to content

Commit 1ab43a4

Browse files
authored
Merge pull request #1223 from github/1094-last-one
Implement `target-api-url` for `generate-script` commands
2 parents b932e62 + 54158a7 commit 1ab43a4

File tree

20 files changed

+161
-49
lines changed

20 files changed

+161
-49
lines changed

RELEASENOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
- Add `--target-api-url` to `gh ado2gh migrate-repo`, `gh bbs2gh migrate-repo`, and `gh gei migrate-org` to support newer GitHub migration paths.
1+
- Add `--target-api-url` to commonly used commands to support newer GitHub migration paths.
22
- Fixed `gh ado2gh rewire-pipeline` command for ADO Team Projects with more than 10,000 Build Definitions.

src/Octoshift/Commands/CreateTeam/CreateTeamCommandBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public CreateTeamCommandBase() : base(name: "create-team", description: "Creates
2222
{
2323
Description = "Personal access token of the GitHub target. Overrides GH_PAT environment variable."
2424
};
25-
public Option<string> TargetApiUrl { get; } = new("--target-api-url")
25+
public virtual Option<string> TargetApiUrl { get; } = new("--target-api-url")
2626
{
2727
Description = "The URL of the target API, if not migrating to github.com. Defaults to https://api.github.com"
2828
};

src/Octoshift/Commands/GenerateMannequinCsv/GenerateMannequinCsvCommandBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public GenerateMannequinCsvCommandBase() : base(
3737
{
3838
Description = "Personal access token of the GitHub target. Overrides GH_PAT environment variable."
3939
};
40-
public Option<string> TargetApiUrl { get; } = new("--target-api-url")
40+
public virtual Option<string> TargetApiUrl { get; } = new("--target-api-url")
4141
{
4242
Description = "The URL of the target API, if not migrating to github.com. Defaults to https://api.github.com"
4343
};

src/Octoshift/Commands/GrantMigratorRole/GrantMigratorRoleCommandBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public GrantMigratorRoleCommandBase() : base(
3030
IsRequired = false,
3131
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."
3232
};
33-
public Option<string> TargetApiUrl { get; } = new("--target-api-url")
33+
public virtual Option<string> TargetApiUrl { get; } = new("--target-api-url")
3434
{
3535
IsRequired = false,
3636
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."

src/Octoshift/Commands/ReclaimMannequin/ReclaimMannequinCommandBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public ReclaimMannequinCommandBase() : base(
6767
Description = "Reclaim mannequins immediately without sending an invitation to the user. Only available for Enterprise Managed Users (EMU) organizations. Warning: this is irreversible!"
6868
};
6969

70-
public Option<string> TargetApiUrl { get; } = new("--target-api-url")
70+
public virtual Option<string> TargetApiUrl { get; } = new("--target-api-url")
7171
{
7272
Description = "The URL of the target API, if not migrating to github.com. Defaults to https://api.github.com"
7373
};

src/OctoshiftCLI.Tests/ado2gh/Commands/GenerateScript/GenerateScriptCommandHandlerTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,34 @@ public async Task SequentialScript_Single_Repo_No_Options()
102102
_scriptOutput.Should().Be(expected);
103103
}
104104

105+
[Fact]
106+
public async Task SequentialScript_Single_Repo_With_TargetApiUrl()
107+
{
108+
// Arrange
109+
_mockAdoInspector.Setup(m => m.GetRepoCount()).ReturnsAsync(1);
110+
_mockAdoInspector.Setup(m => m.GetOrgs()).ReturnsAsync(ADO_ORGS);
111+
_mockAdoInspector.Setup(m => m.GetTeamProjects(ADO_ORG)).ReturnsAsync(ADO_TEAM_PROJECTS);
112+
_mockAdoInspector.Setup(m => m.GetRepos(ADO_ORG, ADO_TEAM_PROJECT)).ReturnsAsync(ADO_REPOS);
113+
var targetApiUrl = "https://foo.com/api/v3";
114+
115+
// Act
116+
var args = new GenerateScriptCommandArgs
117+
{
118+
GithubOrg = GITHUB_ORG,
119+
AdoOrg = ADO_ORG,
120+
Sequential = true,
121+
Output = new FileInfo("unit-test-output"),
122+
TargetApiUrl = targetApiUrl
123+
};
124+
await _handler.Handle(args);
125+
126+
_scriptOutput = TrimNonExecutableLines(_scriptOutput);
127+
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 }}";
128+
129+
// Assert
130+
_scriptOutput.Should().Be(expected);
131+
}
132+
105133
[Fact]
106134
public async Task SequentialScript_Single_Repo_AdoServer()
107135
{

src/OctoshiftCLI.Tests/ado2gh/Commands/GenerateScript/GenerateScriptCommandTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void Should_Have_Options()
3838
var command = new GenerateScriptCommand();
3939
command.Should().NotBeNull();
4040
command.Name.Should().Be("generate-script");
41-
command.Options.Count.Should().Be(17);
41+
command.Options.Count.Should().Be(18);
4242

4343
TestHelpers.VerifyCommandOption(command.Options, "github-org", true);
4444
TestHelpers.VerifyCommandOption(command.Options, "ado-org", false);
@@ -57,6 +57,7 @@ public void Should_Have_Options()
5757
TestHelpers.VerifyCommandOption(command.Options, "rewire-pipelines", false);
5858
TestHelpers.VerifyCommandOption(command.Options, "all", false);
5959
TestHelpers.VerifyCommandOption(command.Options, "repo-list", false);
60+
TestHelpers.VerifyCommandOption(command.Options, "target-api-url", false);
6061
}
6162

6263
[Fact]

src/OctoshiftCLI.Tests/bbs2gh/Commands/GenerateScript/GenerateScriptCommandHandlerTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,41 @@ public async Task One_Repo_With_Smb()
517517
_mockFileSystemProvider.Verify(m => m.WriteAllTextAsync(It.IsAny<string>(), It.Is<string>(script => script.Contains(migrateRepoCommand))));
518518
}
519519

520+
[Fact]
521+
public async Task One_Repo_With_Smb_And_TargetApiUrl()
522+
{
523+
// Arrange
524+
_mockBbsApi.Setup(m => m.GetProjects()).ReturnsAsync(new[]
525+
{
526+
(Id: 1, Key: BBS_FOO_PROJECT_KEY, Name: BBS_FOO_PROJECT_NAME),
527+
});
528+
_mockBbsApi.Setup(m => m.GetRepos(BBS_FOO_PROJECT_KEY)).ReturnsAsync(new[]
529+
{
530+
(Id: 1, Slug: BBS_FOO_REPO_1_SLUG, Name: BBS_FOO_REPO_1_NAME),
531+
});
532+
var targetApiUrl = "https://foo.com/api/v3";
533+
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 }}";
534+
535+
// Act
536+
var args = new GenerateScriptCommandArgs
537+
{
538+
BbsServerUrl = BBS_SERVER_URL,
539+
GithubOrg = GITHUB_ORG,
540+
BbsUsername = BBS_USERNAME,
541+
BbsPassword = BBS_PASSWORD,
542+
BbsSharedHome = BBS_SHARED_HOME,
543+
SmbUser = SMB_USER,
544+
SmbDomain = SMB_DOMAIN,
545+
Output = new FileInfo(OUTPUT),
546+
Verbose = true,
547+
TargetApiUrl = targetApiUrl
548+
};
549+
await _handler.Handle(args);
550+
551+
// Assert
552+
_mockFileSystemProvider.Verify(m => m.WriteAllTextAsync(It.IsAny<string>(), It.Is<string>(script => script.Contains(migrateRepoCommand))));
553+
}
554+
520555
[Fact]
521556
public async Task One_Repo_With_Smb_And_Archive_Download_Host()
522557
{

src/OctoshiftCLI.Tests/bbs2gh/Commands/GenerateScript/GenerateScriptCommandTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void Should_Have_Options()
3636
{
3737
_command.Should().NotBeNull();
3838
_command.Name.Should().Be("generate-script");
39-
_command.Options.Count.Should().Be(19);
39+
_command.Options.Count.Should().Be(20);
4040

4141
TestHelpers.VerifyCommandOption(_command.Options, "bbs-server-url", true);
4242
TestHelpers.VerifyCommandOption(_command.Options, "github-org", true);
@@ -57,6 +57,7 @@ public void Should_Have_Options()
5757
TestHelpers.VerifyCommandOption(_command.Options, "aws-region", false);
5858
TestHelpers.VerifyCommandOption(_command.Options, "keep-archive", false);
5959
TestHelpers.VerifyCommandOption(_command.Options, "no-ssl-verify", false);
60+
TestHelpers.VerifyCommandOption(_command.Options, "target-api-url", false);
6061
}
6162

6263
[Fact]

src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandHandlerTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,33 @@ public async Task Sequential_Github_Single_Repo()
153153
_script.Should().Be(expected);
154154
}
155155

156+
[Fact]
157+
public async Task Sequential_Github_Single_Repo_With_TargetApiUrl()
158+
{
159+
// Arrange
160+
_mockGithubApi
161+
.Setup(m => m.GetRepos(SOURCE_ORG))
162+
.ReturnsAsync(new[] { (REPO, "private") });
163+
var targetApiUrl = "https://foo.com/api/v3";
164+
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 }}";
165+
166+
// Act
167+
var args = new GenerateScriptCommandArgs
168+
{
169+
GithubSourceOrg = SOURCE_ORG,
170+
GithubTargetOrg = TARGET_ORG,
171+
Output = new FileInfo("unit-test-output"),
172+
Sequential = true,
173+
TargetApiUrl = targetApiUrl
174+
};
175+
await _handler.Handle(args);
176+
177+
_script = TrimNonExecutableLines(_script);
178+
179+
// Assert
180+
_script.Should().Be(expected);
181+
}
182+
156183
[Fact]
157184
public async Task Sequential_Github_Multiple_Repos()
158185
{

0 commit comments

Comments
 (0)