Skip to content

Commit fffd8f8

Browse files
Merge pull request #1191 from github/feature/abort-migration
Feature/abort migration
2 parents 142c9f8 + b463368 commit fffd8f8

File tree

9 files changed

+146
-33
lines changed

9 files changed

+146
-33
lines changed

releasenotes/v1.7.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Release Notes:
2+
- Added `abort-migration` command to `gh ado2gh`, `gh bbs2gh` and `gh gei` that will abort a migration that is queued or in-progress.

src/Octoshift/Services/GithubApi.cs

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,42 @@ public virtual async Task<string> GetEnterpriseServerVersion()
10111011
return (string)data["installed_version"];
10121012
}
10131013

1014+
public virtual async Task<bool> AbortMigration(string migrationId)
1015+
{
1016+
var url = $"{_apiUrl}/graphql";
1017+
1018+
var query = @"
1019+
mutation abortRepositoryMigration(
1020+
$migrationId: ID!,
1021+
)";
1022+
var gql = @"
1023+
abortRepositoryMigration(
1024+
input: {
1025+
migrationId: $migrationId
1026+
})
1027+
{ success }";
1028+
1029+
var payload = new
1030+
{
1031+
query = $"{query} {{ {gql} }}",
1032+
variables = new
1033+
{
1034+
migrationId,
1035+
},
1036+
operationName = "abortRepositoryMigration"
1037+
};
1038+
1039+
try
1040+
{
1041+
var data = await _client.PostGraphQLAsync(url, payload);
1042+
return (bool)data["data"]["abortRepositoryMigration"]["success"];
1043+
}
1044+
catch (OctoshiftCliException ex) when (ex.Message.Contains("Could not resolve to a node", StringComparison.OrdinalIgnoreCase))
1045+
{
1046+
throw new OctoshiftCliException($"Invalid migration id: {migrationId}", ex);
1047+
}
1048+
}
1049+
10141050
private static object GetMannequinsPayload(string orgId)
10151051
{
10161052
var query = "query($id: ID!, $first: Int, $after: String)";
@@ -1142,34 +1178,4 @@ private static CodeScanningAlertInstance BuildCodeScanningAlertInstance(JToken s
11421178
StartColumn = (int)scanningAlertInstance["location"]["start_column"],
11431179
EndColumn = (int)scanningAlertInstance["location"]["end_column"]
11441180
};
1145-
1146-
public virtual async Task<bool> AbortMigration(string migrationSourceId)
1147-
{
1148-
var url = $"{_apiUrl}/graphql";
1149-
1150-
var query = @"
1151-
mutation abortRepositoryMigration(
1152-
$migrationId: ID!,
1153-
)";
1154-
var gql = @"
1155-
abortRepositoryMigration(
1156-
input: {
1157-
migrationId: $migrationId
1158-
})
1159-
{ success }";
1160-
1161-
var payload = new
1162-
{
1163-
query = $"{query} {{ {gql} }}",
1164-
variables = new
1165-
{
1166-
migrationId = migrationSourceId,
1167-
},
1168-
operationName = "abortRepositoryMigration"
1169-
};
1170-
1171-
var data = await _client.PostGraphQLAsync(url, payload);
1172-
1173-
return (bool)data["data"]["abortRepositoryMigration"]["success"];
1174-
}
11751181
}

