Skip to content

Commit 50d6912

Browse files
Merge pull request #1304 from amenocal/main
catches exception when Target is not a member of the organization
2 parents a8a0cf1 + 87450a9 commit 50d6912

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

RELEASENOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
- catches exception when Target is not a member of the organization and the `--skip-invitation` flag is enabled

src/Octoshift/Services/GithubApi.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,17 @@ ... on User {
879879
{
880880
throw new OctoshiftCliException($"Reclaiming mannequins with the--skip - invitation flag is not enabled for your GitHub organization.For more details, contact GitHub Support.", ex);
881881
}
882+
catch (OctoshiftCliException ex) when (ex.Message.Contains("Target must be a member"))
883+
{
884+
var result = new ReattributeMannequinToUserResult
885+
{
886+
Errors =
887+
[
888+
new ErrorData { Message = ex.Message }
889+
]
890+
};
891+
return result;
892+
}
882893
}
883894

884895
public virtual async Task<IEnumerable<GithubSecretScanningAlert>> GetSecretScanningAlertsForRepository(string org, string repo)

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,6 +2431,50 @@ ... on User {
24312431
result.Should().BeEquivalentTo(expectedCreateAttributionInvitationResponse);
24322432
}
24332433

2434+
[Fact]
2435+
public async Task ReclaimMannequinSkipInvitation_Returns_Error_When_Target_Not_Member()
2436+
{
2437+
// Arrange
2438+
const string orgId = "ORG_ID";
2439+
const string mannequinId = "NDQ5VXNlcjc4NDc5MzU=";
2440+
const string targetUserId = "NDQ5VXNlcjc4NDc5MzU=";
2441+
const string url = "https://api.github.com/graphql";
2442+
2443+
var payload = @"{""query"":""mutation($orgId: ID!,$sourceId: ID!,$targetId: ID!) { reattributeMannequinToUser(
2444+
input: { ownerId: $orgId, sourceId: $sourceId, targetId: $targetId }
2445+
) {
2446+
source {
2447+
... on Mannequin {
2448+
id
2449+
login
2450+
}
2451+
}
2452+
2453+
target {
2454+
... on User {
2455+
id
2456+
login
2457+
}
2458+
}
2459+
}
2460+
}""" + $",\"variables\":{{\"orgId\":\"{orgId}\", \"sourceId\":\"{mannequinId}\", \"targetId\":\"{targetUserId}\"}}}}";
2461+
2462+
const string errorMessage = "Target must be a member";
2463+
2464+
_githubClientMock
2465+
.Setup(m => m.PostGraphQLAsync(url, It.Is<object>(x => Compact(x.ToJson()) == Compact(payload)), null))
2466+
.ThrowsAsync(new OctoshiftCliException(errorMessage));
2467+
2468+
// Act
2469+
var result = await _githubApi.ReclaimMannequinSkipInvitation(orgId, mannequinId, targetUserId);
2470+
2471+
// Assert
2472+
result.Data.Should().BeNull();
2473+
result.Errors.Should().NotBeNull();
2474+
result.Errors.Should().ContainSingle();
2475+
result.Errors.First().Message.Should().Be(errorMessage);
2476+
}
2477+
24342478
[Fact]
24352479
public async Task StartMetadataArchiveGeneration_Returns_The_Initiated_Migration_Id()
24362480
{

0 commit comments

Comments
 (0)