66import io .pakland .mdas .githubstats .domain .repository .*;
77import io .pakland .mdas .githubstats .infrastructure .github .model .GitHubUserOptionRequest ;
88import io .pakland .mdas .githubstats .infrastructure .github .repository .*;
9- import java .util .List ;
109import lombok .NoArgsConstructor ;
1110import org .slf4j .Logger ;
1211import org .slf4j .LoggerFactory ;
1312import org .springframework .stereotype .Component ;
1413
14+ import java .util .List ;
15+
1516@ Component
1617@ NoArgsConstructor
1718public class GitHubUserController {
@@ -23,38 +24,39 @@ public class GitHubUserController {
2324 private RepositoryExternalRepository repositoryExternalRepository ;
2425 private PullRequestExternalRepository pullRequestExternalRepository ;
2526 private CommitExternalRepository commitExternalRepository ;
27+ private ReviewExternalRepository reviewExternalRepository ;
2628 private CommentExternalRepository commentExternalRepository ;
2729
2830
2931 public GitHubUserController (GitHubUserOptionRequest userOptionRequest ) {
3032 WebClientConfiguration webClientConfiguration = new WebClientConfiguration (
31- "https://api.github.com" , userOptionRequest .getApiKey ());
33+ "https://api.github.com" , userOptionRequest .getApiKey ());
3234 this .organizationExternalRepository = new OrganizationGitHubRepository (
33- webClientConfiguration );
35+ webClientConfiguration );
3436 this .teamExternalRepository = new TeamGitHubRepository (webClientConfiguration );
3537 this .userExternalRepository = new UserGitHubRepository (webClientConfiguration );
3638 this .repositoryExternalRepository = new RepositoryGitHubRepository (webClientConfiguration );
3739 this .pullRequestExternalRepository = new PullRequestGitHubRepository (
38- webClientConfiguration );
40+ webClientConfiguration );
3941 this .organizationExternalRepository = new OrganizationGitHubRepository (
40- webClientConfiguration );
42+ webClientConfiguration );
4143 this .teamExternalRepository = new TeamGitHubRepository (webClientConfiguration );
4244 this .userExternalRepository = new UserGitHubRepository (webClientConfiguration );
4345 this .repositoryExternalRepository = new RepositoryGitHubRepository (webClientConfiguration );
4446 this .pullRequestExternalRepository = new PullRequestGitHubRepository (
45- webClientConfiguration );
47+ webClientConfiguration );
4648 this .commitExternalRepository = new CommitGitHubRepository (webClientConfiguration );
49+ this .reviewExternalRepository = new ReviewGitHubRepository (webClientConfiguration );
4750 this .commentExternalRepository = new CommentGitHubRepository (webClientConfiguration );
48-
4951 }
5052
5153 public void execute () {
5254 try {
5355 // TODO: If the execution succeeds, we should make an entry to the historic_queries table.
5456 // Fetch the API key's available organizations.
5557 List <Organization > organizationList = new FetchAvailableOrganizations (
56- this .organizationExternalRepository )
57- .execute ();
58+ this .organizationExternalRepository )
59+ .execute ();
5860 organizationList .forEach (this ::fetchTeamsFromOrganization );
5961 } catch (HttpException e ) {
6062 throw new RuntimeException (e );
@@ -64,7 +66,7 @@ public void execute() {
6466 private void fetchTeamsFromOrganization (Organization organization ) {
6567 try {
6668 List <Team > teamList = new FetchTeamsFromOrganization (teamExternalRepository )
67- .execute (organization );
69+ .execute (organization );
6870 teamList .forEach (team -> {
6971 this .fetchRepositoriesFromTeam (team );
7072 this .fetchUsersFromTeam (team );
@@ -78,7 +80,7 @@ private void fetchRepositoriesFromTeam(Team team) {
7880 try {
7981 // Fetch the repositories for each team.
8082 List <Repository > repositoryList = new FetchRepositoriesFromTeam (
81- repositoryExternalRepository ).execute (team );
83+ repositoryExternalRepository ).execute (team );
8284 // Add the team to the repository
8385 repositoryList .forEach (this ::fetchPullRequestsFromRepository );
8486 } catch (HttpException e ) {
@@ -99,33 +101,44 @@ private void fetchPullRequestsFromRepository(Repository repository) {
99101 try {
100102 // Fetch pull requests from each team.
101103 List <PullRequest > pullRequestList = new FetchPullRequestsFromRepository (
102- pullRequestExternalRepository )
103- .execute (repository );
104+ pullRequestExternalRepository )
105+ .execute (repository );
104106
105- pullRequestList .forEach (this ::fetchCommitsFromPullRequest );
107+ pullRequestList .forEach (pullRequest -> {
108+ this .fetchCommitsFromPullRequest (pullRequest );
109+ this .fetchReviewsFromPullRequest (pullRequest );
110+ this .fetchCommentsFromPullRequest (pullRequest );
111+ });
106112 } catch (HttpException e ) {
107113 throw new RuntimeException (e );
108114 }
109115 }
110116
111117 private void fetchCommitsFromPullRequest (PullRequest pullRequest ) {
112- /*
113- TODO: if the user of the PR belongs to the team, increment the prs executed inside the team
114- TODO: else increment the prs executed outside the team
115- TODO: Save for later calculate the additions, deletions and commit num. from PR aggregation
116- */
117- //
118118 try {
119- List <Commit > commitList = new FetchCommitsFromPullRequest (
120- commitExternalRepository )
121- .execute (pullRequest );
122- //TODO: Fetch PR Reviews.
119+ // Fetch Commits from each Pull Request.
120+ List <Commit > commitList = new FetchCommitsFromPullRequest (commitExternalRepository )
121+ .execute (pullRequest );
122+ } catch (HttpException e ) {
123+ throw new RuntimeException (e );
124+ }
125+ }
123126
124- Repository repository = pullRequest .getRepository ();
125- List <Comment > commentList = new FetchCommentsFromPullRequest (
126- commentExternalRepository ).execute (repository .getOwnerLogin (), repository .getName (),
127- pullRequest .getNumber ());
127+ private void fetchReviewsFromPullRequest (PullRequest pullRequest ) {
128+ try {
129+ // Fetch Reviews from each Pull Request.
130+ List <UserReview > reviewList = new FetchReviewsFromPullRequest (reviewExternalRepository )
131+ .execute (pullRequest );
132+ } catch (HttpException e ) {
133+ throw new RuntimeException (e );
134+ }
135+ }
128136
137+ private void fetchCommentsFromPullRequest (PullRequest pullRequest ) {
138+ try {
139+ // Fetch Comments from each Pull Request.
140+ List <Comment > commentList = new FetchCommentsFromPullRequest (commentExternalRepository )
141+ .execute (pullRequest );
129142 } catch (HttpException e ) {
130143 throw new RuntimeException (e );
131144 }
0 commit comments