예제 #1
0
        public async Task PushEventOnMaster_RepoConfigIsCreated_QuietAdded()
        {
            var owner = Guid.NewGuid().ToString();
            var repo  = Guid.NewGuid().ToString();

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

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

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

            // Mock Github call
            var getConfigFileCallId = await MockRepoConfigGithubCallHelper.MockRepoConfigGithubCall(owner, repo, "quiet.yml");

            await MockRequiredChecksGithubCallHelper.MockRequiredChecks(owner, repo);

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

            // ASSERT
            var getConfigFileCall = await GetCall(getConfigFileCallId);

            Assert.True(getConfigFileCall.HasBeenMade, "getConfigFile call should have been made");

            var repoConfig = await repoConfigurationCollection.Collection.Find(d => d["Owner"] == owner && d["Repo"] == repo).FirstAsync();

            Assert.NotNull(repoConfig);
            Assert.Equal("all", repoConfig["UpdateBranchStrategy"]);
            Assert.Equal("whitelist-strict", repoConfig["MergePolicy"]);
            Assert.True((bool)repoConfig["Quiet"]);
        }
예제 #2
0
        public async Task MultiplePullRequests_PushEventOnMaster_NextPrHasFailingTests_NextNextPrBranchIsUpdated()
        {
            var owner            = Guid.NewGuid().ToString();
            var repo             = Guid.NewGuid().ToString();
            var secondBranchName = Guid.NewGuid().ToString();
            var thirdBranchName  = Guid.NewGuid().ToString();
            var secondPrId       = 100;
            var thirdPrId        = 101;

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

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

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

            var secondPrCheckStatus = new List <CheckStatus>()
            {
                new CheckStatus {
                    Name   = Consts.TEST_CHECK_A,
                    Status = "failure"
                },
                new CheckStatus {
                    Name   = Consts.TEST_CHECK_B,
                    Status = "success"
                }
            };


            // Insert Merge Requests
            await mergeRequestsCollection.InsertWithTestChecksSuccessAndMergeCommand(owner, repo, thirdPrId, thirdBranchName);

            await mergeRequestsCollection.Insert(owner, repo, secondPrId, secondBranchName, true, secondPrCheckStatus);

            // Make second PR older than the first PR
            await mergeRequestsCollection.UpdateMergeRequest(owner, repo, secondPrId, true, DateTime.UtcNow.AddMinutes(-10));

            await mergeRequestsCollection.UpdateMergeRequest(owner, repo, thirdPrId, true, DateTime.UtcNow.AddMinutes(-5));

            // Mock Github cal
            var updateBranchCallId = await MockGithubCall("post", MergesUrlFor(owner, repo), "ok", false);

            await MockRepoConfigGithubCallHelper.MockRepoConfigGithubCall(owner, repo, "strategyOldest.yml");

            await MockRequiredChecksGithubCallHelper.MockRequiredChecks(owner, repo);

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

            // ASSERT
            var updateBranchCall = await GetCall(updateBranchCallId);

            Assert.True(updateBranchCall.HasBeenMade, "update branch call should have been made on the third branch");
            Assert.Equal(thirdBranchName, updateBranchCall.Details.Body["base"]);
        }
예제 #3
0
        public async Task MultiplePullRequests_PushEventOnDefaultBranch_UpdateBranchIsCalledOnNextPr()
        {
            var owner             = Guid.NewGuid().ToString();
            var repo              = Guid.NewGuid().ToString();
            var secondBranchName  = Guid.NewGuid().ToString();
            var thirdBranchName   = Guid.NewGuid().ToString();
            var secondPrId        = 100;
            var thirdPrId         = 101;
            var defaultBranchName = "some-default-branch";

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

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

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


            // Insert Merge Requests
            await mergeRequestsCollection.InsertWithTestChecksSuccessAndMergeCommand(owner, repo, thirdPrId, thirdBranchName);

            await mergeRequestsCollection.InsertWithTestChecksSuccessAndMergeCommand(owner, repo, secondPrId, secondBranchName);

            // Make second PR older than the first PR
            await mergeRequestsCollection.UpdateMergeRequest(owner, repo, secondPrId, true, DateTime.UtcNow.AddMinutes(-10));

            await mergeRequestsCollection.UpdateMergeRequest(owner, repo, thirdPrId, true, DateTime.UtcNow.AddMinutes(-5));

            // Mock Github call
            var updateBranchCallId = await MockGithubCall("post", MergesUrlFor(owner, repo), "ok", false);

            await MockRepoConfigGithubCallHelper.MockRepoConfigGithubCall(owner, repo, "defaultBranchSomeDefaultBranch.yml");

            await MockRequiredChecksGithubCallHelper.MockRequiredChecks(owner, repo, null, defaultBranchName);

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

            // ASSERT
            var updateBranchCall = await GetCall(updateBranchCallId);

            Assert.True(updateBranchCall.HasBeenMade, "update branch call should have been made on the second branch");
            Assert.Equal(secondBranchName, updateBranchCall.Details.Body["base"]);
            Assert.Equal(defaultBranchName, updateBranchCall.Details.Body["head"]);
        }
예제 #4
0
        public async Task MultiplePullRequests_PushEventOnMaster_ConfigIsSetToNone_NoBranchIsUpdated()
        {
            var owner            = Guid.NewGuid().ToString();
            var repo             = Guid.NewGuid().ToString();
            var secondBranchName = Guid.NewGuid().ToString();
            var thirdBranchName  = Guid.NewGuid().ToString();
            var secondPrId       = 100;
            var thirdPrId        = 101;

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

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

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

            // Insert Merge Requests
            await mergeRequestsCollection.InsertWithTestChecksSuccessAndMergeCommand(owner, repo, thirdPrId, thirdBranchName);

            await mergeRequestsCollection.InsertWithTestChecksSuccessAndMergeCommand(owner, repo, secondPrId, secondBranchName);

            // Mock Github cal
            var updateBranchCallId = await MockGithubCall("post", MergesUrlFor(owner, repo), "ok", false);

            await MockRepoConfigGithubCallHelper.MockRepoConfigGithubCall(owner, repo, "strategyNone.yml");

            await MockRequiredChecksGithubCallHelper.MockRequiredChecks(owner, repo);

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

            // ASSERT
            var updateBranchCall = await GetCall(updateBranchCallId);

            Assert.False(updateBranchCall.HasBeenMade, "update branch call should not have been made");
        }