src/OctoshiftCLI.Tests/Octoshift/Services/GithubApiTests.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3328,7 +3328,7 @@ public async Task AbortMigration_Returns_True_On_Success()
33283328
{
33293329
// Arrange
33303330
const string url = "https://api.github.com/graphql";
3331-
const string migrationSourceId = "MIGRATION_SOURCE_ID";
3331+
const string migrationId = "MIGRATION_ID";
33323332

33333333
const string query = @"
33343334
mutation abortRepositoryMigration(
@@ -3346,7 +3346,7 @@ mutation abortRepositoryMigration(
33463346
query = $"{query} {{ {gql} }}",
33473347
variables = new
33483348
{
3349-
migrationId = migrationSourceId,
3349+
migrationId,
33503350
},
33513351
operationName = "abortRepositoryMigration"
33523352
};
@@ -3368,12 +3368,30 @@ mutation abortRepositoryMigration(
33683368
.ReturnsAsync(response);
33693369

33703370
// Act
3371-
var expectedBooleanResponse = await _githubApi.AbortMigration(migrationSourceId);
3371+
var expectedBooleanResponse = await _githubApi.AbortMigration(migrationId);
33723372

33733373
// Assert
33743374
expectedBooleanResponse.Should().Be(actualBooleanResponse);
33753375
}
33763376

3377+
[Fact]
3378+
public async Task AbortMigration_Surfaces_Error_With_Incorrect_Migration_ID()
3379+
{
3380+
// Arrange
3381+
const string migrationId = "1234";
3382+
const string expectedErrorMessage = $"Invalid migration id: {migrationId}";
3383+
3384+
_githubClientMock
3385+
.Setup(m => m.PostGraphQLAsync(It.IsAny<string>(), It.IsAny<object>(), null))
3386+
.ThrowsAsync(new OctoshiftCliException("Could not resolve to a node"));
3387+
3388+
// Act, Assert
3389+
await _githubApi.Invoking(api => api.AbortMigration(migrationId))
3390+
.Should()
3391+
.ThrowExactlyAsync<OctoshiftCliException>()
3392+
.WithMessage(expectedErrorMessage);
3393+
}
3394+
33773395
private string Compact(string source) =>
33783396
source
33793397
.Replace("\r", "")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using FluentAssertions;
2+
using OctoshiftCLI.AdoToGithub.Commands.AbortMigration;
3+
using Xunit;
4+
5+
namespace OctoshiftCLI.Tests.AdoToGithub.Commands.AbortMigration;
6+
7+
public class AbortMigrationCommandTests
8+
{
9+
[Fact]
10+
public void Should_Have_Options()
11+
{
12+
var command = new AbortMigrationCommand();
13+
command.Should().NotBeNull();
14+
command.Name.Should().Be("abort-migration");
15+
command.Options.Count.Should().Be(3);
16+
17+
TestHelpers.VerifyCommandOption(command.Options, "migration-id", true);
18+
TestHelpers.VerifyCommandOption(command.Options, "github-pat", false);
19+
TestHelpers.VerifyCommandOption(command.Options, "verbose", false);
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using FluentAssertions;
2+
using OctoshiftCLI.BbsToGithub.Commands.AbortMigration;
3+
using Xunit;
4+
5+
namespace OctoshiftCLI.Tests.BbsToGithub.Commands.AbortMigration;
6+
7+
public class AbortMigrationCommandTests
8+
{
9+
[Fact]
10+
public void Should_Have_Options()
11+
{
12+
var command = new AbortMigrationCommand();
13+
command.Should().NotBeNull();
14+
command.Name.Should().Be("abort-migration");
15+
command.Options.Count.Should().Be(3);
16+
17+
TestHelpers.VerifyCommandOption(command.Options, "migration-id", true);
18+
TestHelpers.VerifyCommandOption(command.Options, "github-pat", false);
19+
TestHelpers.VerifyCommandOption(command.Options, "verbose", false);
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using FluentAssertions;
2+
using OctoshiftCLI.GithubEnterpriseImporter.Commands.AbortMigration;
3+
using Xunit;
4+
5+
namespace OctoshiftCLI.Tests.GithubEnterpriseImporter.Commands.AbortMigration;
6+
7+
public class AbortMigrationCommandTests
8+
{
9+
[Fact]
10+
public void Should_Have_Options()
11+
{
12+
var command = new AbortMigrationCommand();
13+
command.Should().NotBeNull();
14+
command.Name.Should().Be("abort-migration");
15+
command.Options.Count.Should().Be(3);
16+
17+
TestHelpers.VerifyCommandOption(command.Options, "migration-id", true);
18+
TestHelpers.VerifyCommandOption(command.Options, "github-pat", false);
19+
TestHelpers.VerifyCommandOption(command.Options, "verbose", false);
20+
}
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using OctoshiftCLI.Commands.AbortMigration;
2+
3+
namespace OctoshiftCLI.AdoToGithub.Commands.AbortMigration;
4+
5+
public sealed class AbortMigrationCommand : AbortMigrationCommandBase
6+
{
7+
public AbortMigrationCommand() : base() => AddOptions();
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using OctoshiftCLI.Commands.AbortMigration;
2+
3+
namespace OctoshiftCLI.BbsToGithub.Commands.AbortMigration;
4+
5+
public sealed class AbortMigrationCommand : AbortMigrationCommandBase
6+
{
7+
public AbortMigrationCommand() : base() => AddOptions();
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using OctoshiftCLI.Commands.AbortMigration;
2+
3+
namespace OctoshiftCLI.GithubEnterpriseImporter.Commands.AbortMigration;
4+
5+
public sealed class AbortMigrationCommand : AbortMigrationCommandBase
6+
{
7+
public AbortMigrationCommand() : base() => AddOptions();
8+
}

0 commit comments

Comments
 (0)