@Test public void postsGithubComment() { final RequestClaimableEvent event = new RequestClaimableEvent(RequestDtoMother.freeCodeCampNoUserStories(), LocalDateTime.now()); final String expectedMessage = "ytufg"; final RequestDto request = event.getRequestDto(); final IssueInformationDto issueInformation = request.getIssueInformation(); final String solver = "gdhfjghiuyutfyd"; final ArgumentCaptor<CreateGithubComment> createGithubCommentArgumentCaptor = ArgumentCaptor.forClass(CreateGithubComment.class); when(githubScraper.fetchGithubIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber())).thenReturn(GithubIssue.builder() .solver(solver) .build()); when(githubCommentFactory.createResolvedComment(request.getId(), solver)).thenReturn(expectedMessage); handler.createGithubCommentOnRequestClaimable(event); verify(githubGateway).createCommentOnIssue(eq(issueInformation.getOwner()), eq(issueInformation.getRepo()), eq(issueInformation.getNumber()), createGithubCommentArgumentCaptor.capture()); assertThat(createGithubCommentArgumentCaptor.getValue().getBody()).isEqualTo(expectedMessage); }
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) public void createGithubCommentOnRequestClaimable(final RequestClaimableEvent event) { if (addComment) { final RequestDto request = event.getRequestDto(); final IssueInformationDto issueInformation = request.getIssueInformation(); if (issueInformation.getPlatform() == Platform.GITHUB) { final String solver = Optional.ofNullable(githubScraper.fetchGithubIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber()).getSolver()) .orElseThrow(() -> new RuntimeException("No solver found for request " + request.getId())); final CreateGithubComment comment = new CreateGithubComment(); comment.setBody(githubCommentFactory.createResolvedComment(request.getId(), solver)); githubGateway.createCommentOnIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber(), comment); } } }
CreateGithubCommentOnResolvedHandler { @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) public void createGithubCommentOnRequestClaimable(final RequestClaimableEvent event) { if (addComment) { final RequestDto request = event.getRequestDto(); final IssueInformationDto issueInformation = request.getIssueInformation(); if (issueInformation.getPlatform() == Platform.GITHUB) { final String solver = Optional.ofNullable(githubScraper.fetchGithubIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber()).getSolver()) .orElseThrow(() -> new RuntimeException("No solver found for request " + request.getId())); final CreateGithubComment comment = new CreateGithubComment(); comment.setBody(githubCommentFactory.createResolvedComment(request.getId(), solver)); githubGateway.createCommentOnIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber(), comment); } } } }
CreateGithubCommentOnResolvedHandler { @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) public void createGithubCommentOnRequestClaimable(final RequestClaimableEvent event) { if (addComment) { final RequestDto request = event.getRequestDto(); final IssueInformationDto issueInformation = request.getIssueInformation(); if (issueInformation.getPlatform() == Platform.GITHUB) { final String solver = Optional.ofNullable(githubScraper.fetchGithubIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber()).getSolver()) .orElseThrow(() -> new RuntimeException("No solver found for request " + request.getId())); final CreateGithubComment comment = new CreateGithubComment(); comment.setBody(githubCommentFactory.createResolvedComment(request.getId(), solver)); githubGateway.createCommentOnIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber(), comment); } } } CreateGithubCommentOnResolvedHandler(final GithubGateway githubGateway,
                                                final GithubScraper githubScraper,
                                                final GithubCommentFactory githubCommentFactory,
                                                @Value("${github.add-comments:false}") final Boolean addComment); }
CreateGithubCommentOnResolvedHandler { @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) public void createGithubCommentOnRequestClaimable(final RequestClaimableEvent event) { if (addComment) { final RequestDto request = event.getRequestDto(); final IssueInformationDto issueInformation = request.getIssueInformation(); if (issueInformation.getPlatform() == Platform.GITHUB) { final String solver = Optional.ofNullable(githubScraper.fetchGithubIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber()).getSolver()) .orElseThrow(() -> new RuntimeException("No solver found for request " + request.getId())); final CreateGithubComment comment = new CreateGithubComment(); comment.setBody(githubCommentFactory.createResolvedComment(request.getId(), solver)); githubGateway.createCommentOnIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber(), comment); } } } CreateGithubCommentOnResolvedHandler(final GithubGateway githubGateway,
                                                final GithubScraper githubScraper,
                                                final GithubCommentFactory githubCommentFactory,
                                                @Value("${github.add-comments:false}") final Boolean addComment); @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) void createGithubCommentOnRequestClaimable(final RequestClaimableEvent event); }
CreateGithubCommentOnResolvedHandler { @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) public void createGithubCommentOnRequestClaimable(final RequestClaimableEvent event) { if (addComment) { final RequestDto request = event.getRequestDto(); final IssueInformationDto issueInformation = request.getIssueInformation(); if (issueInformation.getPlatform() == Platform.GITHUB) { final String solver = Optional.ofNullable(githubScraper.fetchGithubIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber()).getSolver()) .orElseThrow(() -> new RuntimeException("No solver found for request " + request.getId())); final CreateGithubComment comment = new CreateGithubComment(); comment.setBody(githubCommentFactory.createResolvedComment(request.getId(), solver)); githubGateway.createCommentOnIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber(), comment); } } } CreateGithubCommentOnResolvedHandler(final GithubGateway githubGateway,
                                                final GithubScraper githubScraper,
                                                final GithubCommentFactory githubCommentFactory,
                                                @Value("${github.add-comments:false}") final Boolean addComment); @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) void createGithubCommentOnRequestClaimable(final RequestClaimableEvent event);  }