public async Task ReceiveMergeCommand_MergingFails_StrictMergePolicy_UpdateBranchIsCalled() { var payloadString = await File.ReadAllTextAsync("../../../DummyEvents/IssueComment.json"); var payload = JsonConvert.DeserializeObject <dynamic>(payloadString); var owner = Guid.NewGuid().ToString(); var repo = Guid.NewGuid().ToString(); var sha = Guid.NewGuid().ToString(); var branch = "some_test_branch"; // Mock DB await checkListsCollection.InsertWithDefaultChecks(owner, repo); await mergeRequestsCollection.InsertWithTestChecksSuccess(owner, repo, PR_ID, branch, sha); await repoConfigurationCollection.Insert(owner, repo, false, "oldest", "whitelist-strict"); payload["repository"]["name"] = repo; payload["repository"]["owner"]["login"] = owner; // Mock Github Calls await MockReviewGithubCallHelper.MockAllReviewsPassedResponses(owner, repo, PR_ID); var commentReadyForMergingCallId = await MockCommentGithubCallHelper.MockCommentGithubPRIsReadyForMerging(owner, repo, PR_ID); var mergeFailedCommentCallId = await MockCommentGithubCallHelper.MockCommentGithubCallMergeFailed(owner, repo, PR_ID); var mergePrCallId = await MockGithubCall("put", $"{PrUrlFor(owner, repo, PR_ID)}/merge", null, 409); var updateBranchCallId = await MockGithubCall("post", MergesUrlFor(owner, repo), branch, "ok", false); var miroMergeCheckCallId = await MockGithubCall("post", StatusCheckUrlFor(owner, repo, sha), "{}", false); // ACTION await SendWebhookRequest("issue_comment", JsonConvert.SerializeObject(payload)); // Assert var mergePrCall = await GetCall(mergePrCallId); var updateBranchCall = await GetCall(updateBranchCallId); var commentReadyForMergingCall = await GetCall(commentReadyForMergingCallId); var mergeFailedCommentCall = await GetCall(mergeFailedCommentCallId); var miroMergeCheckCall = await GetCall(miroMergeCheckCallId); Assert.True(mergePrCall.HasBeenMade, "PR should have tried to merge"); Assert.True(miroMergeCheckCall.HasBeenMade, "miro merge check success call should have been made"); Assert.True(commentReadyForMergingCall.HasBeenMade, "should get ready for merging comment"); Assert.True(updateBranchCall.HasBeenMade, "PR should have updated branch"); Assert.True(mergeFailedCommentCall.HasBeenMade, "should get PR merge failed comment"); var mergeRequest = await mergeRequestsCollection.Collection.Find(d => d["Owner"] == owner && d["Repo"] == repo && d["PrId"] == PR_ID && d["ReceivedMergeCommand"] == true).FirstAsync(); Assert.True(mergeRequest["ReceivedMergeCommandTimestamp"] < DateTime.UtcNow); Assert.NotNull(mergeRequest); Assert.Equal("Miro merge check", miroMergeCheckCall.Details.Body["context"]); Assert.Equal("success", miroMergeCheckCall.Details.Body["state"]); }
public async Task ReceiveInfoCommand_AllChecksPassed_WriteSuccessComment() { var payloadString = await File.ReadAllTextAsync("../../../DummyEvents/IssueComment.json"); var payload = JsonConvert.DeserializeObject <dynamic>(payloadString); var owner = Guid.NewGuid().ToString(); var repo = Guid.NewGuid().ToString(); // Insert Checkslist and PR to DB await checkListsCollection.InsertWithDefaultChecks(owner, repo); await mergeRequestsCollection.InsertWithTestChecksSuccess(owner, repo, PR_ID); payload["repository"]["name"] = repo; payload["repository"]["owner"]["login"] = owner; payload["issue"]["number"] = PR_ID; payload["comment"]["body"] = "Miro info"; // Mock Github Calls var successCommentCallId = await MockCommentGithubCallHelper.MockCommentGithubPRIsReadyForMerging(owner, repo, PR_ID); await MockReviewGithubCallHelper.MockAllReviewsPassedResponses(owner, repo, PR_ID); // ACTION await SendWebhookRequest("issue_comment", JsonConvert.SerializeObject(payload)); // ASSERT var successCommentCall = await GetCall(successCommentCallId); Assert.True(successCommentCall.HasBeenMade, "Should have recieved a - PR is ready for merging comment"); }
public async Task ReceiveMergeCommand_PrIsApprovedByAllReviewersAndAllChecksPassed_StrictMergePolicy_MergePr() { var payloadString = await File.ReadAllTextAsync("../../../DummyEvents/IssueComment.json"); var payload = JsonConvert.DeserializeObject <dynamic>(payloadString); var owner = Guid.NewGuid().ToString(); var repo = Guid.NewGuid().ToString(); var sha = Guid.NewGuid().ToString(); await checkListsCollection.InsertWithDefaultChecks(owner, repo); await repoConfigurationCollection.Insert(owner, repo, false, "oldest", "whitelist-strict"); payload["repository"]["name"] = repo; payload["repository"]["owner"]["login"] = owner; await mergeRequestsCollection.InsertWithTestChecksSuccess(owner, repo, PR_ID, null, sha); // Mock github calls var mergeCommentCallId = await MockCommentGithubCallHelper.MockCommentGithubCallMerging(owner, repo, PR_ID); var mergePrCallId = await MockMergeGithubCallHelper.MockMergeCall(owner, repo, PR_ID); await MockReviewGithubCallHelper.MockAllReviewsPassedResponses(owner, repo, PR_ID); var commentReadyForMergingCallId = await MockCommentGithubCallHelper.MockCommentGithubPRIsReadyForMerging(owner, repo, PR_ID); var miroMergeCheckCallId = await MockGithubCall("post", StatusCheckUrlFor(owner, repo, sha), "{}", false); // Action await SendWebhookRequest("issue_comment", JsonConvert.SerializeObject(payload)); var commentReadyForMergingCall = await GetCall(commentReadyForMergingCallId); var mergeCommentCall = await GetCall(mergeCommentCallId); var mergePrCall = await GetCall(mergePrCallId); var miroMergeCheckCall = await GetCall(miroMergeCheckCallId); Assert.True(commentReadyForMergingCall.HasBeenMade, "should have receieved a ready for merging comment"); Assert.True(mergeCommentCall.HasBeenMade, "a merging comment should have been posted to the pr"); Assert.True(miroMergeCheckCall.HasBeenMade, "a call to miro merge status check should have been called"); Assert.True(mergePrCall.HasBeenMade, "pr should have been merged"); var mergeRequest = await mergeRequestsCollection.Collection.Find(d => d["Owner"] == owner && d["Repo"] == repo && d["PrId"] == PR_ID && d["ReceivedMergeCommand"] == true).FirstAsync(); Assert.NotNull(mergeRequest); Assert.Equal("Miro merge check", miroMergeCheckCall.Details.Body["context"]); Assert.Equal("success", miroMergeCheckCall.Details.Body["state"]); }
public async Task ReceiveMergeCommand_PrIsApprovedByAllReviewersAndAllChecksPassed_GetRequiredChecksAndMergePr() { var payloadString = await File.ReadAllTextAsync("../../../DummyEvents/IssueComment.json"); var payload = JsonConvert.DeserializeObject <dynamic>(payloadString); var owner = Guid.NewGuid().ToString(); var repo = Guid.NewGuid().ToString(); var sha = Guid.NewGuid().ToString(); payload["repository"]["name"] = repo; payload["repository"]["owner"]["login"] = owner; await mergeRequestsCollection.InsertWithTestChecksSuccess(owner, repo, PR_ID, null, sha); await repoConfigurationCollection.Insert(owner, repo); // Mock Github Calls var mergeCommentCallId = await MockCommentGithubCallHelper.MockCommentGithubCallMerging(owner, repo, PR_ID); var mergePrCallId = await MockMergeGithubCallHelper.MockMergeCall(owner, repo, PR_ID); await MockReviewGithubCallHelper.MockAllReviewsPassedResponses(owner, repo, PR_ID); var commentReadyForMergingCallId = await MockCommentGithubCallHelper.MockCommentGithubPRIsReadyForMerging(owner, repo, PR_ID); var getRequiredChecksCallId = await MockRequiredChecksGithubCallHelper.MockRequiredChecks(owner, repo, new string[] { Consts.TEST_CHECK_A, Consts.TEST_CHECK_B }); // Action await SendWebhookRequest("issue_comment", JsonConvert.SerializeObject(payload)); // Assert var commentReadyForMergingCall = await GetCall(commentReadyForMergingCallId); var mergeCommentCall = await GetCall(mergeCommentCallId); var mergePrCall = await GetCall(mergePrCallId); var getRequiredChecksCall = await GetCall(getRequiredChecksCallId); Assert.True(commentReadyForMergingCall.HasBeenMade, "should have receieved a ready for merging comment"); Assert.True(mergeCommentCall.HasBeenMade, "a merging comment should have been posted to the pr"); Assert.True(getRequiredChecksCall.HasBeenMade, "should have fetched required checks"); Assert.True(mergePrCall.HasBeenMade, "pr should have been merged"); var mergeRequest = await mergeRequestsCollection.Collection.Find(d => d["Owner"] == owner && d["Repo"] == repo && d["PrId"] == PR_ID && d["ReceivedMergeCommand"] == true).FirstAsync(); Assert.NotNull(mergeRequest); }
public async Task ReceiveMergeCommand_MergingFails_CanNotUpdateBecausePrIsFork() { var payloadString = await File.ReadAllTextAsync("../../../DummyEvents/IssueComment.json"); var payload = JsonConvert.DeserializeObject <dynamic>(payloadString); var owner = Guid.NewGuid().ToString(); var repo = Guid.NewGuid().ToString(); var sha = Guid.NewGuid().ToString(); var branch = "some_test_branch"; // Mock DB await checkListsCollection.InsertWithDefaultChecks(owner, repo); await mergeRequestsCollection.InsertWithTestChecksSuccess(owner, repo, PR_ID, branch, sha, true); // IsFork = true await repoConfigurationCollection.Insert(owner, repo); payload["repository"]["name"] = repo; payload["repository"]["owner"]["login"] = owner; // Mock Github Calls await MockReviewGithubCallHelper.MockAllReviewsPassedResponses(owner, repo, PR_ID); await MockCommentGithubCallHelper.MockCommentGithubPRIsReadyForMerging(owner, repo, PR_ID); await MockCommentGithubCallHelper.MockCommentGithubCallMergeFailed(owner, repo, PR_ID); await MockGithubCall("put", $"{PrUrlFor(owner, repo, PR_ID)}/merge", null, 404); await MockGithubCall("post", StatusCheckUrlFor(owner, repo, sha), "{}", false); var updateFailedCommentCallId = await MockCommentGithubCallHelper.MockCommentGithubCallCanNotUpdateBecauseFork(owner, repo, PR_ID); var updateBranchCallId = await MockGithubCall("post", MergesUrlFor(owner, repo), branch, "ok", false); // ACTION await SendWebhookRequest("issue_comment", JsonConvert.SerializeObject(payload)); // Assert var updateBranchCall = await GetCall(updateBranchCallId); var updateFailedCommentCall = await GetCall(updateFailedCommentCallId); Assert.False(updateBranchCall.HasBeenMade, "PR should not have updated branch"); Assert.True(updateFailedCommentCall.HasBeenMade, "Can not update comment should have been called"); var mergeRequest = await mergeRequestsCollection.Collection.Find(d => d["Owner"] == owner && d["Repo"] == repo && d["PrId"] == PR_ID).FirstAsync(); Assert.NotNull(mergeRequest); }
public async Task ActionIsCompleted_ConclusionIsSuccess_NoMergeCommandGiven_PrIsNotMergable_DoNothing() { var payloadString = await File.ReadAllTextAsync("../../../DummyEvents/Status.json"); var payload = JsonConvert.DeserializeObject <dynamic>(payloadString); var owner = Guid.NewGuid().ToString(); var repo = Guid.NewGuid().ToString(); var sha = Guid.NewGuid().ToString(); await checkListsCollection.InsertWithDefaultChecks(owner, repo); var checksAlreadyCompleted = new List <CheckStatus>() { new CheckStatus { Name = Consts.TEST_CHECK_A, Status = "success" } }; payload["repository"]["name"] = repo; payload["repository"]["owner"]["login"] = owner; payload["state"] = "success"; payload["sha"] = sha; payload["context"] = Consts.TEST_CHECK_B; await mergeRequestsCollection.Insert(owner, repo, PR_ID, Consts.DEFAULT_BRANCH, false, checksAlreadyCompleted, sha); var mergePrCallId = await MockMergeGithubCallHelper.MockMergeCall(owner, repo, PR_ID); var prReadyForMergingCommentCallId = await MockCommentGithubCallHelper.MockCommentGithubPRIsReadyForMerging(owner, repo, PR_ID); await MockReviewGithubCallHelper.MockAllReviewsPassedResponses(owner, repo, PR_ID); await SendWebhookRequest("status", JsonConvert.SerializeObject(payload)); var mergePrCall = await GetCall(mergePrCallId); var prReadyForMergingCommentCall = await GetCall(prReadyForMergingCommentCallId); var mergeRequest = await mergeRequestsCollection.Collection.Find(d => d["Owner"] == owner && d["Repo"] == repo && d["PrId"] == PR_ID).FirstAsync(); Assert.True(prReadyForMergingCommentCall.HasBeenMade, "a comment for PR ready for merging should have been called"); Assert.False(mergePrCall.HasBeenMade, "the pr shouldn't be merged"); }