-
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.
create activity endpoint returning pull requests with bad practices(#199
- Loading branch information
Showing
8 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...plication-server/src/main/java/de/tum/in/www1/hephaestus/activity/ActivityController.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,22 @@ | ||
package de.tum.in.www1.hephaestus.activity; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/activity") | ||
public class ActivityController { | ||
|
||
@Autowired | ||
private ActivityService activityService; | ||
|
||
@GetMapping("/{login}") | ||
public ResponseEntity<ActivityDTO> getActivityByUser(@PathVariable String login) { | ||
ActivityDTO activity = activityService.getActivity(login); | ||
return ResponseEntity.ok(activity); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
server/application-server/src/main/java/de/tum/in/www1/hephaestus/activity/ActivityDTO.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,9 @@ | ||
package de.tum.in.www1.hephaestus.activity; | ||
|
||
import io.micrometer.common.lang.NonNull; | ||
|
||
import java.util.List; | ||
|
||
public record ActivityDTO( | ||
@NonNull List<PullRequestWithBadPracticesDTO> pullRequests) { | ||
} |
53 changes: 53 additions & 0 deletions
53
.../application-server/src/main/java/de/tum/in/www1/hephaestus/activity/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,53 @@ | ||
package de.tum.in.www1.hephaestus.activity; | ||
|
||
import de.tum.in.www1.hephaestus.gitprovider.issue.Issue; | ||
import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequest; | ||
import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequestRepository; | ||
import jakarta.transaction.Transactional; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
public class ActivityService { | ||
|
||
@Autowired | ||
private PullRequestRepository pullRequestRepository; | ||
|
||
@Autowired | ||
private PullRequestBadPracticeRepository pullRequestBadPracticeRepository; | ||
|
||
@Transactional | ||
public ActivityDTO getActivity(String login) { | ||
|
||
List<PullRequest> pullRequests = pullRequestRepository | ||
.findAssignedByLoginAndStates(login, Set.of(Issue.State.OPEN)); | ||
|
||
List<PullRequestBadPractice> openPulLRequestBadPractices = pullRequestBadPracticeRepository.findByLogin(login); | ||
|
||
Map<PullRequest, List<PullRequestBadPracticeDTO>> pullRequestBadPracticesMap = openPulLRequestBadPractices.stream() | ||
.collect(Collectors.groupingBy( | ||
PullRequestBadPractice::getPullrequest, | ||
Collectors.collectingAndThen( | ||
Collectors.toList(), | ||
list -> list.stream() | ||
.map(PullRequestBadPractice::getType) | ||
.distinct() | ||
.map(PullRequestBadPracticeDTO::fromPullRequestBadPracticeType) | ||
.collect(Collectors.toList()) | ||
) | ||
)); | ||
|
||
List<PullRequestWithBadPracticesDTO> openPullRequestsWithBadPractices = pullRequests.stream() | ||
.map(pullRequest -> PullRequestWithBadPracticesDTO.fromPullRequest(pullRequest, | ||
pullRequestBadPracticesMap.getOrDefault(pullRequest, List.of())) | ||
) | ||
.collect(Collectors.toList()); | ||
|
||
return new ActivityDTO(openPullRequestsWithBadPractices); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ation-server/src/main/java/de/tum/in/www1/hephaestus/activity/PullRequestBadPractice.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,28 @@ | ||
package de.tum.in.www1.hephaestus.activity; | ||
|
||
import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequest; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@ToString | ||
public class PullRequestBadPractice { | ||
|
||
@Id | ||
private Long id; | ||
|
||
private PullRequestBadPracticeType type; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "pullrequest_id") | ||
private PullRequest pullrequest; | ||
} |
8 changes: 8 additions & 0 deletions
8
...on-server/src/main/java/de/tum/in/www1/hephaestus/activity/PullRequestBadPracticeDTO.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,8 @@ | ||
package de.tum.in.www1.hephaestus.activity; | ||
|
||
public record PullRequestBadPracticeDTO(String title, String description) { | ||
|
||
public static PullRequestBadPracticeDTO fromPullRequestBadPracticeType(PullRequestBadPracticeType type) { | ||
return new PullRequestBadPracticeDTO(type.title, type.description); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...er/src/main/java/de/tum/in/www1/hephaestus/activity/PullRequestBadPracticeRepository.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,19 @@ | ||
package de.tum.in.www1.hephaestus.activity; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface PullRequestBadPracticeRepository extends JpaRepository<PullRequestBadPractice, Long> { | ||
|
||
@Query(""" | ||
SELECT prbp | ||
FROM PullRequestBadPractice prbp | ||
WHERE LOWER(:assigneeLogin) IN (SELECT LOWER(u.login) FROM prbp.pullrequest.assignees u) AND prbp.pullrequest.state = 'OPEN' | ||
""") | ||
List<PullRequestBadPractice> findByLogin(@Param("assigneeLogin") String assigneeLogin); | ||
} |
17 changes: 17 additions & 0 deletions
17
...n-server/src/main/java/de/tum/in/www1/hephaestus/activity/PullRequestBadPracticeType.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,17 @@ | ||
package de.tum.in.www1.hephaestus.activity; | ||
|
||
public enum PullRequestBadPracticeType { | ||
|
||
EMPTY_DESCRIPTION("Empty Description", "The description of your pull request is empty."), | ||
EMPTY_DESCRIPTION_SECTION("Empty Description Section", "The description of your pull request contains an empty section."), | ||
UNCHECKED_CHECKBOX("Unchecked Checkbox", "A checkbox in the description of your pull request is unchecked."); | ||
|
||
public final String title; | ||
|
||
public final String description; | ||
|
||
PullRequestBadPracticeType(String title, String description) { | ||
this.title = title; | ||
this.description = description; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...rver/src/main/java/de/tum/in/www1/hephaestus/activity/PullRequestWithBadPracticesDTO.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,50 @@ | ||
package de.tum.in.www1.hephaestus.activity; | ||
|
||
import de.tum.in.www1.hephaestus.gitprovider.issue.Issue; | ||
import de.tum.in.www1.hephaestus.gitprovider.label.LabelInfoDTO; | ||
import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequest; | ||
import de.tum.in.www1.hephaestus.gitprovider.repository.RepositoryInfoDTO; | ||
import org.springframework.lang.NonNull; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
public record PullRequestWithBadPracticesDTO( | ||
@NonNull Long id, | ||
@NonNull Integer number, | ||
@NonNull String title, | ||
@NonNull Issue.State state, | ||
@NonNull Boolean isDraft, | ||
@NonNull Boolean isMerged, | ||
List<LabelInfoDTO> labels, | ||
RepositoryInfoDTO repository, | ||
@NonNull Integer additions, | ||
@NonNull Integer deletions, | ||
@NonNull String htmlUrl, | ||
OffsetDateTime createdAt, | ||
List<PullRequestBadPracticeDTO> badPractices | ||
) { | ||
|
||
public static PullRequestWithBadPracticesDTO fromPullRequest(PullRequest pullRequest, List<PullRequestBadPracticeDTO> badPractices) { | ||
return new PullRequestWithBadPracticesDTO( | ||
pullRequest.getId(), | ||
pullRequest.getNumber(), | ||
pullRequest.getTitle(), | ||
pullRequest.getState(), | ||
pullRequest.isDraft(), | ||
pullRequest.isMerged(), | ||
pullRequest.getLabels() | ||
.stream() | ||
.map(LabelInfoDTO::fromLabel) | ||
.sorted(Comparator.comparing(LabelInfoDTO::name)) | ||
.toList(), | ||
RepositoryInfoDTO.fromRepository(pullRequest.getRepository()), | ||
pullRequest.getAdditions(), | ||
pullRequest.getDeletions(), | ||
pullRequest.getHtmlUrl(), | ||
pullRequest.getCreatedAt(), | ||
badPractices | ||
); | ||
} | ||
} |