-
Notifications
You must be signed in to change notification settings - Fork 0
feat: fetch commits from pull request #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
26e39ae
feat (WIP): fetchCommitsFromPullRequest Use Case
3a57e29
Merge branch 'main' into feat/fetch_commits_from_pullrequest
4d4d198
feat: tests passing
bec32f5
fix: remove unnecessary comments
mikededo 1d1f8cb
fix: parsing nested date from commit response
mikededo e43a6d7
Merge branch 'main' into feat/fetch_commits_from_pullrequest
mikededo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/io/pakland/mdas/githubstats/application/FetchCommitsFromPullRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package io.pakland.mdas.githubstats.application; | ||
|
|
||
| import io.pakland.mdas.githubstats.application.exceptions.HttpException; | ||
| import io.pakland.mdas.githubstats.domain.Commit; | ||
| import io.pakland.mdas.githubstats.domain.repository.CommitExternalRepository; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class FetchCommitsFromPullRequest { | ||
| private final CommitExternalRepository commitExternalRepository; | ||
|
|
||
| public FetchCommitsFromPullRequest(CommitExternalRepository commitExternalRepository) { | ||
| this.commitExternalRepository = commitExternalRepository; | ||
| } | ||
|
|
||
| public List<Commit> execute(String repositoryOwner, String repositoryName, Integer pullRequestNumber) throws HttpException { | ||
| int page = 1; | ||
| List<Commit> commitList = new ArrayList<>(); | ||
| int responseResults; | ||
| do { | ||
| CommitExternalRepository.FetchCommitsFromPullRequestRequest request = CommitExternalRepository.FetchCommitsFromPullRequestRequest.builder() | ||
| .repositoryOwner(repositoryOwner) | ||
| .repositoryName(repositoryName) | ||
| .pullRequestNumber(pullRequestNumber) | ||
| .page(page) | ||
| .perPage(100) | ||
| .build(); | ||
| List<Commit> apiResults = this.commitExternalRepository.fetchCommitsFromPullRequest( | ||
| request); | ||
|
|
||
| commitList.addAll(apiResults); | ||
| responseResults = apiResults.size(); | ||
| page++; | ||
| } while (responseResults > 0); | ||
|
|
||
| return commitList; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/io/pakland/mdas/githubstats/domain/repository/CommitExternalRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package io.pakland.mdas.githubstats.domain.repository; | ||
|
|
||
| import io.pakland.mdas.githubstats.application.exceptions.HttpException; | ||
| import io.pakland.mdas.githubstats.domain.Commit; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface CommitExternalRepository { | ||
| List<Commit> fetchCommitsFromPullRequest(FetchCommitsFromPullRequestRequest request) throws HttpException; | ||
|
|
||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Builder | ||
| @Getter | ||
| public static class FetchCommitsFromPullRequestRequest { | ||
| private String repositoryOwner; | ||
| private String repositoryName; | ||
| private Integer pullRequestNumber; | ||
| private Integer page; | ||
| private Integer perPage; | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
.../io/pakland/mdas/githubstats/infrastructure/github/repository/CommitGitHubRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package io.pakland.mdas.githubstats.infrastructure.github.repository; | ||
|
|
||
| import io.pakland.mdas.githubstats.application.exceptions.HttpException; | ||
| import io.pakland.mdas.githubstats.domain.Commit; | ||
| import io.pakland.mdas.githubstats.domain.repository.CommitExternalRepository; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.web.reactive.function.client.WebClientResponseException; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class CommitGitHubRepository implements CommitExternalRepository { | ||
| private final WebClientConfiguration webClientConfiguration; | ||
| private final Logger logger = LoggerFactory.getLogger(CommitGitHubRepository.class); | ||
|
|
||
| public CommitGitHubRepository(WebClientConfiguration webClientConfiguration) { | ||
| this.webClientConfiguration = webClientConfiguration; | ||
| } | ||
|
|
||
| @Override | ||
| public List<Commit> fetchCommitsFromPullRequest(FetchCommitsFromPullRequestRequest request) throws HttpException { | ||
|
|
||
| try { | ||
| return this.webClientConfiguration.getWebClient().get() | ||
| .uri(String.format("/repos/%s/%s/pulls/%s/commits?%s", request.getRepositoryOwner(), | ||
| request.getRepositoryName(), request.getPullRequestNumber(), getRequestParams(request))) | ||
| .retrieve() | ||
| .bodyToFlux(Commit.class) | ||
| .collectList() | ||
| .block(); | ||
| } catch (WebClientResponseException ex) { | ||
| logger.error(ex.toString()); | ||
| throw new HttpException(ex.getRawStatusCode(), ex.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| private String getRequestParams(FetchCommitsFromPullRequestRequest request) { | ||
| return String.format("per_page=%d&page=%d", request.getPerPage(), request.getPage() < 0 ? 1 : request.getPage()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.