public async Task PRNeedsMergeGradesAccepted(string commentText, bool gradesExpected, CommentType commentType)
        {
            var gitHubMock = GitHubClientMockFactory.CreateDefault()
                             .WithOrganizationMemberGet("abcabc", true)
                             .WithPullRequestGet(336882879, 24, GitHubMockData.CreatePullRequest(24, Octokit.ItemState.Open, mergeable: true))
                             .WithNeptunTxtContent("NEPT12");
            var gradeStoreMock = GradeStoreMockFactory.Create();

            var eh     = createHandler(commentType, gitHubMock.CreateFactory(), gradeStoreMock.Object);
            var result = await eh.Execute(getPayloadWithComment(commentType, commentText));

            Assert.IsTrue(result.Result.Contains("grade done", System.StringComparison.InvariantCultureIgnoreCase));
            gitHubMock.GitHubClientMock.Verify(c =>
                                               c.PullRequest.Review.Create(336882879, 24, It.IsAny <Octokit.PullRequestReviewCreate>()),
                                               Times.Once());
            gitHubMock.GitHubClientMock.Verify(c =>
                                               c.PullRequest.Merge(336882879, 24, It.IsAny <Octokit.MergePullRequest>()),
                                               Times.Once());

            gradeStoreMock.Verify(c =>
                                  c.StoreGrade("NEPT12", "org1/repo1", 24, "https://www.github.com/org1/repo1/pull/24", It.IsAny <string>(), @"https://github.com/org1/repo1/pull/1#issuecomment-821112111", It.IsAny <IReadOnlyCollection <double> >()),
                                  gradesExpected ? Times.Once() : Times.Never());
            gradeStoreMock.Verify(c =>
                                  c.ConfirmAutoGrade("NEPT12", "org1/repo1", 24, "https://www.github.com/org1/repo1/pull/24", It.IsAny <string>(), @"https://github.com/org1/repo1/pull/1#issuecomment-821112111"),
                                  gradesExpected ? Times.Never() : Times.Once());
        }
        public async Task OtherClosedPullRequestYieldsWarning()
        {
            var gitHubMock = GitHubClientMockFactory.CreateDefault()
                             .WithPullRequestGetAll(c => c.ReturnsAsync(new[]
            {
                GitHubMockData.CreatePullRequest(189, Octokit.ItemState.Open, 556677),
                GitHubMockData.CreatePullRequest(23, Octokit.ItemState.Closed, 556677),
            }))
                             .WithIssueEventGetAll(c => c.ReturnsAsync(new[] { GitHubMockData.CreateIssueEvent(Octokit.EventInfoState.Closed, 444444) }));

            var eh     = new PullRequestOpenDuplicateHandler(gitHubMock.CreateFactory(), MemoryCacheMockFactory.Instance, NullLogger.Instance);
            var result = await eh.Execute(SampleData.PrOpen);

            Assert.IsTrue(result.Result.Contains("already closed PRs", System.StringComparison.InvariantCultureIgnoreCase));
            gitHubMock.GitHubClientMock.Verify(c =>
                                               c.Issue.Comment.Create(339316008, 189, It.IsAny <string>()),
                                               Times.Once());
        }
        public async Task PRAlreadyClosedGradesAccepted(CommentType commentType)
        {
            var gitHubMock = GitHubClientMockFactory.CreateDefault()
                             .WithOrganizationMemberGet("abcabc", true)
                             .WithPullRequestGet(336882879, 24, GitHubMockData.CreatePullRequest(24, Octokit.ItemState.Closed, mergeable: false));
            var gradeStoreMock = GradeStoreMockFactory.Create();

            var eh     = createHandler(commentType, gitHubMock.CreateFactory(), gradeStoreMock.Object);
            var result = await eh.Execute(getPayloadWithComment(commentType, @"/ahk ok"));

            Assert.IsTrue(result.Result.Contains("grade done", System.StringComparison.InvariantCultureIgnoreCase));
            gitHubMock.GitHubClientMock.Verify(c =>
                                               c.PullRequest.Merge(It.IsAny <long>(), It.IsAny <int>(), It.IsAny <Octokit.MergePullRequest>()),
                                               Times.Never());
            gradeStoreMock.Verify(c =>
                                  c.StoreGrade(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <IReadOnlyCollection <double> >()),
                                  Times.Never());
            gradeStoreMock.Verify(c =>
                                  c.ConfirmAutoGrade("ABC123", "org1/repo1", 24, "https://www.github.com/org1/repo1/pull/24", It.IsAny <string>(), @"https://github.com/org1/repo1/pull/1#issuecomment-821112111"),
                                  Times.Once());
        }
        public async Task WorkflowRunsReachedWarningLimit()
        {
            var gitHubMock = GitHubClientMockFactory.CreateDefault();

            var payload = getPayload();
            var gh      = gitHubMock
                          .WithWorkflowRunsCount("aabbcc", "reporep", "someone", 6)
                          .WithPullRequestGetAll(c => c.ReturnsAsync(new[]
            {
                GitHubMockData.CreatePullRequest(1, Octokit.ItemState.Open, 111),
                GitHubMockData.CreatePullRequest(2, Octokit.ItemState.Open, 111),
            }))
                          .CreateFactory();

            var eh     = new ActionWorkflowRunHandler(gh, MemoryCacheMockFactory.Instance, NullLogger.Instance);
            var result = await eh.Execute(payload);

            Assert.IsTrue(result.Result.Contains("workflow_run warning, threshold exceeded", System.StringComparison.InvariantCultureIgnoreCase));
            gitHubMock.GitHubClientMock.Verify(c =>
                                               c.Issue.Comment.Create(283462325, 2, It.IsAny <string>()),
                                               Times.Once());
        }
예제 #5
0
        public async Task AhkMonitorConfigYamlInvalid()
        {
            var gitHubMock = GitHubClientMockFactory.CreateCustom()
                             .WithAhkMonitorConfigYamlContent(c => c.ReturnsAsync(new[] { GitHubMockData.CreateAhkMonitorYamlFileContent("not valid content") }));

            var eh     = new TestHandler(gitHubMock.CreateFactory(), MemoryCacheMockFactory.Instance);
            var result = await eh.Execute(SampleData.BranchCreate.Body);

            Assert.IsTrue(result.Result.Contains("no ahk-monitor.yml or disabled", System.StringComparison.InvariantCultureIgnoreCase));
            gitHubMock.GitHubClientMock.Verify(c =>
                                               c.Repository.Content.GetAllContentsByRef(It.IsAny <long>(), ".github/ahk-monitor.yml", It.IsAny <string>()),
                                               Times.Once());
        }
예제 #6
0
 public GitHubClientMockFactory WithNeptunTxtContent(string content)
 {
     repoContentClient.Setup(c => c.GetAllContentsByRef(It.IsAny <long>(), "neptun.txt", It.IsAny <string>())).ReturnsAsync(new[] { GitHubMockData.CreateNeptunTxtFileContent(content) });
     return(this);
 }
예제 #7
0
 public GitHubClientMockFactory WithDefaultAhkMonitorConfigYamlContent()
 => WithAhkMonitorConfigYamlContent(c => c.ReturnsAsync(new[] { GitHubMockData.CreateAhkMonitorYamlFileContent() }));