Skip to content
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

Create activity endpoint for bad practice detection #224

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rework bad practices(#223)
  • Loading branch information
iam-flo committed Feb 20, 2025
commit cb85716bbbb6aff6fa1c2b7356b28d7669b0daba
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