Skip to content

Commit

Permalink
rework bad practices(#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
iam-flo committed Feb 4, 2025
1 parent 7500d48 commit 42cbb78
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
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 de.tum.in.www1.hephaestus.gitprovider.user.User;
import de.tum.in.www1.hephaestus.gitprovider.user.UserRepository;
import jakarta.transaction.Transactional;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -80,17 +78,13 @@ public ActivityDTO getActivity(String login) {
public List<PullRequestBadPracticeDTO> detectBadPractices(String login) {
logger.info("Detecting bad practices for user with login: {}", login);

User user = userRepository.findByLogin(login).orElseThrow(() -> new IllegalArgumentException("User not found"));
userRepository.findByLogin(login).orElseThrow(() -> new IllegalArgumentException("User not found"));

List<PullRequest> pullRequests = pullRequestRepository.findAssignedByLoginAndStatesAndUpdatedAtAfter(
List<PullRequest> pullRequests = pullRequestRepository.findAssignedByLoginAndStates(
login,
Set.of(Issue.State.OPEN),
user.getLastSyncBadPracticeAt()
Set.of(Issue.State.OPEN)
);

user.setLastSyncBadPracticeAt(OffsetDateTime.now());
userRepository.save(user);

return pullRequests
.stream()
.map(pullRequestBadPracticeDetector::detectAndSyncBadPractices)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class PullRequestBadPractice {
@Id
private Long id;

@ManyToOne
@JoinColumn(name = "rule_id")
private PullRequestBadPracticeRule rule;
private String title;

private String description;

@ManyToOne
@JoinColumn(name = "pullrequest_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
public record PullRequestBadPracticeDTO(String title, String description, boolean resolved) {
public static PullRequestBadPracticeDTO fromPullRequestBadPractice(PullRequestBadPractice badPractice) {
return new PullRequestBadPracticeDTO(
badPractice.getRule().getTitle(),
badPractice.getRule().getDescription(),
badPractice.getTitle(),
badPractice.getDescription(),
badPractice.isResolved()
);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,4 @@ WHERE Type(p) = PullRequest
"""
)
Set<Integer> findAllSyncedPullRequestNumbers(@Param("repositoryId") long repositoryId);

@Query(
"""
SELECT p
FROM PullRequest p
LEFT JOIN FETCH p.labels
JOIN FETCH p.author
LEFT JOIN FETCH p.assignees
LEFT JOIN FETCH p.repository
WHERE (p.author.login ILIKE :assigneeLogin OR LOWER(:assigneeLogin) IN (SELECT LOWER(u.login) FROM p.assignees u))
AND p.state IN :states
AND p.updatedAt >= :updatedAt
ORDER BY p.createdAt DESC
"""
)
List<PullRequest> findAssignedByLoginAndStatesAndUpdatedAtAfter(
@Param("assigneeLogin") String assigneeLogin,
@Param("states") Set<PullRequest.State> states,
@Param("updatedAt") OffsetDateTime updatedAt
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import jakarta.persistence.ManyToMany;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.time.OffsetDateTime;
import java.util.HashSet;
import java.util.Set;
import lombok.Getter;
Expand Down Expand Up @@ -103,8 +102,6 @@ public class User extends BaseGitServiceEntity {
// Current ranking points for the leaderboard leagues
private int leaguePoints;

private OffsetDateTime lastSyncBadPracticeAt;

public enum Type {
USER,
ORGANIZATION,
Expand Down

0 comments on commit 42cbb78

Please sign in to comment.