public async Task ReceivePullRequestEvent_ActionIsReopened_PRHasLatestChecks() { var payloadString = await File.ReadAllTextAsync("../../../DummyEvents/PullRequest.json"); var payload = JsonConvert.DeserializeObject <dynamic>(payloadString); var owner = Guid.NewGuid().ToString(); var repo = Guid.NewGuid().ToString(); var branch = Guid.NewGuid().ToString(); var sha = Guid.NewGuid().ToString(); // Insert Merge Request await checkListsCollection.InsertWithDefaultChecks(owner, repo); payload["repository"]["name"] = repo; payload["repository"]["owner"]["login"] = owner; payload["action"] = "reopened"; payload["pull_request"]["head"]["ref"] = branch; payload["pull_request"]["head"]["sha"] = sha; var prStatusCheckMockedResponse = new[] { new { Context = Consts.TEST_CHECK_A, State = "success" }, new { Context = Consts.TEST_CHECK_B, State = "success" } }; // Mock github calls var miroGetPrStatusChecksCallId = await MockGithubCall("get", StatusCheckUrlFor(owner, repo, sha), JsonConvert.SerializeObject(prStatusCheckMockedResponse)); var mergePrCallId = await MockMergeGithubCallHelper.MockMergeCall(owner, repo, PR_ID); var mergeCommentCallId = await MockCommentGithubCallHelper.MockCommentGithubCallMerging(owner, repo, PR_ID); // Action await SendWebhookRequest("pull_request", JsonConvert.SerializeObject(payload)); // Assert var miroGetPrStatusChecksCall = await GetCall(miroGetPrStatusChecksCallId); Assert.True(miroGetPrStatusChecksCall.HasBeenMade, "get PR status checks call should have been made"); var mergeRequest = await mergeRequestsCollection.Collection.Find(d => d["Owner"] == owner && d["Repo"] == repo && d["PrId"] == PR_ID).FirstOrDefaultAsync(); Assert.NotNull(mergeRequest); Assert.True(((BsonArray)mergeRequest["Checks"]).Any(x => x["Name"] == Consts.TEST_CHECK_A && x["Status"] == "success"), $"MergeRequest should contain {Consts.TEST_CHECK_A}"); Assert.True(((BsonArray)mergeRequest["Checks"]).Any(x => x["Name"] == Consts.TEST_CHECK_B && x["Status"] == "success"), $"MergeRequest should contain {Consts.TEST_CHECK_B}"); }
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 StatusEvent_LastCheckSuccessful_MergePr() { var owner = Guid.NewGuid().ToString(); var repo = Guid.NewGuid().ToString(); var sha = Guid.NewGuid().ToString(); // Insert to DB Default checks needed await checkListsCollection.InsertWithDefaultChecks(owner, repo); // Insert to PR tests completed var checksAlreadyCompleted = new List <CheckStatus>() { new CheckStatus { Name = Consts.TEST_CHECK_A, Status = "success" } }; await mergeRequestsCollection.Insert(owner, repo, PR_ID, Consts.DEFAULT_BRANCH, true, checksAlreadyCompleted, sha); // Generate Status event with succesful test var payloadString = await File.ReadAllTextAsync("../../../DummyEvents/Status.json"); var payload = JsonConvert.DeserializeObject <dynamic>(payloadString); payload["repository"]["name"] = repo; payload["repository"]["owner"]["login"] = owner; payload["state"] = "success"; payload["sha"] = sha; payload["context"] = Consts.TEST_CHECK_B; // Mock Github calls var mergePrCallId = await MockMergeGithubCallHelper.MockMergeCall(owner, repo, PR_ID); var mergeCommentCallId = await MockCommentGithubCallHelper.MockCommentGithubCallMerging(owner, repo, PR_ID); await MockReviewGithubCallHelper.MockAllReviewsPassedResponses(owner, repo, PR_ID); await MockGithubCall("post", StatusCheckUrlFor(owner, repo, sha), "{}", false); // Action - status event await SendWebhookRequest("status", JsonConvert.SerializeObject(payload)); // Assert var mergePrCall = await GetCall(mergePrCallId); var mergeCommentCall = await GetCall(mergeCommentCallId); var mergeRequest = await mergeRequestsCollection.Collection.Find(d => d["Owner"] == owner && d["Repo"] == repo && d["PrId"] == PR_ID).FirstAsync(); Assert.True(mergePrCall.HasBeenMade, "the pr should be merged"); Assert.True(mergeCommentCall.HasBeenMade, "the merge comment should have been written"); }
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 StatusEvent_LastCheckSuccessful_NoMergeCommandGiven_BlackListPolicy_MergePr() { var owner = Guid.NewGuid().ToString(); var repo = Guid.NewGuid().ToString(); var sha = Guid.NewGuid().ToString(); // Required test is TEST_CHECK_A await checkListsCollection.Insert(owner, repo, new string[] { Consts.TEST_CHECK_A }); await repoConfigurationCollection.Insert(owner, repo, false, "oldest", "blacklist"); // Create Pull Request await OpenBlackListPullRequest(owner, repo, PR_ID, sha); // Generate Status event with succesful test var payloadString = await File.ReadAllTextAsync("../../../DummyEvents/Status.json"); var payload = JsonConvert.DeserializeObject <dynamic>(payloadString); payload["repository"]["name"] = repo; payload["repository"]["owner"]["login"] = owner; payload["state"] = "success"; payload["sha"] = sha; payload["context"] = Consts.TEST_CHECK_A; // Mock Github calls var mergePrCallId = await MockMergeGithubCallHelper.MockMergeCall(owner, repo, PR_ID); var mergeCommentCallId = await MockCommentGithubCallHelper.MockCommentGithubCallMerging(owner, repo, PR_ID); await MockReviewGithubCallHelper.MockAllReviewsPassedResponses(owner, repo, PR_ID); await MockGithubCall("post", StatusCheckUrlFor(owner, repo, sha), "{}", false); // Action - status event await SendWebhookRequest("status", JsonConvert.SerializeObject(payload)); // Assert var mergePrCall = await GetCall(mergePrCallId); var mergeCommentCall = await GetCall(mergeCommentCallId); var mergeRequest = await mergeRequestsCollection.Collection.Find(d => d["Owner"] == owner && d["Repo"] == repo && d["PrId"] == PR_ID).FirstAsync(); Assert.True(mergePrCall.HasBeenMade, "the pr should be merged"); Assert.True(mergeCommentCall.HasBeenMade, "the merge comment should have been written"); }
public async Task ReceievePullRequestReviewApprovedEvent_AllTestsPassed_MergePr() { var owner = Guid.NewGuid().ToString(); var repo = Guid.NewGuid().ToString(); var sha = Guid.NewGuid().ToString(); var payloadString = await File.ReadAllTextAsync("../../../DummyEvents/ReviewPullRequest.json"); var payload = JsonConvert.DeserializeObject <dynamic>(payloadString); payload["repository"]["name"] = repo; payload["repository"]["owner"]["login"] = owner; payload["pull_request"]["number"] = PR_ID; // Mock github var mergeCommentCallId = await MockCommentGithubCallHelper.MockCommentGithubCallMerging(owner, repo, PR_ID); var mergePrCallId = await MockMergeGithubCallHelper.MockMergeCall(owner, repo, PR_ID); // var miroMergeCheckCallId = await MockGithubCall("post", StatusCheckUrlFor(owner, repo, sha), "{}", false); await MockReviewGithubCallHelper.MockAllReviewsPassedResponses(owner, repo, PR_ID); // insert to DB with all checks passed await checkListsCollection.InsertWithDefaultChecks(owner, repo); await mergeRequestsCollection.InsertWithTestChecksSuccessAndMergeCommand(owner, repo, PR_ID, null, sha); // ACTION await SendWebhookRequest("pull_request_review", JsonConvert.SerializeObject(payload)); // ASSERT var mergeCommentCall = await GetCall(mergeCommentCallId); var mergePrCall = await GetCall(mergePrCallId); // var miroMergeCheckCall = await GetCall(miroMergeCheckCallId); Assert.True(mergeCommentCall.HasBeenMade, "a merging comment should have been posted to the pr"); // Assert.True(miroMergeCheckCall.HasBeenMade, "a call to delete miro merge 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).FirstAsync(); Assert.NotNull(mergeRequest); }