Skip to content

Commit

Permalink
run java prettier(#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
iam-flo committed Jan 13, 2025
1 parent 5b6b102 commit 831d8e0
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import de.tum.in.www1.hephaestus.activity.model.ActivityDTO;
import de.tum.in.www1.hephaestus.activity.model.PullRequestBadPracticeDTO;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ public ActivityDTO getActivity(String login) {
Collectors.groupingBy(
PullRequestBadPractice::getPullrequest,
Collectors.collectingAndThen(Collectors.toList(), list ->
list
.stream()
.map(PullRequestBadPracticeDTO::fromPullRequestBadPractice)
.toList()
list.stream().map(PullRequestBadPracticeDTO::fromPullRequestBadPractice).toList()
)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
import de.tum.in.www1.hephaestus.activity.model.PullRequestBadPracticeRuleDTO;
import de.tum.in.www1.hephaestus.activity.model.RuleNotFoundException;
import de.tum.in.www1.hephaestus.workspace.RepositoryNotFoundException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/rules")
public class BadPracticeRuleController {
Expand All @@ -18,23 +17,36 @@ public class BadPracticeRuleController {
private BadPracticeRuleService badPracticeRuleService;

@GetMapping("/{owner}/{repository}")
public ResponseEntity<List<PullRequestBadPracticeRuleDTO>> getRulesByRepository(@PathVariable String owner, @PathVariable String repository) {
public ResponseEntity<List<PullRequestBadPracticeRuleDTO>> getRulesByRepository(
@PathVariable String owner,
@PathVariable String repository
) {
List<PullRequestBadPracticeRuleDTO> rules = badPracticeRuleService.getRules(owner + "/" + repository);
return ResponseEntity.ok(rules);
}

@PostMapping("/{owner}/{repository}")
public ResponseEntity<PullRequestBadPracticeRuleDTO> createRule(@PathVariable String owner, @PathVariable String repository, @RequestBody CreateOrUpdateBadPracticeRuleDTO rule) {
public ResponseEntity<PullRequestBadPracticeRuleDTO> createRule(
@PathVariable String owner,
@PathVariable String repository,
@RequestBody CreateOrUpdateBadPracticeRuleDTO rule
) {
try {
PullRequestBadPracticeRuleDTO createdRule = badPracticeRuleService.createRule(owner + "/" + repository, rule);
PullRequestBadPracticeRuleDTO createdRule = badPracticeRuleService.createRule(
owner + "/" + repository,
rule
);
return ResponseEntity.ok(createdRule);
} catch (RepositoryNotFoundException e) {
return ResponseEntity.notFound().build();
}
}

@PutMapping("/{id}")
public ResponseEntity<PullRequestBadPracticeRuleDTO> updateRule(@PathVariable long id, @RequestBody CreateOrUpdateBadPracticeRuleDTO rule) {
public ResponseEntity<PullRequestBadPracticeRuleDTO> updateRule(
@PathVariable long id,
@RequestBody CreateOrUpdateBadPracticeRuleDTO rule
) {
try {
PullRequestBadPracticeRuleDTO updatedRule = badPracticeRuleService.updateRule(id, rule);
return ResponseEntity.ok(updatedRule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import de.tum.in.www1.hephaestus.gitprovider.repository.RepositoryRepository;
import de.tum.in.www1.hephaestus.workspace.RepositoryNotFoundException;
import jakarta.transaction.Transactional;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BadPracticeRuleService {

Expand All @@ -30,18 +29,23 @@ public class BadPracticeRuleService {
public List<PullRequestBadPracticeRuleDTO> getRules(String repositoryNameWithOwner) {
logger.info("Getting rules for repository: {}", repositoryNameWithOwner);

return pullRequestBadPracticeRuleRepository.findByRepositoryName(repositoryNameWithOwner)
.stream()
.map(PullRequestBadPracticeRuleDTO::fromPullRequestBadPracticeRule)
.toList();
return pullRequestBadPracticeRuleRepository
.findByRepositoryName(repositoryNameWithOwner)
.stream()
.map(PullRequestBadPracticeRuleDTO::fromPullRequestBadPracticeRule)
.toList();
}

@Transactional
public PullRequestBadPracticeRuleDTO createRule(String repositoryNameWithOwner, CreateOrUpdateBadPracticeRuleDTO rule) {
public PullRequestBadPracticeRuleDTO createRule(
String repositoryNameWithOwner,
CreateOrUpdateBadPracticeRuleDTO rule
) {
logger.info("Creating rule: {}", rule);

Repository repository = repositoryRepository.findByNameWithOwner(repositoryNameWithOwner)
.orElseThrow(() -> new RepositoryNotFoundException(repositoryNameWithOwner));
Repository repository = repositoryRepository
.findByNameWithOwner(repositoryNameWithOwner)
.orElseThrow(() -> new RepositoryNotFoundException(repositoryNameWithOwner));

PullRequestBadPracticeRule newRule = new PullRequestBadPracticeRule();
newRule.setTitle(rule.title());
Expand All @@ -52,8 +56,9 @@ public PullRequestBadPracticeRuleDTO createRule(String repositoryNameWithOwner,

logger.debug("Saving rule: {}", newRule);

return PullRequestBadPracticeRuleDTO.fromPullRequestBadPracticeRule(
pullRequestBadPracticeRuleRepository.save(newRule));
return PullRequestBadPracticeRuleDTO.fromPullRequestBadPracticeRule(
pullRequestBadPracticeRuleRepository.save(newRule)
);
}

@Transactional
Expand All @@ -72,7 +77,8 @@ public PullRequestBadPracticeRuleDTO updateRule(long id, CreateOrUpdateBadPracti
existingRule.setActive(rule.active());

return PullRequestBadPracticeRuleDTO.fromPullRequestBadPracticeRule(
pullRequestBadPracticeRuleRepository.save(existingRule));
pullRequestBadPracticeRuleRepository.save(existingRule)
);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package de.tum.in.www1.hephaestus.activity;

import de.tum.in.www1.hephaestus.activity.model.PullRequestBadPracticeRule;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PullRequestBadPracticeRuleRepository extends JpaRepository<PullRequestBadPracticeRule, Long> {

@Query(
"""
SELECT prbp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,18 @@ public class PullRequestBadPracticeDetector {
private PullRequestBadPracticeRepository pullRequestBadPracticeRepository;

public List<PullRequestBadPractice> detectAndSyncBadPractices(PullRequest pullRequest) {
logger.info(
"Detecting bad practices for pull request: {}.",
pullRequest.getId()
);
logger.info("Detecting bad practices for pull request: {}.", pullRequest.getId());

List<PullRequestBadPractice> existingBadPractices = pullRequestBadPracticeRepository.findByPullRequestId(
pullRequest.getId()
pullRequest.getId()
);

//TODO connect LLM based detection
List<PullRequestBadPractice> newBadPractices = List.of();

return newBadPractices;
}
/*
/*
updateExistingBadPractices(existingBadPractices, newBadPractices);
return saveBadPractices(existingBadPractices, newBadPractices);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package de.tum.in.www1.hephaestus.activity.model;

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.isResolved());
return new PullRequestBadPracticeDTO(
badPractice.getRule().getTitle(),
badPractice.getRule().getDescription(),
badPractice.isResolved()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
@ToString
public class PullRequestBadPracticeRule {

@Id
@GeneratedValue
private Long id;
@Id
@GeneratedValue
private Long id;

private String title;
private String title;

private String description;
private String description;

private String conditions;
private String conditions;

@ManyToOne
@JoinColumn(name = "repository_id")
private Repository repository;
@ManyToOne
@JoinColumn(name = "repository_id")
private Repository repository;

private boolean active;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.tum.in.www1.hephaestus.activity.model;


import de.tum.in.www1.hephaestus.gitprovider.repository.RepositoryInfoDTO;

public record PullRequestBadPracticeRuleDTO(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.tum.in.www1.hephaestus.activity.model;

public class RuleNotFoundException extends RuntimeException {

public RuleNotFoundException(long id) {
super("Rule with id '" + id + "' not found");
}
Expand Down

0 comments on commit 831d8e0

Please sign in to comment.