-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#144: add reviews to the activity service
- Loading branch information
Showing
8 changed files
with
167 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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 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
41 changes: 0 additions & 41 deletions
41
...r/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ActivityDashboardService.java
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
...ion-server/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ActivityService.java
This file contains 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,70 @@ | ||
package de.tum.in.www1.hephaestus.activitydashboard; | ||
|
||
import de.tum.in.www1.hephaestus.gitprovider.issue.Issue; | ||
import de.tum.in.www1.hephaestus.gitprovider.issue.IssueInfoDTO; | ||
import de.tum.in.www1.hephaestus.gitprovider.issue.IssueRepository; | ||
import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequest; | ||
import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequestInfoDTO; | ||
import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequestRepository; | ||
import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.PullRequestReview; | ||
import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.PullRequestReviewInfoDTO; | ||
import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.PullRequestReviewRepository; | ||
import jakarta.transaction.Transactional; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
@Service | ||
public class ActivityService { | ||
|
||
private PullRequestRepository pullRequestRepository; | ||
|
||
private IssueRepository issueRepository; | ||
|
||
private PullRequestReviewRepository pullRequestReviewRepository; | ||
|
||
public ActivityService(PullRequestRepository pullRequestRepository, IssueRepository issueRepository, PullRequestReviewRepository pullRequestReviewRepository) { | ||
this.pullRequestRepository = pullRequestRepository; | ||
this.issueRepository = issueRepository; | ||
this.pullRequestReviewRepository = pullRequestReviewRepository; | ||
} | ||
|
||
@Transactional | ||
public ActivityDTO getActivity(String login) { | ||
|
||
List<PullRequestInfoDTO> openPullRequests = pullRequestRepository | ||
.findAssignedByLoginAndStates(login, Set.of(Issue.State.OPEN)) | ||
.stream() | ||
.map(PullRequestInfoDTO::fromPullRequest) | ||
.toList(); | ||
|
||
List<IssueInfoDTO> openIssues = issueRepository.findAssignedByLoginAndStates(login, Set.of(Issue.State.OPEN)) | ||
.stream() | ||
.map(IssueInfoDTO::fromIssue) | ||
.toList(); | ||
|
||
List<ReviewActivityDto> reviews = getReviewedOrRequestedPullRequests(login); | ||
|
||
return new ActivityDTO( | ||
openPullRequests, | ||
openIssues, | ||
reviews | ||
); | ||
} | ||
|
||
private List<ReviewActivityDto> getReviewedOrRequestedPullRequests(String login) { | ||
List<ReviewActivityDto> reviews = pullRequestReviewRepository.findAllOpenReviewsByAuthorLogin(login) | ||
.stream() | ||
.map(ReviewActivityDto::fromPullRequestReview) | ||
.toList(); | ||
|
||
List<ReviewActivityDto> requestedReviews = pullRequestRepository.findReviewRequestedByLogin(login) | ||
.stream() | ||
.map(ReviewActivityDto::fromPullRequest) | ||
.toList(); | ||
|
||
requestedReviews.addAll(reviews); | ||
return requestedReviews; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...n-server/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ReviewActivityDto.java
This file contains 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,59 @@ | ||
package de.tum.in.www1.hephaestus.activitydashboard; | ||
|
||
import java.time.OffsetDateTime; | ||
import org.springframework.lang.NonNull; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequest; | ||
import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequestInfoDTO; | ||
import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.PullRequestReview; | ||
import de.tum.in.www1.hephaestus.gitprovider.user.UserInfoDTO; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public record ReviewActivityDto( | ||
@NonNull Long id, | ||
@NonNull Boolean isDismissed, | ||
@NonNull ReviewActivityState state, | ||
@NonNull Integer codeComments, | ||
UserInfoDTO author, | ||
PullRequestInfoDTO pullRequest) { | ||
|
||
public static ReviewActivityDto fromPullRequestReview(PullRequestReview pullRequestReview) { | ||
return new ReviewActivityDto( | ||
pullRequestReview.getId(), | ||
pullRequestReview.isDismissed(), | ||
ReviewActivityDto.fromPullRequestReviewState(pullRequestReview.getState()), | ||
pullRequestReview.getComments().size(), | ||
UserInfoDTO.fromUser(pullRequestReview.getAuthor()), | ||
PullRequestInfoDTO.fromPullRequest(pullRequestReview.getPullRequest()) | ||
); | ||
} | ||
|
||
public static ReviewActivityDto fromPullRequest(PullRequest pullRequest) { | ||
return new ReviewActivityDto( | ||
pullRequest.getId(), | ||
false, | ||
ReviewActivityState.REVIEW_REQUESTED, | ||
0, | ||
UserInfoDTO.fromUser(pullRequest.getAuthor()), | ||
PullRequestInfoDTO.fromPullRequest(pullRequest) | ||
); | ||
} | ||
|
||
public enum ReviewActivityState { | ||
COMMENTED, | ||
APPROVED, | ||
CHANGES_REQUESTED, | ||
REVIEW_REQUESTED, | ||
UNKNOWN; | ||
} | ||
|
||
public static ReviewActivityState fromPullRequestReviewState(PullRequestReview.State state) { | ||
return switch (state) { | ||
case COMMENTED -> ReviewActivityState.COMMENTED; | ||
case APPROVED -> ReviewActivityState.APPROVED; | ||
case CHANGES_REQUESTED -> ReviewActivityState.CHANGES_REQUESTED; | ||
default -> ReviewActivityState.UNKNOWN; | ||
}; | ||
} | ||
} |
This file contains 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 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 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