Beispiel #1
0
        private IDisposable WithExistingPullRequest(SynchronizePullRequestResult checkResult)
        {
            AfterDbUpdateActions.Add(() =>
            {
                var pr = new InProgressPullRequest
                {
                    Url = InProgressPrUrl,
                    ContainedSubscriptions = new List <SubscriptionPullRequestUpdate>
                    {
                        new SubscriptionPullRequestUpdate
                        {
                            BuildId        = -1,
                            SubscriptionId = Subscription.Id
                        }
                    },
                    RequiredUpdates = new List <DependencyUpdateSummary>
                    {
                        new DependencyUpdateSummary
                        {
                            DependencyName = "Ham",
                            FromVersion    = "1.0.0-beta.1",
                            ToVersion      = "1.0.1-beta.1"
                        },
                        new DependencyUpdateSummary
                        {
                            DependencyName = "Ham",
                            FromVersion    = "1.0.0-beta.1",
                            ToVersion      = "1.0.1-beta.1"
                        },
                    }
                };
                StateManager.SetStateAsync(PullRequestActorImplementation.PullRequest, pr);
                ExpectedActorState.Add(PullRequestActorImplementation.PullRequest, pr);
            });

            ActionRunner.Setup(r => r.ExecuteAction(It.IsAny <Expression <Func <Task <ActionResult <SynchronizePullRequestResult> > > > >()))
            .ReturnsAsync(checkResult);

            if (checkResult == SynchronizePullRequestResult.InProgressCanUpdate)
            {
                DarcRemotes.GetOrAddValue(TargetRepo, CreateMock <IRemote>)
                .Setup(r => r.GetPullRequestAsync(InProgressPrUrl))
                .ReturnsAsync(
                    new PullRequest
                {
                    HeadBranch = InProgressPrHeadBranch,
                    BaseBranch = TargetBranch
                });
            }

            return(Disposable.Create(
                       () =>
            {
                ActionRunner.Verify(r => r.ExecuteAction(It.IsAny <Expression <Func <Task <ActionResult <SynchronizePullRequestResult> > > > >()));
                if (checkResult == SynchronizePullRequestResult.InProgressCanUpdate)
                {
                    DarcRemotes[TargetRepo].Verify(r => r.GetPullRequestAsync(InProgressPrUrl));
                }
            }));
        }
Beispiel #2
0
        public async Task MultipleBuildsIncluded()
        {
            // Scenario where a bunch of commits / builds are included in the same non-batched, single subscription PR
            var testObject = GetInstance();
            InProgressPullRequest prToTag = GetInProgressPullRequest("https://api.github.com/repos/orgname/reponame/pulls/12345", 2);

            await testObject.TagSourceRepositoryGitHubContactsAsync(prToTag);

            prToTag.SourceRepoNotified.Should().BeTrue();

            // Second time; no second comment should be made. (If it were made, it'd throw)
            await testObject.TagSourceRepositoryGitHubContactsAsync(prToTag);

            PrCommentsMade.Count.Should().Be(1);
            // Spot check some values
            PrCommentsMade[$"{FakeOrgName}/{FakeRepoName}/12345"].Should().Contain(
                $"Notification for subscribed users from https://github.com/{FakeOrgName}/source-repo1");
            foreach (string individual in FakeSubscriptions[0].PullRequestFailureNotificationTags.Split(';', StringSplitOptions.RemoveEmptyEntries))
            {
                // Make sure normalization happens; test includes a user without @.
                string valueToCheck = individual;
                if (!individual.StartsWith('@'))
                {
                    valueToCheck = $"@{valueToCheck}";
                }

                PrCommentsMade[$"{FakeOrgName}/{FakeRepoName}/12345"].Should().Contain(valueToCheck);
            }
        }
