Skip to content

Commit

Permalink
Prettify into functional approach
Browse files Browse the repository at this point in the history
  • Loading branch information
GODrums committed Sep 4, 2024
1 parent 1806b17 commit 6f7424a
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,18 @@ public Repository fetchRepository(String nameWithOwner) throws IOException {
// preliminary save to make it referenceable
repositoryRepository.save(repository);

Set<PullRequest> prs = getPullRequestsFromGHRepository(ghRepo, repository);
repository.setPullRequests(prs);
pullRequestRepository.saveAll(prs);

repositoryRepository.save(repository);
return repository;
}

private Set<PullRequest> getPullRequestsFromGHRepository(GHRepository ghRepo, Repository repository)
throws IOException {
// Retrieve PRs in pages of 10
Set<PullRequest> prs = ghRepo.queryPullRequests().list().withPageSize(10).toList().stream().map(pr -> {
return ghRepo.queryPullRequests().list().withPageSize(10).toList().stream().map(pr -> {
PullRequest pullRequest = pullRequestConverter.convert(pr);
pullRequest.setRepository(repository);
pullRequestRepository.save(pullRequest);
Expand Down Expand Up @@ -156,11 +166,6 @@ public Repository fetchRepository(String nameWithOwner) throws IOException {

return pullRequest;
}).collect(Collectors.toSet());
repository.setPullRequests(prs);
pullRequestRepository.saveAll(prs);

repositoryRepository.save(repository);
return repository;
}

/**
Expand All @@ -173,7 +178,7 @@ public Repository fetchRepository(String nameWithOwner) throws IOException {
*/
private Set<IssueComment> getCommentsFromGHPullRequest(GHPullRequest pr, PullRequest pullRequest)
throws IOException {
Set<IssueComment> comments = pr.queryComments().list().toList().stream()
return pr.queryComments().list().toList().stream()
.map(comment -> {
IssueComment c = commentConverter.convert(comment);
c.setPullRequest(pullRequest);
Expand All @@ -188,7 +193,6 @@ private Set<IssueComment> getCommentsFromGHPullRequest(GHPullRequest pr, PullReq
c.setAuthor(commentAuthor);
return c;
}).collect(Collectors.toSet());
return comments;
}

private User getUserFromGHUser(org.kohsuke.github.GHUser user) {
Expand Down

0 comments on commit 6f7424a

Please sign in to comment.