Skip to content

Commit

Permalink
Merge pull request #1304 from amenocal/main
Browse files Browse the repository at this point in the history
catches exception when Target is not a member of the organization
  • Loading branch information
begonaguereca authored Dec 7, 2024
2 parents a8a0cf1 + 87450a9 commit 50d6912
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@

- catches exception when Target is not a member of the organization and the `--skip-invitation` flag is enabled
11 changes: 11 additions & 0 deletions src/Octoshift/Services/GithubApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,17 @@ ... on User {
{
throw new OctoshiftCliException($"Reclaiming mannequins with the--skip - invitation flag is not enabled for your GitHub organization.For more details, contact GitHub Support.", ex);
}
catch (OctoshiftCliException ex) when (ex.Message.Contains("Target must be a member"))
{
var result = new ReattributeMannequinToUserResult
{
Errors =
[
new ErrorData { Message = ex.Message }
]
};
return result;
}
}

public virtual async Task<IEnumerable<GithubSecretScanningAlert>> GetSecretScanningAlertsForRepository(string org, string repo)
Expand Down
44 changes: 44 additions & 0 deletions src/OctoshiftCLI.Tests/Octoshift/Services/GithubApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2431,6 +2431,50 @@ ... on User {
result.Should().BeEquivalentTo(expectedCreateAttributionInvitationResponse);
}

[Fact]
public async Task ReclaimMannequinSkipInvitation_Returns_Error_When_Target_Not_Member()
{
// Arrange
const string orgId = "ORG_ID";
const string mannequinId = "NDQ5VXNlcjc4NDc5MzU=";
const string targetUserId = "NDQ5VXNlcjc4NDc5MzU=";
const string url = "https://api.github.com/graphql";

var payload = @"{""query"":""mutation($orgId: ID!,$sourceId: ID!,$targetId: ID!) { reattributeMannequinToUser(
input: { ownerId: $orgId, sourceId: $sourceId, targetId: $targetId }
) {
source {
... on Mannequin {
id
login
}
}
target {
... on User {
id
login
}
}
}
}""" + $",\"variables\":{{\"orgId\":\"{orgId}\", \"sourceId\":\"{mannequinId}\", \"targetId\":\"{targetUserId}\"}}}}";

const string errorMessage = "Target must be a member";

_githubClientMock
.Setup(m => m.PostGraphQLAsync(url, It.Is<object>(x => Compact(x.ToJson()) == Compact(payload)), null))
.ThrowsAsync(new OctoshiftCliException(errorMessage));

// Act
var result = await _githubApi.ReclaimMannequinSkipInvitation(orgId, mannequinId, targetUserId);

// Assert
result.Data.Should().BeNull();
result.Errors.Should().NotBeNull();
result.Errors.Should().ContainSingle();
result.Errors.First().Message.Should().Be(errorMessage);
}

[Fact]
public async Task StartMetadataArchiveGeneration_Returns_The_Initiated_Migration_Id()
{
Expand Down

0 comments on commit 50d6912

Please sign in to comment.