Beispiel #3
0
        public async Task NotifyACheckFailed()
        {
            // Happy Path: Successfully create a comment, try to do it again, ensure it does not happen.
            var testObject = GetInstance();
            InProgressPullRequest prToTag = GetInProgressPullRequest("https://api.github.com/repos/orgname/reponame/pulls/12345");

            await testObject.TagSourceRepositoryGitHubContactsAsync(prToTag);

            prToTag.SourceRepoNotified.Should().BeTrue();

            // Second time; no second comment should be made. (If it were made, it'd throw)
            await testObject.TagSourceRepositoryGitHubContactsAsync(prToTag);

            PrCommentsMade.Count.Should().Be(1);
            // Spot check some values
            PrCommentsMade[$"{FakeOrgName}/{FakeRepoName}/12345"].Should().Contain(
                $"Notification for subscribed users from https://github.com/{FakeOrgName}/source-repo1");
            foreach (string individual in FakeSubscriptions[0].PullRequestFailureNotificationTags.Split(';', StringSplitOptions.RemoveEmptyEntries))
            {
                // Make sure normalization happens; test includes a user without @.
                string valueToCheck = individual;
                if (!individual.StartsWith('@'))
                {
                    valueToCheck = $"@{valueToCheck}";
                }

                PrCommentsMade[$"{FakeOrgName}/{FakeRepoName}/12345"].Should().Contain(valueToCheck);
            }
        }
Beispiel #4
0
        public async Task NoContactAliasesProvided()
        {
            // "Do nothing" Path: Just don't blow up when a subscription object has no tags.
            var testObject = GetInstance();
            InProgressPullRequest prToTag = GetInProgressPullRequestWithoutTags("https://api.github.com/repos/orgname/reponame/pulls/23456");
            await testObject.TagSourceRepositoryGitHubContactsAsync(prToTag);

            prToTag.SourceRepoNotified.Should().BeFalse();
            PrCommentsMade.Count.Should().Be(0);
        }
Beispiel #5
0
        public async Task OnlyMaestroChecksHaveFailedOrErrored()
        {
            // Checks like "all checks succeeded" stay in a failed state until all the other checks, err, succeed.
            // Ensure we don't just go tag everyone's automerge PRs.
            var testObject = GetInstance();
            InProgressPullRequest prToTag = GetInProgressPullRequest("https://api.github.com/repos/orgname/reponame/pulls/67890", 1);

            await testObject.TagSourceRepositoryGitHubContactsAsync(prToTag);

            prToTag.SourceRepoNotified.Should().BeFalse();
            PrCommentsMade.Count.Should().Be(0);
        }
        private IDisposable WithExistingPullRequest(bool updatable)
        {
            var pr = new InProgressPullRequest
            {
                Url = InProgressPrUrl,
                ContainedSubscriptions = new List <SubscriptionPullRequestUpdate>
                {
                    new SubscriptionPullRequestUpdate
                    {
                        BuildId        = -1,
                        SubscriptionId = Subscription.Id
                    }
                }
            };

            StateManager.SetStateAsync(PullRequestActorImplementation.PullRequest, pr);
            ExpectedActorState.Add(PullRequestActorImplementation.PullRequest, pr);

            ActionRunner.Setup(r => r.ExecuteAction(It.IsAny <Expression <Func <Task <ActionResult <bool?> > > > >()))
            .ReturnsAsync(updatable);

            if (updatable)
            {
                DarcRemotes.GetOrAddValue(TargetRepo, CreateMock <IRemote>)
                .Setup(r => r.GetPullRequestAsync(InProgressPrUrl))
                .ReturnsAsync(
                    new PullRequest
                {
                    HeadBranch = InProgressPrHeadBranch,
                    BaseBranch = TargetBranch
                });
            }

            return(Disposable.Create(
                       () =>
            {
                ActionRunner.Verify(r => r.ExecuteAction(It.IsAny <Expression <Func <Task <ActionResult <bool?> > > > >()));
                if (updatable)
                {
                    DarcRemotes[TargetRepo].Verify(r => r.GetPullRequestAsync(InProgressPrUrl));
                }
            }));
        }