Ejemplo n.º 1
0
        public async Task ReceivePullRequestEvent_ActionIsClosedAndPrMerged_DeleteEntityAndDeleteBranch()
        {
            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 branchName = Guid.NewGuid().ToString();

            // Insert Merge Request
            await mergeRequestsCollection.InsertWithTestChecksSuccess(owner, repo, PR_ID, branchName);

            await repoConfigurationCollection.Insert(owner, repo);

            payload["repository"]["name"]           = repo;
            payload["repository"]["owner"]["login"] = owner;
            payload["action"] = "closed";
            payload["pull_request"]["merged"]      = true;
            payload["pull_request"]["head"]["ref"] = branchName;

            // ACTION
            await SendWebhookRequest("pull_request", JsonConvert.SerializeObject(payload));

            // ASSERT
            var mergeRequest = await mergeRequestsCollection.Collection.Find(d => d["Owner"] == owner && d["Repo"] == repo && d["PrId"] == PR_ID).FirstOrDefaultAsync();

            Assert.Null(mergeRequest);
        }
Ejemplo n.º 2
0
        public async Task PushEvent_OnPullRequestBranch_RemoveChecks()
        {
            var owner      = Guid.NewGuid().ToString();
            var repo       = Guid.NewGuid().ToString();
            var branchName = Guid.NewGuid().ToString();
            var oldSha     = Guid.NewGuid().ToString();
            var sha        = Guid.NewGuid().ToString();

            // Load checks in DB
            await checkListsCollection.InsertWithDefaultChecks(owner, repo);

            await mergeRequestsCollection.InsertWithTestChecksSuccess(owner, repo, PR_ID, branchName, oldSha);

            // Issue Push event
            var payloadString = await File.ReadAllTextAsync("../../../DummyEvents/Push.json");

            var payload = JsonConvert.DeserializeObject <dynamic>(payloadString);

            payload["ref"]   = $"refs/heads/{branchName}";
            payload["after"] = sha;
            payload["repository"]["name"]           = repo;
            payload["repository"]["owner"]["login"] = owner;

            // Action
            await SendWebhookRequest("push", JsonConvert.SerializeObject(payload));

            // Assert
            var mergeRequest = await mergeRequestsCollection.Collection.Find(d => d["Owner"] == owner && d["Repo"] == repo && d["PrId"] == PR_ID).FirstAsync();

            Assert.Empty((BsonArray)mergeRequest["Checks"]);
            Assert.Equal(sha, mergeRequest["Sha"]);
        }
Ejemplo n.º 3
0
        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");
        }
Ejemplo n.º 4
0
        public async Task ReceiveMergeCommand_AllChecksPassed_PrHasPendingReviews_PrNotMerged()
        {
            var payloadString = await File.ReadAllTextAsync("../../../DummyEvents/IssueComment.json");

            var payload = JsonConvert.DeserializeObject <dynamic>(payloadString);

            var owner = Guid.NewGuid().ToString();
            var repo  = Guid.NewGuid().ToString();

            await checkListsCollection.InsertWithDefaultChecks(owner, repo);

            await mergeRequestsCollection.InsertWithTestChecksSuccess(owner, repo, PR_ID);

            await repoConfigurationCollection.Insert(owner, repo);

            payload["repository"]["name"]           = repo;
            payload["repository"]["owner"]["login"] = owner;

            var requestedReviewsMockedResponse = new
            {
                teams = Array.Empty <object>(),
                users = new[] { new { login = "******", id = 3 } }
            };

            // Mock github call
            await MockReviewGithubCallHelper.MockReviewsResponses(JsonConvert.SerializeObject(requestedReviewsMockedResponse), "[]", owner, repo, PR_ID);

            var commentPendingReviewsCallId = await MockCommentGithubCallHelper.MockCommentGithubCallPendingReviews(owner, repo, PR_ID, "itay");

            await SendWebhookRequest("issue_comment", JsonConvert.SerializeObject(payload));

            // ASSERT
            var commentPendingReviewsCall = await GetCall(commentPendingReviewsCallId);

            Assert.True(commentPendingReviewsCall.HasBeenMade, "comment should have been written");
            var mergeRequest = await mergeRequestsCollection.Collection.Find(d => d["Owner"] == owner && d["Repo"] == repo && d["PrId"] == PR_ID && d["ReceivedMergeCommand"] == true).FirstAsync();

            Assert.NotNull(mergeRequest);
        }