Ejemplo n.º 1
0
        public async Task ShouldNotCreateIssue(string repoUrl, string branch, string method, string arguments, DateTime errorOccurredAt, bool success)
        {
            // Not testing SubscriptionUpdateHistoryEntry since this is always "no" for them.
            RepositoryBranchUpdateHistoryEntry repositoryBranchUpdate =
                new RepositoryBranchUpdateHistoryEntry
            {
                Repository = repoUrl,
                Branch     = branch,
                Method     = method,
                Timestamp  = errorOccurredAt,
                Arguments  = arguments,
                Success    = success
            };
            Repository repository = new Repository();

            GithubClient.Setup(x => x.Repository.Get(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(repository);
            Maestro.Data.Models.Subscription subscription = new Maestro.Data.Models.Subscription();
            Context.Subscriptions.Add(subscription);
            Context.SaveChanges();
            Mock <Issue> issue = new Mock <Issue>();

            GithubClient.Setup(x => x.Issue.Create(It.IsAny <long>(), It.IsAny <NewIssue>())).ReturnsAsync(issue.Object);
            Context.RepoBranchUpdateInMemory = new List <RepositoryBranchUpdateHistoryEntry>
            {
                repositoryBranchUpdate
            };
            DependencyUpdateErrorProcessor errorProcessor =
                ActivatorUtilities.CreateInstance <DependencyUpdateErrorProcessor>(Scope.ServiceProvider,
                                                                                   Context);
            await errorProcessor.ProcessDependencyUpdateErrorsAsync();

            GithubClient.Verify(x => x.Issue.Create(It.IsAny <long>(), It.IsAny <NewIssue>()), Times.Never);
        }
Ejemplo n.º 2
0
 private Subscription ToClientModelSubscription(Maestro.Data.Models.Subscription other)
 {
     return(new Subscription(
                other.Id,
                other.Enabled,
                other.SourceRepository,
                other.TargetRepository,
                other.TargetBranch)
     {
         Channel = ToClientModelChannel(other.Channel),
         Policy = ToClientModelSubscriptionPolicy(other.PolicyObject)
     });
 }
Ejemplo n.º 3
0
 private Subscription ToClientModelSubscription(Maestro.Data.Models.Subscription other)
 {
     return(new Subscription(
                other.Id,
                other.Enabled,
                other.SourceRepository,
                other.TargetRepository,
                other.TargetBranch)
     {
         Channel = ToClientModelChannel(other.Channel),
         Policy = ToClientModelSubscriptionPolicy(other.PolicyObject),
         LastAppliedBuild = other.LastAppliedBuild != null?ToClientModelBuild(other.LastAppliedBuild) : null
     });
 }
Ejemplo n.º 4
0
        public async Task CreateIssueAndUpdateComment()
        {
            const string AnotherMethod = "ProcessPendingUpdatesAsync";
            RepositoryBranchUpdateHistoryEntry firstError =
                new RepositoryBranchUpdateHistoryEntry
            {
                Repository   = RepoUrl,
                Branch       = Branch,
                Method       = MethodName,
                Timestamp    = new DateTime(2200, 1, 1),
                Arguments    = $"[\"{SubscriptionId}\",\"{MethodName}\",\"{ErrorMessage}\"]",
                Success      = false,
                ErrorMessage = ErrorMessage,
                Action       = "Creating new issue"
            };
            RepositoryBranchUpdateHistoryEntry secondError =
                new RepositoryBranchUpdateHistoryEntry
            {
                Repository   = RepoUrl,
                Branch       = Branch,
                Method       = AnotherMethod,
                Timestamp    = new DateTime(2200, 2, 1),
                Arguments    = "ProcessPendingUpdatesAsync error",
                Success      = false,
                ErrorMessage = ErrorMessage,
                Action       = "Create a new issue comment",
            };

            RepositoryBranchUpdateHistoryEntry thirdError =
                new RepositoryBranchUpdateHistoryEntry
            {
                Repository   = RepoUrl,
                Branch       = Branch,
                Method       = AnotherMethod,
                Timestamp    = new DateTime(2200, 3, 1),
                Arguments    = "ProcessPendingUpdatesAsync arguments",
                Success      = false,
                ErrorMessage = ErrorMessage,
                Action       = "Update the comment",
            };

            Context.RepoBranchUpdateInMemory = new List <RepositoryBranchUpdateHistoryEntry>
            {
                firstError, secondError, thirdError
            };
            Maestro.Data.Models.Subscription subscription = new Maestro.Data.Models.Subscription
            {
                Id = Guid.Parse(SubscriptionId),
                SourceRepository = "Source Repo",
                TargetRepository = "Target Repo",
            };
            Context.Subscriptions.Add(subscription);
            Context.SaveChanges();
            Repository repository = new Repository();

            GithubClient.Setup(x => x.Repository.Get(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(repository);
            Issue updateIssue = GetIssue();

            Octokit.AuthorAssociation author = new Octokit.AuthorAssociation();
            string       nodeId  = "1";
            IssueComment comment = new IssueComment
                                   (
                1,
                nodeId,
                "Url",
                "htmlUrl",
                $"[marker]: <> (subscriptionId: '', method: '{AnotherMethod}', errorMessage: '{ErrorMessage}')",
                new DateTime(2200, 02, 02),
                new DateTime(2200, 03, 01),
                new User(),
                new ReactionSummary(),
                author);
            List <IssueComment> issueComment = new List <IssueComment> {
                comment
            };
            List <NewIssue> newIssues      = new List <NewIssue>();
            List <string>   newCommentInfo = new List <string>();

            GithubClient.Setup(x => x.Issue.Create(It.IsAny <long>(), Capture.In(newIssues))).ReturnsAsync(updateIssue);
            GithubClient.Setup(x => x.Issue.Get(RepoId, IssueNumber)).ReturnsAsync(updateIssue);
            GithubClient.Setup(x => x.Issue.Comment.GetAllForIssue(RepoId, IssueNumber)).ReturnsAsync(issueComment);
            GithubClient.Setup(x => x.Issue.Comment.Create(RepoId, IssueNumber, Capture.In(newCommentInfo))).ReturnsAsync(comment);
            GithubClient.Setup(x => x.Issue.Comment.Update(RepoId, CommentId, Capture.In(newCommentInfo)))
            .ReturnsAsync(comment);
            DependencyUpdateErrorProcessor errorProcessor =
                ActivatorUtilities.CreateInstance <DependencyUpdateErrorProcessor>(Scope.ServiceProvider,
                                                                                   Context);
            await errorProcessor.ProcessDependencyUpdateErrorsAsync();

            newIssues.Should().ContainSingle();
            newIssues[0].Labels[0].Should().Be("DependencyUpdateError");
            newIssues[0].Body.Should().Contain(RepoUrl);
            newIssues[0].Body.Should().Contain(SubscriptionId);
            newCommentInfo[0].Should().Contain(AnotherMethod);
            newCommentInfo[0].Should().NotContain(SubscriptionId);
            newCommentInfo[0].Should().Contain("2/1/2200 12:00:00 AM");
            newCommentInfo[1].Should().Contain(AnotherMethod);
            newCommentInfo[1].Should().Contain("3/1/2200 12:00:00 AM");
            newCommentInfo[1].Should().NotContain(SubscriptionId);
        }