From 8df40a636b93fe09950714c807ca9cbb2f682b87 Mon Sep 17 00:00:00 2001 From: GODrums Date: Sun, 18 Aug 2024 17:04:19 +0200 Subject: [PATCH 01/50] (feat): GraphQL + dot Env --- server/application-server/pom.xml | 9 ++ .../tum/in/www1/hephaestus/Application.java | 14 +++ .../de/tum/in/www1/hephaestus/EnvConfig.java | 17 ++++ .../in/www1/hephaestus/SecurityConfig.java | 18 ++-- .../codereview/CodeReviewController.java | 29 ++++++ .../codereview/CodeReviewRepository.java | 10 ++ .../codereview/CodeReviewService.java | 88 +++++++++++++++++ .../hephaestus/codereview/actor/Actor.java | 56 +++++++++++ .../codereview/comment/Comment.java | 63 ++++++++++++ .../codereview/pullrequest/Pullrequest.java | 95 +++++++++++++++++++ .../codereview/repository/Repository.java | 52 ++++++++++ .../www1/hephaestus/hello/HelloService.java | 3 +- .../src/main/resources/.env.example | 1 + .../src/main/resources/application.yml | 43 +++++---- .../graphql-documents/getrepositoryprs.gql | 38 ++++++++ 15 files changed, 505 insertions(+), 31 deletions(-) create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/EnvConfig.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewController.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewRepository.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java create mode 100644 server/application-server/src/main/resources/.env.example create mode 100644 server/application-server/src/main/resources/graphql-documents/getrepositoryprs.gql diff --git a/server/application-server/pom.xml b/server/application-server/pom.xml index 62d5317c..95d6d86a 100644 --- a/server/application-server/pom.xml +++ b/server/application-server/pom.xml @@ -120,6 +120,15 @@ spring-modulith-starter-test test + + org.springframework.boot + spring-boot-starter-graphql + + + me.paulschwarz + spring-dotenv + 4.0.0 + diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java index 0d39f321..9a3d34fa 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java @@ -1,15 +1,29 @@ package de.tum.in.www1.hephaestus; +import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; import org.springframework.modulith.Modulithic; +import de.tum.in.www1.hephaestus.codereview.CodeReviewService; +import de.tum.in.www1.hephaestus.codereview.repository.Repository; + @SpringBootApplication @Modulithic(systemName = "Hephaestus") +@EnableConfigurationProperties(EnvConfig.class) public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } + @Bean + CommandLineRunner commandLineRunner(CodeReviewService service) { + return args -> { + Repository repo = service.getHephaestusRepository(); + System.out.println(repo); + }; + } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/EnvConfig.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/EnvConfig.java new file mode 100644 index 00000000..fd3b89c2 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/EnvConfig.java @@ -0,0 +1,17 @@ +package de.tum.in.www1.hephaestus; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "environment") +public class EnvConfig { + + private String githubPat; + + public EnvConfig(String githubPat) { + this.githubPat = githubPat; + } + + public String getGithubPat() { + return githubPat; + } +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/SecurityConfig.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/SecurityConfig.java index 04a1e0f3..7bb18cae 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/SecurityConfig.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/SecurityConfig.java @@ -1,6 +1,5 @@ package de.tum.in.www1.hephaestus; -import java.util.Arrays; import java.util.List; import org.springframework.context.annotation.Bean; @@ -20,14 +19,13 @@ public class SecurityConfig { @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http - .csrf(csrf -> csrf.disable()) - .cors(cors -> cors.configurationSource(corsConfigurationSource())) - .authorizeHttpRequests(authorizeRequests -> authorizeRequests - .requestMatchers("/admin/**").authenticated() - .anyRequest().permitAll() - ) - .formLogin(Customizer.withDefaults()) - .logout(Customizer.withDefaults()); + .csrf(csrf -> csrf.disable()) + .cors(cors -> cors.configurationSource(corsConfigurationSource())) + .authorizeHttpRequests(authorizeRequests -> authorizeRequests + .requestMatchers("/admin/**").authenticated() + .anyRequest().permitAll()) + .formLogin(Customizer.withDefaults()) + .logout(Customizer.withDefaults()); return http.build(); } @@ -38,7 +36,7 @@ CorsConfigurationSource corsConfigurationSource() { configuration.applyPermitDefaultValues(); configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD")); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - source.registerCorsConfiguration("/**",configuration); + source.registerCorsConfiguration("/**", configuration); return source; } } \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewController.java new file mode 100644 index 00000000..778a9634 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewController.java @@ -0,0 +1,29 @@ +package de.tum.in.www1.hephaestus.codereview; + +import java.util.List; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import de.tum.in.www1.hephaestus.codereview.repository.Repository; + +@RestController +@RequestMapping("/codereview") +public class CodeReviewController { + private final CodeReviewService codeReviewService; + + public CodeReviewController(CodeReviewService codeReviewService) { + this.codeReviewService = codeReviewService; + } + + /** + * Retrieves all {@link Repository} entities. + * + * @return A list of all Repository entities + */ + @GetMapping + public List getAllRepositories() { + return codeReviewService.getAllRepositories(); + } +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewRepository.java new file mode 100644 index 00000000..b99fe256 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewRepository.java @@ -0,0 +1,10 @@ +package de.tum.in.www1.hephaestus.codereview; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface CodeReviewRepository + extends JpaRepository { + +} \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java new file mode 100644 index 00000000..972f9241 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java @@ -0,0 +1,88 @@ +package de.tum.in.www1.hephaestus.codereview; + +import java.time.Instant; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestClient; +import org.springframework.data.domain.Example; +import org.springframework.graphql.client.ClientGraphQlResponse; +import org.springframework.graphql.client.HttpSyncGraphQlClient; + +import de.tum.in.www1.hephaestus.EnvConfig; +import de.tum.in.www1.hephaestus.codereview.repository.Repository; + +@Service +public class CodeReviewService { + + private static final Logger logger = LoggerFactory.getLogger(CodeReviewService.class); + + private final HttpSyncGraphQlClient graphQlClient; + + private final CodeReviewRepository codeReviewRepository; + + private final EnvConfig envConfig; + + public CodeReviewService(CodeReviewRepository codeReviewRepository, EnvConfig envConfig) { + logger.info("Hello from CodeReviewService!"); + + this.codeReviewRepository = codeReviewRepository; + this.envConfig = envConfig; + + RestClient restClient = RestClient.builder() + .baseUrl("https://api.github.com/graphql") + .build(); + + String githubPat = this.envConfig.getGithubPat(); + logger.info("Github PAT: " + githubPat); + + graphQlClient = HttpSyncGraphQlClient.builder(restClient) + .headers(headers -> headers.setBearerAuth(githubPat)) + .build(); + } + + public Repository getHephaestusRepository() { + Repository example = new Repository(); + example.setName("hephaestus"); + example.setNameWithOwner("ls1intum/hephaestus"); + Optional foundRepo = codeReviewRepository.findOne(Example.of(example)); + logger.info("All repositories: " + codeReviewRepository.findAll().toString()); + + logger.info("Saved repo: " + foundRepo.toString()); + if (foundRepo.isPresent()) { + return foundRepo.get(); + } + + logger.info("No repo found, creating new one..."); + + HashMap variables = new HashMap<>(); + variables.put("owner", "ls1intum"); + variables.put("name", "hephaestus"); + variables.put("first", 10); + + ClientGraphQlResponse response = graphQlClient.documentName("getrepositoryprs") + .variables(variables) + .executeSync(); + + logger.info("Response: " + response.getData()); + if (response.getErrors().size() > 0) { + logger.error("Error while fetching repository: " + response.getErrors().toString()); + return null; + } + Repository repository = response.toEntity(Repository.class); + repository.setAddedAt(Instant.now()); + + System.out.println("Repository: " + repository.getName()); + codeReviewRepository.save(repository); + return repository; + } + + public List getAllRepositories() { + return codeReviewRepository.findAll(); + } + +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java new file mode 100644 index 00000000..682e652d --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java @@ -0,0 +1,56 @@ +package de.tum.in.www1.hephaestus.codereview.actor; + +import jakarta.persistence.Id; +import jakarta.persistence.Table; + +import java.util.List; + +import de.tum.in.www1.hephaestus.codereview.comment.Comment; +import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.OneToMany; +import lombok.Getter; +import lombok.Setter; + +@Entity +@Table +@Getter +@Setter +public class Actor { + /** + * Unique identifier for a User entity. + */ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + /** + * Login of the User entity. + * This field is mandatory. + */ + @Column(nullable = false) + private String login; + + /** + * URL of the User entity. + * This field is mandatory. + */ + @Column(nullable = false) + private String url; + + /** + * The Pullrequests of the User entity. + */ + @OneToMany(mappedBy = "author", fetch = FetchType.LAZY) + private List pullrequests; + + /** + * The Comments of the User entity. + */ + @OneToMany(mappedBy = "author", fetch = FetchType.LAZY) + private List comments; +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java new file mode 100644 index 00000000..b20a46ff --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java @@ -0,0 +1,63 @@ +package de.tum.in.www1.hephaestus.codereview.comment; + +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import de.tum.in.www1.hephaestus.codereview.actor.Actor; +import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import lombok.Getter; +import lombok.Setter; + +@Entity +@Table +@Getter +@Setter +public class Comment { + /** + * Unique identifier for a Comment entity. + */ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + /** + * Body of the Comment entity. + * This field is mandatory. + */ + @Column(nullable = false) + private String body; + + /** + * Timestamp of when the Comment entity was created. + * This field is mandatory. + */ + @Column(nullable = false) + private Long createdAt; + + /** + * Timestamp of when the Comment entity was updated. + * This field is mandatory. + */ + @Column(nullable = false) + private Long updatedAt; + + /** + * The author of the Comment entity. + */ + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "author_id") + private Actor author; + + /** + * The pullrequest of the Comment entity. + */ + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "pullrequest_id") + private Pullrequest pullrequest; +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java new file mode 100644 index 00000000..4b46c7e9 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -0,0 +1,95 @@ +package de.tum.in.www1.hephaestus.codereview.pullrequest; + +import java.time.Instant; +import java.util.List; + +import de.tum.in.www1.hephaestus.codereview.actor.Actor; +import de.tum.in.www1.hephaestus.codereview.comment.Comment; +import de.tum.in.www1.hephaestus.codereview.repository.Repository; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import lombok.Getter; +import lombok.Setter; + +@Entity +@Table +@Getter +@Setter +public class Pullrequest { + + /** + * Unique identifier for a Pullrequest entity. + */ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + /** + * Title of the Pullrequest. + * This field is mandatory. + */ + @Column(nullable = false) + private String title; + + /** + * URL of the Pullrequest. + * This field is mandatory. + */ + @Column(nullable = false) + private String url; + + /** + * State of the Pullrequest. + * This field is mandatory. + */ + @Column(nullable = false) + private String state; + + /** + * Timestamp of when the Pullrequest entity was created. + * This field is mandatory. + */ + @Column(nullable = false) + private Instant createdAt; + + /** + * Timestamp of when the Pullrequest entity was updated. + * This field is mandatory. + */ + @Column(nullable = false) + private Instant updatedAt; + + /** + * Timestamp of when the Pullrequest entity was merged. + */ + @Column(nullable = true) + private Instant mergedAt; + + /** + * The author of the Pullrequest entity. + */ + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "author_id") + private Actor author; + + /** + * The comments of the Pullrequest entity. + */ + @OneToMany(mappedBy = "pullrequest", fetch = FetchType.LAZY) + private List comments; + + /** + * The repository of the Pullrequest entity. + */ + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "repository_id") + private Repository repository; +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java new file mode 100644 index 00000000..30afcd60 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -0,0 +1,52 @@ +package de.tum.in.www1.hephaestus.codereview.repository; + +import java.time.Instant; +import java.util.List; + +import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; + +@Entity +@Table +@Getter +@Setter +public class Repository { + + /** + * Unique identifier for a Repository + */ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long uid; + + @NotNull + private String id; + + @NotNull + private String name; + + @NotNull + private String nameWithOwner; + + @NotNull + private String description; + + @NotNull + private String url; + + @OneToMany(mappedBy = "repository", fetch = FetchType.LAZY) + private List pullRequests; + + @NotNull + private Instant addedAt; +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/hello/HelloService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/hello/HelloService.java index b8d394b4..e3f6d072 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/hello/HelloService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/hello/HelloService.java @@ -30,7 +30,8 @@ public List getAllHellos() { } /** - * Creates a new {@link Hello} entity with the current timestamp and saves it to the repository. + * Creates a new {@link Hello} entity with the current timestamp and saves it to + * the repository. * * @return The created Hello entity */ diff --git a/server/application-server/src/main/resources/.env.example b/server/application-server/src/main/resources/.env.example new file mode 100644 index 00000000..aa701ea5 --- /dev/null +++ b/server/application-server/src/main/resources/.env.example @@ -0,0 +1 @@ +GITHUB_PAT="" \ No newline at end of file diff --git a/server/application-server/src/main/resources/application.yml b/server/application-server/src/main/resources/application.yml index ab369fa7..4527b520 100644 --- a/server/application-server/src/main/resources/application.yml +++ b/server/application-server/src/main/resources/application.yml @@ -1,26 +1,29 @@ spring: - application: - name: Hephaestus + application: + name: Hephaestus - datasource: - url: jdbc:postgresql://localhost:5432/hephaestus - username: root - password: root - - jpa: - hibernate: - ddl-auto: create-drop - properties: - hibernate: - dialect: org.hibernate.dialect.PostgreSQLDialect + datasource: + url: jdbc:postgresql://localhost:5432/hephaestus + username: root + password: root - liquibase: - change-log: classpath:db/master.xml + jpa: + hibernate: + ddl-auto: create-drop + properties: + hibernate: + dialect: org.hibernate.dialect.PostgreSQLDialect - security: - user: - name: admin - password: admin + liquibase: + change-log: classpath:db/master.xml + + security: + user: + name: admin + password: admin springdoc: - default-produces-media-type: application/json + default-produces-media-type: application/json + +environment: + githubPat: ${GITHUB_PAT} diff --git a/server/application-server/src/main/resources/graphql-documents/getrepositoryprs.gql b/server/application-server/src/main/resources/graphql-documents/getrepositoryprs.gql new file mode 100644 index 00000000..32c1aa5a --- /dev/null +++ b/server/application-server/src/main/resources/graphql-documents/getrepositoryprs.gql @@ -0,0 +1,38 @@ +query GetRepositoryPRs($owner: String!, $name: String!, $first: Int!) { + repository(owner: $owner, name: $name) { + id + name + nameWithOwner + description + url + pullRequests(first: $first, states: [OPEN, MERGED]) { + nodes { + id + title + url + state + createdAt + updatedAt + mergedAt + author { + avatarUrl + login + url + } + comments(last: 100) { + nodes { + id + body + createdAt + updatedAt + author { + avatarUrl + login + url + } + } + } + } + } + } +} From 5ff5a8bd08f3632509c078271289205a52559ca2 Mon Sep 17 00:00:00 2001 From: GODrums Date: Sun, 18 Aug 2024 21:21:19 +0200 Subject: [PATCH 02/50] Create GraphQL connection relations --- .../codereview/CodeReviewService.java | 14 ++++---- .../codereview/comment/Comment.java | 12 ++++--- .../codereview/comment/CommentConnection.java | 31 +++++++++++++++++ .../codereview/pullrequest/Pullrequest.java | 24 +++++++------ .../pullrequest/PullrequestConnection.java | 31 +++++++++++++++++ .../codereview/repository/Repository.java | 34 +++++++++++-------- .../graphql-documents/getrepositoryprs.gql | 20 ++++++----- 7 files changed, 118 insertions(+), 48 deletions(-) create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java index 972f9241..b2f8959d 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java @@ -10,7 +10,6 @@ import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; import org.springframework.data.domain.Example; -import org.springframework.graphql.client.ClientGraphQlResponse; import org.springframework.graphql.client.HttpSyncGraphQlClient; import de.tum.in.www1.hephaestus.EnvConfig; @@ -64,19 +63,18 @@ public Repository getHephaestusRepository() { variables.put("name", "hephaestus"); variables.put("first", 10); - ClientGraphQlResponse response = graphQlClient.documentName("getrepositoryprs") + Repository repository = graphQlClient.documentName("getrepositoryprs") .variables(variables) - .executeSync(); + .retrieveSync("repository") + .toEntity(Repository.class); - logger.info("Response: " + response.getData()); - if (response.getErrors().size() > 0) { - logger.error("Error while fetching repository: " + response.getErrors().toString()); + if (repository == null) { + logger.error("Error while fetching repository!"); return null; } - Repository repository = response.toEntity(Repository.class); repository.setAddedAt(Instant.now()); - System.out.println("Repository: " + repository.getName()); + System.out.println("Repository: " + repository.toString()); codeReviewRepository.save(repository); return repository; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java index b20a46ff..562e6cdb 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java @@ -3,7 +3,6 @@ import jakarta.persistence.Id; import jakarta.persistence.Table; import de.tum.in.www1.hephaestus.codereview.actor.Actor; -import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; @@ -26,6 +25,9 @@ public class Comment { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(name = "github_id") + private String githubId; + /** * Body of the Comment entity. * This field is mandatory. @@ -38,14 +40,14 @@ public class Comment { * This field is mandatory. */ @Column(nullable = false) - private Long createdAt; + private String createdAt; /** * Timestamp of when the Comment entity was updated. * This field is mandatory. */ @Column(nullable = false) - private Long updatedAt; + private String updatedAt; /** * The author of the Comment entity. @@ -58,6 +60,6 @@ public class Comment { * The pullrequest of the Comment entity. */ @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "pullrequest_id") - private Pullrequest pullrequest; + @JoinColumn(name = "c_connection_id") + private CommentConnection connection; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java new file mode 100644 index 00000000..b4a5cc5e --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java @@ -0,0 +1,31 @@ +package de.tum.in.www1.hephaestus.codereview.comment; + +import java.util.List; + +import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; +import lombok.Getter; +import lombok.Setter; + +@Entity +@Table +@Getter +@Setter +public class CommentConnection { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToMany(mappedBy = "connection", fetch = FetchType.LAZY) + private List nodes; + + @OneToOne(mappedBy = "comments", fetch = FetchType.LAZY) + private Pullrequest pullrequest; +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index 4b46c7e9..1cdf1095 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -1,11 +1,9 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; import java.time.Instant; -import java.util.List; import de.tum.in.www1.hephaestus.codereview.actor.Actor; -import de.tum.in.www1.hephaestus.codereview.comment.Comment; -import de.tum.in.www1.hephaestus.codereview.repository.Repository; +import de.tum.in.www1.hephaestus.codereview.comment.CommentConnection; import jakarta.persistence.Id; import jakarta.persistence.Table; import jakarta.persistence.Column; @@ -15,7 +13,7 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; import lombok.Getter; import lombok.Setter; @@ -32,6 +30,9 @@ public class Pullrequest { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(name = "github_id") + private String githubId; + /** * Title of the Pullrequest. * This field is mandatory. @@ -58,20 +59,20 @@ public class Pullrequest { * This field is mandatory. */ @Column(nullable = false) - private Instant createdAt; + private String createdAt; /** * Timestamp of when the Pullrequest entity was updated. * This field is mandatory. */ @Column(nullable = false) - private Instant updatedAt; + private String updatedAt; /** * Timestamp of when the Pullrequest entity was merged. */ @Column(nullable = true) - private Instant mergedAt; + private String mergedAt; /** * The author of the Pullrequest entity. @@ -83,13 +84,14 @@ public class Pullrequest { /** * The comments of the Pullrequest entity. */ - @OneToMany(mappedBy = "pullrequest", fetch = FetchType.LAZY) - private List comments; + @OneToOne(optional = false) + @JoinColumn(name = "c_connection_id") + private CommentConnection comments; /** * The repository of the Pullrequest entity. */ @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "repository_id") - private Repository repository; + @JoinColumn(name = "pr_connection_id") + private PullrequestConnection connection; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java new file mode 100644 index 00000000..01df35ad --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java @@ -0,0 +1,31 @@ +package de.tum.in.www1.hephaestus.codereview.pullrequest; + +import java.util.List; + +import de.tum.in.www1.hephaestus.codereview.repository.Repository; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import lombok.Getter; +import lombok.Setter; + +@Entity +@Table +@Getter +@Setter +public class PullrequestConnection { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToMany(mappedBy = "connection", fetch = FetchType.LAZY) + private List nodes; + + @OneToOne(mappedBy = "pullRequests", fetch = FetchType.LAZY) + private Repository repository; +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index 30afcd60..6904ec10 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -1,18 +1,16 @@ package de.tum.in.www1.hephaestus.codereview.repository; import java.time.Instant; -import java.util.List; -import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; +import de.tum.in.www1.hephaestus.codereview.pullrequest.PullrequestConnection; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; import jakarta.persistence.Table; -import jakarta.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; @@ -27,26 +25,32 @@ public class Repository { */ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long uid; + private Long id; - @NotNull - private String id; + @Column(name = "github_id") + private String githubId; - @NotNull + @Column private String name; - @NotNull + @Column(name = "name_with_owner") private String nameWithOwner; - @NotNull + @Column private String description; - @NotNull + @Column private String url; - @OneToMany(mappedBy = "repository", fetch = FetchType.LAZY) - private List pullRequests; + @OneToOne(optional = false) + @JoinColumn(name = "connection_id") + private PullrequestConnection pullRequests; - @NotNull + @Column(name = "added_at") private Instant addedAt; + + public String toString() { + return "Repository [id=" + id + ", name=" + name + ", nameWithOwner=" + nameWithOwner + ", description=" + + description + ", url=" + url + ", pullRequests=" + pullRequests + ", addedAt=" + addedAt + "]"; + } } diff --git a/server/application-server/src/main/resources/graphql-documents/getrepositoryprs.gql b/server/application-server/src/main/resources/graphql-documents/getrepositoryprs.gql index 32c1aa5a..fd8d82e8 100644 --- a/server/application-server/src/main/resources/graphql-documents/getrepositoryprs.gql +++ b/server/application-server/src/main/resources/graphql-documents/getrepositoryprs.gql @@ -1,13 +1,13 @@ query GetRepositoryPRs($owner: String!, $name: String!, $first: Int!) { repository(owner: $owner, name: $name) { - id + githubId: id name nameWithOwner description url pullRequests(first: $first, states: [OPEN, MERGED]) { nodes { - id + githubId: id title url state @@ -15,20 +15,16 @@ query GetRepositoryPRs($owner: String!, $name: String!, $first: Int!) { updatedAt mergedAt author { - avatarUrl - login - url + ...authorFields } comments(last: 100) { nodes { - id + githubId: id body createdAt updatedAt author { - avatarUrl - login - url + ...authorFields } } } @@ -36,3 +32,9 @@ query GetRepositoryPRs($owner: String!, $name: String!, $first: Int!) { } } } + +fragment authorFields on Actor { + avatarUrl + login + url +} From 8e625b3317f421a5f00a1fef7ed627800973401d Mon Sep 17 00:00:00 2001 From: GODrums Date: Mon, 19 Aug 2024 00:40:06 +0200 Subject: [PATCH 03/50] fix: add referenced column names --- .../in/www1/hephaestus/codereview/comment/Comment.java | 3 ++- .../hephaestus/codereview/comment/CommentConnection.java | 3 --- .../hephaestus/codereview/pullrequest/Pullrequest.java | 8 +++----- .../codereview/pullrequest/PullrequestConnection.java | 3 --- .../www1/hephaestus/codereview/repository/Repository.java | 2 +- 5 files changed, 6 insertions(+), 13 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java index 562e6cdb..c5200141 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java @@ -60,6 +60,7 @@ public class Comment { * The pullrequest of the Comment entity. */ @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "c_connection_id") + @JoinColumn(name = "c_connection_id", referencedColumnName = "id") private CommentConnection connection; + } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java index b4a5cc5e..f7798962 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java @@ -25,7 +25,4 @@ public class CommentConnection { @OneToMany(mappedBy = "connection", fetch = FetchType.LAZY) private List nodes; - - @OneToOne(mappedBy = "comments", fetch = FetchType.LAZY) - private Pullrequest pullrequest; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index 1cdf1095..fbdf135d 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -6,6 +6,7 @@ import de.tum.in.www1.hephaestus.codereview.comment.CommentConnection; import jakarta.persistence.Id; import jakarta.persistence.Table; +import jakarta.persistence.Transient; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; @@ -85,13 +86,10 @@ public class Pullrequest { * The comments of the Pullrequest entity. */ @OneToOne(optional = false) - @JoinColumn(name = "c_connection_id") + @JoinColumn(name = "c_connection_id", referencedColumnName = "id") private CommentConnection comments; - /** - * The repository of the Pullrequest entity. - */ @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "pr_connection_id") + @JoinColumn(name = "pr_connection_id", referencedColumnName = "id") private PullrequestConnection connection; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java index 01df35ad..2b3800c0 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java @@ -25,7 +25,4 @@ public class PullrequestConnection { @OneToMany(mappedBy = "connection", fetch = FetchType.LAZY) private List nodes; - - @OneToOne(mappedBy = "pullRequests", fetch = FetchType.LAZY) - private Repository repository; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index 6904ec10..87f69cf3 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -43,7 +43,7 @@ public class Repository { private String url; @OneToOne(optional = false) - @JoinColumn(name = "connection_id") + @JoinColumn(name = "connection_id", referencedColumnName = "id") private PullrequestConnection pullRequests; @Column(name = "added_at") From 28c226c4ed9f1076510836bf69b41656f06c467b Mon Sep 17 00:00:00 2001 From: GODrums Date: Tue, 20 Aug 2024 15:40:19 +0200 Subject: [PATCH 04/50] Replace .env with application-local.yml --- .gitignore | 4 +- server/application-server/HELP.md | 58 ++++++++++++------- server/application-server/pom.xml | 7 +-- .../src/main/resources/.env.example | 1 - 4 files changed, 41 insertions(+), 29 deletions(-) delete mode 100644 server/application-server/src/main/resources/.env.example diff --git a/.gitignore b/.gitignore index af353c7f..2f74a32a 100644 --- a/.gitignore +++ b/.gitignore @@ -162,4 +162,6 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ -node_modules/ \ No newline at end of file +node_modules/ + +application-local.yml \ No newline at end of file diff --git a/server/application-server/HELP.md b/server/application-server/HELP.md index 03b59ce7..66b8f80d 100644 --- a/server/application-server/HELP.md +++ b/server/application-server/HELP.md @@ -1,38 +1,53 @@ # Getting Started +### Local development + +The Spring Boot Maven Plugin supports running your application with a local development environment. To do this, you can use the `spring-boot:run` goal: + +```shell +mvn spring-boot:run +``` + +This will start your application in a local development environment. You can access the application at `http://localhost:8080`. + +Setting environment variables works through profile-based `application.yml` files. For local development, create a `application-local.yml` file overwriting the original properties. See [Using the Plugin :: Spring Boot](https://docs.spring.io/spring-boot/maven-plugin/using.html#using.overriding-command-line) for more information. + ### Reference Documentation + For further reference, please consider the following sections: -* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) -* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.3.2/maven-plugin/reference/html/) -* [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.3.2/maven-plugin/reference/html/#build-image) -* [Docker Compose Support](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#features.docker-compose) -* [Spring Boot DevTools](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#using.devtools) -* [Spring Web](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#web) -* [Spring Security](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#web.security) -* [Spring Data JPA](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#data.sql.jpa-and-spring-data) -* [Spring Boot Actuator](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#actuator) -* [Liquibase Migration](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#howto.data-initialization.migration-tool.liquibase) -* [OAuth2 Client](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#web.security.oauth2.client) -* [OAuth2 Resource Server](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#web.security.oauth2.server) +- [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) +- [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.3.2/maven-plugin/reference/html/) +- [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.3.2/maven-plugin/reference/html/#build-image) +- [Docker Compose Support](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#features.docker-compose) +- [Spring Boot DevTools](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#using.devtools) +- [Spring Web](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#web) +- [Spring Security](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#web.security) +- [Spring Data JPA](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#data.sql.jpa-and-spring-data) +- [Spring Boot Actuator](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#actuator) +- [Liquibase Migration](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#howto.data-initialization.migration-tool.liquibase) +- [OAuth2 Client](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#web.security.oauth2.client) +- [OAuth2 Resource Server](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#web.security.oauth2.server) ### Guides + The following guides illustrate how to use some features concretely: -* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) -* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) -* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) -* [Securing a Web Application](https://spring.io/guides/gs/securing-web/) -* [Spring Boot and OAuth2](https://spring.io/guides/tutorials/spring-boot-oauth2/) -* [Authenticating a User with LDAP](https://spring.io/guides/gs/authenticating-ldap/) -* [Accessing Data with JPA](https://spring.io/guides/gs/accessing-data-jpa/) -* [Building a RESTful Web Service with Spring Boot Actuator](https://spring.io/guides/gs/actuator-service/) +- [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +- [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +- [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) +- [Securing a Web Application](https://spring.io/guides/gs/securing-web/) +- [Spring Boot and OAuth2](https://spring.io/guides/tutorials/spring-boot-oauth2/) +- [Authenticating a User with LDAP](https://spring.io/guides/gs/authenticating-ldap/) +- [Accessing Data with JPA](https://spring.io/guides/gs/accessing-data-jpa/) +- [Building a RESTful Web Service with Spring Boot Actuator](https://spring.io/guides/gs/actuator-service/) ### Docker Compose support + This project contains a Docker Compose file named `compose.yaml`. In this file, the following services have been defined: -* postgres: [`postgres:latest`](https://hub.docker.com/_/postgres) +- postgres: [`postgres:latest`](https://hub.docker.com/_/postgres) Please review the tags of the used images and set them to the same as you're running in production. @@ -42,4 +57,3 @@ Due to Maven's design, elements are inherited from the parent POM to the project While most of the inheritance is fine, it also inherits unwanted elements like `` and `` from the parent. To prevent this, the project POM contains empty overrides for these elements. If you manually switch to a different parent and actually want the inheritance, you need to remove those overrides. - diff --git a/server/application-server/pom.xml b/server/application-server/pom.xml index 95d6d86a..5a353d20 100644 --- a/server/application-server/pom.xml +++ b/server/application-server/pom.xml @@ -29,6 +29,7 @@ 21 + local,dev @@ -124,11 +125,6 @@ org.springframework.boot spring-boot-starter-graphql - - me.paulschwarz - spring-dotenv - 4.0.0 - @@ -167,6 +163,7 @@ org.springframework.boot spring-boot-maven-plugin + ${app.profiles} -Dspring.application.admin.enabled=true diff --git a/server/application-server/src/main/resources/.env.example b/server/application-server/src/main/resources/.env.example deleted file mode 100644 index aa701ea5..00000000 --- a/server/application-server/src/main/resources/.env.example +++ /dev/null @@ -1 +0,0 @@ -GITHUB_PAT="" \ No newline at end of file From 45a6140ff79daa28f35030578cabbef6609b7922 Mon Sep 17 00:00:00 2001 From: GODrums Date: Tue, 20 Aug 2024 18:17:54 +0200 Subject: [PATCH 05/50] fix: transient value error --- .../www1/hephaestus/codereview/CodeReviewService.java | 5 +++-- .../in/www1/hephaestus/codereview/actor/Actor.java | 5 ++--- .../www1/hephaestus/codereview/comment/Comment.java | 5 +++-- .../codereview/comment/CommentConnection.java | 5 +---- .../codereview/pullrequest/Pullrequest.java | 11 ++++++----- .../codereview/pullrequest/PullrequestConnection.java | 5 +---- .../hephaestus/codereview/repository/Repository.java | 3 ++- 7 files changed, 18 insertions(+), 21 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java index b2f8959d..6d218095 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java @@ -49,7 +49,7 @@ public Repository getHephaestusRepository() { example.setName("hephaestus"); example.setNameWithOwner("ls1intum/hephaestus"); Optional foundRepo = codeReviewRepository.findOne(Example.of(example)); - logger.info("All repositories: " + codeReviewRepository.findAll().toString()); + logger.info("Repository count: " + codeReviewRepository.count()); logger.info("Saved repo: " + foundRepo.toString()); if (foundRepo.isPresent()) { @@ -75,7 +75,8 @@ public Repository getHephaestusRepository() { repository.setAddedAt(Instant.now()); System.out.println("Repository: " + repository.toString()); - codeReviewRepository.save(repository); + codeReviewRepository.saveAndFlush(repository); + System.out.println("New Repository count: " + codeReviewRepository.count()); return repository; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java index 682e652d..34396ab6 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java @@ -9,7 +9,6 @@ import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.OneToMany; @@ -45,12 +44,12 @@ public class Actor { /** * The Pullrequests of the User entity. */ - @OneToMany(mappedBy = "author", fetch = FetchType.LAZY) + @OneToMany(mappedBy = "author") private List pullrequests; /** * The Comments of the User entity. */ - @OneToMany(mappedBy = "author", fetch = FetchType.LAZY) + @OneToMany(mappedBy = "author") private List comments; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java index c5200141..17fcfa1c 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java @@ -10,6 +10,7 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToOne; import lombok.Getter; import lombok.Setter; @@ -57,9 +58,9 @@ public class Comment { private Actor author; /** - * The pullrequest of the Comment entity. + * The parent connection to the pullrequest of the Comment entity. */ - @ManyToOne(fetch = FetchType.LAZY) + @OneToOne(optional = false) @JoinColumn(name = "c_connection_id", referencedColumnName = "id") private CommentConnection connection; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java index f7798962..bc926473 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java @@ -2,14 +2,11 @@ import java.util.List; -import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.OneToMany; -import jakarta.persistence.OneToOne; import jakarta.persistence.Table; import lombok.Getter; import lombok.Setter; @@ -23,6 +20,6 @@ public class CommentConnection { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToMany(mappedBy = "connection", fetch = FetchType.LAZY) + @OneToMany(mappedBy = "connection") private List nodes; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index fbdf135d..26701001 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -1,12 +1,10 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; -import java.time.Instant; - import de.tum.in.www1.hephaestus.codereview.actor.Actor; import de.tum.in.www1.hephaestus.codereview.comment.CommentConnection; import jakarta.persistence.Id; import jakarta.persistence.Table; -import jakarta.persistence.Transient; +import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; @@ -85,11 +83,14 @@ public class Pullrequest { /** * The comments of the Pullrequest entity. */ - @OneToOne(optional = false) + @OneToOne(cascade = CascadeType.ALL, optional = false) @JoinColumn(name = "c_connection_id", referencedColumnName = "id") private CommentConnection comments; - @ManyToOne(fetch = FetchType.LAZY) + /** + * The parent connection of the Pullrequest entity. + */ + @OneToOne(optional = false) @JoinColumn(name = "pr_connection_id", referencedColumnName = "id") private PullrequestConnection connection; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java index 2b3800c0..29a89128 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java @@ -2,13 +2,10 @@ import java.util.List; -import de.tum.in.www1.hephaestus.codereview.repository.Repository; import jakarta.persistence.Id; import jakarta.persistence.OneToMany; -import jakarta.persistence.OneToOne; import jakarta.persistence.Table; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import lombok.Getter; @@ -23,6 +20,6 @@ public class PullrequestConnection { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToMany(mappedBy = "connection", fetch = FetchType.LAZY) + @OneToMany(mappedBy = "connection") private List nodes; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index 87f69cf3..c597988f 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -3,6 +3,7 @@ import java.time.Instant; import de.tum.in.www1.hephaestus.codereview.pullrequest.PullrequestConnection; +import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -42,7 +43,7 @@ public class Repository { @Column private String url; - @OneToOne(optional = false) + @OneToOne(cascade = CascadeType.ALL, optional = false) @JoinColumn(name = "connection_id", referencedColumnName = "id") private PullrequestConnection pullRequests; From 45f228dd7a6260fcb13e1adf6306198cd614ec94 Mon Sep 17 00:00:00 2001 From: GODrums Date: Wed, 21 Aug 2024 22:46:17 +0200 Subject: [PATCH 06/50] Rework for Github API --- server/application-server/pom.xml | 6 ++ .../tum/in/www1/hephaestus/Application.java | 10 +++- .../codereview/CodeReviewService.java | 33 ++++++++--- .../codereview/comment/Comment.java | 8 +-- .../codereview/comment/CommentConnection.java | 25 -------- .../codereview/pullrequest/Pullrequest.java | 21 ++++--- .../pullrequest/PullrequestConnection.java | 25 -------- .../codereview/repository/Repository.java | 14 ++--- .../repository/RepositoryConverter.java | 28 +++++++++ .../repository/RepositoryRepository.java | 14 +++++ .../repository/RepositoryService.java | 57 +++++++++++++++++++ 11 files changed, 159 insertions(+), 82 deletions(-) delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryRepository.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java diff --git a/server/application-server/pom.xml b/server/application-server/pom.xml index 5a353d20..926e774d 100644 --- a/server/application-server/pom.xml +++ b/server/application-server/pom.xml @@ -125,6 +125,12 @@ org.springframework.boot spring-boot-starter-graphql + + org.kohsuke + github-api + 1.324 + + diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java index 9a3d34fa..9b9bd2b2 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java @@ -9,6 +9,7 @@ import de.tum.in.www1.hephaestus.codereview.CodeReviewService; import de.tum.in.www1.hephaestus.codereview.repository.Repository; +import de.tum.in.www1.hephaestus.codereview.repository.RepositoryService; @SpringBootApplication @Modulithic(systemName = "Hephaestus") @@ -20,10 +21,15 @@ public static void main(String[] args) { } @Bean - CommandLineRunner commandLineRunner(CodeReviewService service) { + CommandLineRunner commandLineRunner(CodeReviewService service, RepositoryService repositoryService) { return args -> { - Repository repo = service.getHephaestusRepository(); + Repository repo = service.fetchHephaestus(); System.out.println(repo); + repositoryService.saveRepository(repo); + System.out.println("Saved repo: " + repositoryService.countRepositories()); + + Repository repo2 = repositoryService.getAllRepositories().get(0); + System.out.println(repo2); }; } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java index 6d218095..b7212e16 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java @@ -1,10 +1,14 @@ package de.tum.in.www1.hephaestus.codereview; +import java.io.IOException; import java.time.Instant; import java.util.HashMap; import java.util.List; import java.util.Optional; +import org.kohsuke.github.GHRepository; +import org.kohsuke.github.GitHub; +import org.kohsuke.github.GitHubBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -14,6 +18,7 @@ import de.tum.in.www1.hephaestus.EnvConfig; import de.tum.in.www1.hephaestus.codereview.repository.Repository; +import de.tum.in.www1.hephaestus.codereview.repository.RepositoryConverter; @Service public class CodeReviewService { @@ -22,6 +27,8 @@ public class CodeReviewService { private final HttpSyncGraphQlClient graphQlClient; + private GitHub github; + private final CodeReviewRepository codeReviewRepository; private final EnvConfig envConfig; @@ -42,6 +49,24 @@ public CodeReviewService(CodeReviewRepository codeReviewRepository, EnvConfig en graphQlClient = HttpSyncGraphQlClient.builder(restClient) .headers(headers -> headers.setBearerAuth(githubPat)) .build(); + try { + github = new GitHubBuilder().withOAuthToken(envConfig.getGithubPat()).build(); + } catch (IOException e) { + logger.error("Error while creating GitHub client: " + e.getMessage()); + return; + } + } + + public Repository fetchHephaestus() throws IOException { + if (github == null) { + logger.error("GitHub client not initialized!"); + return null; + } + + GHRepository ghRepo = github.getRepository("ls1intum/hephaestus"); + System.out.println("Repository: " + ghRepo.toString()); + Repository repository = new RepositoryConverter().convert(ghRepo); + return repository; } public Repository getHephaestusRepository() { @@ -49,15 +74,11 @@ public Repository getHephaestusRepository() { example.setName("hephaestus"); example.setNameWithOwner("ls1intum/hephaestus"); Optional foundRepo = codeReviewRepository.findOne(Example.of(example)); - logger.info("Repository count: " + codeReviewRepository.count()); - - logger.info("Saved repo: " + foundRepo.toString()); if (foundRepo.isPresent()) { return foundRepo.get(); } logger.info("No repo found, creating new one..."); - HashMap variables = new HashMap<>(); variables.put("owner", "ls1intum"); variables.put("name", "hephaestus"); @@ -67,16 +88,12 @@ public Repository getHephaestusRepository() { .variables(variables) .retrieveSync("repository") .toEntity(Repository.class); - if (repository == null) { logger.error("Error while fetching repository!"); return null; } repository.setAddedAt(Instant.now()); - - System.out.println("Repository: " + repository.toString()); codeReviewRepository.saveAndFlush(repository); - System.out.println("New Repository count: " + codeReviewRepository.count()); return repository; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java index 17fcfa1c..1d371c78 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java @@ -3,6 +3,7 @@ import jakarta.persistence.Id; import jakarta.persistence.Table; import de.tum.in.www1.hephaestus.codereview.actor.Actor; +import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; @@ -10,7 +11,6 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToOne; import lombok.Getter; import lombok.Setter; @@ -60,8 +60,8 @@ public class Comment { /** * The parent connection to the pullrequest of the Comment entity. */ - @OneToOne(optional = false) - @JoinColumn(name = "c_connection_id", referencedColumnName = "id") - private CommentConnection connection; + @ManyToOne(optional = false) + @JoinColumn(name = "pullrequest_id", referencedColumnName = "id") + private Pullrequest pullrequest; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java deleted file mode 100644 index bc926473..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview.comment; - -import java.util.List; - -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; -import jakarta.persistence.Table; -import lombok.Getter; -import lombok.Setter; - -@Entity -@Table -@Getter -@Setter -public class CommentConnection { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @OneToMany(mappedBy = "connection") - private List nodes; -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index 26701001..c4c7abde 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -1,7 +1,10 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; +import java.util.List; + import de.tum.in.www1.hephaestus.codereview.actor.Actor; -import de.tum.in.www1.hephaestus.codereview.comment.CommentConnection; +import de.tum.in.www1.hephaestus.codereview.comment.Comment; +import de.tum.in.www1.hephaestus.codereview.repository.Repository; import jakarta.persistence.Id; import jakarta.persistence.Table; import jakarta.persistence.CascadeType; @@ -12,7 +15,7 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToOne; +import jakarta.persistence.OneToMany; import lombok.Getter; import lombok.Setter; @@ -80,17 +83,13 @@ public class Pullrequest { @JoinColumn(name = "author_id") private Actor author; - /** - * The comments of the Pullrequest entity. - */ - @OneToOne(cascade = CascadeType.ALL, optional = false) - @JoinColumn(name = "c_connection_id", referencedColumnName = "id") - private CommentConnection comments; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "pullrequest") + private List pullRequests; /** * The parent connection of the Pullrequest entity. */ - @OneToOne(optional = false) - @JoinColumn(name = "pr_connection_id", referencedColumnName = "id") - private PullrequestConnection connection; + @ManyToOne(optional = false) + @JoinColumn(name = "repository_id", referencedColumnName = "id") + private Repository repository; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java deleted file mode 100644 index 29a89128..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview.pullrequest; - -import java.util.List; - -import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; -import jakarta.persistence.Table; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import lombok.Getter; -import lombok.Setter; - -@Entity -@Table -@Getter -@Setter -public class PullrequestConnection { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @OneToMany(mappedBy = "connection") - private List nodes; -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index c597988f..45ea91c2 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -1,16 +1,16 @@ package de.tum.in.www1.hephaestus.codereview.repository; import java.time.Instant; +import java.util.List; -import de.tum.in.www1.hephaestus.codereview.pullrequest.PullrequestConnection; +import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.OneToOne; +import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import lombok.Getter; import lombok.Setter; @@ -43,15 +43,15 @@ public class Repository { @Column private String url; - @OneToOne(cascade = CascadeType.ALL, optional = false) - @JoinColumn(name = "connection_id", referencedColumnName = "id") - private PullrequestConnection pullRequests; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "repository") + private List pullRequests; @Column(name = "added_at") private Instant addedAt; public String toString() { return "Repository [id=" + id + ", name=" + name + ", nameWithOwner=" + nameWithOwner + ", description=" - + description + ", url=" + url + ", pullRequests=" + pullRequests + ", addedAt=" + addedAt + "]"; + + description + ", url=" + url + ", pullRequests=" + pullRequests + ", addedAt=" + addedAt + + "]"; } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java new file mode 100644 index 00000000..026130b2 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java @@ -0,0 +1,28 @@ +package de.tum.in.www1.hephaestus.codereview.repository; + +import java.time.Instant; + +import org.kohsuke.github.GHRepository; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.convert.ReadingConverter; +import org.springframework.lang.NonNull; +import org.springframework.lang.Nullable; +import org.springframework.stereotype.Service; + +@Service +@ReadingConverter +public class RepositoryConverter implements Converter { + + @Override + @Nullable + public Repository convert(@NonNull GHRepository source) { + Repository repository = new Repository(); + repository.setName(source.getName()); + repository.setNameWithOwner(source.getFullName()); + repository.setUrl(source.getHtmlUrl().toString()); + repository.setDescription(source.getDescription()); + repository.setAddedAt(Instant.now()); + return repository; + } + +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryRepository.java new file mode 100644 index 00000000..61faa18b --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryRepository.java @@ -0,0 +1,14 @@ +package de.tum.in.www1.hephaestus.codereview.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import de.tum.in.www1.hephaestus.codereview.repository.Repository; + +@org.springframework.stereotype.Repository +public interface RepositoryRepository + extends JpaRepository { + + @Query("SELECT r FROM Repository r WHERE r.nameWithOwner = ?1") + Repository findByNameWithOwner(String nameWithOwner); +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java new file mode 100644 index 00000000..fbcac491 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java @@ -0,0 +1,57 @@ +package de.tum.in.www1.hephaestus.codereview.repository; + +import java.time.Instant; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +@Service +public class RepositoryService { + private static final Logger logger = LoggerFactory.getLogger(Repository.class); + + private final RepositoryRepository repositoryRepository; + + public RepositoryService(RepositoryRepository repositoryRepository) { + this.repositoryRepository = repositoryRepository; + } + + /** + * Retrieves all {@link Repository} entities. + * + * @return A list of all Repository entities + */ + public List getAllRepositories() { + var repositories = repositoryRepository.findAll(); + logger.info("Getting Repositories: {}", repositories); + return repositoryRepository.findAll(); + } + + public Repository getRepository(String nameWithOwner) { + return repositoryRepository.findByNameWithOwner(nameWithOwner); + } + + /** + * Creates a new {@link Repository} entity with the current timestamp and saves + * it to + * the repository. + * + * @return The created Repository entity + */ + public Repository addRepository() { + Repository repository = new Repository(); + repository.setAddedAt(Instant.now()); + logger.info("Adding new Repository with timestamp: {}", repository.getAddedAt()); + return repositoryRepository.save(repository); + } + + public Repository saveRepository(Repository repository) { + logger.info("Adding Repository: {}", repository.getNameWithOwner()); + return repositoryRepository.save(repository); + } + + public long countRepositories() { + return repositoryRepository.count(); + } +} From 37d1d2b2bdc0cec75d8ae1c6e43a8c182e84e798 Mon Sep 17 00:00:00 2001 From: GODrums Date: Sat, 24 Aug 2024 03:44:49 +0200 Subject: [PATCH 07/50] Rework repo fetch --- .../tum/in/www1/hephaestus/Application.java | 8 +- .../codereview/CodeReviewRepository.java | 10 --- .../codereview/CodeReviewService.java | 76 +++++++++++++++++-- .../hephaestus/codereview/actor/Actor.java | 2 +- .../codereview/comment/Comment.java | 13 +++- .../codereview/comment/CommentConverter.java | 32 ++++++++ .../codereview/comment/CommentRepository.java | 7 ++ .../codereview/pullrequest/Pullrequest.java | 8 +- .../pullrequest/PullrequestConverter.java | 40 ++++++++++ .../pullrequest/PullrequestRepository.java | 18 +++++ .../codereview/repository/Repository.java | 7 +- .../repository/RepositoryConverter.java | 3 + .../repository/RepositoryService.java | 9 ++- .../src/main/resources/application.yml | 3 + 14 files changed, 204 insertions(+), 32 deletions(-) delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewRepository.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConverter.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentRepository.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java index 9b9bd2b2..94905467 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java @@ -1,5 +1,7 @@ package de.tum.in.www1.hephaestus; +import java.util.List; + import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -24,12 +26,12 @@ public static void main(String[] args) { CommandLineRunner commandLineRunner(CodeReviewService service, RepositoryService repositoryService) { return args -> { Repository repo = service.fetchHephaestus(); - System.out.println(repo); + System.out.println("Got repo: " + repo); repositoryService.saveRepository(repo); System.out.println("Saved repo: " + repositoryService.countRepositories()); - Repository repo2 = repositoryService.getAllRepositories().get(0); - System.out.println(repo2); + List repo2 = repositoryService.getAllRepositories(); + System.out.println("Repositories: " + repo2); }; } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewRepository.java deleted file mode 100644 index b99fe256..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface CodeReviewRepository - extends JpaRepository { - -} \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java index b7212e16..6e1df9f6 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java @@ -2,9 +2,11 @@ import java.io.IOException; import java.time.Instant; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; import org.kohsuke.github.GHRepository; import org.kohsuke.github.GitHub; @@ -13,12 +15,20 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; + import org.springframework.data.domain.Example; import org.springframework.graphql.client.HttpSyncGraphQlClient; import de.tum.in.www1.hephaestus.EnvConfig; +import de.tum.in.www1.hephaestus.codereview.comment.Comment; +import de.tum.in.www1.hephaestus.codereview.comment.CommentConverter; +import de.tum.in.www1.hephaestus.codereview.comment.CommentRepository; +import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; +import de.tum.in.www1.hephaestus.codereview.pullrequest.PullrequestConverter; +import de.tum.in.www1.hephaestus.codereview.pullrequest.PullrequestRepository; import de.tum.in.www1.hephaestus.codereview.repository.Repository; import de.tum.in.www1.hephaestus.codereview.repository.RepositoryConverter; +import de.tum.in.www1.hephaestus.codereview.repository.RepositoryRepository; @Service public class CodeReviewService { @@ -29,22 +39,26 @@ public class CodeReviewService { private GitHub github; - private final CodeReviewRepository codeReviewRepository; + private final RepositoryRepository repositoryRepository; + private final PullrequestRepository pullrequestRepository; + private final CommentRepository commentRepository; private final EnvConfig envConfig; - public CodeReviewService(CodeReviewRepository codeReviewRepository, EnvConfig envConfig) { + public CodeReviewService(EnvConfig envConfig, RepositoryRepository repositoryRepository, + PullrequestRepository pullrequestRepository, CommentRepository commentRepository) { logger.info("Hello from CodeReviewService!"); - this.codeReviewRepository = codeReviewRepository; this.envConfig = envConfig; + this.repositoryRepository = repositoryRepository; + this.pullrequestRepository = pullrequestRepository; + this.commentRepository = commentRepository; RestClient restClient = RestClient.builder() .baseUrl("https://api.github.com/graphql") .build(); String githubPat = this.envConfig.getGithubPat(); - logger.info("Github PAT: " + githubPat); graphQlClient = HttpSyncGraphQlClient.builder(restClient) .headers(headers -> headers.setBearerAuth(githubPat)) @@ -57,6 +71,11 @@ public CodeReviewService(CodeReviewRepository codeReviewRepository, EnvConfig en } } + /** + * Rest API implementation of fetching the hephaestus Github repository. + * + * @return The hephaestus repository. + */ public Repository fetchHephaestus() throws IOException { if (github == null) { logger.error("GitHub client not initialized!"); @@ -64,16 +83,57 @@ public Repository fetchHephaestus() throws IOException { } GHRepository ghRepo = github.getRepository("ls1intum/hephaestus"); - System.out.println("Repository: " + ghRepo.toString()); + logger.info("Fetched from GitHub: " + ghRepo.toString()); Repository repository = new RepositoryConverter().convert(ghRepo); + if (repository == null) { + logger.error("Error while fetching repository!"); + return null; + } + // preliminary save to make it referenceable + repositoryRepository.save(repository); + + PullrequestConverter prConverter = new PullrequestConverter(); + CommentConverter commentConverter = new CommentConverter(); + + List prs = ghRepo.queryPullRequests().list().withPageSize(1).toList().stream().map(pr -> { + Pullrequest pullrequest = prConverter.convert(pr); + if (pullrequest != null) { + pullrequest.setRepository(repository); + pullrequestRepository.save(pullrequest); + try { + List comments = pr.queryComments().list().toList().stream() + .map(comment -> { + Comment c = commentConverter.convert(comment); + if (c != null) { + c.setPullrequest(pullrequest); + } + return c; + }).collect(Collectors.toList()); + pullrequest.setComments(comments); + commentRepository.saveAll(comments); + } catch (IOException e) { + logger.error("Error while fetching comments!"); + pullrequest.setComments(new ArrayList<>()); + } + } + return pullrequest; + }).collect(Collectors.toList()); + repository.setPullRequests(prs); + pullrequestRepository.saveAll(prs); + repositoryRepository.save(repository); return repository; } + /** + * GraphQL implementation of fetching the hephaestus Github repository. + * + * @return The hephaestus repository. + */ public Repository getHephaestusRepository() { Repository example = new Repository(); example.setName("hephaestus"); example.setNameWithOwner("ls1intum/hephaestus"); - Optional foundRepo = codeReviewRepository.findOne(Example.of(example)); + Optional foundRepo = repositoryRepository.findOne(Example.of(example)); if (foundRepo.isPresent()) { return foundRepo.get(); } @@ -93,12 +153,12 @@ public Repository getHephaestusRepository() { return null; } repository.setAddedAt(Instant.now()); - codeReviewRepository.saveAndFlush(repository); + repositoryRepository.saveAndFlush(repository); return repository; } public List getAllRepositories() { - return codeReviewRepository.findAll(); + return repositoryRepository.findAll(); } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java index 34396ab6..c30e54e5 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java @@ -16,7 +16,7 @@ import lombok.Setter; @Entity -@Table +@Table(name = "actors") @Getter @Setter public class Actor { diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java index 1d371c78..b9977baf 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java @@ -15,7 +15,7 @@ import lombok.Setter; @Entity -@Table +@Table(name = "comments") @Getter @Setter public class Comment { @@ -27,7 +27,7 @@ public class Comment { private Long id; @Column(name = "github_id") - private String githubId; + private Long githubId; /** * Body of the Comment entity. @@ -64,4 +64,13 @@ public class Comment { @JoinColumn(name = "pullrequest_id", referencedColumnName = "id") private Pullrequest pullrequest; + public Comment() { + + } + + public Comment(String body, String createdAt, String updatedAt) { + this.body = body; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConverter.java new file mode 100644 index 00000000..1a0c5f97 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConverter.java @@ -0,0 +1,32 @@ +package de.tum.in.www1.hephaestus.codereview.comment; + +import java.io.IOException; + +import org.kohsuke.github.GHIssueComment; +import org.springframework.core.convert.converter.Converter; +import org.springframework.lang.NonNull; + +public class CommentConverter implements Converter { + + @Override + public Comment convert(@NonNull GHIssueComment source) { + Comment comment = new Comment(); + comment.setBody(source.getBody()); + comment.setGithubId(source.getId()); + try { + comment.setCreatedAt(source.getCreatedAt().toString()); + } catch (IOException e) { + comment.setCreatedAt(null); + } + try { + comment.setUpdatedAt(source.getUpdatedAt().toString()); + } catch (IOException e) { + comment.setUpdatedAt(null); + } + // set preliminary values to be filled in later + comment.setPullrequest(null); + comment.setAuthor(null); + return comment; + } + +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentRepository.java new file mode 100644 index 00000000..f224b751 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentRepository.java @@ -0,0 +1,7 @@ +package de.tum.in.www1.hephaestus.codereview.comment; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CommentRepository extends JpaRepository { + +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index c4c7abde..1dc23fbd 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -20,7 +20,7 @@ import lombok.Setter; @Entity -@Table +@Table(name = "pullrequests") @Getter @Setter public class Pullrequest { @@ -33,7 +33,7 @@ public class Pullrequest { private Long id; @Column(name = "github_id") - private String githubId; + private Long githubId; /** * Title of the Pullrequest. @@ -84,12 +84,12 @@ public class Pullrequest { private Actor author; @OneToMany(cascade = CascadeType.ALL, mappedBy = "pullrequest") - private List pullRequests; + private List comments; /** * The parent connection of the Pullrequest entity. */ - @ManyToOne(optional = false) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "repository_id", referencedColumnName = "id") private Repository repository; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java new file mode 100644 index 00000000..f44d1d96 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java @@ -0,0 +1,40 @@ +package de.tum.in.www1.hephaestus.codereview.pullrequest; + +import java.io.IOException; +import java.util.ArrayList; + +import org.kohsuke.github.GHPullRequest; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.convert.ReadingConverter; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Service; + +@Service +@ReadingConverter +public class PullrequestConverter implements Converter { + @Override + public Pullrequest convert(@NonNull GHPullRequest source) { + Pullrequest pullrequest = new Pullrequest(); + pullrequest.setGithubId(source.getId()); + pullrequest.setTitle(source.getTitle()); + pullrequest.setUrl(source.getHtmlUrl().toString()); + pullrequest.setState(source.getState().toString()); + try { + pullrequest.setCreatedAt(source.getCreatedAt().toString()); + } catch (IOException e) { + pullrequest.setCreatedAt(null); + } + try { + pullrequest.setUpdatedAt(source.getUpdatedAt().toString()); + } catch (IOException e) { + pullrequest.setUpdatedAt(null); + } + pullrequest.setMergedAt(source.getMergedAt() != null ? source.getMergedAt().toString() : null); + // set preliminary values to be filled in later + pullrequest.setComments(new ArrayList<>()); + pullrequest.setAuthor(null); + pullrequest.setRepository(null); + return pullrequest; + } + +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java new file mode 100644 index 00000000..c4a1e532 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java @@ -0,0 +1,18 @@ +package de.tum.in.www1.hephaestus.codereview.pullrequest; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import de.tum.in.www1.hephaestus.codereview.actor.Actor; + +@Repository +public interface PullrequestRepository extends JpaRepository { + + @Query("SELECT p FROM Pullrequest p WHERE p.githubId = ?1") + Pullrequest findByGithubId(Long githubId); + + @Query("SELECT p FROM Pullrequest p WHERE p.author = ?1") + Pullrequest findByAuthor(Actor author); + +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index 45ea91c2..583ca5b8 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -7,6 +7,7 @@ import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; @@ -16,7 +17,7 @@ import lombok.Setter; @Entity -@Table +@Table(name = "repositories") @Getter @Setter public class Repository { @@ -29,7 +30,7 @@ public class Repository { private Long id; @Column(name = "github_id") - private String githubId; + private Long githubId; @Column private String name; @@ -43,7 +44,7 @@ public class Repository { @Column private String url; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "repository") + @OneToMany(cascade = CascadeType.ALL, mappedBy = "repository", fetch = FetchType.EAGER) private List pullRequests; @Column(name = "added_at") diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java index 026130b2..7b54699e 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java @@ -1,6 +1,7 @@ package de.tum.in.www1.hephaestus.codereview.repository; import java.time.Instant; +import java.util.ArrayList; import org.kohsuke.github.GHRepository; import org.springframework.core.convert.converter.Converter; @@ -22,6 +23,8 @@ public Repository convert(@NonNull GHRepository source) { repository.setUrl(source.getHtmlUrl().toString()); repository.setDescription(source.getDescription()); repository.setAddedAt(Instant.now()); + repository.setGithubId(source.getId()); + repository.setPullRequests(new ArrayList<>()); return repository; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java index fbcac491..806bc239 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java @@ -24,7 +24,7 @@ public RepositoryService(RepositoryRepository repositoryRepository) { */ public List getAllRepositories() { var repositories = repositoryRepository.findAll(); - logger.info("Getting Repositories: {}", repositories); + logger.info("Getting Repositories: {}", repositories.toArray()); return repositoryRepository.findAll(); } @@ -47,6 +47,13 @@ public Repository addRepository() { } public Repository saveRepository(Repository repository) { + Repository existingRepository = repositoryRepository.findByNameWithOwner(repository.getNameWithOwner()); + logger.info("Found Repository: {}", existingRepository); + if (existingRepository != null) { + logger.info("Repository already exists: {}", existingRepository.getNameWithOwner()); + return existingRepository; + } + logger.info("Adding Repository: {}", repository.getNameWithOwner()); return repositoryRepository.save(repository); } diff --git a/server/application-server/src/main/resources/application.yml b/server/application-server/src/main/resources/application.yml index 4527b520..383f97cd 100644 --- a/server/application-server/src/main/resources/application.yml +++ b/server/application-server/src/main/resources/application.yml @@ -9,10 +9,13 @@ spring: jpa: hibernate: + # ddl-auto: update ddl-auto: create-drop + # show-sql: "true" properties: hibernate: dialect: org.hibernate.dialect.PostgreSQLDialect + format_sql: "true" liquibase: change-log: classpath:db/master.xml From 78db6d299e99b3c1ae988ec99d68c1d504ed5b1c Mon Sep 17 00:00:00 2001 From: GODrums Date: Mon, 26 Aug 2024 01:58:58 +0200 Subject: [PATCH 08/50] Add endpoints for entities --- .../tum/in/www1/hephaestus/Application.java | 10 +- .../codereview/CodeReviewController.java | 21 ++-- .../codereview/CodeReviewService.java | 112 +++++++++++++----- .../hephaestus/codereview/actor/Actor.java | 35 ++++++ .../codereview/actor/ActorController.java | 22 ++++ .../codereview/actor/ActorConverter.java | 27 +++++ .../codereview/actor/ActorRepository.java | 10 ++ .../codereview/actor/ActorService.java | 22 ++++ .../codereview/comment/Comment.java | 13 ++ .../codereview/pullrequest/Pullrequest.java | 14 +++ .../pullrequest/PullrequestController.java | 28 +++++ .../pullrequest/PullrequestRepository.java | 8 +- .../pullrequest/PullrequestService.java | 29 +++++ .../codereview/repository/Repository.java | 2 +- .../repository/RepositoryController.java | 39 ++++++ .../repository/RepositoryService.java | 1 + 16 files changed, 338 insertions(+), 55 deletions(-) create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorController.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorConverter.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorRepository.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorService.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryController.java diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java index 94905467..54cf5ea1 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java @@ -11,7 +11,6 @@ import de.tum.in.www1.hephaestus.codereview.CodeReviewService; import de.tum.in.www1.hephaestus.codereview.repository.Repository; -import de.tum.in.www1.hephaestus.codereview.repository.RepositoryService; @SpringBootApplication @Modulithic(systemName = "Hephaestus") @@ -23,15 +22,10 @@ public static void main(String[] args) { } @Bean - CommandLineRunner commandLineRunner(CodeReviewService service, RepositoryService repositoryService) { + CommandLineRunner commandLineRunner(CodeReviewService service) { return args -> { - Repository repo = service.fetchHephaestus(); + Repository repo = service.fetchRepository("ls1intum/hephaestus"); System.out.println("Got repo: " + repo); - repositoryService.saveRepository(repo); - System.out.println("Saved repo: " + repositoryService.countRepositories()); - - List repo2 = repositoryService.getAllRepositories(); - System.out.println("Repositories: " + repo2); }; } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewController.java index 778a9634..0066bc98 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewController.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewController.java @@ -1,9 +1,10 @@ package de.tum.in.www1.hephaestus.codereview; -import java.util.List; +import java.io.IOException; -import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import de.tum.in.www1.hephaestus.codereview.repository.Repository; @@ -17,13 +18,13 @@ public CodeReviewController(CodeReviewService codeReviewService) { this.codeReviewService = codeReviewService; } - /** - * Retrieves all {@link Repository} entities. - * - * @return A list of all Repository entities - */ - @GetMapping - public List getAllRepositories() { - return codeReviewService.getAllRepositories(); + @PutMapping("/repository/{nameWithOwner}") + public Repository addRepository(@RequestParam String nameWithOwner) { + try { + return codeReviewService.fetchRepository(nameWithOwner); + } catch (IOException e) { + e.printStackTrace(); + return null; + } } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java index 6e1df9f6..f41c8894 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java @@ -8,7 +8,9 @@ import java.util.Optional; import java.util.stream.Collectors; +import org.kohsuke.github.GHPullRequest; import org.kohsuke.github.GHRepository; +import org.kohsuke.github.GHUser; import org.kohsuke.github.GitHub; import org.kohsuke.github.GitHubBuilder; import org.slf4j.Logger; @@ -20,6 +22,9 @@ import org.springframework.graphql.client.HttpSyncGraphQlClient; import de.tum.in.www1.hephaestus.EnvConfig; +import de.tum.in.www1.hephaestus.codereview.actor.Actor; +import de.tum.in.www1.hephaestus.codereview.actor.ActorConverter; +import de.tum.in.www1.hephaestus.codereview.actor.ActorRepository; import de.tum.in.www1.hephaestus.codereview.comment.Comment; import de.tum.in.www1.hephaestus.codereview.comment.CommentConverter; import de.tum.in.www1.hephaestus.codereview.comment.CommentRepository; @@ -42,17 +47,20 @@ public class CodeReviewService { private final RepositoryRepository repositoryRepository; private final PullrequestRepository pullrequestRepository; private final CommentRepository commentRepository; + private final ActorRepository actorRepository; private final EnvConfig envConfig; public CodeReviewService(EnvConfig envConfig, RepositoryRepository repositoryRepository, - PullrequestRepository pullrequestRepository, CommentRepository commentRepository) { + PullrequestRepository pullrequestRepository, CommentRepository commentRepository, + ActorRepository actorRepository) { logger.info("Hello from CodeReviewService!"); this.envConfig = envConfig; this.repositoryRepository = repositoryRepository; this.pullrequestRepository = pullrequestRepository; this.commentRepository = commentRepository; + this.actorRepository = actorRepository; RestClient restClient = RestClient.builder() .baseUrl("https://api.github.com/graphql") @@ -72,18 +80,25 @@ public CodeReviewService(EnvConfig envConfig, RepositoryRepository repositoryRep } /** - * Rest API implementation of fetching the hephaestus Github repository. + * Rest API implementation of fetching a Github repository. * - * @return The hephaestus repository. + * @return The repository corresponding to the given nameWithOwner. + * @throws IOException */ - public Repository fetchHephaestus() throws IOException { + public Repository fetchRepository(String nameWithOwner) throws IOException { if (github == null) { - logger.error("GitHub client not initialized!"); + logger.error("GitHub client not initialized correctly!"); return null; } - GHRepository ghRepo = github.getRepository("ls1intum/hephaestus"); - logger.info("Fetched from GitHub: " + ghRepo.toString()); + // Avoid double fetching of the same repository + Repository existingRepository = repositoryRepository.findByNameWithOwner(nameWithOwner); + if (existingRepository != null) { + logger.info("Found existing repository: " + existingRepository); + return existingRepository; + } + + GHRepository ghRepo = github.getRepository(nameWithOwner); Repository repository = new RepositoryConverter().convert(ghRepo); if (repository == null) { logger.error("Error while fetching repository!"); @@ -93,29 +108,27 @@ public Repository fetchHephaestus() throws IOException { repositoryRepository.save(repository); PullrequestConverter prConverter = new PullrequestConverter(); - CommentConverter commentConverter = new CommentConverter(); - List prs = ghRepo.queryPullRequests().list().withPageSize(1).toList().stream().map(pr -> { + // Retrieve PRs in pages of 10 + List prs = ghRepo.queryPullRequests().list().withPageSize(10).toList().stream().map(pr -> { Pullrequest pullrequest = prConverter.convert(pr); - if (pullrequest != null) { - pullrequest.setRepository(repository); - pullrequestRepository.save(pullrequest); - try { - List comments = pr.queryComments().list().toList().stream() - .map(comment -> { - Comment c = commentConverter.convert(comment); - if (c != null) { - c.setPullrequest(pullrequest); - } - return c; - }).collect(Collectors.toList()); - pullrequest.setComments(comments); - commentRepository.saveAll(comments); - } catch (IOException e) { - logger.error("Error while fetching comments!"); - pullrequest.setComments(new ArrayList<>()); - } + pullrequest.setRepository(repository); + pullrequestRepository.save(pullrequest); + try { + List comments = getCommentsFromGHPullRequest(pr, pullrequest); + pullrequest.setComments(comments); + commentRepository.saveAll(comments); + } catch (IOException e) { + logger.error("Error while fetching PR comments!"); + pullrequest.setComments(new ArrayList<>()); + } + try { + pullrequest.setAuthor(getActorFromGHUser(pr.getUser())); + } catch (IOException e) { + logger.error("Error while fetching PR author!"); + pullrequest.setAuthor(null); } + return pullrequest; }).collect(Collectors.toList()); repository.setPullRequests(prs); @@ -124,9 +137,49 @@ public Repository fetchHephaestus() throws IOException { return repository; } + /** + * Retrieves the comments of a given pull request. + * + * @param pr The GH pull request. + * @param pullrequest Stored PR to which the comments belong. + * @return The comments of the given pull request. + * @throws IOException + */ + private List getCommentsFromGHPullRequest(GHPullRequest pr, Pullrequest pullrequest) + throws IOException { + CommentConverter commentConverter = new CommentConverter(); + List comments = pr.queryComments().list().toList().stream() + .map(comment -> { + Comment c = commentConverter.convert(comment); + c.setPullrequest(pullrequest); + Actor author; + try { + author = getActorFromGHUser(comment.getUser()); + author.addComment(c); + author.addPullrequest(pullrequest); + } catch (IOException e) { + logger.error("Error while fetching author!"); + author = null; + } + c.setAuthor(author); + return c; + }).collect(Collectors.toList()); + return comments; + } + + private Actor getActorFromGHUser(GHUser user) { + Actor actor = actorRepository.findByLogin(user.getLogin()); + if (actor == null) { + actor = new ActorConverter().convert(user); + actorRepository.save(actor); + } + return actor; + } + /** * GraphQL implementation of fetching the hephaestus Github repository. * + * @see #fetchRepository(String) * @return The hephaestus repository. */ public Repository getHephaestusRepository() { @@ -156,9 +209,4 @@ public Repository getHephaestusRepository() { repositoryRepository.saveAndFlush(repository); return repository; } - - public List getAllRepositories() { - return repositoryRepository.findAll(); - } - } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java index c30e54e5..57749bbc 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java @@ -3,8 +3,12 @@ import jakarta.persistence.Id; import jakarta.persistence.Table; +import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; + import de.tum.in.www1.hephaestus.codereview.comment.Comment; import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; import jakarta.persistence.Column; @@ -19,6 +23,7 @@ @Table(name = "actors") @Getter @Setter +@JsonInclude(JsonInclude.Include.NON_EMPTY) public class Actor { /** * Unique identifier for a User entity. @@ -34,6 +39,9 @@ public class Actor { @Column(nullable = false) private String login; + @Column + private String email; + /** * URL of the User entity. * This field is mandatory. @@ -45,11 +53,38 @@ public class Actor { * The Pullrequests of the User entity. */ @OneToMany(mappedBy = "author") + @JsonIgnore private List pullrequests; /** * The Comments of the User entity. */ @OneToMany(mappedBy = "author") + @JsonIgnore private List comments; + + public void addComment(Comment comment) { + if (comments == null) { + comments = new ArrayList<>(); + } + if (!comments.contains(comment)) { + comments.add(comment); + } + } + + public void addPullrequest(Pullrequest pullrequest) { + if (pullrequests == null) { + pullrequests = new ArrayList<>(); + } + if (!pullrequests.contains(pullrequest)) { + pullrequests.add(pullrequest); + } + } + + @Override + public String toString() { + return "Actor [id=" + id + ", login=" + login + ", email=" + email + ", url=" + + url + ", #pullrequests=" + + pullrequests.size() + ", #comments=" + comments.size() + "]"; + } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorController.java new file mode 100644 index 00000000..34249681 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorController.java @@ -0,0 +1,22 @@ +package de.tum.in.www1.hephaestus.codereview.actor; + +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("/actor") +public class ActorController { + private final ActorService actorService; + + public ActorController(ActorService actorService) { + this.actorService = actorService; + } + + @GetMapping("/{login}") + public Actor getActor(@PathVariable String login) { + return actorService.getActor(login); + } + +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorConverter.java new file mode 100644 index 00000000..88f911e9 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorConverter.java @@ -0,0 +1,27 @@ +package de.tum.in.www1.hephaestus.codereview.actor; + +import java.io.IOException; +import java.util.ArrayList; + +import org.kohsuke.github.GHUser; +import org.springframework.core.convert.converter.Converter; +import org.springframework.lang.NonNull; + +public class ActorConverter implements Converter { + + @Override + public Actor convert(@NonNull GHUser source) { + Actor actor = new Actor(); + actor.setLogin(source.getLogin()); + try { + actor.setEmail(source.getEmail()); + } catch (IOException e) { + actor.setEmail(null); + } + actor.setUrl(source.getHtmlUrl().toString()); + actor.setPullrequests(new ArrayList<>()); + actor.setComments(new ArrayList<>()); + return actor; + } + +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorRepository.java new file mode 100644 index 00000000..8d0dcd4d --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorRepository.java @@ -0,0 +1,10 @@ +package de.tum.in.www1.hephaestus.codereview.actor; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +public interface ActorRepository extends JpaRepository { + + @Query("SELECT a FROM Actor a WHERE a.login = ?1") + Actor findByLogin(String login); +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorService.java new file mode 100644 index 00000000..5da9471a --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorService.java @@ -0,0 +1,22 @@ +package de.tum.in.www1.hephaestus.codereview.actor; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +@Service +public class ActorService { + private static final Logger logger = LoggerFactory.getLogger(Actor.class); + + private final ActorRepository actorRepository; + + public ActorService(ActorRepository actorRepository) { + this.actorRepository = actorRepository; + } + + public Actor getActor(String login) { + logger.info("Getting actor with login: " + login); + return actorRepository.findByLogin(login); + } + +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java index b9977baf..a8c49dbc 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java @@ -2,6 +2,10 @@ import jakarta.persistence.Id; import jakarta.persistence.Table; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; + import de.tum.in.www1.hephaestus.codereview.actor.Actor; import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; import jakarta.persistence.Column; @@ -18,6 +22,7 @@ @Table(name = "comments") @Getter @Setter +@JsonInclude(JsonInclude.Include.NON_EMPTY) public class Comment { /** * Unique identifier for a Comment entity. @@ -62,6 +67,7 @@ public class Comment { */ @ManyToOne(optional = false) @JoinColumn(name = "pullrequest_id", referencedColumnName = "id") + @JsonIgnore private Pullrequest pullrequest; public Comment() { @@ -73,4 +79,11 @@ public Comment(String body, String createdAt, String updatedAt) { this.createdAt = createdAt; this.updatedAt = updatedAt; } + + @Override + public String toString() { + return "Comment [id=" + id + ", githubId=" + githubId + ", body=" + body + ", createdAt=" + createdAt + + ", updatedAt=" + updatedAt + ", author=" + author.getLogin() + ", pullrequest=" + + pullrequest.getTitle() + "]"; + } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index 1dc23fbd..ed66a8ac 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -2,6 +2,9 @@ import java.util.List; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; + import de.tum.in.www1.hephaestus.codereview.actor.Actor; import de.tum.in.www1.hephaestus.codereview.comment.Comment; import de.tum.in.www1.hephaestus.codereview.repository.Repository; @@ -23,6 +26,7 @@ @Table(name = "pullrequests") @Getter @Setter +@JsonInclude(JsonInclude.Include.NON_EMPTY) public class Pullrequest { /** @@ -91,5 +95,15 @@ public class Pullrequest { */ @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "repository_id", referencedColumnName = "id") + @JsonIgnore private Repository repository; + + @Override + public String toString() { + return "Pullrequest [id=" + id + ", githubId=" + githubId + ", title=" + + title + ", url=" + url + ", state=" + + state + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + ", mergedAt=" + mergedAt + + ", author=" + author.getLogin() + ", #comments=" + comments.size() + ", repository=" + + repository.getNameWithOwner() + "]"; + } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java new file mode 100644 index 00000000..4367ab06 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java @@ -0,0 +1,28 @@ +package de.tum.in.www1.hephaestus.codereview.pullrequest; + +import java.util.List; + +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("/pr") +public class PullrequestController { + private final PullrequestService pullrequestService; + + public PullrequestController(PullrequestService pullrequestService) { + this.pullrequestService = pullrequestService; + } + + @GetMapping("/{id}") + public Pullrequest getPullrequest(@PathVariable Long id) { + return pullrequestService.getPullrequestById(id); + } + + @GetMapping("/author/{login}") + public List getPullrequestsByAuthor(@PathVariable String login) { + return pullrequestService.getPullrequestsByAuthor(login); + } +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java index c4a1e532..ab9f5fef 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java @@ -1,18 +1,18 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; -import de.tum.in.www1.hephaestus.codereview.actor.Actor; - @Repository public interface PullrequestRepository extends JpaRepository { @Query("SELECT p FROM Pullrequest p WHERE p.githubId = ?1") Pullrequest findByGithubId(Long githubId); - @Query("SELECT p FROM Pullrequest p WHERE p.author = ?1") - Pullrequest findByAuthor(Actor author); + @Query("SELECT p FROM Pullrequest p, Actor a WHERE p.author = a AND a.login = ?1") + List findByAuthor(String authorLogin); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java new file mode 100644 index 00000000..c9c96d15 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java @@ -0,0 +1,29 @@ +package de.tum.in.www1.hephaestus.codereview.pullrequest; + +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +@Service +public class PullrequestService { + private static final Logger logger = LoggerFactory.getLogger(Pullrequest.class); + + private final PullrequestRepository pullrequestRepository; + + public PullrequestService(PullrequestRepository pullrequestRepository) { + this.pullrequestRepository = pullrequestRepository; + } + + public Pullrequest getPullrequestById(Long id) { + logger.info("Getting pullrequest with id: " + id); + return pullrequestRepository.findById(id).orElse(null); + } + + public List getPullrequestsByAuthor(String login) { + logger.info("Getting pullrequest by author: " + login); + return pullrequestRepository.findByAuthor(login); + } + +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index 583ca5b8..81eb4854 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -52,7 +52,7 @@ public class Repository { public String toString() { return "Repository [id=" + id + ", name=" + name + ", nameWithOwner=" + nameWithOwner + ", description=" - + description + ", url=" + url + ", pullRequests=" + pullRequests + ", addedAt=" + addedAt + + description + ", url=" + url + ", #pullRequests=" + pullRequests.size() + ", addedAt=" + addedAt + "]"; } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryController.java new file mode 100644 index 00000000..a0f26e6f --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryController.java @@ -0,0 +1,39 @@ +package de.tum.in.www1.hephaestus.codereview.repository; + +import java.util.List; + +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("/repository") +public class RepositoryController { + private final RepositoryService repositoryService; + + public RepositoryController(RepositoryService repositoryService) { + this.repositoryService = repositoryService; + } + + /** + * Retrieves all {@link Repository} entities. + * + * @return A list of all Repository entities + */ + @GetMapping + public List getAllRepositories() { + return repositoryService.getAllRepositories(); + } + + /** + * Retrieves a {@link Repository} entity by its full name. + * + * @param nameWithOwner The full name of the Repository + * @return The Repository entity + */ + @GetMapping("/{owner}/{name}") + public Repository getRepositoryByNameWithOwner(@PathVariable String owner, @PathVariable String name) { + return repositoryService.getRepository(owner + "/" + name); + } +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java index 806bc239..d6d476dd 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java @@ -29,6 +29,7 @@ public List getAllRepositories() { } public Repository getRepository(String nameWithOwner) { + logger.info("Getting repository with nameWithOwner: " + nameWithOwner); return repositoryRepository.findByNameWithOwner(nameWithOwner); } From fbb09e846cf878c7884c591346ab6a214f3d28e8 Mon Sep 17 00:00:00 2001 From: GODrums Date: Mon, 26 Aug 2024 02:35:30 +0200 Subject: [PATCH 09/50] Add entity constructors --- .../de/tum/in/www1/hephaestus/codereview/actor/Actor.java | 2 ++ .../tum/in/www1/hephaestus/codereview/comment/Comment.java | 6 ++---- .../www1/hephaestus/codereview/pullrequest/Pullrequest.java | 2 ++ .../www1/hephaestus/codereview/repository/Repository.java | 2 ++ 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java index 57749bbc..aac7eca9 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java @@ -17,12 +17,14 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.OneToMany; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; @Entity @Table(name = "actors") @Getter @Setter +@NoArgsConstructor @JsonInclude(JsonInclude.Include.NON_EMPTY) public class Actor { /** diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java index a8c49dbc..dcac4dd6 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java @@ -16,12 +16,14 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; @Entity @Table(name = "comments") @Getter @Setter +@NoArgsConstructor @JsonInclude(JsonInclude.Include.NON_EMPTY) public class Comment { /** @@ -70,10 +72,6 @@ public class Comment { @JsonIgnore private Pullrequest pullrequest; - public Comment() { - - } - public Comment(String body, String createdAt, String updatedAt) { this.body = body; this.createdAt = createdAt; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index ed66a8ac..23d9c6e7 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -20,12 +20,14 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; @Entity @Table(name = "pullrequests") @Getter @Setter +@NoArgsConstructor @JsonInclude(JsonInclude.Include.NON_EMPTY) public class Pullrequest { diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index 81eb4854..1be2f236 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -14,12 +14,14 @@ import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; @Entity @Table(name = "repositories") @Getter @Setter +@NoArgsConstructor public class Repository { /** From bae89803025f2f0d895b9d9c0925de6408d2eeb0 Mon Sep 17 00:00:00 2001 From: GODrums Date: Wed, 28 Aug 2024 18:52:48 +0200 Subject: [PATCH 10/50] table names to singular --- .../java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java | 2 +- .../de/tum/in/www1/hephaestus/codereview/comment/Comment.java | 2 +- .../in/www1/hephaestus/codereview/pullrequest/Pullrequest.java | 2 +- .../in/www1/hephaestus/codereview/repository/Repository.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java index aac7eca9..11c1ce5c 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java @@ -21,7 +21,7 @@ import lombok.Setter; @Entity -@Table(name = "actors") +@Table(name = "actor") @Getter @Setter @NoArgsConstructor diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java index dcac4dd6..3ffa18a8 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java @@ -20,7 +20,7 @@ import lombok.Setter; @Entity -@Table(name = "comments") +@Table(name = "comment") @Getter @Setter @NoArgsConstructor diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index 23d9c6e7..376e7121 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -24,7 +24,7 @@ import lombok.Setter; @Entity -@Table(name = "pullrequests") +@Table(name = "pullrequest") @Getter @Setter @NoArgsConstructor diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index 1be2f236..4db6dcce 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -18,7 +18,7 @@ import lombok.Setter; @Entity -@Table(name = "repositories") +@Table(name = "repository") @Getter @Setter @NoArgsConstructor From d5711f208687f36a90370fdbcbd24b2548e6939b Mon Sep 17 00:00:00 2001 From: GODrums Date: Wed, 28 Aug 2024 19:17:26 +0200 Subject: [PATCH 11/50] replace list with set --- .../codereview/CodeReviewService.java | 18 +++++++++--------- .../hephaestus/codereview/actor/Actor.java | 12 ++++++------ .../codereview/actor/ActorConverter.java | 6 +++--- .../codereview/pullrequest/Pullrequest.java | 4 ++-- .../pullrequest/PullrequestConverter.java | 4 ++-- .../codereview/repository/Repository.java | 4 ++-- .../repository/RepositoryConverter.java | 4 ++-- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java index f41c8894..e6b2918c 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java @@ -2,10 +2,10 @@ import java.io.IOException; import java.time.Instant; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; +import java.util.HashSet; import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; import org.kohsuke.github.GHPullRequest; @@ -110,17 +110,17 @@ public Repository fetchRepository(String nameWithOwner) throws IOException { PullrequestConverter prConverter = new PullrequestConverter(); // Retrieve PRs in pages of 10 - List prs = ghRepo.queryPullRequests().list().withPageSize(10).toList().stream().map(pr -> { + Set prs = ghRepo.queryPullRequests().list().withPageSize(10).toList().stream().map(pr -> { Pullrequest pullrequest = prConverter.convert(pr); pullrequest.setRepository(repository); pullrequestRepository.save(pullrequest); try { - List comments = getCommentsFromGHPullRequest(pr, pullrequest); + Set comments = getCommentsFromGHPullRequest(pr, pullrequest); pullrequest.setComments(comments); commentRepository.saveAll(comments); } catch (IOException e) { logger.error("Error while fetching PR comments!"); - pullrequest.setComments(new ArrayList<>()); + pullrequest.setComments(new HashSet<>()); } try { pullrequest.setAuthor(getActorFromGHUser(pr.getUser())); @@ -130,7 +130,7 @@ public Repository fetchRepository(String nameWithOwner) throws IOException { } return pullrequest; - }).collect(Collectors.toList()); + }).collect(Collectors.toSet()); repository.setPullRequests(prs); pullrequestRepository.saveAll(prs); repositoryRepository.save(repository); @@ -145,10 +145,10 @@ public Repository fetchRepository(String nameWithOwner) throws IOException { * @return The comments of the given pull request. * @throws IOException */ - private List getCommentsFromGHPullRequest(GHPullRequest pr, Pullrequest pullrequest) + private Set getCommentsFromGHPullRequest(GHPullRequest pr, Pullrequest pullrequest) throws IOException { CommentConverter commentConverter = new CommentConverter(); - List comments = pr.queryComments().list().toList().stream() + Set comments = pr.queryComments().list().toList().stream() .map(comment -> { Comment c = commentConverter.convert(comment); c.setPullrequest(pullrequest); @@ -163,7 +163,7 @@ private List getCommentsFromGHPullRequest(GHPullRequest pr, Pullrequest } c.setAuthor(author); return c; - }).collect(Collectors.toList()); + }).collect(Collectors.toSet()); return comments; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java index 11c1ce5c..0cfdcaf4 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java @@ -3,8 +3,8 @@ import jakarta.persistence.Id; import jakarta.persistence.Table; -import java.util.ArrayList; -import java.util.List; +import java.util.HashSet; +import java.util.Set; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; @@ -56,18 +56,18 @@ public class Actor { */ @OneToMany(mappedBy = "author") @JsonIgnore - private List pullrequests; + private Set pullrequests; /** * The Comments of the User entity. */ @OneToMany(mappedBy = "author") @JsonIgnore - private List comments; + private Set comments; public void addComment(Comment comment) { if (comments == null) { - comments = new ArrayList<>(); + comments = new HashSet<>(); } if (!comments.contains(comment)) { comments.add(comment); @@ -76,7 +76,7 @@ public void addComment(Comment comment) { public void addPullrequest(Pullrequest pullrequest) { if (pullrequests == null) { - pullrequests = new ArrayList<>(); + pullrequests = new HashSet<>(); } if (!pullrequests.contains(pullrequest)) { pullrequests.add(pullrequest); diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorConverter.java index 88f911e9..b4581931 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorConverter.java @@ -1,7 +1,7 @@ package de.tum.in.www1.hephaestus.codereview.actor; import java.io.IOException; -import java.util.ArrayList; +import java.util.HashSet; import org.kohsuke.github.GHUser; import org.springframework.core.convert.converter.Converter; @@ -19,8 +19,8 @@ public Actor convert(@NonNull GHUser source) { actor.setEmail(null); } actor.setUrl(source.getHtmlUrl().toString()); - actor.setPullrequests(new ArrayList<>()); - actor.setComments(new ArrayList<>()); + actor.setPullrequests(new HashSet<>()); + actor.setComments(new HashSet<>()); return actor; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index 376e7121..005515f2 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -1,6 +1,6 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; -import java.util.List; +import java.util.Set; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; @@ -90,7 +90,7 @@ public class Pullrequest { private Actor author; @OneToMany(cascade = CascadeType.ALL, mappedBy = "pullrequest") - private List comments; + private Set comments; /** * The parent connection of the Pullrequest entity. diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java index f44d1d96..ebfa27e6 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java @@ -1,7 +1,7 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; import java.io.IOException; -import java.util.ArrayList; +import java.util.HashSet; import org.kohsuke.github.GHPullRequest; import org.springframework.core.convert.converter.Converter; @@ -31,7 +31,7 @@ public Pullrequest convert(@NonNull GHPullRequest source) { } pullrequest.setMergedAt(source.getMergedAt() != null ? source.getMergedAt().toString() : null); // set preliminary values to be filled in later - pullrequest.setComments(new ArrayList<>()); + pullrequest.setComments(new HashSet<>()); pullrequest.setAuthor(null); pullrequest.setRepository(null); return pullrequest; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index 4db6dcce..ca50dcf2 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -1,7 +1,7 @@ package de.tum.in.www1.hephaestus.codereview.repository; import java.time.Instant; -import java.util.List; +import java.util.Set; import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; import jakarta.persistence.CascadeType; @@ -47,7 +47,7 @@ public class Repository { private String url; @OneToMany(cascade = CascadeType.ALL, mappedBy = "repository", fetch = FetchType.EAGER) - private List pullRequests; + private Set pullRequests; @Column(name = "added_at") private Instant addedAt; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java index 7b54699e..eedf017e 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java @@ -1,7 +1,7 @@ package de.tum.in.www1.hephaestus.codereview.repository; import java.time.Instant; -import java.util.ArrayList; +import java.util.HashSet; import org.kohsuke.github.GHRepository; import org.springframework.core.convert.converter.Converter; @@ -24,7 +24,7 @@ public Repository convert(@NonNull GHRepository source) { repository.setDescription(source.getDescription()); repository.setAddedAt(Instant.now()); repository.setGithubId(source.getId()); - repository.setPullRequests(new ArrayList<>()); + repository.setPullRequests(new HashSet<>()); return repository; } From de9adc43a0eebffee30ae203a1353f03806c1d34 Mon Sep 17 00:00:00 2001 From: GODrums Date: Wed, 28 Aug 2024 19:20:20 +0200 Subject: [PATCH 12/50] Add cascade types for actor relations --- .../de/tum/in/www1/hephaestus/codereview/actor/Actor.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java index 0cfdcaf4..3aea789f 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java @@ -11,6 +11,7 @@ import de.tum.in.www1.hephaestus.codereview.comment.Comment; import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; +import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -54,14 +55,14 @@ public class Actor { /** * The Pullrequests of the User entity. */ - @OneToMany(mappedBy = "author") + @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") @JsonIgnore private Set pullrequests; /** * The Comments of the User entity. */ - @OneToMany(mappedBy = "author") + @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") @JsonIgnore private Set comments; From 4a372f119c7c09318ca239815f1058f993cd0d7d Mon Sep 17 00:00:00 2001 From: GODrums Date: Wed, 28 Aug 2024 19:24:12 +0200 Subject: [PATCH 13/50] Directly init relation sets --- .../tum/in/www1/hephaestus/codereview/actor/Actor.java | 10 ++-------- .../hephaestus/codereview/actor/ActorConverter.java | 3 --- .../hephaestus/codereview/pullrequest/Pullrequest.java | 3 ++- .../codereview/pullrequest/PullrequestConverter.java | 2 -- .../hephaestus/codereview/repository/Repository.java | 3 ++- .../codereview/repository/RepositoryConverter.java | 2 -- 6 files changed, 6 insertions(+), 17 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java index 3aea789f..ef050772 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java @@ -57,28 +57,22 @@ public class Actor { */ @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") @JsonIgnore - private Set pullrequests; + private Set pullrequests = new HashSet<>();; /** * The Comments of the User entity. */ @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") @JsonIgnore - private Set comments; + private Set comments = new HashSet<>();; public void addComment(Comment comment) { - if (comments == null) { - comments = new HashSet<>(); - } if (!comments.contains(comment)) { comments.add(comment); } } public void addPullrequest(Pullrequest pullrequest) { - if (pullrequests == null) { - pullrequests = new HashSet<>(); - } if (!pullrequests.contains(pullrequest)) { pullrequests.add(pullrequest); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorConverter.java index b4581931..d82f1bf9 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorConverter.java @@ -1,7 +1,6 @@ package de.tum.in.www1.hephaestus.codereview.actor; import java.io.IOException; -import java.util.HashSet; import org.kohsuke.github.GHUser; import org.springframework.core.convert.converter.Converter; @@ -19,8 +18,6 @@ public Actor convert(@NonNull GHUser source) { actor.setEmail(null); } actor.setUrl(source.getHtmlUrl().toString()); - actor.setPullrequests(new HashSet<>()); - actor.setComments(new HashSet<>()); return actor; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index 005515f2..614f80d7 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -1,5 +1,6 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; +import java.util.HashSet; import java.util.Set; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -90,7 +91,7 @@ public class Pullrequest { private Actor author; @OneToMany(cascade = CascadeType.ALL, mappedBy = "pullrequest") - private Set comments; + private Set comments = new HashSet<>();; /** * The parent connection of the Pullrequest entity. diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java index ebfa27e6..f3f305fc 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java @@ -1,7 +1,6 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; import java.io.IOException; -import java.util.HashSet; import org.kohsuke.github.GHPullRequest; import org.springframework.core.convert.converter.Converter; @@ -31,7 +30,6 @@ public Pullrequest convert(@NonNull GHPullRequest source) { } pullrequest.setMergedAt(source.getMergedAt() != null ? source.getMergedAt().toString() : null); // set preliminary values to be filled in later - pullrequest.setComments(new HashSet<>()); pullrequest.setAuthor(null); pullrequest.setRepository(null); return pullrequest; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index ca50dcf2..2d3c867d 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -1,6 +1,7 @@ package de.tum.in.www1.hephaestus.codereview.repository; import java.time.Instant; +import java.util.HashSet; import java.util.Set; import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; @@ -47,7 +48,7 @@ public class Repository { private String url; @OneToMany(cascade = CascadeType.ALL, mappedBy = "repository", fetch = FetchType.EAGER) - private Set pullRequests; + private Set pullRequests = new HashSet<>();; @Column(name = "added_at") private Instant addedAt; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java index eedf017e..1d4fe501 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java @@ -1,7 +1,6 @@ package de.tum.in.www1.hephaestus.codereview.repository; import java.time.Instant; -import java.util.HashSet; import org.kohsuke.github.GHRepository; import org.springframework.core.convert.converter.Converter; @@ -24,7 +23,6 @@ public Repository convert(@NonNull GHRepository source) { repository.setDescription(source.getDescription()); repository.setAddedAt(Instant.now()); repository.setGithubId(source.getId()); - repository.setPullRequests(new HashSet<>()); return repository; } From 85f9e4cbf0e06394358776aa1efda762df2ccb39 Mon Sep 17 00:00:00 2001 From: GODrums Date: Wed, 28 Aug 2024 19:28:40 +0200 Subject: [PATCH 14/50] Improve toString printing --- .../de/tum/in/www1/hephaestus/codereview/actor/Actor.java | 4 ++-- .../de/tum/in/www1/hephaestus/codereview/comment/Comment.java | 4 ++-- .../www1/hephaestus/codereview/pullrequest/Pullrequest.java | 4 ++-- .../in/www1/hephaestus/codereview/repository/Repository.java | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java index ef050772..d77b4a7f 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java @@ -80,8 +80,8 @@ public void addPullrequest(Pullrequest pullrequest) { @Override public String toString() { - return "Actor [id=" + id + ", login=" + login + ", email=" + email + ", url=" + return "Actor{id=" + id + ", login=" + login + ", email=" + email + ", url=" + url + ", #pullrequests=" - + pullrequests.size() + ", #comments=" + comments.size() + "]"; + + pullrequests.size() + ", #comments=" + comments.size() + "}"; } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java index 3ffa18a8..9787178d 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java @@ -80,8 +80,8 @@ public Comment(String body, String createdAt, String updatedAt) { @Override public String toString() { - return "Comment [id=" + id + ", githubId=" + githubId + ", body=" + body + ", createdAt=" + createdAt + return "Comment{id=" + id + ", githubId=" + githubId + ", body=" + body + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + ", author=" + author.getLogin() + ", pullrequest=" - + pullrequest.getTitle() + "]"; + + pullrequest.getTitle() + "}"; } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index 614f80d7..40b000c1 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -103,10 +103,10 @@ public class Pullrequest { @Override public String toString() { - return "Pullrequest [id=" + id + ", githubId=" + githubId + ", title=" + + return "Pullrequest{id=" + id + ", githubId=" + githubId + ", title=" + title + ", url=" + url + ", state=" + state + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + ", mergedAt=" + mergedAt + ", author=" + author.getLogin() + ", #comments=" + comments.size() + ", repository=" + - repository.getNameWithOwner() + "]"; + repository.getNameWithOwner() + "}"; } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index 2d3c867d..dad39581 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -54,8 +54,8 @@ public class Repository { private Instant addedAt; public String toString() { - return "Repository [id=" + id + ", name=" + name + ", nameWithOwner=" + nameWithOwner + ", description=" + return "Repository{id=" + id + ", name=" + name + ", nameWithOwner=" + nameWithOwner + ", description=" + description + ", url=" + url + ", #pullRequests=" + pullRequests.size() + ", addedAt=" + addedAt - + "]"; + + "}"; } } From 8a8381bea4e4b563a669c658ad125420a7fa9271 Mon Sep 17 00:00:00 2001 From: GODrums Date: Wed, 28 Aug 2024 19:38:05 +0200 Subject: [PATCH 15/50] Replace toString with annotations --- .../in/www1/hephaestus/codereview/actor/Actor.java | 11 ++++------- .../hephaestus/codereview/comment/Comment.java | 11 ++++------- .../codereview/pullrequest/Pullrequest.java | 14 +++++--------- .../codereview/repository/Repository.java | 9 +++------ 4 files changed, 16 insertions(+), 29 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java index d77b4a7f..015677fc 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java @@ -20,6 +20,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; @Entity @Table(name = "actor") @@ -27,6 +28,7 @@ @Setter @NoArgsConstructor @JsonInclude(JsonInclude.Include.NON_EMPTY) +@ToString public class Actor { /** * Unique identifier for a User entity. @@ -57,6 +59,7 @@ public class Actor { */ @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") @JsonIgnore + @ToString.Exclude private Set pullrequests = new HashSet<>();; /** @@ -64,6 +67,7 @@ public class Actor { */ @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") @JsonIgnore + @ToString.Exclude private Set comments = new HashSet<>();; public void addComment(Comment comment) { @@ -77,11 +81,4 @@ public void addPullrequest(Pullrequest pullrequest) { pullrequests.add(pullrequest); } } - - @Override - public String toString() { - return "Actor{id=" + id + ", login=" + login + ", email=" + email + ", url=" - + url + ", #pullrequests=" - + pullrequests.size() + ", #comments=" + comments.size() + "}"; - } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java index 9787178d..0008b8eb 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java @@ -18,6 +18,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; @Entity @Table(name = "comment") @@ -25,6 +26,7 @@ @Setter @NoArgsConstructor @JsonInclude(JsonInclude.Include.NON_EMPTY) +@ToString public class Comment { /** * Unique identifier for a Comment entity. @@ -62,6 +64,7 @@ public class Comment { */ @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "author_id") + @ToString.Exclude private Actor author; /** @@ -70,6 +73,7 @@ public class Comment { @ManyToOne(optional = false) @JoinColumn(name = "pullrequest_id", referencedColumnName = "id") @JsonIgnore + @ToString.Exclude private Pullrequest pullrequest; public Comment(String body, String createdAt, String updatedAt) { @@ -77,11 +81,4 @@ public Comment(String body, String createdAt, String updatedAt) { this.createdAt = createdAt; this.updatedAt = updatedAt; } - - @Override - public String toString() { - return "Comment{id=" + id + ", githubId=" + githubId + ", body=" + body + ", createdAt=" + createdAt - + ", updatedAt=" + updatedAt + ", author=" + author.getLogin() + ", pullrequest=" - + pullrequest.getTitle() + "}"; - } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index 40b000c1..77daaf07 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -23,6 +23,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; @Entity @Table(name = "pullrequest") @@ -30,6 +31,7 @@ @Setter @NoArgsConstructor @JsonInclude(JsonInclude.Include.NON_EMPTY) +@ToString public class Pullrequest { /** @@ -88,9 +90,11 @@ public class Pullrequest { */ @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "author_id") + @ToString.Exclude private Actor author; @OneToMany(cascade = CascadeType.ALL, mappedBy = "pullrequest") + @ToString.Exclude private Set comments = new HashSet<>();; /** @@ -99,14 +103,6 @@ public class Pullrequest { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "repository_id", referencedColumnName = "id") @JsonIgnore + @ToString.Exclude private Repository repository; - - @Override - public String toString() { - return "Pullrequest{id=" + id + ", githubId=" + githubId + ", title=" + - title + ", url=" + url + ", state=" - + state + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + ", mergedAt=" + mergedAt - + ", author=" + author.getLogin() + ", #comments=" + comments.size() + ", repository=" + - repository.getNameWithOwner() + "}"; - } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index dad39581..f4e5b009 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -17,12 +17,14 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; @Entity @Table(name = "repository") @Getter @Setter @NoArgsConstructor +@ToString public class Repository { /** @@ -48,14 +50,9 @@ public class Repository { private String url; @OneToMany(cascade = CascadeType.ALL, mappedBy = "repository", fetch = FetchType.EAGER) + @ToString.Exclude private Set pullRequests = new HashSet<>();; @Column(name = "added_at") private Instant addedAt; - - public String toString() { - return "Repository{id=" + id + ", name=" + name + ", nameWithOwner=" + nameWithOwner + ", description=" - + description + ", url=" + url + ", #pullRequests=" + pullRequests.size() + ", addedAt=" + addedAt - + "}"; - } } From 21d3f7fb90088c2b832df2a5d37596faf7ba7946 Mon Sep 17 00:00:00 2001 From: GODrums Date: Wed, 28 Aug 2024 20:18:15 +0200 Subject: [PATCH 16/50] Prefer nonnull over nullable column --- .../in/www1/hephaestus/codereview/actor/Actor.java | 4 +++- .../hephaestus/codereview/comment/Comment.java | 8 +++++--- .../codereview/pullrequest/Pullrequest.java | 14 ++++++++------ .../codereview/repository/Repository.java | 8 +++++--- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java index 015677fc..519e59a5 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java @@ -6,6 +6,8 @@ import java.util.HashSet; import java.util.Set; +import org.springframework.lang.NonNull; + import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; @@ -41,7 +43,7 @@ public class Actor { * Login of the User entity. * This field is mandatory. */ - @Column(nullable = false) + @NonNull private String login; @Column diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java index 0008b8eb..779c16ee 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java @@ -3,6 +3,8 @@ import jakarta.persistence.Id; import jakarta.persistence.Table; +import org.springframework.lang.NonNull; + import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; @@ -42,21 +44,21 @@ public class Comment { * Body of the Comment entity. * This field is mandatory. */ - @Column(nullable = false) + @NonNull private String body; /** * Timestamp of when the Comment entity was created. * This field is mandatory. */ - @Column(nullable = false) + @NonNull private String createdAt; /** * Timestamp of when the Comment entity was updated. * This field is mandatory. */ - @Column(nullable = false) + @NonNull private String updatedAt; /** diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index 77daaf07..887413f0 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -3,6 +3,8 @@ import java.util.HashSet; import java.util.Set; +import org.springframework.lang.NonNull; + import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; @@ -48,41 +50,41 @@ public class Pullrequest { * Title of the Pullrequest. * This field is mandatory. */ - @Column(nullable = false) + @NonNull private String title; /** * URL of the Pullrequest. * This field is mandatory. */ - @Column(nullable = false) + @NonNull private String url; /** * State of the Pullrequest. * This field is mandatory. */ - @Column(nullable = false) + @NonNull private String state; /** * Timestamp of when the Pullrequest entity was created. * This field is mandatory. */ - @Column(nullable = false) + @NonNull private String createdAt; /** * Timestamp of when the Pullrequest entity was updated. * This field is mandatory. */ - @Column(nullable = false) + @NonNull private String updatedAt; /** * Timestamp of when the Pullrequest entity was merged. */ - @Column(nullable = true) + @Column private String mergedAt; /** diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index f4e5b009..3f093700 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -4,6 +4,8 @@ import java.util.HashSet; import java.util.Set; +import org.springframework.lang.NonNull; + import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; @@ -37,16 +39,16 @@ public class Repository { @Column(name = "github_id") private Long githubId; - @Column + @NonNull private String name; @Column(name = "name_with_owner") private String nameWithOwner; - @Column + @NonNull private String description; - @Column + @NonNull private String url; @OneToMany(cascade = CascadeType.ALL, mappedBy = "repository", fetch = FetchType.EAGER) From 7474b78f4b83135137d1c2d427fae673f31afc51 Mon Sep 17 00:00:00 2001 From: GODrums Date: Thu, 29 Aug 2024 00:38:02 +0200 Subject: [PATCH 17/50] Rename Actor, Pullrequest and Comment --- .../codereview/CodeReviewService.java | 53 +++++++++---------- .../codereview/actor/ActorConverter.java | 24 --------- .../actor/{Actor.java => GHUser.java} | 20 +++---- ...rController.java => GHUserController.java} | 10 ++-- .../codereview/actor/GHUserConverter.java | 23 ++++++++ ...rRepository.java => GHUserRepository.java} | 6 ++- .../{ActorService.java => GHUserService.java} | 12 +++-- .../{Comment.java => IssueComment.java} | 14 ++--- ...verter.java => IssueCommentConverter.java} | 6 +-- ...itory.java => IssueCommentRepository.java} | 2 +- .../codereview/pullrequest/Pullrequest.java | 12 ++--- .../pullrequest/PullrequestController.java | 10 ++-- .../pullrequest/PullrequestConverter.java | 6 +-- .../pullrequest/PullrequestRepository.java | 7 +-- .../pullrequest/PullrequestService.java | 12 ++--- .../codereview/repository/Repository.java | 4 +- 16 files changed, 112 insertions(+), 109 deletions(-) delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorConverter.java rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/{Actor.java => GHUser.java} (76%) rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/{ActorController.java => GHUserController.java} (67%) create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserConverter.java rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/{ActorRepository.java => GHUserRepository.java} (62%) rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/{ActorService.java => GHUserService.java} (63%) rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/{Comment.java => IssueComment.java} (85%) rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/{CommentConverter.java => IssueCommentConverter.java} (80%) rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/{CommentRepository.java => IssueCommentRepository.java} (59%) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java index e6b2918c..d4d41cb1 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java @@ -10,7 +10,6 @@ import org.kohsuke.github.GHPullRequest; import org.kohsuke.github.GHRepository; -import org.kohsuke.github.GHUser; import org.kohsuke.github.GitHub; import org.kohsuke.github.GitHubBuilder; import org.slf4j.Logger; @@ -22,15 +21,15 @@ import org.springframework.graphql.client.HttpSyncGraphQlClient; import de.tum.in.www1.hephaestus.EnvConfig; -import de.tum.in.www1.hephaestus.codereview.actor.Actor; -import de.tum.in.www1.hephaestus.codereview.actor.ActorConverter; -import de.tum.in.www1.hephaestus.codereview.actor.ActorRepository; -import de.tum.in.www1.hephaestus.codereview.comment.Comment; -import de.tum.in.www1.hephaestus.codereview.comment.CommentConverter; -import de.tum.in.www1.hephaestus.codereview.comment.CommentRepository; -import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; -import de.tum.in.www1.hephaestus.codereview.pullrequest.PullrequestConverter; -import de.tum.in.www1.hephaestus.codereview.pullrequest.PullrequestRepository; +import de.tum.in.www1.hephaestus.codereview.actor.GHUser; +import de.tum.in.www1.hephaestus.codereview.actor.GHUserConverter; +import de.tum.in.www1.hephaestus.codereview.actor.GHUserRepository; +import de.tum.in.www1.hephaestus.codereview.comment.IssueComment; +import de.tum.in.www1.hephaestus.codereview.comment.IssueCommentConverter; +import de.tum.in.www1.hephaestus.codereview.comment.IssueCommentRepository; +import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest; +import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequestConverter; +import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequestRepository; import de.tum.in.www1.hephaestus.codereview.repository.Repository; import de.tum.in.www1.hephaestus.codereview.repository.RepositoryConverter; import de.tum.in.www1.hephaestus.codereview.repository.RepositoryRepository; @@ -45,15 +44,15 @@ public class CodeReviewService { private GitHub github; private final RepositoryRepository repositoryRepository; - private final PullrequestRepository pullrequestRepository; - private final CommentRepository commentRepository; - private final ActorRepository actorRepository; + private final PullRequestRepository pullrequestRepository; + private final IssueCommentRepository commentRepository; + private final GHUserRepository actorRepository; private final EnvConfig envConfig; public CodeReviewService(EnvConfig envConfig, RepositoryRepository repositoryRepository, - PullrequestRepository pullrequestRepository, CommentRepository commentRepository, - ActorRepository actorRepository) { + PullRequestRepository pullrequestRepository, IssueCommentRepository commentRepository, + GHUserRepository actorRepository) { logger.info("Hello from CodeReviewService!"); this.envConfig = envConfig; @@ -107,15 +106,15 @@ public Repository fetchRepository(String nameWithOwner) throws IOException { // preliminary save to make it referenceable repositoryRepository.save(repository); - PullrequestConverter prConverter = new PullrequestConverter(); + PullRequestConverter prConverter = new PullRequestConverter(); // Retrieve PRs in pages of 10 - Set prs = ghRepo.queryPullRequests().list().withPageSize(10).toList().stream().map(pr -> { - Pullrequest pullrequest = prConverter.convert(pr); + Set prs = ghRepo.queryPullRequests().list().withPageSize(10).toList().stream().map(pr -> { + PullRequest pullrequest = prConverter.convert(pr); pullrequest.setRepository(repository); pullrequestRepository.save(pullrequest); try { - Set comments = getCommentsFromGHPullRequest(pr, pullrequest); + Set comments = getCommentsFromGHPullRequest(pr, pullrequest); pullrequest.setComments(comments); commentRepository.saveAll(comments); } catch (IOException e) { @@ -145,14 +144,14 @@ public Repository fetchRepository(String nameWithOwner) throws IOException { * @return The comments of the given pull request. * @throws IOException */ - private Set getCommentsFromGHPullRequest(GHPullRequest pr, Pullrequest pullrequest) + private Set getCommentsFromGHPullRequest(GHPullRequest pr, PullRequest pullrequest) throws IOException { - CommentConverter commentConverter = new CommentConverter(); - Set comments = pr.queryComments().list().toList().stream() + IssueCommentConverter commentConverter = new IssueCommentConverter(); + Set comments = pr.queryComments().list().toList().stream() .map(comment -> { - Comment c = commentConverter.convert(comment); + IssueComment c = commentConverter.convert(comment); c.setPullrequest(pullrequest); - Actor author; + GHUser author; try { author = getActorFromGHUser(comment.getUser()); author.addComment(c); @@ -167,10 +166,10 @@ private Set getCommentsFromGHPullRequest(GHPullRequest pr, Pullrequest return comments; } - private Actor getActorFromGHUser(GHUser user) { - Actor actor = actorRepository.findByLogin(user.getLogin()); + private GHUser getActorFromGHUser(org.kohsuke.github.GHUser user) { + GHUser actor = actorRepository.findByLogin(user.getLogin()); if (actor == null) { - actor = new ActorConverter().convert(user); + actor = new GHUserConverter().convert(user); actorRepository.save(actor); } return actor; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorConverter.java deleted file mode 100644 index d82f1bf9..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorConverter.java +++ /dev/null @@ -1,24 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview.actor; - -import java.io.IOException; - -import org.kohsuke.github.GHUser; -import org.springframework.core.convert.converter.Converter; -import org.springframework.lang.NonNull; - -public class ActorConverter implements Converter { - - @Override - public Actor convert(@NonNull GHUser source) { - Actor actor = new Actor(); - actor.setLogin(source.getLogin()); - try { - actor.setEmail(source.getEmail()); - } catch (IOException e) { - actor.setEmail(null); - } - actor.setUrl(source.getHtmlUrl().toString()); - return actor; - } - -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUser.java similarity index 76% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUser.java index 519e59a5..243b6c2b 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUser.java @@ -11,8 +11,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; -import de.tum.in.www1.hephaestus.codereview.comment.Comment; -import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; +import de.tum.in.www1.hephaestus.codereview.comment.IssueComment; +import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -25,13 +25,13 @@ import lombok.ToString; @Entity -@Table(name = "actor") +@Table(name = "gh_user") @Getter @Setter @NoArgsConstructor @JsonInclude(JsonInclude.Include.NON_EMPTY) @ToString -public class Actor { +public class GHUser { /** * Unique identifier for a User entity. */ @@ -62,7 +62,7 @@ public class Actor { @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") @JsonIgnore @ToString.Exclude - private Set pullrequests = new HashSet<>();; + private Set pullRequests = new HashSet<>();; /** * The Comments of the User entity. @@ -70,17 +70,17 @@ public class Actor { @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") @JsonIgnore @ToString.Exclude - private Set comments = new HashSet<>();; + private Set comments = new HashSet<>();; - public void addComment(Comment comment) { + public void addComment(IssueComment comment) { if (!comments.contains(comment)) { comments.add(comment); } } - public void addPullrequest(Pullrequest pullrequest) { - if (!pullrequests.contains(pullrequest)) { - pullrequests.add(pullrequest); + public void addPullrequest(PullRequest pullrequest) { + if (!pullRequests.contains(pullrequest)) { + pullRequests.add(pullrequest); } } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserController.java similarity index 67% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorController.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserController.java index 34249681..b6cb30ea 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorController.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserController.java @@ -6,16 +6,16 @@ import org.springframework.web.bind.annotation.RestController; @RestController -@RequestMapping("/actor") -public class ActorController { - private final ActorService actorService; +@RequestMapping("/ghuser") +public class GHUserController { + private final GHUserService actorService; - public ActorController(ActorService actorService) { + public GHUserController(GHUserService actorService) { this.actorService = actorService; } @GetMapping("/{login}") - public Actor getActor(@PathVariable String login) { + public GHUser getActor(@PathVariable String login) { return actorService.getActor(login); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserConverter.java new file mode 100644 index 00000000..9574c65d --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserConverter.java @@ -0,0 +1,23 @@ +package de.tum.in.www1.hephaestus.codereview.actor; + +import java.io.IOException; + +import org.springframework.core.convert.converter.Converter; +import org.springframework.lang.NonNull; + +public class GHUserConverter implements Converter { + + @Override + public GHUser convert(@NonNull org.kohsuke.github.GHUser source) { + GHUser user = new GHUser(); + user.setLogin(source.getLogin()); + try { + user.setEmail(source.getEmail()); + } catch (IOException e) { + user.setEmail(null); + } + user.setUrl(source.getHtmlUrl().toString()); + return user; + } + +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserRepository.java similarity index 62% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorRepository.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserRepository.java index 8d0dcd4d..d715d990 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorRepository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserRepository.java @@ -1,10 +1,12 @@ package de.tum.in.www1.hephaestus.codereview.actor; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; -public interface ActorRepository extends JpaRepository { +public interface GHUserRepository extends JpaRepository { @Query("SELECT a FROM Actor a WHERE a.login = ?1") - Actor findByLogin(String login); + GHUser findByLogin(String login); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserService.java similarity index 63% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorService.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserService.java index 5da9471a..e05a100f 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/ActorService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserService.java @@ -1,20 +1,22 @@ package de.tum.in.www1.hephaestus.codereview.actor; +import java.util.Optional; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @Service -public class ActorService { - private static final Logger logger = LoggerFactory.getLogger(Actor.class); +public class GHUserService { + private static final Logger logger = LoggerFactory.getLogger(GHUser.class); - private final ActorRepository actorRepository; + private final GHUserRepository actorRepository; - public ActorService(ActorRepository actorRepository) { + public GHUserService(GHUserRepository actorRepository) { this.actorRepository = actorRepository; } - public Actor getActor(String login) { + public GHUser getActor(String login) { logger.info("Getting actor with login: " + login); return actorRepository.findByLogin(login); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java similarity index 85% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java index 779c16ee..89f5e4db 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java @@ -8,8 +8,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; -import de.tum.in.www1.hephaestus.codereview.actor.Actor; -import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; +import de.tum.in.www1.hephaestus.codereview.actor.GHUser; +import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; @@ -23,13 +23,13 @@ import lombok.ToString; @Entity -@Table(name = "comment") +@Table(name = "issue_comment") @Getter @Setter @NoArgsConstructor @JsonInclude(JsonInclude.Include.NON_EMPTY) @ToString -public class Comment { +public class IssueComment { /** * Unique identifier for a Comment entity. */ @@ -67,7 +67,7 @@ public class Comment { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "author_id") @ToString.Exclude - private Actor author; + private GHUser author; /** * The parent connection to the pullrequest of the Comment entity. @@ -76,9 +76,9 @@ public class Comment { @JoinColumn(name = "pullrequest_id", referencedColumnName = "id") @JsonIgnore @ToString.Exclude - private Pullrequest pullrequest; + private PullRequest pullrequest; - public Comment(String body, String createdAt, String updatedAt) { + public IssueComment(String body, String createdAt, String updatedAt) { this.body = body; this.createdAt = createdAt; this.updatedAt = updatedAt; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java similarity index 80% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConverter.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java index 1a0c5f97..f8a3e47e 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java @@ -6,11 +6,11 @@ import org.springframework.core.convert.converter.Converter; import org.springframework.lang.NonNull; -public class CommentConverter implements Converter { +public class IssueCommentConverter implements Converter { @Override - public Comment convert(@NonNull GHIssueComment source) { - Comment comment = new Comment(); + public IssueComment convert(@NonNull GHIssueComment source) { + IssueComment comment = new IssueComment(); comment.setBody(source.getBody()); comment.setGithubId(source.getId()); try { diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentRepository.java similarity index 59% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentRepository.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentRepository.java index f224b751..adacc0d7 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentRepository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentRepository.java @@ -2,6 +2,6 @@ import org.springframework.data.jpa.repository.JpaRepository; -public interface CommentRepository extends JpaRepository { +public interface IssueCommentRepository extends JpaRepository { } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index 887413f0..099c0d6c 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -8,8 +8,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; -import de.tum.in.www1.hephaestus.codereview.actor.Actor; -import de.tum.in.www1.hephaestus.codereview.comment.Comment; +import de.tum.in.www1.hephaestus.codereview.actor.GHUser; +import de.tum.in.www1.hephaestus.codereview.comment.IssueComment; import de.tum.in.www1.hephaestus.codereview.repository.Repository; import jakarta.persistence.Id; import jakarta.persistence.Table; @@ -28,13 +28,13 @@ import lombok.ToString; @Entity -@Table(name = "pullrequest") +@Table(name = "pull_request") @Getter @Setter @NoArgsConstructor @JsonInclude(JsonInclude.Include.NON_EMPTY) @ToString -public class Pullrequest { +public class PullRequest { /** * Unique identifier for a Pullrequest entity. @@ -93,11 +93,11 @@ public class Pullrequest { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "author_id") @ToString.Exclude - private Actor author; + private GHUser author; @OneToMany(cascade = CascadeType.ALL, mappedBy = "pullrequest") @ToString.Exclude - private Set comments = new HashSet<>();; + private Set comments = new HashSet<>();; /** * The parent connection of the Pullrequest entity. diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java index 4367ab06..98fad311 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java @@ -9,20 +9,20 @@ @RestController @RequestMapping("/pr") -public class PullrequestController { - private final PullrequestService pullrequestService; +public class PullRequestController { + private final PullRequestService pullrequestService; - public PullrequestController(PullrequestService pullrequestService) { + public PullRequestController(PullRequestService pullrequestService) { this.pullrequestService = pullrequestService; } @GetMapping("/{id}") - public Pullrequest getPullrequest(@PathVariable Long id) { + public PullRequest getPullrequest(@PathVariable Long id) { return pullrequestService.getPullrequestById(id); } @GetMapping("/author/{login}") - public List getPullrequestsByAuthor(@PathVariable String login) { + public List getPullrequestsByAuthor(@PathVariable String login) { return pullrequestService.getPullrequestsByAuthor(login); } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java index f3f305fc..9bafe62a 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java @@ -10,10 +10,10 @@ @Service @ReadingConverter -public class PullrequestConverter implements Converter { +public class PullRequestConverter implements Converter { @Override - public Pullrequest convert(@NonNull GHPullRequest source) { - Pullrequest pullrequest = new Pullrequest(); + public PullRequest convert(@NonNull GHPullRequest source) { + PullRequest pullrequest = new PullRequest(); pullrequest.setGithubId(source.getId()); pullrequest.setTitle(source.getTitle()); pullrequest.setUrl(source.getHtmlUrl().toString()); diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java index ab9f5fef..9c80e43b 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java @@ -1,18 +1,19 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; import java.util.List; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @Repository -public interface PullrequestRepository extends JpaRepository { +public interface PullRequestRepository extends JpaRepository { @Query("SELECT p FROM Pullrequest p WHERE p.githubId = ?1") - Pullrequest findByGithubId(Long githubId); + PullRequest findByGithubId(Long githubId); @Query("SELECT p FROM Pullrequest p, Actor a WHERE p.author = a AND a.login = ?1") - List findByAuthor(String authorLogin); + List findByAuthor(String authorLogin); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java index c9c96d15..11295f08 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java @@ -7,21 +7,21 @@ import org.springframework.stereotype.Service; @Service -public class PullrequestService { - private static final Logger logger = LoggerFactory.getLogger(Pullrequest.class); +public class PullRequestService { + private static final Logger logger = LoggerFactory.getLogger(PullRequest.class); - private final PullrequestRepository pullrequestRepository; + private final PullRequestRepository pullrequestRepository; - public PullrequestService(PullrequestRepository pullrequestRepository) { + public PullRequestService(PullRequestRepository pullrequestRepository) { this.pullrequestRepository = pullrequestRepository; } - public Pullrequest getPullrequestById(Long id) { + public PullRequest getPullrequestById(Long id) { logger.info("Getting pullrequest with id: " + id); return pullrequestRepository.findById(id).orElse(null); } - public List getPullrequestsByAuthor(String login) { + public List getPullrequestsByAuthor(String login) { logger.info("Getting pullrequest by author: " + login); return pullrequestRepository.findByAuthor(login); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index 3f093700..68803e97 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -6,7 +6,7 @@ import org.springframework.lang.NonNull; -import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; +import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -53,7 +53,7 @@ public class Repository { @OneToMany(cascade = CascadeType.ALL, mappedBy = "repository", fetch = FetchType.EAGER) @ToString.Exclude - private Set pullRequests = new HashSet<>();; + private Set pullRequests = new HashSet<>();; @Column(name = "added_at") private Instant addedAt; From 05ed3440569e8a215ede05e2e8385ceb0b8fe08d Mon Sep 17 00:00:00 2001 From: GODrums Date: Thu, 29 Aug 2024 00:49:32 +0200 Subject: [PATCH 18/50] Add user name attribute --- .../de/tum/in/www1/hephaestus/codereview/actor/GHUser.java | 7 ++++++- .../www1/hephaestus/codereview/actor/GHUserConverter.java | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUser.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUser.java index 243b6c2b..9280b6f2 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUser.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUser.java @@ -49,13 +49,18 @@ public class GHUser { @Column private String email; + @Column + private String name; + /** * URL of the User entity. * This field is mandatory. */ - @Column(nullable = false) + @NonNull private String url; + @Column() + /** * The Pullrequests of the User entity. */ diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserConverter.java index 9574c65d..588ba805 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserConverter.java @@ -11,6 +11,11 @@ public class GHUserConverter implements Converter Date: Thu, 29 Aug 2024 04:06:18 +0200 Subject: [PATCH 19/50] Introduce DTO for user --- .../tum/in/www1/hephaestus/Application.java | 2 -- .../codereview/CodeReviewService.java | 21 ++++++------- .../codereview/actor/GHUserController.java | 22 -------------- .../codereview/actor/GHUserRepository.java | 12 -------- .../codereview/actor/GHUserService.java | 24 --------------- .../codereview/comment/IssueComment.java | 2 +- .../codereview/pullrequest/Pullrequest.java | 2 +- .../pullrequest/PullrequestConverter.java | 2 ++ .../pullrequest/PullrequestRepository.java | 5 ++-- .../repository/RepositoryRepository.java | 2 -- .../codereview/{actor => user}/GHUser.java | 8 +---- .../codereview/user/GHUserController.java | 30 +++++++++++++++++++ .../{actor => user}/GHUserConverter.java | 2 +- .../hephaestus/codereview/user/GHUserDTO.java | 7 +++++ .../codereview/user/GHUserRepository.java | 19 ++++++++++++ .../codereview/user/GHUserService.java | 28 +++++++++++++++++ .../errors/EntityNotFoundException.java | 29 ++++++++++++++++++ 17 files changed, 132 insertions(+), 85 deletions(-) delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserController.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserRepository.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserService.java rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/{actor => user}/GHUser.java (90%) create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserController.java rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/{actor => user}/GHUserConverter.java (93%) create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserDTO.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserRepository.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserService.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/errors/EntityNotFoundException.java diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java index 54cf5ea1..e0429bdd 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java @@ -1,7 +1,5 @@ package de.tum.in.www1.hephaestus; -import java.util.List; - import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java index d4d41cb1..2ec7bd65 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java @@ -21,9 +21,6 @@ import org.springframework.graphql.client.HttpSyncGraphQlClient; import de.tum.in.www1.hephaestus.EnvConfig; -import de.tum.in.www1.hephaestus.codereview.actor.GHUser; -import de.tum.in.www1.hephaestus.codereview.actor.GHUserConverter; -import de.tum.in.www1.hephaestus.codereview.actor.GHUserRepository; import de.tum.in.www1.hephaestus.codereview.comment.IssueComment; import de.tum.in.www1.hephaestus.codereview.comment.IssueCommentConverter; import de.tum.in.www1.hephaestus.codereview.comment.IssueCommentRepository; @@ -33,6 +30,9 @@ import de.tum.in.www1.hephaestus.codereview.repository.Repository; import de.tum.in.www1.hephaestus.codereview.repository.RepositoryConverter; import de.tum.in.www1.hephaestus.codereview.repository.RepositoryRepository; +import de.tum.in.www1.hephaestus.codereview.user.GHUser; +import de.tum.in.www1.hephaestus.codereview.user.GHUserConverter; +import de.tum.in.www1.hephaestus.codereview.user.GHUserRepository; @Service public class CodeReviewService { @@ -46,7 +46,7 @@ public class CodeReviewService { private final RepositoryRepository repositoryRepository; private final PullRequestRepository pullrequestRepository; private final IssueCommentRepository commentRepository; - private final GHUserRepository actorRepository; + private final GHUserRepository ghUserRepository; private final EnvConfig envConfig; @@ -59,7 +59,7 @@ public CodeReviewService(EnvConfig envConfig, RepositoryRepository repositoryRep this.repositoryRepository = repositoryRepository; this.pullrequestRepository = pullrequestRepository; this.commentRepository = commentRepository; - this.actorRepository = actorRepository; + this.ghUserRepository = actorRepository; RestClient restClient = RestClient.builder() .baseUrl("https://api.github.com/graphql") @@ -167,12 +167,13 @@ private Set getCommentsFromGHPullRequest(GHPullRequest pr, PullReq } private GHUser getActorFromGHUser(org.kohsuke.github.GHUser user) { - GHUser actor = actorRepository.findByLogin(user.getLogin()); - if (actor == null) { - actor = new GHUserConverter().convert(user); - actorRepository.save(actor); + GHUser ghUser = ghUserRepository.findByLogin(user.getLogin()).orElse(null); + if (ghUser == null) { + ghUser = new GHUserConverter().convert(user); + ghUserRepository.save(ghUser); } - return actor; + return ghUser; + } /** diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserController.java deleted file mode 100644 index b6cb30ea..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserController.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview.actor; - -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("/ghuser") -public class GHUserController { - private final GHUserService actorService; - - public GHUserController(GHUserService actorService) { - this.actorService = actorService; - } - - @GetMapping("/{login}") - public GHUser getActor(@PathVariable String login) { - return actorService.getActor(login); - } - -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserRepository.java deleted file mode 100644 index d715d990..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview.actor; - -import java.util.Optional; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; - -public interface GHUserRepository extends JpaRepository { - - @Query("SELECT a FROM Actor a WHERE a.login = ?1") - GHUser findByLogin(String login); -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserService.java deleted file mode 100644 index e05a100f..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserService.java +++ /dev/null @@ -1,24 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview.actor; - -import java.util.Optional; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -@Service -public class GHUserService { - private static final Logger logger = LoggerFactory.getLogger(GHUser.class); - - private final GHUserRepository actorRepository; - - public GHUserService(GHUserRepository actorRepository) { - this.actorRepository = actorRepository; - } - - public GHUser getActor(String login) { - logger.info("Getting actor with login: " + login); - return actorRepository.findByLogin(login); - } - -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java index 89f5e4db..6245c757 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java @@ -8,8 +8,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; -import de.tum.in.www1.hephaestus.codereview.actor.GHUser; import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest; +import de.tum.in.www1.hephaestus.codereview.user.GHUser; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index 099c0d6c..148bc458 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -8,9 +8,9 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; -import de.tum.in.www1.hephaestus.codereview.actor.GHUser; import de.tum.in.www1.hephaestus.codereview.comment.IssueComment; import de.tum.in.www1.hephaestus.codereview.repository.Repository; +import de.tum.in.www1.hephaestus.codereview.user.GHUser; import jakarta.persistence.Id; import jakarta.persistence.Table; import jakarta.persistence.CascadeType; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java index 9bafe62a..9df32a87 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java @@ -21,11 +21,13 @@ public PullRequest convert(@NonNull GHPullRequest source) { try { pullrequest.setCreatedAt(source.getCreatedAt().toString()); } catch (IOException e) { + // find a better way to handle this pullrequest.setCreatedAt(null); } try { pullrequest.setUpdatedAt(source.getUpdatedAt().toString()); } catch (IOException e) { + // find a better way to handle this pullrequest.setUpdatedAt(null); } pullrequest.setMergedAt(source.getMergedAt() != null ? source.getMergedAt().toString() : null); diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java index 9c80e43b..c88b60f1 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java @@ -1,7 +1,6 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; import java.util.List; -import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -10,10 +9,10 @@ @Repository public interface PullRequestRepository extends JpaRepository { - @Query("SELECT p FROM Pullrequest p WHERE p.githubId = ?1") + @Query("SELECT p FROM PullRequest p WHERE p.githubId = ?1") PullRequest findByGithubId(Long githubId); - @Query("SELECT p FROM Pullrequest p, Actor a WHERE p.author = a AND a.login = ?1") + @Query("SELECT p FROM PullRequest p, GHUser a WHERE p.author = a AND a.login = ?1") List findByAuthor(String authorLogin); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryRepository.java index 61faa18b..b4d1f4df 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryRepository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryRepository.java @@ -3,8 +3,6 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; -import de.tum.in.www1.hephaestus.codereview.repository.Repository; - @org.springframework.stereotype.Repository public interface RepositoryRepository extends JpaRepository { diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUser.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUser.java similarity index 90% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUser.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUser.java index 9280b6f2..4e54865e 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUser.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUser.java @@ -1,4 +1,4 @@ -package de.tum.in.www1.hephaestus.codereview.actor; +package de.tum.in.www1.hephaestus.codereview.user; import jakarta.persistence.Id; import jakarta.persistence.Table; @@ -9,7 +9,6 @@ import org.springframework.lang.NonNull; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; import de.tum.in.www1.hephaestus.codereview.comment.IssueComment; import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest; @@ -29,7 +28,6 @@ @Getter @Setter @NoArgsConstructor -@JsonInclude(JsonInclude.Include.NON_EMPTY) @ToString public class GHUser { /** @@ -59,14 +57,11 @@ public class GHUser { @NonNull private String url; - @Column() - /** * The Pullrequests of the User entity. */ @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") @JsonIgnore - @ToString.Exclude private Set pullRequests = new HashSet<>();; /** @@ -74,7 +69,6 @@ public class GHUser { */ @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") @JsonIgnore - @ToString.Exclude private Set comments = new HashSet<>();; public void addComment(IssueComment comment) { diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserController.java new file mode 100644 index 00000000..7bc36039 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserController.java @@ -0,0 +1,30 @@ +package de.tum.in.www1.hephaestus.codereview.user; + +import java.util.Optional; + +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; + +import de.tum.in.www1.hephaestus.errors.EntityNotFoundException; + +@RestController +@RequestMapping("/ghuser") +public class GHUserController { + private final GHUserService ghUserService; + + public GHUserController(GHUserService actorService) { + this.ghUserService = actorService; + } + + @GetMapping("/{login}") + public GHUserDTO getUser(@PathVariable String login) { + Optional user = ghUserService.getGHUserDTO(login); + if (user.isEmpty()) { + throw new EntityNotFoundException("Actor with login " + login + " not found!"); + } + return user.get(); + } + +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserConverter.java similarity index 93% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserConverter.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserConverter.java index 588ba805..bb8e0cdd 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/GHUserConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserConverter.java @@ -1,4 +1,4 @@ -package de.tum.in.www1.hephaestus.codereview.actor; +package de.tum.in.www1.hephaestus.codereview.user; import java.io.IOException; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserDTO.java new file mode 100644 index 00000000..b7d6dfa9 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserDTO.java @@ -0,0 +1,7 @@ +package de.tum.in.www1.hephaestus.codereview.user; + +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public record GHUserDTO(String login, String email, String name, String url) { +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserRepository.java new file mode 100644 index 00000000..1a2b185d --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserRepository.java @@ -0,0 +1,19 @@ +package de.tum.in.www1.hephaestus.codereview.user; + +import java.util.Optional; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface GHUserRepository extends JpaRepository { + + Optional findByLogin(String login); + + @Query(""" + SELECT new de.tum.in.www1.hephaestus.codereview.actor.GHUserDTO(u.login, u.email, u.name, u.url) + FROM GHUser u + WHERE u.login = :login + """) + Optional findUserDTO(@Param("login") String login); +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserService.java new file mode 100644 index 00000000..c40d36ef --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserService.java @@ -0,0 +1,28 @@ +package de.tum.in.www1.hephaestus.codereview.user; + +import java.util.Optional; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +@Service +public class GHUserService { + private static final Logger logger = LoggerFactory.getLogger(GHUser.class); + + private final GHUserRepository ghuserRepository; + + public GHUserService(GHUserRepository actorRepository) { + this.ghuserRepository = actorRepository; + } + + public Optional getGHUser(String login) { + logger.info("Getting user with login: " + login); + return ghuserRepository.findByLogin(login); + } + + public Optional getGHUserDTO(String login) { + logger.info("Getting userDTO with login: " + login); + return ghuserRepository.findUserDTO(login); + } +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/errors/EntityNotFoundException.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/errors/EntityNotFoundException.java new file mode 100644 index 00000000..3cbb8d06 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/errors/EntityNotFoundException.java @@ -0,0 +1,29 @@ +package de.tum.in.www1.hephaestus.errors; + +import java.io.Serial; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(HttpStatus.NOT_FOUND) +public class EntityNotFoundException extends RuntimeException { + + @Serial + private static final long serialVersionUID = 1L; + + public EntityNotFoundException() { + super(); + } + + public EntityNotFoundException(String message) { + super(message); + } + + public EntityNotFoundException(String entityName, Long entityId) { + super(entityName + " with id: \"" + entityId + "\" does not exist"); + } + + public EntityNotFoundException(String entityName, String entityIdentifier) { + super(entityName + " with identifier: \"" + entityIdentifier + "\" does not exist"); + } +} From 567df1587f016dcdac18b74cc90dc38d5e0c02b3 Mon Sep 17 00:00:00 2001 From: GODrums Date: Thu, 29 Aug 2024 04:08:07 +0200 Subject: [PATCH 20/50] Replace logger classes --- .../hephaestus/codereview/pullrequest/PullrequestService.java | 2 +- .../hephaestus/codereview/repository/RepositoryService.java | 2 +- .../tum/in/www1/hephaestus/codereview/user/GHUserService.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java index 11295f08..ca608bb6 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java @@ -8,7 +8,7 @@ @Service public class PullRequestService { - private static final Logger logger = LoggerFactory.getLogger(PullRequest.class); + private static final Logger logger = LoggerFactory.getLogger(PullRequestService.class); private final PullRequestRepository pullrequestRepository; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java index d6d476dd..8e5aea56 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java @@ -9,7 +9,7 @@ @Service public class RepositoryService { - private static final Logger logger = LoggerFactory.getLogger(Repository.class); + private static final Logger logger = LoggerFactory.getLogger(RepositoryService.class); private final RepositoryRepository repositoryRepository; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserService.java index c40d36ef..1248482a 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserService.java @@ -8,7 +8,7 @@ @Service public class GHUserService { - private static final Logger logger = LoggerFactory.getLogger(GHUser.class); + private static final Logger logger = LoggerFactory.getLogger(GHUserService.class); private final GHUserRepository ghuserRepository; From 1faa0dc96aa8789ce72dd0617ad4951afa7fbcea Mon Sep 17 00:00:00 2001 From: GODrums Date: Thu, 29 Aug 2024 04:18:59 +0200 Subject: [PATCH 21/50] Create GHIssueState enum --- .../codereview/pullrequest/GHIssueState.java | 5 +++++ .../codereview/pullrequest/Pullrequest.java | 2 +- .../pullrequest/PullrequestConverter.java | 15 ++++++++++++++- .../codereview/user/GHUserRepository.java | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/GHIssueState.java diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/GHIssueState.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/GHIssueState.java new file mode 100644 index 00000000..a906342f --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/GHIssueState.java @@ -0,0 +1,5 @@ +package de.tum.in.www1.hephaestus.codereview.pullrequest; + +public enum GHIssueState { + ALL, CLOSED, OPEN +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index 148bc458..0f714ba6 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -65,7 +65,7 @@ public class PullRequest { * This field is mandatory. */ @NonNull - private String state; + private GHIssueState state; /** * Timestamp of when the Pullrequest entity was created. diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java index 9df32a87..7087b663 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java @@ -17,7 +17,7 @@ public PullRequest convert(@NonNull GHPullRequest source) { pullrequest.setGithubId(source.getId()); pullrequest.setTitle(source.getTitle()); pullrequest.setUrl(source.getHtmlUrl().toString()); - pullrequest.setState(source.getState().toString()); + pullrequest.setState(convertState(source.getState())); try { pullrequest.setCreatedAt(source.getCreatedAt().toString()); } catch (IOException e) { @@ -37,4 +37,17 @@ public PullRequest convert(@NonNull GHPullRequest source) { return pullrequest; } + private GHIssueState convertState(org.kohsuke.github.GHIssueState state) { + switch (state) { + case OPEN: + return GHIssueState.OPEN; + case CLOSED: + return GHIssueState.CLOSED; + case ALL: + return GHIssueState.ALL; + default: + return GHIssueState.ALL; + } + } + } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserRepository.java index 1a2b185d..eb16068c 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserRepository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserRepository.java @@ -11,7 +11,7 @@ public interface GHUserRepository extends JpaRepository { Optional findByLogin(String login); @Query(""" - SELECT new de.tum.in.www1.hephaestus.codereview.actor.GHUserDTO(u.login, u.email, u.name, u.url) + SELECT new de.tum.in.www1.hephaestus.codereview.user.GHUserDTO(u.login, u.email, u.name, u.url) FROM GHUser u WHERE u.login = :login """) From 930a3ef30779bbb929b4559cea411a1d4dec940a Mon Sep 17 00:00:00 2001 From: GODrums Date: Thu, 29 Aug 2024 04:34:17 +0200 Subject: [PATCH 22/50] Deleted unused classes --- .../repository/RepositoryController.java | 39 ----------- .../repository/RepositoryService.java | 65 ------------------- 2 files changed, 104 deletions(-) delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryController.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryController.java deleted file mode 100644 index a0f26e6f..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryController.java +++ /dev/null @@ -1,39 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview.repository; - -import java.util.List; - -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("/repository") -public class RepositoryController { - private final RepositoryService repositoryService; - - public RepositoryController(RepositoryService repositoryService) { - this.repositoryService = repositoryService; - } - - /** - * Retrieves all {@link Repository} entities. - * - * @return A list of all Repository entities - */ - @GetMapping - public List getAllRepositories() { - return repositoryService.getAllRepositories(); - } - - /** - * Retrieves a {@link Repository} entity by its full name. - * - * @param nameWithOwner The full name of the Repository - * @return The Repository entity - */ - @GetMapping("/{owner}/{name}") - public Repository getRepositoryByNameWithOwner(@PathVariable String owner, @PathVariable String name) { - return repositoryService.getRepository(owner + "/" + name); - } -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java deleted file mode 100644 index 8e5aea56..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryService.java +++ /dev/null @@ -1,65 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview.repository; - -import java.time.Instant; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -@Service -public class RepositoryService { - private static final Logger logger = LoggerFactory.getLogger(RepositoryService.class); - - private final RepositoryRepository repositoryRepository; - - public RepositoryService(RepositoryRepository repositoryRepository) { - this.repositoryRepository = repositoryRepository; - } - - /** - * Retrieves all {@link Repository} entities. - * - * @return A list of all Repository entities - */ - public List getAllRepositories() { - var repositories = repositoryRepository.findAll(); - logger.info("Getting Repositories: {}", repositories.toArray()); - return repositoryRepository.findAll(); - } - - public Repository getRepository(String nameWithOwner) { - logger.info("Getting repository with nameWithOwner: " + nameWithOwner); - return repositoryRepository.findByNameWithOwner(nameWithOwner); - } - - /** - * Creates a new {@link Repository} entity with the current timestamp and saves - * it to - * the repository. - * - * @return The created Repository entity - */ - public Repository addRepository() { - Repository repository = new Repository(); - repository.setAddedAt(Instant.now()); - logger.info("Adding new Repository with timestamp: {}", repository.getAddedAt()); - return repositoryRepository.save(repository); - } - - public Repository saveRepository(Repository repository) { - Repository existingRepository = repositoryRepository.findByNameWithOwner(repository.getNameWithOwner()); - logger.info("Found Repository: {}", existingRepository); - if (existingRepository != null) { - logger.info("Repository already exists: {}", existingRepository.getNameWithOwner()); - return existingRepository; - } - - logger.info("Adding Repository: {}", repository.getNameWithOwner()); - return repositoryRepository.save(repository); - } - - public long countRepositories() { - return repositoryRepository.count(); - } -} From f629070da993c200e4e8853a84a2c640ac56ef22 Mon Sep 17 00:00:00 2001 From: GODrums Date: Thu, 29 Aug 2024 05:12:23 +0200 Subject: [PATCH 23/50] Remove more unused code --- .../codereview/CodeReviewController.java | 4 +- .../codereview/CodeReviewService.java | 57 +------------------ .../pullrequest/PullrequestRepository.java | 1 - .../repository/RepositoryRepository.java | 2 - .../graphql-documents/getrepositoryprs.gql | 40 ------------- 5 files changed, 4 insertions(+), 100 deletions(-) delete mode 100644 server/application-server/src/main/resources/graphql-documents/getrepositoryprs.gql diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewController.java index 0066bc98..f89a8cfe 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewController.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewController.java @@ -2,9 +2,9 @@ import java.io.IOException; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import de.tum.in.www1.hephaestus.codereview.repository.Repository; @@ -19,7 +19,7 @@ public CodeReviewController(CodeReviewService codeReviewService) { } @PutMapping("/repository/{nameWithOwner}") - public Repository addRepository(@RequestParam String nameWithOwner) { + public Repository addRepository(@PathVariable String nameWithOwner) { try { return codeReviewService.fetchRepository(nameWithOwner); } catch (IOException e) { diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java index 2ec7bd65..97809a6c 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java @@ -1,10 +1,7 @@ package de.tum.in.www1.hephaestus.codereview; import java.io.IOException; -import java.time.Instant; -import java.util.HashMap; import java.util.HashSet; -import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -15,10 +12,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; -import org.springframework.web.client.RestClient; - -import org.springframework.data.domain.Example; -import org.springframework.graphql.client.HttpSyncGraphQlClient; +import org.springframework.context.annotation.Configuration; import de.tum.in.www1.hephaestus.EnvConfig; import de.tum.in.www1.hephaestus.codereview.comment.IssueComment; @@ -34,13 +28,12 @@ import de.tum.in.www1.hephaestus.codereview.user.GHUserConverter; import de.tum.in.www1.hephaestus.codereview.user.GHUserRepository; +@Configuration @Service public class CodeReviewService { private static final Logger logger = LoggerFactory.getLogger(CodeReviewService.class); - private final HttpSyncGraphQlClient graphQlClient; - private GitHub github; private final RepositoryRepository repositoryRepository; @@ -48,28 +41,16 @@ public class CodeReviewService { private final IssueCommentRepository commentRepository; private final GHUserRepository ghUserRepository; - private final EnvConfig envConfig; - public CodeReviewService(EnvConfig envConfig, RepositoryRepository repositoryRepository, PullRequestRepository pullrequestRepository, IssueCommentRepository commentRepository, GHUserRepository actorRepository) { logger.info("Hello from CodeReviewService!"); - this.envConfig = envConfig; this.repositoryRepository = repositoryRepository; this.pullrequestRepository = pullrequestRepository; this.commentRepository = commentRepository; this.ghUserRepository = actorRepository; - RestClient restClient = RestClient.builder() - .baseUrl("https://api.github.com/graphql") - .build(); - - String githubPat = this.envConfig.getGithubPat(); - - graphQlClient = HttpSyncGraphQlClient.builder(restClient) - .headers(headers -> headers.setBearerAuth(githubPat)) - .build(); try { github = new GitHubBuilder().withOAuthToken(envConfig.getGithubPat()).build(); } catch (IOException e) { @@ -175,38 +156,4 @@ private GHUser getActorFromGHUser(org.kohsuke.github.GHUser user) { return ghUser; } - - /** - * GraphQL implementation of fetching the hephaestus Github repository. - * - * @see #fetchRepository(String) - * @return The hephaestus repository. - */ - public Repository getHephaestusRepository() { - Repository example = new Repository(); - example.setName("hephaestus"); - example.setNameWithOwner("ls1intum/hephaestus"); - Optional foundRepo = repositoryRepository.findOne(Example.of(example)); - if (foundRepo.isPresent()) { - return foundRepo.get(); - } - - logger.info("No repo found, creating new one..."); - HashMap variables = new HashMap<>(); - variables.put("owner", "ls1intum"); - variables.put("name", "hephaestus"); - variables.put("first", 10); - - Repository repository = graphQlClient.documentName("getrepositoryprs") - .variables(variables) - .retrieveSync("repository") - .toEntity(Repository.class); - if (repository == null) { - logger.error("Error while fetching repository!"); - return null; - } - repository.setAddedAt(Instant.now()); - repositoryRepository.saveAndFlush(repository); - return repository; - } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java index c88b60f1..838a10c2 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java @@ -9,7 +9,6 @@ @Repository public interface PullRequestRepository extends JpaRepository { - @Query("SELECT p FROM PullRequest p WHERE p.githubId = ?1") PullRequest findByGithubId(Long githubId); @Query("SELECT p FROM PullRequest p, GHUser a WHERE p.author = a AND a.login = ?1") diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryRepository.java index b4d1f4df..836d8ffb 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryRepository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryRepository.java @@ -1,12 +1,10 @@ package de.tum.in.www1.hephaestus.codereview.repository; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; @org.springframework.stereotype.Repository public interface RepositoryRepository extends JpaRepository { - @Query("SELECT r FROM Repository r WHERE r.nameWithOwner = ?1") Repository findByNameWithOwner(String nameWithOwner); } diff --git a/server/application-server/src/main/resources/graphql-documents/getrepositoryprs.gql b/server/application-server/src/main/resources/graphql-documents/getrepositoryprs.gql deleted file mode 100644 index fd8d82e8..00000000 --- a/server/application-server/src/main/resources/graphql-documents/getrepositoryprs.gql +++ /dev/null @@ -1,40 +0,0 @@ -query GetRepositoryPRs($owner: String!, $name: String!, $first: Int!) { - repository(owner: $owner, name: $name) { - githubId: id - name - nameWithOwner - description - url - pullRequests(first: $first, states: [OPEN, MERGED]) { - nodes { - githubId: id - title - url - state - createdAt - updatedAt - mergedAt - author { - ...authorFields - } - comments(last: 100) { - nodes { - githubId: id - body - createdAt - updatedAt - author { - ...authorFields - } - } - } - } - } - } -} - -fragment authorFields on Actor { - avatarUrl - login - url -} From 6e6b16624a29d66f79c6d318fdead06c4cd48719 Mon Sep 17 00:00:00 2001 From: GODrums Date: Thu, 29 Aug 2024 21:20:46 +0200 Subject: [PATCH 24/50] Remove github_id from entities --- .../tum/in/www1/hephaestus/codereview/CodeReviewService.java | 2 -- .../in/www1/hephaestus/codereview/comment/IssueComment.java | 3 --- .../hephaestus/codereview/comment/IssueCommentConverter.java | 1 - .../in/www1/hephaestus/codereview/pullrequest/Pullrequest.java | 3 --- .../codereview/pullrequest/PullrequestConverter.java | 1 - .../codereview/pullrequest/PullrequestRepository.java | 2 -- .../in/www1/hephaestus/codereview/repository/Repository.java | 3 --- .../hephaestus/codereview/repository/RepositoryConverter.java | 1 - 8 files changed, 16 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java index 97809a6c..d6078e53 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java @@ -12,7 +12,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; -import org.springframework.context.annotation.Configuration; import de.tum.in.www1.hephaestus.EnvConfig; import de.tum.in.www1.hephaestus.codereview.comment.IssueComment; @@ -28,7 +27,6 @@ import de.tum.in.www1.hephaestus.codereview.user.GHUserConverter; import de.tum.in.www1.hephaestus.codereview.user.GHUserRepository; -@Configuration @Service public class CodeReviewService { diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java index 6245c757..56427398 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java @@ -37,9 +37,6 @@ public class IssueComment { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(name = "github_id") - private Long githubId; - /** * Body of the Comment entity. * This field is mandatory. diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java index f8a3e47e..fd03c237 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java @@ -12,7 +12,6 @@ public class IssueCommentConverter implements Converter { - PullRequest findByGithubId(Long githubId); - @Query("SELECT p FROM PullRequest p, GHUser a WHERE p.author = a AND a.login = ?1") List findByAuthor(String authorLogin); diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index 68803e97..5f8465a7 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -36,9 +36,6 @@ public class Repository { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(name = "github_id") - private Long githubId; - @NonNull private String name; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java index 1d4fe501..026130b2 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java @@ -22,7 +22,6 @@ public Repository convert(@NonNull GHRepository source) { repository.setUrl(source.getHtmlUrl().toString()); repository.setDescription(source.getDescription()); repository.setAddedAt(Instant.now()); - repository.setGithubId(source.getId()); return repository; } From 7d8df6536660aab2e774b75c59a399c25abee91f Mon Sep 17 00:00:00 2001 From: GODrums Date: Thu, 29 Aug 2024 21:42:35 +0200 Subject: [PATCH 25/50] Improve entity comments --- .../codereview/comment/IssueComment.java | 22 +------------ .../codereview/pullrequest/Pullrequest.java | 32 ++----------------- .../hephaestus/codereview/user/GHUser.java | 32 +++++++++---------- .../codereview/user/GHUserConverter.java | 1 + 4 files changed, 19 insertions(+), 68 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java index 56427398..7814c47d 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java @@ -30,45 +30,25 @@ @JsonInclude(JsonInclude.Include.NON_EMPTY) @ToString public class IssueComment { - /** - * Unique identifier for a Comment entity. - */ + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - /** - * Body of the Comment entity. - * This field is mandatory. - */ @NonNull private String body; - /** - * Timestamp of when the Comment entity was created. - * This field is mandatory. - */ @NonNull private String createdAt; - /** - * Timestamp of when the Comment entity was updated. - * This field is mandatory. - */ @NonNull private String updatedAt; - /** - * The author of the Comment entity. - */ @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "author_id") @ToString.Exclude private GHUser author; - /** - * The parent connection to the pullrequest of the Comment entity. - */ @ManyToOne(optional = false) @JoinColumn(name = "pullrequest_id", referencedColumnName = "id") @JsonIgnore diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index 4e11333c..208c2104 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -36,57 +36,32 @@ @ToString public class PullRequest { - /** - * Unique identifier for a Pullrequest entity. - */ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - /** - * Title of the Pullrequest. - * This field is mandatory. - */ @NonNull private String title; - /** - * URL of the Pullrequest. - * This field is mandatory. - */ @NonNull private String url; /** - * State of the Pullrequest. - * This field is mandatory. + * State of the PullRequest. + * Does not include the state of the merge. */ @NonNull private GHIssueState state; - /** - * Timestamp of when the Pullrequest entity was created. - * This field is mandatory. - */ @NonNull private String createdAt; - /** - * Timestamp of when the Pullrequest entity was updated. - * This field is mandatory. - */ @NonNull private String updatedAt; - /** - * Timestamp of when the Pullrequest entity was merged. - */ @Column private String mergedAt; - /** - * The author of the Pullrequest entity. - */ @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "author_id") @ToString.Exclude @@ -96,9 +71,6 @@ public class PullRequest { @ToString.Exclude private Set comments = new HashSet<>();; - /** - * The parent connection of the Pullrequest entity. - */ @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "repository_id", referencedColumnName = "id") @JsonIgnore diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUser.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUser.java index 4e54865e..b60e0a7b 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUser.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUser.java @@ -30,16 +30,13 @@ @NoArgsConstructor @ToString public class GHUser { - /** - * Unique identifier for a User entity. - */ + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; /** - * Login of the User entity. - * This field is mandatory. + * Unique login identifier for a user. */ @NonNull private String login; @@ -47,39 +44,40 @@ public class GHUser { @Column private String email; + /** + * Display name of the user. + */ @Column private String name; /** - * URL of the User entity. - * This field is mandatory. + * Unique URL to the user's profile. + * Not the website a user can set in their profile. */ @NonNull private String url; /** - * The Pullrequests of the User entity. + * URL to the user's avatar. + * If unavailable, a fallback can be generated from the login, e.g. on Github: + * https://github.com/{login}.png */ + @NonNull + private String avatarUrl; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") @JsonIgnore private Set pullRequests = new HashSet<>();; - /** - * The Comments of the User entity. - */ @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") @JsonIgnore private Set comments = new HashSet<>();; public void addComment(IssueComment comment) { - if (!comments.contains(comment)) { - comments.add(comment); - } + comments.add(comment); } public void addPullrequest(PullRequest pullrequest) { - if (!pullRequests.contains(pullrequest)) { - pullRequests.add(pullrequest); - } + pullRequests.add(pullrequest); } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserConverter.java index bb8e0cdd..394c74aa 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserConverter.java @@ -22,6 +22,7 @@ public GHUser convert(@NonNull org.kohsuke.github.GHUser source) { user.setEmail(null); } user.setUrl(source.getHtmlUrl().toString()); + user.setAvatarUrl(source.getAvatarUrl()); return user; } From 9121e61789c6d4449696fa212e185e6fdcf6bcdd Mon Sep 17 00:00:00 2001 From: GODrums Date: Fri, 30 Aug 2024 05:19:53 +0200 Subject: [PATCH 26/50] Add more DTOs and Superclass --- server/application-server/pom.xml | 4 --- .../codereview/CodeReviewService.java | 22 +++++++------- .../codereview/base/BaseGitServiceEntity.java | 25 ++++++++++++++++ .../codereview/comment/IssueComment.java | 24 ++++----------- .../codereview/comment/IssueCommentDTO.java | 14 +++++++++ .../pullrequest/PullRequestDTO.java | 18 ++++++++++++ .../codereview/pullrequest/Pullrequest.java | 25 ++++------------ .../pullrequest/PullrequestRepository.java | 2 +- .../codereview/repository/Repository.java | 20 ++----------- .../repository/RepositoryConverter.java | 3 -- .../codereview/repository/RepositoryDTO.java | 12 ++++++++ .../hephaestus/codereview/user/GHUserDTO.java | 7 ----- .../codereview/user/GHUserRepository.java | 19 ------------ .../codereview/user/GHUserService.java | 28 ------------------ .../user/{GHUser.java => User.java} | 25 +++++----------- ...serController.java => UserController.java} | 14 ++++----- ...HUserConverter.java => UserConverter.java} | 6 ++-- .../hephaestus/codereview/user/UserDTO.java | 16 ++++++++++ .../codereview/user/UserRepository.java | 29 +++++++++++++++++++ .../codereview/user/UserService.java | 28 ++++++++++++++++++ .../src/main/resources/application.yml | 1 + 21 files changed, 185 insertions(+), 157 deletions(-) create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntity.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentDTO.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestDTO.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryDTO.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserDTO.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserRepository.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserService.java rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/{GHUser.java => User.java} (75%) rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/{GHUserController.java => UserController.java} (64%) rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/{GHUserConverter.java => UserConverter.java} (76%) create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserDTO.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserRepository.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserService.java diff --git a/server/application-server/pom.xml b/server/application-server/pom.xml index b6601e85..8bcad39c 100644 --- a/server/application-server/pom.xml +++ b/server/application-server/pom.xml @@ -121,10 +121,6 @@ spring-modulith-starter-test test - - org.springframework.boot - spring-boot-starter-graphql - org.kohsuke github-api diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java index d6078e53..33bf7703 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java @@ -23,9 +23,9 @@ import de.tum.in.www1.hephaestus.codereview.repository.Repository; import de.tum.in.www1.hephaestus.codereview.repository.RepositoryConverter; import de.tum.in.www1.hephaestus.codereview.repository.RepositoryRepository; -import de.tum.in.www1.hephaestus.codereview.user.GHUser; -import de.tum.in.www1.hephaestus.codereview.user.GHUserConverter; -import de.tum.in.www1.hephaestus.codereview.user.GHUserRepository; +import de.tum.in.www1.hephaestus.codereview.user.User; +import de.tum.in.www1.hephaestus.codereview.user.UserConverter; +import de.tum.in.www1.hephaestus.codereview.user.UserRepository; @Service public class CodeReviewService { @@ -37,17 +37,17 @@ public class CodeReviewService { private final RepositoryRepository repositoryRepository; private final PullRequestRepository pullrequestRepository; private final IssueCommentRepository commentRepository; - private final GHUserRepository ghUserRepository; + private final UserRepository userRepository; public CodeReviewService(EnvConfig envConfig, RepositoryRepository repositoryRepository, PullRequestRepository pullrequestRepository, IssueCommentRepository commentRepository, - GHUserRepository actorRepository) { + UserRepository actorRepository) { logger.info("Hello from CodeReviewService!"); this.repositoryRepository = repositoryRepository; this.pullrequestRepository = pullrequestRepository; this.commentRepository = commentRepository; - this.ghUserRepository = actorRepository; + this.userRepository = actorRepository; try { github = new GitHubBuilder().withOAuthToken(envConfig.getGithubPat()).build(); @@ -130,7 +130,7 @@ private Set getCommentsFromGHPullRequest(GHPullRequest pr, PullReq .map(comment -> { IssueComment c = commentConverter.convert(comment); c.setPullrequest(pullrequest); - GHUser author; + User author; try { author = getActorFromGHUser(comment.getUser()); author.addComment(c); @@ -145,11 +145,11 @@ private Set getCommentsFromGHPullRequest(GHPullRequest pr, PullReq return comments; } - private GHUser getActorFromGHUser(org.kohsuke.github.GHUser user) { - GHUser ghUser = ghUserRepository.findByLogin(user.getLogin()).orElse(null); + private User getActorFromGHUser(org.kohsuke.github.GHUser user) { + User ghUser = userRepository.findUser(user.getLogin()).orElse(null); if (ghUser == null) { - ghUser = new GHUserConverter().convert(user); - ghUserRepository.save(ghUser); + ghUser = new UserConverter().convert(user); + userRepository.save(ghUser); } return ghUser; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntity.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntity.java new file mode 100644 index 00000000..1a069dc1 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntity.java @@ -0,0 +1,25 @@ +package de.tum.in.www1.hephaestus.codereview.base; + +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.MappedSuperclass; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@MappedSuperclass +@Getter +@Setter +@NoArgsConstructor +@ToString +public class BaseGitServiceEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + protected Long id; + + protected String createdAt; + + protected String updatedAt; +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java index 7814c47d..d0be0c10 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java @@ -1,6 +1,5 @@ package de.tum.in.www1.hephaestus.codereview.comment; -import jakarta.persistence.Id; import jakarta.persistence.Table; import org.springframework.lang.NonNull; @@ -8,13 +7,11 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; +import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntity; import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest; -import de.tum.in.www1.hephaestus.codereview.user.GHUser; -import jakarta.persistence.Column; +import de.tum.in.www1.hephaestus.codereview.user.User; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import lombok.Getter; @@ -28,26 +25,15 @@ @Setter @NoArgsConstructor @JsonInclude(JsonInclude.Include.NON_EMPTY) -@ToString -public class IssueComment { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - +@ToString(callSuper = true) +public class IssueComment extends BaseGitServiceEntity { @NonNull private String body; - @NonNull - private String createdAt; - - @NonNull - private String updatedAt; - @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "author_id") @ToString.Exclude - private GHUser author; + private User author; @ManyToOne(optional = false) @JoinColumn(name = "pullrequest_id", referencedColumnName = "id") diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentDTO.java new file mode 100644 index 00000000..790a49ed --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentDTO.java @@ -0,0 +1,14 @@ +package de.tum.in.www1.hephaestus.codereview.comment; + +import com.fasterxml.jackson.annotation.JsonInclude; + +import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequestDTO; +import de.tum.in.www1.hephaestus.codereview.user.UserDTO; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public record IssueCommentDTO(String body, String createdAt, String updatedAt, UserDTO author, + PullRequestDTO pullrequest) { + public IssueCommentDTO(String body, String createdAt, String updatedAt) { + this(body, createdAt, updatedAt, null, null); + } +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestDTO.java new file mode 100644 index 00000000..5fec317e --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestDTO.java @@ -0,0 +1,18 @@ +package de.tum.in.www1.hephaestus.codereview.pullrequest; + +import java.util.Set; + +import com.fasterxml.jackson.annotation.JsonInclude; + +import de.tum.in.www1.hephaestus.codereview.comment.IssueCommentDTO; +import de.tum.in.www1.hephaestus.codereview.repository.RepositoryDTO; +import de.tum.in.www1.hephaestus.codereview.user.UserDTO; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public record PullRequestDTO(String title, String url, GHIssueState state, String createdAt, String updatedAt, + String mergedAt, UserDTO author, Set comments, RepositoryDTO repository) { + public PullRequestDTO(String title, String url, GHIssueState state, String createdAt, String updatedAt, + String mergedAt) { + this(title, url, state, createdAt, updatedAt, mergedAt, null, null, null); + } +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index 208c2104..fb4c1078 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -5,20 +5,17 @@ import org.springframework.lang.NonNull; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; +import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntity; import de.tum.in.www1.hephaestus.codereview.comment.IssueComment; import de.tum.in.www1.hephaestus.codereview.repository.Repository; -import de.tum.in.www1.hephaestus.codereview.user.GHUser; -import jakarta.persistence.Id; +import de.tum.in.www1.hephaestus.codereview.user.User; import jakarta.persistence.Table; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; @@ -33,13 +30,8 @@ @Setter @NoArgsConstructor @JsonInclude(JsonInclude.Include.NON_EMPTY) -@ToString -public class PullRequest { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - +@ToString(callSuper = true) +public class PullRequest extends BaseGitServiceEntity { @NonNull private String title; @@ -53,19 +45,13 @@ public class PullRequest { @NonNull private GHIssueState state; - @NonNull - private String createdAt; - - @NonNull - private String updatedAt; - @Column private String mergedAt; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "author_id") @ToString.Exclude - private GHUser author; + private User author; @OneToMany(cascade = CascadeType.ALL, mappedBy = "pullrequest") @ToString.Exclude @@ -73,7 +59,6 @@ public class PullRequest { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "repository_id", referencedColumnName = "id") - @JsonIgnore @ToString.Exclude private Repository repository; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java index 6dc10da0..c99d53e9 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java @@ -9,7 +9,7 @@ @Repository public interface PullRequestRepository extends JpaRepository { - @Query("SELECT p FROM PullRequest p, GHUser a WHERE p.author = a AND a.login = ?1") + @Query("SELECT p FROM PullRequest p, User a WHERE p.author = a AND a.login = ?1") List findByAuthor(String authorLogin); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index 5f8465a7..7f821be4 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -1,19 +1,16 @@ package de.tum.in.www1.hephaestus.codereview.repository; -import java.time.Instant; import java.util.HashSet; import java.util.Set; import org.springframework.lang.NonNull; +import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntity; import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import lombok.Getter; @@ -26,16 +23,8 @@ @Getter @Setter @NoArgsConstructor -@ToString -public class Repository { - - /** - * Unique identifier for a Repository - */ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - +@ToString(callSuper = true) +public class Repository extends BaseGitServiceEntity { @NonNull private String name; @@ -51,7 +40,4 @@ public class Repository { @OneToMany(cascade = CascadeType.ALL, mappedBy = "repository", fetch = FetchType.EAGER) @ToString.Exclude private Set pullRequests = new HashSet<>();; - - @Column(name = "added_at") - private Instant addedAt; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java index 026130b2..5f2e65d9 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java @@ -1,7 +1,5 @@ package de.tum.in.www1.hephaestus.codereview.repository; -import java.time.Instant; - import org.kohsuke.github.GHRepository; import org.springframework.core.convert.converter.Converter; import org.springframework.data.convert.ReadingConverter; @@ -21,7 +19,6 @@ public Repository convert(@NonNull GHRepository source) { repository.setNameWithOwner(source.getFullName()); repository.setUrl(source.getHtmlUrl().toString()); repository.setDescription(source.getDescription()); - repository.setAddedAt(Instant.now()); return repository; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryDTO.java new file mode 100644 index 00000000..5defadbe --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryDTO.java @@ -0,0 +1,12 @@ +package de.tum.in.www1.hephaestus.codereview.repository; + +import java.util.Set; + +import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequestDTO; + +public record RepositoryDTO(String name, String nameWithOwner, String description, String url, + Set pullRequests) { + public RepositoryDTO(String name, String nameWithOwner, String description, String url) { + this(name, nameWithOwner, description, url, null); + } +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserDTO.java deleted file mode 100644 index b7d6dfa9..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserDTO.java +++ /dev/null @@ -1,7 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview.user; - -import com.fasterxml.jackson.annotation.JsonInclude; - -@JsonInclude(JsonInclude.Include.NON_EMPTY) -public record GHUserDTO(String login, String email, String name, String url) { -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserRepository.java deleted file mode 100644 index eb16068c..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview.user; - -import java.util.Optional; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -public interface GHUserRepository extends JpaRepository { - - Optional findByLogin(String login); - - @Query(""" - SELECT new de.tum.in.www1.hephaestus.codereview.user.GHUserDTO(u.login, u.email, u.name, u.url) - FROM GHUser u - WHERE u.login = :login - """) - Optional findUserDTO(@Param("login") String login); -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserService.java deleted file mode 100644 index 1248482a..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserService.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview.user; - -import java.util.Optional; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -@Service -public class GHUserService { - private static final Logger logger = LoggerFactory.getLogger(GHUserService.class); - - private final GHUserRepository ghuserRepository; - - public GHUserService(GHUserRepository actorRepository) { - this.ghuserRepository = actorRepository; - } - - public Optional getGHUser(String login) { - logger.info("Getting user with login: " + login); - return ghuserRepository.findByLogin(login); - } - - public Optional getGHUserDTO(String login) { - logger.info("Getting userDTO with login: " + login); - return ghuserRepository.findUserDTO(login); - } -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUser.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java similarity index 75% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUser.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java index b60e0a7b..515ce0b1 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUser.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java @@ -1,6 +1,5 @@ package de.tum.in.www1.hephaestus.codereview.user; -import jakarta.persistence.Id; import jakarta.persistence.Table; import java.util.HashSet; @@ -8,15 +7,12 @@ import org.springframework.lang.NonNull; -import com.fasterxml.jackson.annotation.JsonIgnore; - +import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntity; import de.tum.in.www1.hephaestus.codereview.comment.IssueComment; import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; import jakarta.persistence.OneToMany; import lombok.Getter; import lombok.NoArgsConstructor; @@ -24,17 +20,12 @@ import lombok.ToString; @Entity -@Table(name = "gh_user") +@Table(name = "user", schema = "public") @Getter @Setter @NoArgsConstructor -@ToString -public class GHUser { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - +@ToString(callSuper = true) +public class User extends BaseGitServiceEntity { /** * Unique login identifier for a user. */ @@ -62,16 +53,14 @@ public class GHUser { * If unavailable, a fallback can be generated from the login, e.g. on Github: * https://github.com/{login}.png */ - @NonNull + @Column(nullable = false, name = "avatar_url") private String avatarUrl; @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") - @JsonIgnore - private Set pullRequests = new HashSet<>();; + private Set pullRequests = new HashSet<>(); @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") - @JsonIgnore - private Set comments = new HashSet<>();; + private Set comments = new HashSet<>(); public void addComment(IssueComment comment) { comments.add(comment); diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserController.java similarity index 64% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserController.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserController.java index 7bc36039..57758eac 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserController.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserController.java @@ -10,17 +10,17 @@ import de.tum.in.www1.hephaestus.errors.EntityNotFoundException; @RestController -@RequestMapping("/ghuser") -public class GHUserController { - private final GHUserService ghUserService; +@RequestMapping("/user") +public class UserController { + private final UserService userService; - public GHUserController(GHUserService actorService) { - this.ghUserService = actorService; + public UserController(UserService actorService) { + this.userService = actorService; } @GetMapping("/{login}") - public GHUserDTO getUser(@PathVariable String login) { - Optional user = ghUserService.getGHUserDTO(login); + public UserDTO getUser(@PathVariable String login) { + Optional user = userService.getUserDTO(login); if (user.isEmpty()) { throw new EntityNotFoundException("Actor with login " + login + " not found!"); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java similarity index 76% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserConverter.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java index 394c74aa..d830d078 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/GHUserConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java @@ -5,11 +5,11 @@ import org.springframework.core.convert.converter.Converter; import org.springframework.lang.NonNull; -public class GHUserConverter implements Converter { +public class UserConverter implements Converter { @Override - public GHUser convert(@NonNull org.kohsuke.github.GHUser source) { - GHUser user = new GHUser(); + public User convert(@NonNull org.kohsuke.github.GHUser source) { + User user = new User(); user.setLogin(source.getLogin()); try { user.setName(source.getName()); diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserDTO.java new file mode 100644 index 00000000..f85257ac --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserDTO.java @@ -0,0 +1,16 @@ +package de.tum.in.www1.hephaestus.codereview.user; + +import java.util.Set; + +import com.fasterxml.jackson.annotation.JsonInclude; + +import de.tum.in.www1.hephaestus.codereview.comment.IssueCommentDTO; +import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequestDTO; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public record UserDTO(String login, String email, String name, String url, Set pullRequests, + Set comments) { + public UserDTO(String login, String email, String name, String url) { + this(login, email, name, url, null, null); + } +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserRepository.java new file mode 100644 index 00000000..1fdc663e --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserRepository.java @@ -0,0 +1,29 @@ +package de.tum.in.www1.hephaestus.codereview.user; + +import java.util.Optional; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface UserRepository extends JpaRepository { + + @Query("SELECT u FROM User u WHERE u.login = :login") + Optional findUser(@Param("login") String login); + + @Query(""" + SELECT new de.tum.in.www1.hephaestus.codereview.user.UserDTO(u.login, u.email, u.name, u.url) + FROM User u + WHERE u.login = :login + """) + Optional findByLogin(@Param("login") String login); + + // @Query(""" + // SELECT new de.tum.in.www1.hephaestus.codereview.user.UserDTO(u.login, + // u.email, u.name, u.url, u.pullRequests, u.comments) + // FROM User u + // WHERE u.login = :login + // """) + // Optional findByLoginWithPullRequestsAndComments(@Param("login") + // String login); +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserService.java new file mode 100644 index 00000000..1c3703a3 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserService.java @@ -0,0 +1,28 @@ +package de.tum.in.www1.hephaestus.codereview.user; + +import java.util.Optional; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +@Service +public class UserService { + private static final Logger logger = LoggerFactory.getLogger(UserService.class); + + private final UserRepository userRepository; + + public UserService(UserRepository actorRepository) { + this.userRepository = actorRepository; + } + + public Optional getUser(String login) { + logger.info("Getting user with login: " + login); + return userRepository.findUser(login); + } + + public Optional getUserDTO(String login) { + logger.info("Getting userDTO with login: " + login); + return userRepository.findByLogin(login); + } +} diff --git a/server/application-server/src/main/resources/application.yml b/server/application-server/src/main/resources/application.yml index 383f97cd..0af6a844 100644 --- a/server/application-server/src/main/resources/application.yml +++ b/server/application-server/src/main/resources/application.yml @@ -11,6 +11,7 @@ spring: hibernate: # ddl-auto: update ddl-auto: create-drop + # ddl-auto: none # show-sql: "true" properties: hibernate: From 06528e87fcec71c43297a64a970e25d5e60f649e Mon Sep 17 00:00:00 2001 From: "Felix T.J. Dietrich" Date: Fri, 30 Aug 2024 13:53:01 +0200 Subject: [PATCH 27/50] fix indentiation of application.yml --- .../src/main/resources/application.yml | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/server/application-server/src/main/resources/application.yml b/server/application-server/src/main/resources/application.yml index 2c385239..4b517f37 100644 --- a/server/application-server/src/main/resources/application.yml +++ b/server/application-server/src/main/resources/application.yml @@ -1,37 +1,37 @@ spring: - application: - name: Hephaestus + application: + name: Hephaestus - datasource: - url: jdbc:postgresql://localhost:5432/hephaestus - username: root - password: root + datasource: + url: jdbc:postgresql://localhost:5432/hephaestus + username: root + password: root - jpa: - hibernate: - # ddl-auto: update - ddl-auto: create-drop - # ddl-auto: none - # show-sql: "true" - properties: - hibernate: - dialect: org.hibernate.dialect.PostgreSQLDialect - format_sql: "true" + jpa: + hibernate: + # ddl-auto: update + ddl-auto: create-drop + # ddl-auto: none + # show-sql: "true" + properties: + hibernate: + dialect: org.hibernate.dialect.PostgreSQLDialect + format_sql: "true" - liquibase: - change-log: classpath:db/master.xml + liquibase: + change-log: classpath:db/master.xml - security: - user: - name: admin - password: admin + security: + user: + name: admin + password: admin docker: compose: file: server/application-server/compose.yaml springdoc: - default-produces-media-type: application/json + default-produces-media-type: application/json environment: - githubPat: ${GITHUB_PAT} + githubPat: ${GITHUB_PAT} From bbb2ef723d2b621ec25292e11f1b2c9b992ca300 Mon Sep 17 00:00:00 2001 From: GODrums Date: Fri, 30 Aug 2024 14:52:41 +0200 Subject: [PATCH 28/50] Implement feedback from review --- server/application-server/pom.xml | 6 +++- ...assImportIntegratorIntegratorProvider.java | 29 +++++++++++++++++++ .../codereview/CodeReviewService.java | 4 +-- .../codereview/base/BaseGitServiceEntity.java | 2 +- .../codereview/comment/IssueComment.java | 7 +---- .../comment/IssueCommentConverter.java | 2 +- .../{GHIssueState.java => IssueState.java} | 4 +-- .../pullrequest/PullRequestDTO.java | 4 +-- .../codereview/pullrequest/Pullrequest.java | 9 ++---- .../pullrequest/PullrequestController.java | 12 ++++---- .../pullrequest/PullrequestConverter.java | 10 +++---- .../pullrequest/PullrequestRepository.java | 7 ++--- .../pullrequest/PullrequestService.java | 8 ++--- .../codereview/repository/Repository.java | 3 +- .../www1/hephaestus/codereview/user/User.java | 3 +- .../codereview/user/UserRepository.java | 11 +------ .../src/main/resources/application.yml | 5 ++-- 17 files changed, 67 insertions(+), 59 deletions(-) create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/ClassImportIntegratorIntegratorProvider.java rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/{GHIssueState.java => IssueState.java} (55%) diff --git a/server/application-server/pom.xml b/server/application-server/pom.xml index 8bcad39c..35ca8c00 100644 --- a/server/application-server/pom.xml +++ b/server/application-server/pom.xml @@ -126,7 +126,11 @@ github-api 1.324 - + + io.hypersistence + hypersistence-utils-hibernate-63 + 3.8.2 + diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/ClassImportIntegratorIntegratorProvider.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/ClassImportIntegratorIntegratorProvider.java new file mode 100644 index 00000000..ec7ca8bb --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/ClassImportIntegratorIntegratorProvider.java @@ -0,0 +1,29 @@ +package de.tum.in.www1.hephaestus; + +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.integrator.spi.Integrator; +import org.hibernate.jpa.boot.spi.IntegratorProvider; + +import de.tum.in.www1.hephaestus.codereview.comment.IssueCommentDTO; +import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequestDTO; +import de.tum.in.www1.hephaestus.codereview.repository.RepositoryDTO; +import de.tum.in.www1.hephaestus.codereview.user.UserDTO; +import io.hypersistence.utils.hibernate.type.util.ClassImportIntegrator; + +public class ClassImportIntegratorIntegratorProvider implements IntegratorProvider { + + @Override + public List getIntegrators() { + // Accessible DTOs + @SuppressWarnings("rawtypes") + List classes = new ArrayList<>(); + classes.add(UserDTO.class); + classes.add(PullRequestDTO.class); + classes.add(IssueCommentDTO.class); + classes.add(RepositoryDTO.class); + + return List.of(new ClassImportIntegrator(classes)); + } +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java index 33bf7703..8533b3ae 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java @@ -129,12 +129,12 @@ private Set getCommentsFromGHPullRequest(GHPullRequest pr, PullReq Set comments = pr.queryComments().list().toList().stream() .map(comment -> { IssueComment c = commentConverter.convert(comment); - c.setPullrequest(pullrequest); + c.setPullRequest(pullrequest); User author; try { author = getActorFromGHUser(comment.getUser()); author.addComment(c); - author.addPullrequest(pullrequest); + author.addPullRequest(pullrequest); } catch (IOException e) { logger.error("Error while fetching author!"); author = null; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntity.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntity.java index 1a069dc1..1f708b0d 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntity.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntity.java @@ -14,7 +14,7 @@ @Setter @NoArgsConstructor @ToString -public class BaseGitServiceEntity { +public abstract class BaseGitServiceEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) protected Long id; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java index d0be0c10..954445e0 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java @@ -4,9 +4,6 @@ import org.springframework.lang.NonNull; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; - import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntity; import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest; import de.tum.in.www1.hephaestus.codereview.user.User; @@ -24,7 +21,6 @@ @Getter @Setter @NoArgsConstructor -@JsonInclude(JsonInclude.Include.NON_EMPTY) @ToString(callSuper = true) public class IssueComment extends BaseGitServiceEntity { @NonNull @@ -37,9 +33,8 @@ public class IssueComment extends BaseGitServiceEntity { @ManyToOne(optional = false) @JoinColumn(name = "pullrequest_id", referencedColumnName = "id") - @JsonIgnore @ToString.Exclude - private PullRequest pullrequest; + private PullRequest pullRequest; public IssueComment(String body, String createdAt, String updatedAt) { this.body = body; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java index fd03c237..fbba9476 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java @@ -23,7 +23,7 @@ public IssueComment convert(@NonNull GHIssueComment source) { comment.setUpdatedAt(null); } // set preliminary values to be filled in later - comment.setPullrequest(null); + comment.setPullRequest(null); comment.setAuthor(null); return comment; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/GHIssueState.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/IssueState.java similarity index 55% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/GHIssueState.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/IssueState.java index a906342f..07ae6da8 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/GHIssueState.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/IssueState.java @@ -1,5 +1,5 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; -public enum GHIssueState { - ALL, CLOSED, OPEN +public enum IssueState { + CLOSED, OPEN } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestDTO.java index 5fec317e..bf7fcf65 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestDTO.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestDTO.java @@ -9,9 +9,9 @@ import de.tum.in.www1.hephaestus.codereview.user.UserDTO; @JsonInclude(JsonInclude.Include.NON_EMPTY) -public record PullRequestDTO(String title, String url, GHIssueState state, String createdAt, String updatedAt, +public record PullRequestDTO(String title, String url, IssueState state, String createdAt, String updatedAt, String mergedAt, UserDTO author, Set comments, RepositoryDTO repository) { - public PullRequestDTO(String title, String url, GHIssueState state, String createdAt, String updatedAt, + public PullRequestDTO(String title, String url, IssueState state, String createdAt, String updatedAt, String mergedAt) { this(title, url, state, createdAt, updatedAt, mergedAt, null, null, null); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index fb4c1078..86da8870 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -5,15 +5,12 @@ import org.springframework.lang.NonNull; -import com.fasterxml.jackson.annotation.JsonInclude; - import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntity; import de.tum.in.www1.hephaestus.codereview.comment.IssueComment; import de.tum.in.www1.hephaestus.codereview.repository.Repository; import de.tum.in.www1.hephaestus.codereview.user.User; import jakarta.persistence.Table; import jakarta.persistence.CascadeType; -import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.JoinColumn; @@ -29,7 +26,6 @@ @Getter @Setter @NoArgsConstructor -@JsonInclude(JsonInclude.Include.NON_EMPTY) @ToString(callSuper = true) public class PullRequest extends BaseGitServiceEntity { @NonNull @@ -43,9 +39,8 @@ public class PullRequest extends BaseGitServiceEntity { * Does not include the state of the merge. */ @NonNull - private GHIssueState state; + private IssueState state; - @Column private String mergedAt; @ManyToOne(fetch = FetchType.LAZY) @@ -53,7 +48,7 @@ public class PullRequest extends BaseGitServiceEntity { @ToString.Exclude private User author; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "pullrequest") + @OneToMany(cascade = CascadeType.ALL, mappedBy = "pullRequest") @ToString.Exclude private Set comments = new HashSet<>();; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java index 98fad311..4fed968d 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java @@ -1,6 +1,6 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; -import java.util.List; +import java.util.Set; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController -@RequestMapping("/pr") +@RequestMapping("/pullrequest") public class PullRequestController { private final PullRequestService pullrequestService; @@ -17,12 +17,12 @@ public PullRequestController(PullRequestService pullrequestService) { } @GetMapping("/{id}") - public PullRequest getPullrequest(@PathVariable Long id) { - return pullrequestService.getPullrequestById(id); + public PullRequest getPullRequest(@PathVariable Long id) { + return pullrequestService.getPullRequestById(id); } @GetMapping("/author/{login}") - public List getPullrequestsByAuthor(@PathVariable String login) { - return pullrequestService.getPullrequestsByAuthor(login); + public Set getPullRequestsByAuthor(@PathVariable String login) { + return pullrequestService.getPullRequestsByAuthor(login); } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java index 08879cb3..171c4e18 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java @@ -36,16 +36,14 @@ public PullRequest convert(@NonNull GHPullRequest source) { return pullrequest; } - private GHIssueState convertState(org.kohsuke.github.GHIssueState state) { + private IssueState convertState(org.kohsuke.github.GHIssueState state) { switch (state) { case OPEN: - return GHIssueState.OPEN; + return IssueState.OPEN; case CLOSED: - return GHIssueState.CLOSED; - case ALL: - return GHIssueState.ALL; + return IssueState.CLOSED; default: - return GHIssueState.ALL; + return IssueState.OPEN; } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java index c99d53e9..f74be306 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java @@ -1,15 +1,12 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; -import java.util.List; +import java.util.Set; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @Repository public interface PullRequestRepository extends JpaRepository { - @Query("SELECT p FROM PullRequest p, User a WHERE p.author = a AND a.login = ?1") - List findByAuthor(String authorLogin); - + Set findByAuthor_Login(String authorLogin); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java index ca608bb6..1c0ed4e8 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java @@ -1,6 +1,6 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; -import java.util.List; +import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,14 +16,14 @@ public PullRequestService(PullRequestRepository pullrequestRepository) { this.pullrequestRepository = pullrequestRepository; } - public PullRequest getPullrequestById(Long id) { + public PullRequest getPullRequestById(Long id) { logger.info("Getting pullrequest with id: " + id); return pullrequestRepository.findById(id).orElse(null); } - public List getPullrequestsByAuthor(String login) { + public Set getPullRequestsByAuthor(String login) { logger.info("Getting pullrequest by author: " + login); - return pullrequestRepository.findByAuthor(login); + return pullrequestRepository.findByAuthor_Login(login); } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index 7f821be4..8d2bd1a9 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -8,7 +8,6 @@ import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntity; import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest; import jakarta.persistence.CascadeType; -import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.OneToMany; @@ -28,7 +27,7 @@ public class Repository extends BaseGitServiceEntity { @NonNull private String name; - @Column(name = "name_with_owner") + @NonNull private String nameWithOwner; @NonNull diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java index 515ce0b1..d6655faa 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java @@ -53,7 +53,6 @@ public class User extends BaseGitServiceEntity { * If unavailable, a fallback can be generated from the login, e.g. on Github: * https://github.com/{login}.png */ - @Column(nullable = false, name = "avatar_url") private String avatarUrl; @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") @@ -66,7 +65,7 @@ public void addComment(IssueComment comment) { comments.add(comment); } - public void addPullrequest(PullRequest pullrequest) { + public void addPullRequest(PullRequest pullrequest) { pullRequests.add(pullrequest); } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserRepository.java index 1fdc663e..14292569 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserRepository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserRepository.java @@ -12,18 +12,9 @@ public interface UserRepository extends JpaRepository { Optional findUser(@Param("login") String login); @Query(""" - SELECT new de.tum.in.www1.hephaestus.codereview.user.UserDTO(u.login, u.email, u.name, u.url) + SELECT new UserDTO(u.login, u.email, u.name, u.url) FROM User u WHERE u.login = :login """) Optional findByLogin(@Param("login") String login); - - // @Query(""" - // SELECT new de.tum.in.www1.hephaestus.codereview.user.UserDTO(u.login, - // u.email, u.name, u.url, u.pullRequests, u.comments) - // FROM User u - // WHERE u.login = :login - // """) - // Optional findByLoginWithPullRequestsAndComments(@Param("login") - // String login); } diff --git a/server/application-server/src/main/resources/application.yml b/server/application-server/src/main/resources/application.yml index 2c385239..a700a536 100644 --- a/server/application-server/src/main/resources/application.yml +++ b/server/application-server/src/main/resources/application.yml @@ -16,6 +16,7 @@ spring: properties: hibernate: dialect: org.hibernate.dialect.PostgreSQLDialect + integrator_provider: de.tum.in.www1.hephaestus.ClassImportIntegratorIntegratorProvider format_sql: "true" liquibase: @@ -26,9 +27,9 @@ spring: name: admin password: admin - docker: +docker: compose: - file: server/application-server/compose.yaml + file: server/application-server/compose.yaml springdoc: default-produces-media-type: application/json From a9a24107c507002de6245896bedc7100c0df4192 Mon Sep 17 00:00:00 2001 From: GODrums Date: Fri, 30 Aug 2024 20:00:32 +0200 Subject: [PATCH 29/50] Improve Entity generation --- .../codereview/base/BaseGitServiceEntity.java | 5 ++-- .../codereview/comment/IssueComment.java | 12 ++++++--- .../comment/IssueCommentConverter.java | 20 ++++++-------- .../codereview/pullrequest/Pullrequest.java | 17 ++++++++++++ .../pullrequest/PullrequestConverter.java | 27 +++++++------------ .../codereview/repository/Repository.java | 17 +++++++++++- .../repository/RepositoryConverter.java | 21 +++++++++++---- .../www1/hephaestus/codereview/user/User.java | 18 +++++++++++++ .../codereview/user/UserConverter.java | 22 +++++++-------- 9 files changed, 107 insertions(+), 52 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntity.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntity.java index 1f708b0d..926bfe1a 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntity.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntity.java @@ -1,9 +1,8 @@ package de.tum.in.www1.hephaestus.codereview.base; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.MappedSuperclass; +import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -13,10 +12,10 @@ @Getter @Setter @NoArgsConstructor +@AllArgsConstructor @ToString public abstract class BaseGitServiceEntity { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) protected Long id; protected String createdAt; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java index 954445e0..b4db1d99 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java @@ -36,9 +36,15 @@ public class IssueComment extends BaseGitServiceEntity { @ToString.Exclude private PullRequest pullRequest; - public IssueComment(String body, String createdAt, String updatedAt) { + public IssueComment(Long id, String body, String createdAt, String updatedAt, User author, + PullRequest pullRequest) { + super(id, createdAt, updatedAt); this.body = body; - this.createdAt = createdAt; - this.updatedAt = updatedAt; + this.author = author; + this.pullRequest = pullRequest; + } + + public IssueComment(Long id, String body, String createdAt, String updatedAt) { + this(id, body, createdAt, updatedAt, null, null); } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java index fbba9476..8e4beb3f 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java @@ -10,21 +10,17 @@ public class IssueCommentConverter implements Converter(), null); + } + + public PullRequest(Long id, String title, String url, IssueState state, String createdAt, String updatedAt, + String mergedAt, User author, Set comments, Repository repository) { + super(id, createdAt, updatedAt); + this.title = title; + this.url = url; + this.state = state; + this.mergedAt = mergedAt; + this.author = author; + this.comments = comments; + this.repository = repository; + } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java index 171c4e18..661f6b37 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java @@ -13,26 +13,19 @@ public class PullRequestConverter implements Converter { @Override public PullRequest convert(@NonNull GHPullRequest source) { - PullRequest pullrequest = new PullRequest(); - pullrequest.setTitle(source.getTitle()); - pullrequest.setUrl(source.getHtmlUrl().toString()); - pullrequest.setState(convertState(source.getState())); + Long id = source.getId(); + String title = source.getTitle(); + String url = source.getHtmlUrl().toString(); + String mergedAt = source.getMergedAt() != null ? source.getMergedAt().toString() : null; + IssueState state = convertState(source.getState()); + PullRequest pullrequest; try { - pullrequest.setCreatedAt(source.getCreatedAt().toString()); + String createdAt = source.getCreatedAt().toString(); + String updatedAt = source.getUpdatedAt().toString(); + pullrequest = new PullRequest(id, title, url, state, createdAt, updatedAt, mergedAt); } catch (IOException e) { - // find a better way to handle this - pullrequest.setCreatedAt(null); + pullrequest = new PullRequest(id, title, url, state, mergedAt, null, null); } - try { - pullrequest.setUpdatedAt(source.getUpdatedAt().toString()); - } catch (IOException e) { - // find a better way to handle this - pullrequest.setUpdatedAt(null); - } - pullrequest.setMergedAt(source.getMergedAt() != null ? source.getMergedAt().toString() : null); - // set preliminary values to be filled in later - pullrequest.setAuthor(null); - pullrequest.setRepository(null); return pullrequest; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index 8d2bd1a9..46c5f4cc 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -38,5 +38,20 @@ public class Repository extends BaseGitServiceEntity { @OneToMany(cascade = CascadeType.ALL, mappedBy = "repository", fetch = FetchType.EAGER) @ToString.Exclude - private Set pullRequests = new HashSet<>();; + private Set pullRequests = new HashSet<>(); + + public Repository(Long id, String name, String nameWithOwner, String description, String url, String createdAt, + String updatedAt) { + this(id, name, nameWithOwner, description, url, createdAt, updatedAt, new HashSet<>()); + } + + public Repository(Long id, String name, String nameWithOwner, String description, String url, String createdAt, + String updatedAt, Set pullRequests) { + super(id, createdAt, updatedAt); + this.name = name; + this.nameWithOwner = nameWithOwner; + this.description = description; + this.url = url; + this.pullRequests = pullRequests; + } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java index 5f2e65d9..c8bacd72 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java @@ -1,5 +1,7 @@ package de.tum.in.www1.hephaestus.codereview.repository; +import java.io.IOException; + import org.kohsuke.github.GHRepository; import org.springframework.core.convert.converter.Converter; import org.springframework.data.convert.ReadingConverter; @@ -14,11 +16,20 @@ public class RepositoryConverter implements Converter @Override @Nullable public Repository convert(@NonNull GHRepository source) { - Repository repository = new Repository(); - repository.setName(source.getName()); - repository.setNameWithOwner(source.getFullName()); - repository.setUrl(source.getHtmlUrl().toString()); - repository.setDescription(source.getDescription()); + Long id = source.getId(); + String name = source.getName(); + String nameWithOwner = source.getFullName(); + String description = source.getDescription(); + String url = source.getHtmlUrl().toString(); + + Repository repository; + try { + String createdAt = source.getCreatedAt().toString(); + String updatedAt = source.getUpdatedAt().toString(); + repository = new Repository(id, name, nameWithOwner, description, url, createdAt, updatedAt); + } catch (IOException e) { + repository = new Repository(id, name, nameWithOwner, description, url, null, null); + } return repository; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java index d6655faa..0a1c615d 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java @@ -61,6 +61,24 @@ public class User extends BaseGitServiceEntity { @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") private Set comments = new HashSet<>(); + public User(Long id, String login, String email, String name, String url, String avatarlUrl, String createdAt, + String updatedAt) { + this(id, login, email, name, url, avatarlUrl, createdAt, updatedAt, null, null); + } + + public User(Long id, String login, String email, String name, String url, String avatarlUrl, String createdAt, + String updatedAt, + Set pullRequests, Set comments) { + super(id, createdAt, updatedAt); + this.login = login; + this.email = email; + this.name = name; + this.url = url; + this.avatarUrl = avatarlUrl; + this.pullRequests = pullRequests; + this.comments = comments; + } + public void addComment(IssueComment comment) { comments.add(comment); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java index d830d078..5891ca43 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java @@ -9,20 +9,20 @@ public class UserConverter implements Converter @Override public User convert(@NonNull org.kohsuke.github.GHUser source) { - User user = new User(); - user.setLogin(source.getLogin()); + Long id = source.getId(); + String login = source.getLogin(); + String url = source.getHtmlUrl().toString(); + String avatarlUrl = source.getAvatarUrl(); + User user; try { - user.setName(source.getName()); + String name = source.getName(); + String email = source.getEmail(); + String createdAt = source.getCreatedAt().toString(); + String updatedAt = source.getUpdatedAt().toString(); + user = new User(id, login, email, name, url, avatarlUrl, createdAt, updatedAt); } catch (IOException e) { - user.setName(null); + user = new User(id, login, null, null, url, avatarlUrl, null, null); } - try { - user.setEmail(source.getEmail()); - } catch (IOException e) { - user.setEmail(null); - } - user.setUrl(source.getHtmlUrl().toString()); - user.setAvatarUrl(source.getAvatarUrl()); return user; } From eab0543face5219a2674bedd5f32bc9d15423eca Mon Sep 17 00:00:00 2001 From: GODrums Date: Fri, 30 Aug 2024 23:20:48 +0200 Subject: [PATCH 30/50] Refactor converts with BaseGitServiceEntityConverter --- .../codereview/base/BaseGitServiceEntity.java | 6 ++- .../base/BaseGitServiceEntityConverter.java | 43 +++++++++++++++++++ .../codereview/comment/IssueComment.java | 12 ------ .../comment/IssueCommentConverter.java | 21 +++------ .../codereview/pullrequest/Pullrequest.java | 17 -------- .../pullrequest/PullrequestConverter.java | 25 +++++------ .../codereview/repository/Repository.java | 15 ------- .../repository/RepositoryConverter.java | 27 ++++-------- .../www1/hephaestus/codereview/user/User.java | 18 -------- .../codereview/user/UserConverter.java | 28 ++++++------ 10 files changed, 87 insertions(+), 125 deletions(-) create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntityConverter.java diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntity.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntity.java index 926bfe1a..d66dc62f 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntity.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntity.java @@ -1,5 +1,7 @@ package de.tum.in.www1.hephaestus.codereview.base; +import java.time.OffsetDateTime; + import jakarta.persistence.Id; import jakarta.persistence.MappedSuperclass; import lombok.AllArgsConstructor; @@ -18,7 +20,7 @@ public abstract class BaseGitServiceEntity { @Id protected Long id; - protected String createdAt; + protected OffsetDateTime createdAt; - protected String updatedAt; + protected OffsetDateTime updatedAt; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntityConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntityConverter.java new file mode 100644 index 00000000..bf490dce --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntityConverter.java @@ -0,0 +1,43 @@ +package de.tum.in.www1.hephaestus.codereview.base; + +import org.kohsuke.github.GHObject; +import org.springframework.core.convert.converter.Converter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.util.Date; + +public abstract class BaseGitServiceEntityConverter + implements Converter { + + private static final Logger logger = LoggerFactory.getLogger(BaseGitServiceEntityConverter.class); + + protected void convertBaseFields(S source, T target) { + if (source == null || target == null) { + throw new IllegalArgumentException("Source and target must not be null"); + } + + // Map common fields + target.setId(source.getId()); + + try { + target.setCreatedAt(convertToOffsetDateTime(source.getCreatedAt())); + } catch (IOException e) { + logger.error("Failed to convert createdAt field for source {}: {}", source.getId(), e.getMessage()); + target.setCreatedAt(null); + } + + try { + target.setUpdatedAt(convertToOffsetDateTime(source.getUpdatedAt())); + } catch (IOException e) { + logger.error("Failed to convert updatedAt field for source {}: {}", source.getId(), e.getMessage()); + target.setUpdatedAt(null); + } + } + + private OffsetDateTime convertToOffsetDateTime(Date date) { + return date != null ? date.toInstant().atOffset(ZoneOffset.UTC) : null; + } +} \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java index b4db1d99..0b3dfd50 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java @@ -35,16 +35,4 @@ public class IssueComment extends BaseGitServiceEntity { @JoinColumn(name = "pullrequest_id", referencedColumnName = "id") @ToString.Exclude private PullRequest pullRequest; - - public IssueComment(Long id, String body, String createdAt, String updatedAt, User author, - PullRequest pullRequest) { - super(id, createdAt, updatedAt); - this.body = body; - this.author = author; - this.pullRequest = pullRequest; - } - - public IssueComment(Long id, String body, String createdAt, String updatedAt) { - this(id, body, createdAt, updatedAt, null, null); - } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java index 8e4beb3f..cf94b9c5 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java @@ -1,26 +1,17 @@ package de.tum.in.www1.hephaestus.codereview.comment; -import java.io.IOException; - import org.kohsuke.github.GHIssueComment; -import org.springframework.core.convert.converter.Converter; import org.springframework.lang.NonNull; -public class IssueCommentConverter implements Converter { +import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntityConverter; + +public class IssueCommentConverter extends BaseGitServiceEntityConverter { @Override public IssueComment convert(@NonNull GHIssueComment source) { - Long id = source.getId(); - String body = source.getBody(); - - IssueComment comment; - try { - String createdAt = source.getCreatedAt().toString(); - String updatedAt = source.getUpdatedAt().toString(); - comment = new IssueComment(id, body, createdAt, updatedAt); - } catch (IOException e) { - comment = new IssueComment(id, body, null, null); - } + IssueComment comment = new IssueComment(); + convertBaseFields(source, comment); + comment.setBody(source.getBody()); return comment; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index 23510511..86da8870 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -56,21 +56,4 @@ public class PullRequest extends BaseGitServiceEntity { @JoinColumn(name = "repository_id", referencedColumnName = "id") @ToString.Exclude private Repository repository; - - public PullRequest(Long id, String title, String url, IssueState state, String createdAt, String updatedAt, - String mergedAt) { - this(id, title, url, state, createdAt, updatedAt, mergedAt, null, new HashSet<>(), null); - } - - public PullRequest(Long id, String title, String url, IssueState state, String createdAt, String updatedAt, - String mergedAt, User author, Set comments, Repository repository) { - super(id, createdAt, updatedAt); - this.title = title; - this.url = url; - this.state = state; - this.mergedAt = mergedAt; - this.author = author; - this.comments = comments; - this.repository = repository; - } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java index 661f6b37..1df65b17 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java @@ -1,30 +1,25 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; -import java.io.IOException; - import org.kohsuke.github.GHPullRequest; -import org.springframework.core.convert.converter.Converter; import org.springframework.data.convert.ReadingConverter; import org.springframework.lang.NonNull; import org.springframework.stereotype.Service; +import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntityConverter; + @Service @ReadingConverter -public class PullRequestConverter implements Converter { +public class PullRequestConverter extends BaseGitServiceEntityConverter { @Override public PullRequest convert(@NonNull GHPullRequest source) { - Long id = source.getId(); - String title = source.getTitle(); - String url = source.getHtmlUrl().toString(); - String mergedAt = source.getMergedAt() != null ? source.getMergedAt().toString() : null; IssueState state = convertState(source.getState()); - PullRequest pullrequest; - try { - String createdAt = source.getCreatedAt().toString(); - String updatedAt = source.getUpdatedAt().toString(); - pullrequest = new PullRequest(id, title, url, state, createdAt, updatedAt, mergedAt); - } catch (IOException e) { - pullrequest = new PullRequest(id, title, url, state, mergedAt, null, null); + PullRequest pullrequest = new PullRequest(); + convertBaseFields(source, pullrequest); + pullrequest.setTitle(source.getTitle()); + pullrequest.setUrl(source.getHtmlUrl().toString()); + pullrequest.setState(state); + if (source.getMergedAt() != null) { + pullrequest.setMergedAt(source.getMergedAt().toString()); } return pullrequest; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index 46c5f4cc..5ad3c220 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -39,19 +39,4 @@ public class Repository extends BaseGitServiceEntity { @OneToMany(cascade = CascadeType.ALL, mappedBy = "repository", fetch = FetchType.EAGER) @ToString.Exclude private Set pullRequests = new HashSet<>(); - - public Repository(Long id, String name, String nameWithOwner, String description, String url, String createdAt, - String updatedAt) { - this(id, name, nameWithOwner, description, url, createdAt, updatedAt, new HashSet<>()); - } - - public Repository(Long id, String name, String nameWithOwner, String description, String url, String createdAt, - String updatedAt, Set pullRequests) { - super(id, createdAt, updatedAt); - this.name = name; - this.nameWithOwner = nameWithOwner; - this.description = description; - this.url = url; - this.pullRequests = pullRequests; - } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java index c8bacd72..5e8da2c9 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java @@ -1,35 +1,26 @@ package de.tum.in.www1.hephaestus.codereview.repository; -import java.io.IOException; - import org.kohsuke.github.GHRepository; -import org.springframework.core.convert.converter.Converter; import org.springframework.data.convert.ReadingConverter; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.springframework.stereotype.Service; +import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntityConverter; + @Service @ReadingConverter -public class RepositoryConverter implements Converter { +public class RepositoryConverter extends BaseGitServiceEntityConverter { @Override @Nullable public Repository convert(@NonNull GHRepository source) { - Long id = source.getId(); - String name = source.getName(); - String nameWithOwner = source.getFullName(); - String description = source.getDescription(); - String url = source.getHtmlUrl().toString(); - - Repository repository; - try { - String createdAt = source.getCreatedAt().toString(); - String updatedAt = source.getUpdatedAt().toString(); - repository = new Repository(id, name, nameWithOwner, description, url, createdAt, updatedAt); - } catch (IOException e) { - repository = new Repository(id, name, nameWithOwner, description, url, null, null); - } + Repository repository = new Repository(); + convertBaseFields(source, repository); + repository.setName(source.getName()); + repository.setNameWithOwner(source.getFullName()); + repository.setDescription(source.getDescription()); + repository.setUrl(source.getHtmlUrl().toString()); return repository; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java index 0a1c615d..d6655faa 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java @@ -61,24 +61,6 @@ public class User extends BaseGitServiceEntity { @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") private Set comments = new HashSet<>(); - public User(Long id, String login, String email, String name, String url, String avatarlUrl, String createdAt, - String updatedAt) { - this(id, login, email, name, url, avatarlUrl, createdAt, updatedAt, null, null); - } - - public User(Long id, String login, String email, String name, String url, String avatarlUrl, String createdAt, - String updatedAt, - Set pullRequests, Set comments) { - super(id, createdAt, updatedAt); - this.login = login; - this.email = email; - this.name = name; - this.url = url; - this.avatarUrl = avatarlUrl; - this.pullRequests = pullRequests; - this.comments = comments; - } - public void addComment(IssueComment comment) { comments.add(comment); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java index 5891ca43..de91333f 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java @@ -2,26 +2,28 @@ import java.io.IOException; -import org.springframework.core.convert.converter.Converter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.lang.NonNull; -public class UserConverter implements Converter { +import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntityConverter; + +public class UserConverter extends BaseGitServiceEntityConverter { + + protected static final Logger logger = LoggerFactory.getLogger(UserConverter.class); @Override public User convert(@NonNull org.kohsuke.github.GHUser source) { - Long id = source.getId(); - String login = source.getLogin(); - String url = source.getHtmlUrl().toString(); - String avatarlUrl = source.getAvatarUrl(); - User user; + User user = new User(); + convertBaseFields(source, user); + user.setLogin(source.getLogin()); + user.setUrl(source.getHtmlUrl().toString()); + user.setAvatarUrl(source.getAvatarUrl()); try { - String name = source.getName(); - String email = source.getEmail(); - String createdAt = source.getCreatedAt().toString(); - String updatedAt = source.getUpdatedAt().toString(); - user = new User(id, login, email, name, url, avatarlUrl, createdAt, updatedAt); + user.setName(source.getName()); + user.setEmail(source.getEmail()); } catch (IOException e) { - user = new User(id, login, null, null, url, avatarlUrl, null, null); + logger.error("Failed to convert user fields for source {}: {}", source.getId(), e.getMessage()); } return user; } From cf50f374ca6b82acf920ee77052427b67025d493 Mon Sep 17 00:00:00 2001 From: GODrums Date: Fri, 30 Aug 2024 23:35:25 +0200 Subject: [PATCH 31/50] Add id to DTOs --- .../www1/hephaestus/codereview/comment/IssueCommentDTO.java | 6 +++--- .../hephaestus/codereview/pullrequest/PullRequestDTO.java | 6 +++--- .../de/tum/in/www1/hephaestus/codereview/user/UserDTO.java | 6 +++--- .../in/www1/hephaestus/codereview/user/UserRepository.java | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentDTO.java index 790a49ed..6c85b799 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentDTO.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentDTO.java @@ -6,9 +6,9 @@ import de.tum.in.www1.hephaestus.codereview.user.UserDTO; @JsonInclude(JsonInclude.Include.NON_EMPTY) -public record IssueCommentDTO(String body, String createdAt, String updatedAt, UserDTO author, +public record IssueCommentDTO(Long id, String body, String createdAt, String updatedAt, UserDTO author, PullRequestDTO pullrequest) { - public IssueCommentDTO(String body, String createdAt, String updatedAt) { - this(body, createdAt, updatedAt, null, null); + public IssueCommentDTO(Long id, String body, String createdAt, String updatedAt) { + this(id, body, createdAt, updatedAt, null, null); } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestDTO.java index bf7fcf65..9e85f02c 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestDTO.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestDTO.java @@ -9,10 +9,10 @@ import de.tum.in.www1.hephaestus.codereview.user.UserDTO; @JsonInclude(JsonInclude.Include.NON_EMPTY) -public record PullRequestDTO(String title, String url, IssueState state, String createdAt, String updatedAt, +public record PullRequestDTO(Long id, String title, String url, IssueState state, String createdAt, String updatedAt, String mergedAt, UserDTO author, Set comments, RepositoryDTO repository) { - public PullRequestDTO(String title, String url, IssueState state, String createdAt, String updatedAt, + public PullRequestDTO(Long id, String title, String url, IssueState state, String createdAt, String updatedAt, String mergedAt) { - this(title, url, state, createdAt, updatedAt, mergedAt, null, null, null); + this(id, title, url, state, createdAt, updatedAt, mergedAt, null, null, null); } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserDTO.java index f85257ac..64d8051b 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserDTO.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserDTO.java @@ -8,9 +8,9 @@ import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequestDTO; @JsonInclude(JsonInclude.Include.NON_EMPTY) -public record UserDTO(String login, String email, String name, String url, Set pullRequests, +public record UserDTO(Long id, String login, String email, String name, String url, Set pullRequests, Set comments) { - public UserDTO(String login, String email, String name, String url) { - this(login, email, name, url, null, null); + public UserDTO(Long id, String login, String email, String name, String url) { + this(id, login, email, name, url, null, null); } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserRepository.java index 14292569..64696cb4 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserRepository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserRepository.java @@ -12,7 +12,7 @@ public interface UserRepository extends JpaRepository { Optional findUser(@Param("login") String login); @Query(""" - SELECT new UserDTO(u.login, u.email, u.name, u.url) + SELECT new UserDTO(u.id, u.login, u.email, u.name, u.url) FROM User u WHERE u.login = :login """) From f9af54add8ff2333304671cca06a7a1ca4ec0687 Mon Sep 17 00:00:00 2001 From: GODrums Date: Sat, 31 Aug 2024 02:39:38 +0200 Subject: [PATCH 32/50] Add more Repository attributes --- .../codereview/repository/Repository.java | 8 ++++++++ .../codereview/repository/RepositoryConverter.java | 14 ++++++++++++++ .../repository/RepositoryVisibility.java | 5 +++++ 3 files changed, 27 insertions(+) create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryVisibility.java diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index 5ad3c220..2ebad800 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -33,9 +33,17 @@ public class Repository extends BaseGitServiceEntity { @NonNull private String description; + @NonNull + String defaultBranch; + + @NonNull + private RepositoryVisibility visibility; + @NonNull private String url; + String homepage; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "repository", fetch = FetchType.EAGER) @ToString.Exclude private Set pullRequests = new HashSet<>(); diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java index 5e8da2c9..fccc292b 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java @@ -1,6 +1,7 @@ package de.tum.in.www1.hephaestus.codereview.repository; import org.kohsuke.github.GHRepository; +import org.kohsuke.github.GHRepository.Visibility; import org.springframework.data.convert.ReadingConverter; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; @@ -21,7 +22,20 @@ public Repository convert(@NonNull GHRepository source) { repository.setNameWithOwner(source.getFullName()); repository.setDescription(source.getDescription()); repository.setUrl(source.getHtmlUrl().toString()); + repository.setDefaultBranch(source.getDefaultBranch()); + repository.setVisibility(convertVisibility(source.getVisibility())); + repository.setHomepage(source.getHomepage()); return repository; } + private RepositoryVisibility convertVisibility(Visibility visibility) { + switch (visibility) { + case PRIVATE: + return RepositoryVisibility.PRIVATE; + case PUBLIC: + return RepositoryVisibility.PUBLIC; + default: + return RepositoryVisibility.PRIVATE; + } + } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryVisibility.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryVisibility.java new file mode 100644 index 00000000..83143a1b --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryVisibility.java @@ -0,0 +1,5 @@ +package de.tum.in.www1.hephaestus.codereview.repository; + +public enum RepositoryVisibility { + PUBLIC, PRIVATE +} From 79a1194acb68ce7fb650b721dd2b6a9c6c7ace83 Mon Sep 17 00:00:00 2001 From: GODrums Date: Sat, 31 Aug 2024 03:31:55 +0200 Subject: [PATCH 33/50] Refactor github sync with cron --- .../tum/in/www1/hephaestus/Application.java | 15 -- .../de/tum/in/www1/hephaestus/EnvConfig.java | 17 -- .../codereview/CodeReviewController.java | 30 ---- .../codereview/CodeReviewService.java | 157 ----------------- .../DailyGitHubDataSyncScheduler.java | 55 ++++++ .../scheduler/GitHubDataSyncService.java | 159 ++++++++++++++++++ .../src/main/resources/application.yml | 10 +- 7 files changed, 222 insertions(+), 221 deletions(-) delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/EnvConfig.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewController.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/DailyGitHubDataSyncScheduler.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java index e0429bdd..b56dce19 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/Application.java @@ -1,29 +1,14 @@ package de.tum.in.www1.hephaestus; -import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; import org.springframework.modulith.Modulithic; -import de.tum.in.www1.hephaestus.codereview.CodeReviewService; -import de.tum.in.www1.hephaestus.codereview.repository.Repository; - @SpringBootApplication @Modulithic(systemName = "Hephaestus") -@EnableConfigurationProperties(EnvConfig.class) public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } - - @Bean - CommandLineRunner commandLineRunner(CodeReviewService service) { - return args -> { - Repository repo = service.fetchRepository("ls1intum/hephaestus"); - System.out.println("Got repo: " + repo); - }; - } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/EnvConfig.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/EnvConfig.java deleted file mode 100644 index fd3b89c2..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/EnvConfig.java +++ /dev/null @@ -1,17 +0,0 @@ -package de.tum.in.www1.hephaestus; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -@ConfigurationProperties(prefix = "environment") -public class EnvConfig { - - private String githubPat; - - public EnvConfig(String githubPat) { - this.githubPat = githubPat; - } - - public String getGithubPat() { - return githubPat; - } -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewController.java deleted file mode 100644 index f89a8cfe..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewController.java +++ /dev/null @@ -1,30 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview; - -import java.io.IOException; - -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import de.tum.in.www1.hephaestus.codereview.repository.Repository; - -@RestController -@RequestMapping("/codereview") -public class CodeReviewController { - private final CodeReviewService codeReviewService; - - public CodeReviewController(CodeReviewService codeReviewService) { - this.codeReviewService = codeReviewService; - } - - @PutMapping("/repository/{nameWithOwner}") - public Repository addRepository(@PathVariable String nameWithOwner) { - try { - return codeReviewService.fetchRepository(nameWithOwner); - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java deleted file mode 100644 index 8533b3ae..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java +++ /dev/null @@ -1,157 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview; - -import java.io.IOException; -import java.util.HashSet; -import java.util.Set; -import java.util.stream.Collectors; - -import org.kohsuke.github.GHPullRequest; -import org.kohsuke.github.GHRepository; -import org.kohsuke.github.GitHub; -import org.kohsuke.github.GitHubBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -import de.tum.in.www1.hephaestus.EnvConfig; -import de.tum.in.www1.hephaestus.codereview.comment.IssueComment; -import de.tum.in.www1.hephaestus.codereview.comment.IssueCommentConverter; -import de.tum.in.www1.hephaestus.codereview.comment.IssueCommentRepository; -import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest; -import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequestConverter; -import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequestRepository; -import de.tum.in.www1.hephaestus.codereview.repository.Repository; -import de.tum.in.www1.hephaestus.codereview.repository.RepositoryConverter; -import de.tum.in.www1.hephaestus.codereview.repository.RepositoryRepository; -import de.tum.in.www1.hephaestus.codereview.user.User; -import de.tum.in.www1.hephaestus.codereview.user.UserConverter; -import de.tum.in.www1.hephaestus.codereview.user.UserRepository; - -@Service -public class CodeReviewService { - - private static final Logger logger = LoggerFactory.getLogger(CodeReviewService.class); - - private GitHub github; - - private final RepositoryRepository repositoryRepository; - private final PullRequestRepository pullrequestRepository; - private final IssueCommentRepository commentRepository; - private final UserRepository userRepository; - - public CodeReviewService(EnvConfig envConfig, RepositoryRepository repositoryRepository, - PullRequestRepository pullrequestRepository, IssueCommentRepository commentRepository, - UserRepository actorRepository) { - logger.info("Hello from CodeReviewService!"); - - this.repositoryRepository = repositoryRepository; - this.pullrequestRepository = pullrequestRepository; - this.commentRepository = commentRepository; - this.userRepository = actorRepository; - - try { - github = new GitHubBuilder().withOAuthToken(envConfig.getGithubPat()).build(); - } catch (IOException e) { - logger.error("Error while creating GitHub client: " + e.getMessage()); - return; - } - } - - /** - * Rest API implementation of fetching a Github repository. - * - * @return The repository corresponding to the given nameWithOwner. - * @throws IOException - */ - public Repository fetchRepository(String nameWithOwner) throws IOException { - if (github == null) { - logger.error("GitHub client not initialized correctly!"); - return null; - } - - // Avoid double fetching of the same repository - Repository existingRepository = repositoryRepository.findByNameWithOwner(nameWithOwner); - if (existingRepository != null) { - logger.info("Found existing repository: " + existingRepository); - return existingRepository; - } - - GHRepository ghRepo = github.getRepository(nameWithOwner); - Repository repository = new RepositoryConverter().convert(ghRepo); - if (repository == null) { - logger.error("Error while fetching repository!"); - return null; - } - // preliminary save to make it referenceable - repositoryRepository.save(repository); - - PullRequestConverter prConverter = new PullRequestConverter(); - - // Retrieve PRs in pages of 10 - Set prs = ghRepo.queryPullRequests().list().withPageSize(10).toList().stream().map(pr -> { - PullRequest pullrequest = prConverter.convert(pr); - pullrequest.setRepository(repository); - pullrequestRepository.save(pullrequest); - try { - Set comments = getCommentsFromGHPullRequest(pr, pullrequest); - pullrequest.setComments(comments); - commentRepository.saveAll(comments); - } catch (IOException e) { - logger.error("Error while fetching PR comments!"); - pullrequest.setComments(new HashSet<>()); - } - try { - pullrequest.setAuthor(getActorFromGHUser(pr.getUser())); - } catch (IOException e) { - logger.error("Error while fetching PR author!"); - pullrequest.setAuthor(null); - } - - return pullrequest; - }).collect(Collectors.toSet()); - repository.setPullRequests(prs); - pullrequestRepository.saveAll(prs); - repositoryRepository.save(repository); - return repository; - } - - /** - * Retrieves the comments of a given pull request. - * - * @param pr The GH pull request. - * @param pullrequest Stored PR to which the comments belong. - * @return The comments of the given pull request. - * @throws IOException - */ - private Set getCommentsFromGHPullRequest(GHPullRequest pr, PullRequest pullrequest) - throws IOException { - IssueCommentConverter commentConverter = new IssueCommentConverter(); - Set comments = pr.queryComments().list().toList().stream() - .map(comment -> { - IssueComment c = commentConverter.convert(comment); - c.setPullRequest(pullrequest); - User author; - try { - author = getActorFromGHUser(comment.getUser()); - author.addComment(c); - author.addPullRequest(pullrequest); - } catch (IOException e) { - logger.error("Error while fetching author!"); - author = null; - } - c.setAuthor(author); - return c; - }).collect(Collectors.toSet()); - return comments; - } - - private User getActorFromGHUser(org.kohsuke.github.GHUser user) { - User ghUser = userRepository.findUser(user.getLogin()).orElse(null); - if (ghUser == null) { - ghUser = new UserConverter().convert(user); - userRepository.save(ghUser); - } - return ghUser; - - } -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/DailyGitHubDataSyncScheduler.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/DailyGitHubDataSyncScheduler.java new file mode 100644 index 00000000..bd585e36 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/DailyGitHubDataSyncScheduler.java @@ -0,0 +1,55 @@ +package de.tum.in.www1.hephaestus.scheduler; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import jakarta.annotation.PostConstruct; + +import java.io.IOException; + +@Component +public class DailyGitHubDataSyncScheduler { + + private static final Logger logger = LoggerFactory.getLogger(DailyGitHubDataSyncScheduler.class); + private final GitHubDataSyncService dataSyncService; + + @Value("${monitoring.runOnStartup:true}") + private boolean runOnStartup; + + @Value("${monitoring.repositories}") + private String[] repositoriesToMonitor; + + public DailyGitHubDataSyncScheduler(GitHubDataSyncService dataSyncService) { + this.dataSyncService = dataSyncService; + } + + @PostConstruct + public void onStartup() { + if (runOnStartup) { + logger.info("Starting initial GitHub data sync for Hephaestus..."); + try { + dataSyncService.syncData("ls1intum/hephaestus"); + logger.info("Initial GitHub data sync completed successfully for repository: ls1intum/hephaestus"); + } catch (IOException e) { + logger.error("Error during GitHub data sync: ", e); + } + } + } + + @Scheduled(cron = "${monitoring.repository-sync-cron}") + public void syncDataDaily() { + logger.info("Starting daily GitHub data sync..."); + for (String repositoryName : repositoriesToMonitor) { + try { + dataSyncService.syncData(repositoryName); + logger.info("Daily GitHub data sync completed successfully for repository: " + repositoryName); + } catch (IOException e) { + logger.error("Error during GitHub data sync: ", e); + } + } + logger.info("Daily GitHub data sync completed."); + } +} \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java new file mode 100644 index 00000000..bb9e7f1e --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java @@ -0,0 +1,159 @@ +package de.tum.in.www1.hephaestus.scheduler; + +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; + +import org.kohsuke.github.GHPullRequest; +import org.kohsuke.github.GHRepository; +import org.kohsuke.github.GitHub; +import org.kohsuke.github.GitHubBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import de.tum.in.www1.hephaestus.codereview.comment.IssueComment; +import de.tum.in.www1.hephaestus.codereview.comment.IssueCommentConverter; +import de.tum.in.www1.hephaestus.codereview.comment.IssueCommentRepository; +import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest; +import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequestConverter; +import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequestRepository; +import de.tum.in.www1.hephaestus.codereview.repository.Repository; +import de.tum.in.www1.hephaestus.codereview.repository.RepositoryConverter; +import de.tum.in.www1.hephaestus.codereview.repository.RepositoryRepository; +import de.tum.in.www1.hephaestus.codereview.user.User; +import de.tum.in.www1.hephaestus.codereview.user.UserConverter; +import de.tum.in.www1.hephaestus.codereview.user.UserRepository; + +@Service +public class GitHubDataSyncService { + private static final Logger logger = LoggerFactory.getLogger(GitHubDataSyncService.class); + + @Value("${github.authToken}") + private String ghAuthToken; + + private GitHub github; + + private final RepositoryRepository repositoryRepository; + private final PullRequestRepository pullrequestRepository; + private final IssueCommentRepository commentRepository; + private final UserRepository userRepository; + + public GitHubDataSyncService(RepositoryRepository repositoryRepository, PullRequestRepository pullrequestRepository, + IssueCommentRepository commentRepository, UserRepository userRepository) { + logger.info("Hello from GitHubDataSyncService!"); + + this.repositoryRepository = repositoryRepository; + this.pullrequestRepository = pullrequestRepository; + this.commentRepository = commentRepository; + this.userRepository = userRepository; + } + + public void syncData(String repositoryName) throws IOException { + if (github == null) { + github = new GitHubBuilder().withOAuthToken(ghAuthToken).build(); + } + Repository repo = this.fetchRepository(repositoryName); + logger.info("Synced repository until " + repo.getUpdatedAt()); + } + + /** + * Rest API implementation of fetching a Github repository. + * + * @return The repository corresponding to the given nameWithOwner. + * @throws IOException + */ + public Repository fetchRepository(String nameWithOwner) throws IOException { + if (github == null) { + logger.error("GitHub client not initialized correctly!"); + return null; + } + + // Avoid double fetching of the same repository + Repository existingRepository = repositoryRepository.findByNameWithOwner(nameWithOwner); + if (existingRepository != null) { + logger.info("Found existing repository: " + existingRepository); + return existingRepository; + } + + GHRepository ghRepo = github.getRepository(nameWithOwner); + Repository repository = new RepositoryConverter().convert(ghRepo); + if (repository == null) { + logger.error("Error while fetching repository!"); + return null; + } + // preliminary save to make it referenceable + repositoryRepository.save(repository); + + PullRequestConverter prConverter = new PullRequestConverter(); + + // Retrieve PRs in pages of 10 + Set prs = ghRepo.queryPullRequests().list().withPageSize(10).toList().stream().map(pr -> { + PullRequest pullrequest = prConverter.convert(pr); + pullrequest.setRepository(repository); + pullrequestRepository.save(pullrequest); + try { + Set comments = getCommentsFromGHPullRequest(pr, pullrequest); + pullrequest.setComments(comments); + commentRepository.saveAll(comments); + } catch (IOException e) { + logger.error("Error while fetching PR comments!"); + pullrequest.setComments(new HashSet<>()); + } + try { + pullrequest.setAuthor(getActorFromGHUser(pr.getUser())); + } catch (IOException e) { + logger.error("Error while fetching PR author!"); + pullrequest.setAuthor(null); + } + + return pullrequest; + }).collect(Collectors.toSet()); + repository.setPullRequests(prs); + pullrequestRepository.saveAll(prs); + repositoryRepository.save(repository); + return repository; + } + + /** + * Retrieves the comments of a given pull request. + * + * @param pr The GH pull request. + * @param pullrequest Stored PR to which the comments belong. + * @return The comments of the given pull request. + * @throws IOException + */ + private Set getCommentsFromGHPullRequest(GHPullRequest pr, PullRequest pullrequest) + throws IOException { + IssueCommentConverter commentConverter = new IssueCommentConverter(); + Set comments = pr.queryComments().list().toList().stream() + .map(comment -> { + IssueComment c = commentConverter.convert(comment); + c.setPullRequest(pullrequest); + User author; + try { + author = getActorFromGHUser(comment.getUser()); + author.addComment(c); + author.addPullRequest(pullrequest); + } catch (IOException e) { + logger.error("Error while fetching author!"); + author = null; + } + c.setAuthor(author); + return c; + }).collect(Collectors.toSet()); + return comments; + } + + private User getActorFromGHUser(org.kohsuke.github.GHUser user) { + User ghUser = userRepository.findUser(user.getLogin()).orElse(null); + if (ghUser == null) { + ghUser = new UserConverter().convert(user); + userRepository.save(ghUser); + } + return ghUser; + + } +} diff --git a/server/application-server/src/main/resources/application.yml b/server/application-server/src/main/resources/application.yml index ca7e40b6..30b4c747 100644 --- a/server/application-server/src/main/resources/application.yml +++ b/server/application-server/src/main/resources/application.yml @@ -30,5 +30,11 @@ spring: springdoc: default-produces-media-type: application/json -environment: - githubPat: ${GITHUB_PAT} +monitoring: + runOnStartup: true + repository-sync-cron: "0 0 3 * * ?" + repositories: ls1intum/hephaestus, ls1intum/pyris + +# Can be any OAuth token, such as the PAT +github: + authToken: ${GITHUB_PAT} From 3588ed7a46b04c20c83c7206b90161ba1b59f244 Mon Sep 17 00:00:00 2001 From: "Felix T.J. Dietrich" Date: Sat, 31 Aug 2024 10:29:43 +0200 Subject: [PATCH 34/50] rename files and pullrequest --- .../codereview/comment/IssueCommentDTO.java | 2 +- .../codereview/pullrequest/PullRequest.java | 59 +++++++++++++++++++ .../pullrequest/PullRequestController.java | 28 +++++++++ .../pullrequest/PullRequestConverter.java | 38 ++++++++++++ .../pullrequest/PullRequestRepository.java | 12 ++++ .../pullrequest/PullRequestService.java | 29 +++++++++ .../pullrequest/PullrequestController.java | 10 ++-- .../pullrequest/PullrequestConverter.java | 14 ++--- .../pullrequest/PullrequestService.java | 14 ++--- .../www1/hephaestus/codereview/user/User.java | 4 +- .../scheduler/GitHubDataSyncService.java | 34 +++++------ 11 files changed, 205 insertions(+), 39 deletions(-) create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequest.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestController.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestConverter.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestRepository.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestService.java diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentDTO.java index 6c85b799..6e2b537f 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentDTO.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentDTO.java @@ -7,7 +7,7 @@ @JsonInclude(JsonInclude.Include.NON_EMPTY) public record IssueCommentDTO(Long id, String body, String createdAt, String updatedAt, UserDTO author, - PullRequestDTO pullrequest) { + PullRequestDTO pullRequest) { public IssueCommentDTO(Long id, String body, String createdAt, String updatedAt) { this(id, body, createdAt, updatedAt, null, null); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequest.java new file mode 100644 index 00000000..86da8870 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequest.java @@ -0,0 +1,59 @@ +package de.tum.in.www1.hephaestus.codereview.pullrequest; + +import java.util.HashSet; +import java.util.Set; + +import org.springframework.lang.NonNull; + +import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntity; +import de.tum.in.www1.hephaestus.codereview.comment.IssueComment; +import de.tum.in.www1.hephaestus.codereview.repository.Repository; +import de.tum.in.www1.hephaestus.codereview.user.User; +import jakarta.persistence.Table; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Entity +@Table(name = "pull_request") +@Getter +@Setter +@NoArgsConstructor +@ToString(callSuper = true) +public class PullRequest extends BaseGitServiceEntity { + @NonNull + private String title; + + @NonNull + private String url; + + /** + * State of the PullRequest. + * Does not include the state of the merge. + */ + @NonNull + private IssueState state; + + private String mergedAt; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "author_id") + @ToString.Exclude + private User author; + + @OneToMany(cascade = CascadeType.ALL, mappedBy = "pullRequest") + @ToString.Exclude + private Set comments = new HashSet<>();; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "repository_id", referencedColumnName = "id") + @ToString.Exclude + private Repository repository; +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestController.java new file mode 100644 index 00000000..ff6652d6 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestController.java @@ -0,0 +1,28 @@ +package de.tum.in.www1.hephaestus.codereview.pullrequest; + +import java.util.Set; + +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("/pullrequest") +public class PullRequestController { + private final PullRequestService pullRequestService; + + public PullRequestController(PullRequestService pullRequestService) { + this.pullRequestService = pullRequestService; + } + + @GetMapping("/{id}") + public PullRequest getPullRequest(@PathVariable Long id) { + return pullRequestService.getPullRequestById(id); + } + + @GetMapping("/author/{login}") + public Set getPullRequestsByAuthor(@PathVariable String login) { + return pullRequestService.getPullRequestsByAuthor(login); + } +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestConverter.java new file mode 100644 index 00000000..7987dc3b --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestConverter.java @@ -0,0 +1,38 @@ +package de.tum.in.www1.hephaestus.codereview.pullrequest; + +import org.kohsuke.github.GHPullRequest; +import org.springframework.data.convert.ReadingConverter; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Service; + +import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntityConverter; + +@Service +@ReadingConverter +public class PullRequestConverter extends BaseGitServiceEntityConverter { + @Override + public PullRequest convert(@NonNull GHPullRequest source) { + IssueState state = convertState(source.getState()); + PullRequest pullRequest = new PullRequest(); + convertBaseFields(source, pullRequest); + pullRequest.setTitle(source.getTitle()); + pullRequest.setUrl(source.getHtmlUrl().toString()); + pullRequest.setState(state); + if (source.getMergedAt() != null) { + pullRequest.setMergedAt(source.getMergedAt().toString()); + } + return pullRequest; + } + + private IssueState convertState(org.kohsuke.github.GHIssueState state) { + switch (state) { + case OPEN: + return IssueState.OPEN; + case CLOSED: + return IssueState.CLOSED; + default: + return IssueState.OPEN; + } + } + +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestRepository.java new file mode 100644 index 00000000..f74be306 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestRepository.java @@ -0,0 +1,12 @@ +package de.tum.in.www1.hephaestus.codereview.pullrequest; + +import java.util.Set; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface PullRequestRepository extends JpaRepository { + + Set findByAuthor_Login(String authorLogin); +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestService.java new file mode 100644 index 00000000..a3b28b7d --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestService.java @@ -0,0 +1,29 @@ +package de.tum.in.www1.hephaestus.codereview.pullrequest; + +import java.util.Set; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +@Service +public class PullRequestService { + private static final Logger logger = LoggerFactory.getLogger(PullRequestService.class); + + private final PullRequestRepository pullRequestRepository; + + public PullRequestService(PullRequestRepository pullRequestRepository) { + this.pullRequestRepository = pullRequestRepository; + } + + public PullRequest getPullRequestById(Long id) { + logger.info("Getting pullRequest with id: " + id); + return pullRequestRepository.findById(id).orElse(null); + } + + public Set getPullRequestsByAuthor(String login) { + logger.info("Getting pullRequest by author: " + login); + return pullRequestRepository.findByAuthor_Login(login); + } + +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java index 4fed968d..ff6652d6 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java @@ -10,19 +10,19 @@ @RestController @RequestMapping("/pullrequest") public class PullRequestController { - private final PullRequestService pullrequestService; + private final PullRequestService pullRequestService; - public PullRequestController(PullRequestService pullrequestService) { - this.pullrequestService = pullrequestService; + public PullRequestController(PullRequestService pullRequestService) { + this.pullRequestService = pullRequestService; } @GetMapping("/{id}") public PullRequest getPullRequest(@PathVariable Long id) { - return pullrequestService.getPullRequestById(id); + return pullRequestService.getPullRequestById(id); } @GetMapping("/author/{login}") public Set getPullRequestsByAuthor(@PathVariable String login) { - return pullrequestService.getPullRequestsByAuthor(login); + return pullRequestService.getPullRequestsByAuthor(login); } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java index 1df65b17..7987dc3b 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java @@ -13,15 +13,15 @@ public class PullRequestConverter extends BaseGitServiceEntityConverter getPullRequestsByAuthor(String login) { - logger.info("Getting pullrequest by author: " + login); - return pullrequestRepository.findByAuthor_Login(login); + logger.info("Getting pullRequest by author: " + login); + return pullRequestRepository.findByAuthor_Login(login); } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java index d6655faa..e0180ade 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java @@ -65,7 +65,7 @@ public void addComment(IssueComment comment) { comments.add(comment); } - public void addPullRequest(PullRequest pullrequest) { - pullRequests.add(pullrequest); + public void addPullRequest(PullRequest pullRequest) { + pullRequests.add(pullRequest); } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java index bb9e7f1e..2a18e7fa 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java @@ -37,16 +37,16 @@ public class GitHubDataSyncService { private GitHub github; private final RepositoryRepository repositoryRepository; - private final PullRequestRepository pullrequestRepository; + private final PullRequestRepository pullRequestRepository; private final IssueCommentRepository commentRepository; private final UserRepository userRepository; - public GitHubDataSyncService(RepositoryRepository repositoryRepository, PullRequestRepository pullrequestRepository, + public GitHubDataSyncService(RepositoryRepository repositoryRepository, PullRequestRepository pullRequestRepository, IssueCommentRepository commentRepository, UserRepository userRepository) { logger.info("Hello from GitHubDataSyncService!"); this.repositoryRepository = repositoryRepository; - this.pullrequestRepository = pullrequestRepository; + this.pullRequestRepository = pullRequestRepository; this.commentRepository = commentRepository; this.userRepository = userRepository; } @@ -91,28 +91,28 @@ public Repository fetchRepository(String nameWithOwner) throws IOException { // Retrieve PRs in pages of 10 Set prs = ghRepo.queryPullRequests().list().withPageSize(10).toList().stream().map(pr -> { - PullRequest pullrequest = prConverter.convert(pr); - pullrequest.setRepository(repository); - pullrequestRepository.save(pullrequest); + PullRequest pullRequest = prConverter.convert(pr); + pullRequest.setRepository(repository); + pullRequestRepository.save(pullRequest); try { - Set comments = getCommentsFromGHPullRequest(pr, pullrequest); - pullrequest.setComments(comments); + Set comments = getCommentsFromGHPullRequest(pr, pullRequest); + pullRequest.setComments(comments); commentRepository.saveAll(comments); } catch (IOException e) { logger.error("Error while fetching PR comments!"); - pullrequest.setComments(new HashSet<>()); + pullRequest.setComments(new HashSet<>()); } try { - pullrequest.setAuthor(getActorFromGHUser(pr.getUser())); + pullRequest.setAuthor(getActorFromGHUser(pr.getUser())); } catch (IOException e) { logger.error("Error while fetching PR author!"); - pullrequest.setAuthor(null); + pullRequest.setAuthor(null); } - return pullrequest; + return pullRequest; }).collect(Collectors.toSet()); repository.setPullRequests(prs); - pullrequestRepository.saveAll(prs); + pullRequestRepository.saveAll(prs); repositoryRepository.save(repository); return repository; } @@ -121,22 +121,22 @@ public Repository fetchRepository(String nameWithOwner) throws IOException { * Retrieves the comments of a given pull request. * * @param pr The GH pull request. - * @param pullrequest Stored PR to which the comments belong. + * @param pullRequest Stored PR to which the comments belong. * @return The comments of the given pull request. * @throws IOException */ - private Set getCommentsFromGHPullRequest(GHPullRequest pr, PullRequest pullrequest) + private Set getCommentsFromGHPullRequest(GHPullRequest pr, PullRequest pullRequest) throws IOException { IssueCommentConverter commentConverter = new IssueCommentConverter(); Set comments = pr.queryComments().list().toList().stream() .map(comment -> { IssueComment c = commentConverter.convert(comment); - c.setPullRequest(pullrequest); + c.setPullRequest(pullRequest); User author; try { author = getActorFromGHUser(comment.getUser()); author.addComment(c); - author.addPullRequest(pullrequest); + author.addPullRequest(pullRequest); } catch (IOException e) { logger.error("Error while fetching author!"); author = null; From 17e6528f92bc920e4bea416360aa2cd0329f09c7 Mon Sep 17 00:00:00 2001 From: GODrums Date: Sat, 31 Aug 2024 21:54:40 +0200 Subject: [PATCH 35/50] Rename scheduler --- ...uler.java => GitHubDataSyncScheduler.java} | 24 +++++++++---------- .../scheduler/GitHubDataSyncService.java | 23 ++++++++++++------ 2 files changed, 28 insertions(+), 19 deletions(-) rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/{DailyGitHubDataSyncScheduler.java => GitHubDataSyncScheduler.java} (64%) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/DailyGitHubDataSyncScheduler.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncScheduler.java similarity index 64% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/DailyGitHubDataSyncScheduler.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncScheduler.java index bd585e36..acd1c2d9 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/DailyGitHubDataSyncScheduler.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncScheduler.java @@ -11,9 +11,9 @@ import java.io.IOException; @Component -public class DailyGitHubDataSyncScheduler { +public class GitHubDataSyncScheduler { - private static final Logger logger = LoggerFactory.getLogger(DailyGitHubDataSyncScheduler.class); + private static final Logger logger = LoggerFactory.getLogger(GitHubDataSyncScheduler.class); private final GitHubDataSyncService dataSyncService; @Value("${monitoring.runOnStartup:true}") @@ -22,7 +22,7 @@ public class DailyGitHubDataSyncScheduler { @Value("${monitoring.repositories}") private String[] repositoriesToMonitor; - public DailyGitHubDataSyncScheduler(GitHubDataSyncService dataSyncService) { + public GitHubDataSyncScheduler(GitHubDataSyncService dataSyncService) { this.dataSyncService = dataSyncService; } @@ -30,26 +30,26 @@ public DailyGitHubDataSyncScheduler(GitHubDataSyncService dataSyncService) { public void onStartup() { if (runOnStartup) { logger.info("Starting initial GitHub data sync for Hephaestus..."); - try { - dataSyncService.syncData("ls1intum/hephaestus"); - logger.info("Initial GitHub data sync completed successfully for repository: ls1intum/hephaestus"); - } catch (IOException e) { - logger.error("Error during GitHub data sync: ", e); - } + syncAllRepositories(); + logger.info("Initial GitHub data sync completed successfully."); } } @Scheduled(cron = "${monitoring.repository-sync-cron}") - public void syncDataDaily() { + public void syncDataCron() { logger.info("Starting daily GitHub data sync..."); + syncAllRepositories(); + logger.info("Daily GitHub data sync completed successfully."); + } + + private void syncAllRepositories() { for (String repositoryName : repositoriesToMonitor) { try { dataSyncService.syncData(repositoryName); - logger.info("Daily GitHub data sync completed successfully for repository: " + repositoryName); + logger.info("GitHub data sync completed successfully for repository: " + repositoryName); } catch (IOException e) { logger.error("Error during GitHub data sync: ", e); } } - logger.info("Daily GitHub data sync completed."); } } \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java index 2a18e7fa..5f4e1f11 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java @@ -41,14 +41,26 @@ public class GitHubDataSyncService { private final IssueCommentRepository commentRepository; private final UserRepository userRepository; + private final RepositoryConverter repositoryConverter; + private final PullRequestConverter pullRequestConverter; + private final IssueCommentConverter commentConverter; + private final UserConverter userConverter; + public GitHubDataSyncService(RepositoryRepository repositoryRepository, PullRequestRepository pullRequestRepository, - IssueCommentRepository commentRepository, UserRepository userRepository) { + IssueCommentRepository commentRepository, UserRepository userRepository, + RepositoryConverter repositoryConverter, PullRequestConverter pullRequestConverter, + IssueCommentConverter commentConverter, UserConverter userConverter) { logger.info("Hello from GitHubDataSyncService!"); this.repositoryRepository = repositoryRepository; this.pullRequestRepository = pullRequestRepository; this.commentRepository = commentRepository; this.userRepository = userRepository; + + this.repositoryConverter = repositoryConverter; + this.pullRequestConverter = pullRequestConverter; + this.commentConverter = commentConverter; + this.userConverter = userConverter; } public void syncData(String repositoryName) throws IOException { @@ -79,7 +91,7 @@ public Repository fetchRepository(String nameWithOwner) throws IOException { } GHRepository ghRepo = github.getRepository(nameWithOwner); - Repository repository = new RepositoryConverter().convert(ghRepo); + Repository repository = repositoryConverter.convert(ghRepo); if (repository == null) { logger.error("Error while fetching repository!"); return null; @@ -87,11 +99,9 @@ public Repository fetchRepository(String nameWithOwner) throws IOException { // preliminary save to make it referenceable repositoryRepository.save(repository); - PullRequestConverter prConverter = new PullRequestConverter(); - // Retrieve PRs in pages of 10 Set prs = ghRepo.queryPullRequests().list().withPageSize(10).toList().stream().map(pr -> { - PullRequest pullRequest = prConverter.convert(pr); + PullRequest pullRequest = pullRequestConverter.convert(pr); pullRequest.setRepository(repository); pullRequestRepository.save(pullRequest); try { @@ -127,7 +137,6 @@ public Repository fetchRepository(String nameWithOwner) throws IOException { */ private Set getCommentsFromGHPullRequest(GHPullRequest pr, PullRequest pullRequest) throws IOException { - IssueCommentConverter commentConverter = new IssueCommentConverter(); Set comments = pr.queryComments().list().toList().stream() .map(comment -> { IssueComment c = commentConverter.convert(comment); @@ -150,7 +159,7 @@ private Set getCommentsFromGHPullRequest(GHPullRequest pr, PullReq private User getActorFromGHUser(org.kohsuke.github.GHUser user) { User ghUser = userRepository.findUser(user.getLogin()).orElse(null); if (ghUser == null) { - ghUser = new UserConverter().convert(user); + ghUser = userConverter.convert(user); userRepository.save(ghUser); } return ghUser; From 22ead12ade7bc7634951d376dc78e1875835663a Mon Sep 17 00:00:00 2001 From: GODrums Date: Sat, 31 Aug 2024 21:54:55 +0200 Subject: [PATCH 36/50] Change repositories to fetch --- server/application-server/src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/application-server/src/main/resources/application.yml b/server/application-server/src/main/resources/application.yml index 30b4c747..67c06829 100644 --- a/server/application-server/src/main/resources/application.yml +++ b/server/application-server/src/main/resources/application.yml @@ -33,7 +33,7 @@ springdoc: monitoring: runOnStartup: true repository-sync-cron: "0 0 3 * * ?" - repositories: ls1intum/hephaestus, ls1intum/pyris + repositories: ls1intum/Artemis, ls1intum/Pyris, ls1intum/Athena, ls1intum/Athena-CoFee, ls1intum/artemis-ansible-collection, ls1intum/Ares, ls1intum/Ares2, ls1intum/Aeolus, ls1intum/hades, ls1intum/Apollon, ls1intum/Hephaestus, ls1intum/Apollon_standalone # Can be any OAuth token, such as the PAT github: From e23c516f15facec648f5c6e032789aca0159a48d Mon Sep 17 00:00:00 2001 From: GODrums Date: Sun, 1 Sep 2024 02:00:18 +0200 Subject: [PATCH 37/50] Redo pullrequest naming --- .../pullrequest/PullrequestController.java | 28 -------------- .../pullrequest/PullrequestConverter.java | 38 ------------------- .../pullrequest/PullrequestService.java | 29 -------------- 3 files changed, 95 deletions(-) delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java deleted file mode 100644 index ff6652d6..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestController.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview.pullrequest; - -import java.util.Set; - -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("/pullrequest") -public class PullRequestController { - private final PullRequestService pullRequestService; - - public PullRequestController(PullRequestService pullRequestService) { - this.pullRequestService = pullRequestService; - } - - @GetMapping("/{id}") - public PullRequest getPullRequest(@PathVariable Long id) { - return pullRequestService.getPullRequestById(id); - } - - @GetMapping("/author/{login}") - public Set getPullRequestsByAuthor(@PathVariable String login) { - return pullRequestService.getPullRequestsByAuthor(login); - } -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java deleted file mode 100644 index 7987dc3b..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConverter.java +++ /dev/null @@ -1,38 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview.pullrequest; - -import org.kohsuke.github.GHPullRequest; -import org.springframework.data.convert.ReadingConverter; -import org.springframework.lang.NonNull; -import org.springframework.stereotype.Service; - -import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntityConverter; - -@Service -@ReadingConverter -public class PullRequestConverter extends BaseGitServiceEntityConverter { - @Override - public PullRequest convert(@NonNull GHPullRequest source) { - IssueState state = convertState(source.getState()); - PullRequest pullRequest = new PullRequest(); - convertBaseFields(source, pullRequest); - pullRequest.setTitle(source.getTitle()); - pullRequest.setUrl(source.getHtmlUrl().toString()); - pullRequest.setState(state); - if (source.getMergedAt() != null) { - pullRequest.setMergedAt(source.getMergedAt().toString()); - } - return pullRequest; - } - - private IssueState convertState(org.kohsuke.github.GHIssueState state) { - switch (state) { - case OPEN: - return IssueState.OPEN; - case CLOSED: - return IssueState.CLOSED; - default: - return IssueState.OPEN; - } - } - -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java deleted file mode 100644 index a3b28b7d..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestService.java +++ /dev/null @@ -1,29 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview.pullrequest; - -import java.util.Set; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -@Service -public class PullRequestService { - private static final Logger logger = LoggerFactory.getLogger(PullRequestService.class); - - private final PullRequestRepository pullRequestRepository; - - public PullRequestService(PullRequestRepository pullRequestRepository) { - this.pullRequestRepository = pullRequestRepository; - } - - public PullRequest getPullRequestById(Long id) { - logger.info("Getting pullRequest with id: " + id); - return pullRequestRepository.findById(id).orElse(null); - } - - public Set getPullRequestsByAuthor(String login) { - logger.info("Getting pullRequest by author: " + login); - return pullRequestRepository.findByAuthor_Login(login); - } - -} From 3571d400242b9ac00a88c19d6cd917c864ae907b Mon Sep 17 00:00:00 2001 From: GODrums Date: Sun, 1 Sep 2024 02:49:09 +0200 Subject: [PATCH 38/50] Make converter services --- .gitignore | 3 +++ .../codereview/base/BaseGitServiceEntityConverter.java | 2 ++ .../hephaestus/codereview/comment/IssueComment.java | 4 ++++ .../codereview/comment/IssueCommentConverter.java | 2 ++ .../codereview/pullrequest/PullRequestController.java | 7 +++++-- .../codereview/pullrequest/PullRequestConverter.java | 2 -- .../codereview/pullrequest/PullRequestService.java | 9 +++++---- .../codereview/repository/RepositoryConverter.java | 2 -- .../hephaestus/codereview/user/UserController.java | 10 +++------- .../www1/hephaestus/codereview/user/UserConverter.java | 2 ++ 10 files changed, 26 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 2f74a32a..f62e12af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ .venv .DS_Store +# Idea files +.idea/ + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntityConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntityConverter.java index bf490dce..82aa9b98 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntityConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/BaseGitServiceEntityConverter.java @@ -2,6 +2,7 @@ import org.kohsuke.github.GHObject; import org.springframework.core.convert.converter.Converter; +import org.springframework.data.convert.ReadingConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; @@ -9,6 +10,7 @@ import java.time.ZoneOffset; import java.util.Date; +@ReadingConverter public abstract class BaseGitServiceEntityConverter implements Converter { diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java index 0b3dfd50..fa89fa43 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueComment.java @@ -7,9 +7,11 @@ import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntity; import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest; import de.tum.in.www1.hephaestus.codereview.user.User; +import jakarta.persistence.Basic; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.JoinColumn; +import jakarta.persistence.Lob; import jakarta.persistence.ManyToOne; import lombok.Getter; import lombok.NoArgsConstructor; @@ -24,6 +26,8 @@ @ToString(callSuper = true) public class IssueComment extends BaseGitServiceEntity { @NonNull + @Lob + @Basic(fetch = FetchType.EAGER) private String body; @ManyToOne(fetch = FetchType.LAZY) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java index cf94b9c5..e48b9659 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java @@ -2,9 +2,11 @@ import org.kohsuke.github.GHIssueComment; import org.springframework.lang.NonNull; +import org.springframework.stereotype.Service; import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntityConverter; +@Service public class IssueCommentConverter extends BaseGitServiceEntityConverter { @Override diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestController.java index ff6652d6..8af92a91 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestController.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestController.java @@ -1,7 +1,9 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; +import java.util.Optional; import java.util.Set; +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; @@ -17,8 +19,9 @@ public PullRequestController(PullRequestService pullRequestService) { } @GetMapping("/{id}") - public PullRequest getPullRequest(@PathVariable Long id) { - return pullRequestService.getPullRequestById(id); + public ResponseEntity getPullRequest(@PathVariable Long id) { + Optional pullRequest =pullRequestService.getPullRequestById(id); + return pullRequest.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); } @GetMapping("/author/{login}") diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestConverter.java index 7987dc3b..c0e487c2 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestConverter.java @@ -1,14 +1,12 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; import org.kohsuke.github.GHPullRequest; -import org.springframework.data.convert.ReadingConverter; import org.springframework.lang.NonNull; import org.springframework.stereotype.Service; import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntityConverter; @Service -@ReadingConverter public class PullRequestConverter extends BaseGitServiceEntityConverter { @Override public PullRequest convert(@NonNull GHPullRequest source) { diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestService.java index a3b28b7d..4c3fdbf3 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestService.java @@ -1,5 +1,6 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; +import java.util.Optional; import java.util.Set; import org.slf4j.Logger; @@ -16,13 +17,13 @@ public PullRequestService(PullRequestRepository pullRequestRepository) { this.pullRequestRepository = pullRequestRepository; } - public PullRequest getPullRequestById(Long id) { - logger.info("Getting pullRequest with id: " + id); - return pullRequestRepository.findById(id).orElse(null); + public Optional getPullRequestById(Long id) { + logger.info("Getting pullRequest with id: {}", id); + return pullRequestRepository.findById(id); } public Set getPullRequestsByAuthor(String login) { - logger.info("Getting pullRequest by author: " + login); + logger.info("Getting pullRequest by author: {}", login); return pullRequestRepository.findByAuthor_Login(login); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java index fccc292b..27e03139 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java @@ -2,7 +2,6 @@ import org.kohsuke.github.GHRepository; import org.kohsuke.github.GHRepository.Visibility; -import org.springframework.data.convert.ReadingConverter; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.springframework.stereotype.Service; @@ -10,7 +9,6 @@ import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntityConverter; @Service -@ReadingConverter public class RepositoryConverter extends BaseGitServiceEntityConverter { @Override diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserController.java index 57758eac..bc31c831 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserController.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserController.java @@ -2,13 +2,12 @@ import java.util.Optional; +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; -import de.tum.in.www1.hephaestus.errors.EntityNotFoundException; - @RestController @RequestMapping("/user") public class UserController { @@ -19,12 +18,9 @@ public UserController(UserService actorService) { } @GetMapping("/{login}") - public UserDTO getUser(@PathVariable String login) { + public ResponseEntity getUser(@PathVariable String login) { Optional user = userService.getUserDTO(login); - if (user.isEmpty()) { - throw new EntityNotFoundException("Actor with login " + login + " not found!"); - } - return user.get(); + return user.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java index de91333f..29d317be 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java @@ -5,9 +5,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.lang.NonNull; +import org.springframework.stereotype.Service; import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntityConverter; +@Service public class UserConverter extends BaseGitServiceEntityConverter { protected static final Logger logger = LoggerFactory.getLogger(UserConverter.class); From 87a2620727a44c122f7f075caa9c3e333ab20e2d Mon Sep 17 00:00:00 2001 From: GODrums Date: Sun, 1 Sep 2024 03:22:34 +0200 Subject: [PATCH 39/50] Delete EntityNotFoundException --- .../errors/EntityNotFoundException.java | 29 ------------------- 1 file changed, 29 deletions(-) delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/errors/EntityNotFoundException.java diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/errors/EntityNotFoundException.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/errors/EntityNotFoundException.java deleted file mode 100644 index 3cbb8d06..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/errors/EntityNotFoundException.java +++ /dev/null @@ -1,29 +0,0 @@ -package de.tum.in.www1.hephaestus.errors; - -import java.io.Serial; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(HttpStatus.NOT_FOUND) -public class EntityNotFoundException extends RuntimeException { - - @Serial - private static final long serialVersionUID = 1L; - - public EntityNotFoundException() { - super(); - } - - public EntityNotFoundException(String message) { - super(message); - } - - public EntityNotFoundException(String entityName, Long entityId) { - super(entityName + " with id: \"" + entityId + "\" does not exist"); - } - - public EntityNotFoundException(String entityName, String entityIdentifier) { - super(entityName + " with identifier: \"" + entityIdentifier + "\" does not exist"); - } -} From 5b99ac1e513ab8b92fd12576c0309fd2ab392e6a Mon Sep 17 00:00:00 2001 From: GODrums Date: Sun, 1 Sep 2024 20:47:19 +0200 Subject: [PATCH 40/50] Change to @Component --- .../hephaestus/codereview/comment/IssueCommentConverter.java | 4 ++-- .../codereview/pullrequest/PullRequestConverter.java | 4 ++-- .../hephaestus/codereview/repository/RepositoryConverter.java | 4 ++-- .../tum/in/www1/hephaestus/codereview/user/UserConverter.java | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java index e48b9659..1cef439d 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/IssueCommentConverter.java @@ -2,11 +2,11 @@ import org.kohsuke.github.GHIssueComment; import org.springframework.lang.NonNull; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntityConverter; -@Service +@Component public class IssueCommentConverter extends BaseGitServiceEntityConverter { @Override diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestConverter.java index c0e487c2..d779a1ac 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestConverter.java @@ -2,11 +2,11 @@ import org.kohsuke.github.GHPullRequest; import org.springframework.lang.NonNull; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntityConverter; -@Service +@Component public class PullRequestConverter extends BaseGitServiceEntityConverter { @Override public PullRequest convert(@NonNull GHPullRequest source) { diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java index 27e03139..2482b505 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/RepositoryConverter.java @@ -4,11 +4,11 @@ import org.kohsuke.github.GHRepository.Visibility; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntityConverter; -@Service +@Component public class RepositoryConverter extends BaseGitServiceEntityConverter { @Override diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java index 29d317be..2d26e0fb 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserConverter.java @@ -5,11 +5,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.lang.NonNull; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntityConverter; -@Service +@Component public class UserConverter extends BaseGitServiceEntityConverter { protected static final Logger logger = LoggerFactory.getLogger(UserConverter.class); From 827cb8a54fde82818d152842166d57d06a628a61 Mon Sep 17 00:00:00 2001 From: Armin Stanitzok <21990230+GODrums@users.noreply.github.com> Date: Mon, 2 Sep 2024 03:56:00 +0200 Subject: [PATCH 41/50] Delete Pullrequest.java --- .../codereview/pullrequest/Pullrequest.java | 59 ------------------- 1 file changed, 59 deletions(-) delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java deleted file mode 100644 index 86da8870..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ /dev/null @@ -1,59 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview.pullrequest; - -import java.util.HashSet; -import java.util.Set; - -import org.springframework.lang.NonNull; - -import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntity; -import de.tum.in.www1.hephaestus.codereview.comment.IssueComment; -import de.tum.in.www1.hephaestus.codereview.repository.Repository; -import de.tum.in.www1.hephaestus.codereview.user.User; -import jakarta.persistence.Table; -import jakarta.persistence.CascadeType; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToMany; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -@Entity -@Table(name = "pull_request") -@Getter -@Setter -@NoArgsConstructor -@ToString(callSuper = true) -public class PullRequest extends BaseGitServiceEntity { - @NonNull - private String title; - - @NonNull - private String url; - - /** - * State of the PullRequest. - * Does not include the state of the merge. - */ - @NonNull - private IssueState state; - - private String mergedAt; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "author_id") - @ToString.Exclude - private User author; - - @OneToMany(cascade = CascadeType.ALL, mappedBy = "pullRequest") - @ToString.Exclude - private Set comments = new HashSet<>();; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "repository_id", referencedColumnName = "id") - @ToString.Exclude - private Repository repository; -} From 84573744e556f88b814b9037f237e1211fd54a5c Mon Sep 17 00:00:00 2001 From: Armin Stanitzok <21990230+GODrums@users.noreply.github.com> Date: Mon, 2 Sep 2024 03:56:32 +0200 Subject: [PATCH 42/50] Delete PullrequestRepository.java --- .../pullrequest/PullrequestRepository.java | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java deleted file mode 100644 index f74be306..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.tum.in.www1.hephaestus.codereview.pullrequest; - -import java.util.Set; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface PullRequestRepository extends JpaRepository { - - Set findByAuthor_Login(String authorLogin); -} From 55e0486f7d8c9ca113c9ac422e6d5e8f12668bc6 Mon Sep 17 00:00:00 2001 From: GODrums Date: Mon, 2 Sep 2024 04:02:59 +0200 Subject: [PATCH 43/50] Recommit correct casing files --- .../in/www1/hephaestus/codereview/pullrequest/PullRequest.java | 2 +- .../codereview/pullrequest/PullRequestRepository.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequest.java index 86da8870..564c1ce4 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequest.java @@ -56,4 +56,4 @@ public class PullRequest extends BaseGitServiceEntity { @JoinColumn(name = "repository_id", referencedColumnName = "id") @ToString.Exclude private Repository repository; -} +} \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestRepository.java index f74be306..255d1749 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestRepository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestRepository.java @@ -9,4 +9,4 @@ public interface PullRequestRepository extends JpaRepository { Set findByAuthor_Login(String authorLogin); -} +} \ No newline at end of file From e12ed625e005907900490acbf42e07074d116566 Mon Sep 17 00:00:00 2001 From: GODrums Date: Mon, 2 Sep 2024 04:06:08 +0200 Subject: [PATCH 44/50] Add default value for ghAuthToken --- .../in/www1/hephaestus/scheduler/GitHubDataSyncService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java index 5f4e1f11..6a0fb15f 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java @@ -31,7 +31,7 @@ public class GitHubDataSyncService { private static final Logger logger = LoggerFactory.getLogger(GitHubDataSyncService.class); - @Value("${github.authToken}") + @Value("${github.authToken:}") private String ghAuthToken; private GitHub github; @@ -64,6 +64,10 @@ public GitHubDataSyncService(RepositoryRepository repositoryRepository, PullRequ } public void syncData(String repositoryName) throws IOException { + if (ghAuthToken == null || ghAuthToken.isEmpty()) { + logger.error("No GitHub auth token provided!"); + return; + } if (github == null) { github = new GitHubBuilder().withOAuthToken(ghAuthToken).build(); } From ce402ec69f18ed5f4685d046abfbd13871f571d9 Mon Sep 17 00:00:00 2001 From: GODrums Date: Mon, 2 Sep 2024 04:20:23 +0200 Subject: [PATCH 45/50] Create a non-environement ghAuthToken --- .../in/www1/hephaestus/scheduler/GitHubDataSyncService.java | 4 ++-- server/application-server/src/main/resources/application.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java index 6a0fb15f..a0ff6bf8 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java @@ -31,7 +31,7 @@ public class GitHubDataSyncService { private static final Logger logger = LoggerFactory.getLogger(GitHubDataSyncService.class); - @Value("${github.authToken:}") + @Value("${github.authToken:null}") private String ghAuthToken; private GitHub github; @@ -64,7 +64,7 @@ public GitHubDataSyncService(RepositoryRepository repositoryRepository, PullRequ } public void syncData(String repositoryName) throws IOException { - if (ghAuthToken == null || ghAuthToken.isEmpty()) { + if (ghAuthToken == null || ghAuthToken.isEmpty() || ghAuthToken.equals("null")) { logger.error("No GitHub auth token provided!"); return; } diff --git a/server/application-server/src/main/resources/application.yml b/server/application-server/src/main/resources/application.yml index 67c06829..6feb75f9 100644 --- a/server/application-server/src/main/resources/application.yml +++ b/server/application-server/src/main/resources/application.yml @@ -31,10 +31,10 @@ springdoc: default-produces-media-type: application/json monitoring: - runOnStartup: true + runOnStartup: false repository-sync-cron: "0 0 3 * * ?" repositories: ls1intum/Artemis, ls1intum/Pyris, ls1intum/Athena, ls1intum/Athena-CoFee, ls1intum/artemis-ansible-collection, ls1intum/Ares, ls1intum/Ares2, ls1intum/Aeolus, ls1intum/hades, ls1intum/Apollon, ls1intum/Hephaestus, ls1intum/Apollon_standalone # Can be any OAuth token, such as the PAT github: - authToken: ${GITHUB_PAT} + authToken: null From 21704cfff952ee666c0be22931be2d2babd41de3 Mon Sep 17 00:00:00 2001 From: GODrums Date: Mon, 2 Sep 2024 04:25:02 +0200 Subject: [PATCH 46/50] New OpenAPI specs --- server/application-server/openapi.yaml | 284 ++++++++++++++++++++++++- 1 file changed, 281 insertions(+), 3 deletions(-) diff --git a/server/application-server/openapi.yaml b/server/application-server/openapi.yaml index b9d8cfbe..14b7bdf4 100644 --- a/server/application-server/openapi.yaml +++ b/server/application-server/openapi.yaml @@ -42,6 +42,64 @@ paths: application/json: schema: $ref: "#/components/schemas/Hello" + /user/{login}: + get: + tags: + - user + operationId: getUser + parameters: + - name: login + in: path + required: true + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/UserDTO" + /pullrequest/{id}: + get: + tags: + - pull-request + operationId: getPullRequest + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/PullRequest" + /pullrequest/author/{login}: + get: + tags: + - pull-request + operationId: getPullRequestsByAuthor + parameters: + - name: login + in: path + required: true + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + uniqueItems: true + type: array + items: + $ref: "#/components/schemas/PullRequest" /admin: get: tags: @@ -65,7 +123,227 @@ components: format: int64 timestamp: type: string - description: |- - Timestamp of when the Hello entity was created. - This field is mandatory. + description: "Timestamp of when the Hello entity was created.\r\n This field\ + \ is mandatory." format: date-time + IssueCommentDTO: + type: object + properties: + id: + type: integer + format: int64 + body: + type: string + createdAt: + type: string + updatedAt: + type: string + author: + $ref: "#/components/schemas/UserDTO" + pullRequest: + $ref: "#/components/schemas/PullRequestDTO" + PullRequestDTO: + type: object + properties: + id: + type: integer + format: int64 + title: + type: string + url: + type: string + state: + type: string + enum: + - CLOSED + - OPEN + createdAt: + type: string + updatedAt: + type: string + mergedAt: + type: string + author: + $ref: "#/components/schemas/UserDTO" + comments: + uniqueItems: true + type: array + items: + $ref: "#/components/schemas/IssueCommentDTO" + repository: + $ref: "#/components/schemas/RepositoryDTO" + RepositoryDTO: + type: object + properties: + name: + type: string + nameWithOwner: + type: string + description: + type: string + url: + type: string + UserDTO: + type: object + properties: + id: + type: integer + format: int64 + login: + type: string + email: + type: string + name: + type: string + url: + type: string + pullRequests: + uniqueItems: true + type: array + items: + $ref: "#/components/schemas/PullRequestDTO" + comments: + uniqueItems: true + type: array + items: + $ref: "#/components/schemas/IssueCommentDTO" + IssueComment: + required: + - body + type: object + properties: + id: + type: integer + format: int64 + createdAt: + type: string + format: date-time + updatedAt: + type: string + format: date-time + body: + type: string + author: + $ref: "#/components/schemas/User" + pullRequest: + $ref: "#/components/schemas/PullRequest" + PullRequest: + required: + - state + - title + - url + type: object + properties: + id: + type: integer + format: int64 + createdAt: + type: string + format: date-time + updatedAt: + type: string + format: date-time + title: + type: string + url: + type: string + state: + type: string + description: "State of the PullRequest.\r\n Does not include the state of\ + \ the merge." + enum: + - CLOSED + - OPEN + mergedAt: + type: string + author: + $ref: "#/components/schemas/User" + comments: + uniqueItems: true + type: array + items: + $ref: "#/components/schemas/IssueComment" + repository: + $ref: "#/components/schemas/Repository" + Repository: + required: + - defaultBranch + - description + - name + - nameWithOwner + - url + - visibility + type: object + properties: + id: + type: integer + format: int64 + createdAt: + type: string + format: date-time + updatedAt: + type: string + format: date-time + name: + type: string + nameWithOwner: + type: string + description: + type: string + defaultBranch: + type: string + visibility: + type: string + enum: + - PUBLIC + - PRIVATE + url: + type: string + homepage: + type: string + pullRequests: + uniqueItems: true + type: array + items: + $ref: "#/components/schemas/PullRequest" + User: + required: + - login + - url + type: object + properties: + id: + type: integer + format: int64 + createdAt: + type: string + format: date-time + updatedAt: + type: string + format: date-time + login: + type: string + description: Unique login identifier for a user. + email: + type: string + name: + type: string + description: Display name of the user. + url: + type: string + description: "Unique URL to the user's profile.\r\n Not the website a user\ + \ can set in their profile." + avatarUrl: + type: string + description: "URL to the user's avatar.\r\n If unavailable, a fallback can\ + \ be generated from the login, e.g. on Github:\r\n https://github.com/{login}.png" + pullRequests: + uniqueItems: true + type: array + items: + $ref: "#/components/schemas/PullRequest" + comments: + uniqueItems: true + type: array + items: + $ref: "#/components/schemas/IssueComment" From 1530549c16888ca6dafc9dff87402b6d286ade3a Mon Sep 17 00:00:00 2001 From: GODrums Date: Mon, 2 Sep 2024 04:29:36 +0200 Subject: [PATCH 47/50] Execute generate:api:application-server-client --- .../modules/openapi/.openapi-generator/FILES | 13 +- .../src/app/core/modules/openapi/api/api.ts | 8 +- .../openapi/api/pull-request.service.ts | 224 ++++++++++++++++++ .../api/pull-request.serviceInterface.ts | 41 ++++ .../core/modules/openapi/api/user.service.ts | 161 +++++++++++++ .../openapi/api/user.serviceInterface.ts | 34 +++ .../app/core/modules/openapi/model/hello.ts | 2 +- .../openapi/model/issue-comment-dto.ts | 24 ++ .../modules/openapi/model/issue-comment.ts | 24 ++ .../app/core/modules/openapi/model/models.ts | 8 + .../modules/openapi/model/pull-request-dto.ts | 37 +++ .../modules/openapi/model/pull-request.ts | 40 ++++ .../modules/openapi/model/repository-dto.ts | 20 ++ .../core/modules/openapi/model/repository.ts | 36 +++ .../core/modules/openapi/model/user-dto.ts | 25 ++ .../app/core/modules/openapi/model/user.ts | 40 ++++ 16 files changed, 734 insertions(+), 3 deletions(-) create mode 100644 webapp/src/app/core/modules/openapi/api/pull-request.service.ts create mode 100644 webapp/src/app/core/modules/openapi/api/pull-request.serviceInterface.ts create mode 100644 webapp/src/app/core/modules/openapi/api/user.service.ts create mode 100644 webapp/src/app/core/modules/openapi/api/user.serviceInterface.ts create mode 100644 webapp/src/app/core/modules/openapi/model/issue-comment-dto.ts create mode 100644 webapp/src/app/core/modules/openapi/model/issue-comment.ts create mode 100644 webapp/src/app/core/modules/openapi/model/pull-request-dto.ts create mode 100644 webapp/src/app/core/modules/openapi/model/pull-request.ts create mode 100644 webapp/src/app/core/modules/openapi/model/repository-dto.ts create mode 100644 webapp/src/app/core/modules/openapi/model/repository.ts create mode 100644 webapp/src/app/core/modules/openapi/model/user-dto.ts create mode 100644 webapp/src/app/core/modules/openapi/model/user.ts diff --git a/webapp/src/app/core/modules/openapi/.openapi-generator/FILES b/webapp/src/app/core/modules/openapi/.openapi-generator/FILES index a74bc16f..5137b882 100644 --- a/webapp/src/app/core/modules/openapi/.openapi-generator/FILES +++ b/webapp/src/app/core/modules/openapi/.openapi-generator/FILES @@ -1,5 +1,4 @@ .gitignore -.openapi-generator-ignore README.md api.module.ts api/admin.service.ts @@ -7,11 +6,23 @@ api/admin.serviceInterface.ts api/api.ts api/hello.service.ts api/hello.serviceInterface.ts +api/pull-request.service.ts +api/pull-request.serviceInterface.ts +api/user.service.ts +api/user.serviceInterface.ts configuration.ts encoder.ts git_push.sh index.ts model/hello.ts +model/issue-comment-dto.ts +model/issue-comment.ts model/models.ts +model/pull-request-dto.ts +model/pull-request.ts +model/repository-dto.ts +model/repository.ts +model/user-dto.ts +model/user.ts param.ts variables.ts diff --git a/webapp/src/app/core/modules/openapi/api/api.ts b/webapp/src/app/core/modules/openapi/api/api.ts index 496ee4fc..49c6e262 100644 --- a/webapp/src/app/core/modules/openapi/api/api.ts +++ b/webapp/src/app/core/modules/openapi/api/api.ts @@ -4,4 +4,10 @@ export * from './admin.serviceInterface'; export * from './hello.service'; import { HelloService } from './hello.service'; export * from './hello.serviceInterface'; -export const APIS = [AdminService, HelloService]; +export * from './pull-request.service'; +import { PullRequestService } from './pull-request.service'; +export * from './pull-request.serviceInterface'; +export * from './user.service'; +import { UserService } from './user.service'; +export * from './user.serviceInterface'; +export const APIS = [AdminService, HelloService, PullRequestService, UserService]; diff --git a/webapp/src/app/core/modules/openapi/api/pull-request.service.ts b/webapp/src/app/core/modules/openapi/api/pull-request.service.ts new file mode 100644 index 00000000..5511e994 --- /dev/null +++ b/webapp/src/app/core/modules/openapi/api/pull-request.service.ts @@ -0,0 +1,224 @@ +/** + * Hephaestus API + * API documentation for the Hephaestus application server. + * + * The version of the OpenAPI document: 0.0.1 + * Contact: felixtj.dietrich@tum.de + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +/* tslint:disable:no-unused-variable member-ordering */ + +import { Inject, Injectable, Optional } from '@angular/core'; +import { HttpClient, HttpHeaders, HttpParams, + HttpResponse, HttpEvent, HttpParameterCodec, HttpContext + } from '@angular/common/http'; +import { CustomHttpParameterCodec } from '../encoder'; +import { Observable } from 'rxjs'; + +// @ts-ignore +import { PullRequest } from '../model/pull-request'; + +// @ts-ignore +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; +import { + PullRequestServiceInterface +} from './pull-request.serviceInterface'; + + + +@Injectable({ + providedIn: 'root' +}) +export class PullRequestService implements PullRequestServiceInterface { + + protected basePath = 'http://localhost'; + public defaultHeaders = new HttpHeaders(); + public configuration = new Configuration(); + public encoder: HttpParameterCodec; + + constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string|string[], @Optional() configuration: Configuration) { + if (configuration) { + this.configuration = configuration; + } + if (typeof this.configuration.basePath !== 'string') { + const firstBasePath = Array.isArray(basePath) ? basePath[0] : undefined; + if (firstBasePath != undefined) { + basePath = firstBasePath; + } + + if (typeof basePath !== 'string') { + basePath = this.basePath; + } + this.configuration.basePath = basePath; + } + this.encoder = this.configuration.encoder || new CustomHttpParameterCodec(); + } + + + // @ts-ignore + private addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + if (typeof value === "object" && value instanceof Date === false) { + httpParams = this.addToHttpParamsRecursive(httpParams, value); + } else { + httpParams = this.addToHttpParamsRecursive(httpParams, value, key); + } + return httpParams; + } + + private addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + if (value == null) { + return httpParams; + } + + if (typeof value === "object") { + if (Array.isArray(value)) { + (value as any[]).forEach( elem => httpParams = this.addToHttpParamsRecursive(httpParams, elem, key)); + } else if (value instanceof Date) { + if (key != null) { + httpParams = httpParams.append(key, (value as Date).toISOString().substring(0, 10)); + } else { + throw Error("key may not be null if value is Date"); + } + } else { + Object.keys(value).forEach( k => httpParams = this.addToHttpParamsRecursive( + httpParams, value[k], key != null ? `${key}.${k}` : k)); + } + } else if (key != null) { + httpParams = httpParams.append(key, value); + } else { + throw Error("key may not be null if value is not object or array"); + } + return httpParams; + } + + /** + * @param id + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + public getPullRequest(id: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; + public getPullRequest(id: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getPullRequest(id: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getPullRequest(id: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + if (id === null || id === undefined) { + throw new Error('Required parameter id was null or undefined when calling getPullRequest.'); + } + + let localVarHeaders = this.defaultHeaders; + + let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept; + if (localVarHttpHeaderAcceptSelected === undefined) { + // to determine the Accept header + const httpHeaderAccepts: string[] = [ + 'application/json' + ]; + localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts); + } + if (localVarHttpHeaderAcceptSelected !== undefined) { + localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); + } + + let localVarHttpContext: HttpContext | undefined = options && options.context; + if (localVarHttpContext === undefined) { + localVarHttpContext = new HttpContext(); + } + + let localVarTransferCache: boolean | undefined = options && options.transferCache; + if (localVarTransferCache === undefined) { + localVarTransferCache = true; + } + + + let responseType_: 'text' | 'json' | 'blob' = 'json'; + if (localVarHttpHeaderAcceptSelected) { + if (localVarHttpHeaderAcceptSelected.startsWith('text')) { + responseType_ = 'text'; + } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) { + responseType_ = 'json'; + } else { + responseType_ = 'blob'; + } + } + + let localVarPath = `/pullrequest/${this.configuration.encodeParam({name: "id", value: id, in: "path", style: "simple", explode: false, dataType: "number", dataFormat: "int64"})}`; + return this.httpClient.request('get', `${this.configuration.basePath}${localVarPath}`, + { + context: localVarHttpContext, + responseType: responseType_, + withCredentials: this.configuration.withCredentials, + headers: localVarHeaders, + observe: observe, + transferCache: localVarTransferCache, + reportProgress: reportProgress + } + ); + } + + /** + * @param login + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + public getPullRequestsByAuthor(login: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getPullRequestsByAuthor(login: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>>; + public getPullRequestsByAuthor(login: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>>; + public getPullRequestsByAuthor(login: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + if (login === null || login === undefined) { + throw new Error('Required parameter login was null or undefined when calling getPullRequestsByAuthor.'); + } + + let localVarHeaders = this.defaultHeaders; + + let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept; + if (localVarHttpHeaderAcceptSelected === undefined) { + // to determine the Accept header + const httpHeaderAccepts: string[] = [ + 'application/json' + ]; + localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts); + } + if (localVarHttpHeaderAcceptSelected !== undefined) { + localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); + } + + let localVarHttpContext: HttpContext | undefined = options && options.context; + if (localVarHttpContext === undefined) { + localVarHttpContext = new HttpContext(); + } + + let localVarTransferCache: boolean | undefined = options && options.transferCache; + if (localVarTransferCache === undefined) { + localVarTransferCache = true; + } + + + let responseType_: 'text' | 'json' | 'blob' = 'json'; + if (localVarHttpHeaderAcceptSelected) { + if (localVarHttpHeaderAcceptSelected.startsWith('text')) { + responseType_ = 'text'; + } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) { + responseType_ = 'json'; + } else { + responseType_ = 'blob'; + } + } + + let localVarPath = `/pullrequest/author/${this.configuration.encodeParam({name: "login", value: login, in: "path", style: "simple", explode: false, dataType: "string", dataFormat: undefined})}`; + return this.httpClient.request>('get', `${this.configuration.basePath}${localVarPath}`, + { + context: localVarHttpContext, + responseType: responseType_, + withCredentials: this.configuration.withCredentials, + headers: localVarHeaders, + observe: observe, + transferCache: localVarTransferCache, + reportProgress: reportProgress + } + ); + } + +} diff --git a/webapp/src/app/core/modules/openapi/api/pull-request.serviceInterface.ts b/webapp/src/app/core/modules/openapi/api/pull-request.serviceInterface.ts new file mode 100644 index 00000000..66d5615b --- /dev/null +++ b/webapp/src/app/core/modules/openapi/api/pull-request.serviceInterface.ts @@ -0,0 +1,41 @@ +/** + * Hephaestus API + * API documentation for the Hephaestus application server. + * + * The version of the OpenAPI document: 0.0.1 + * Contact: felixtj.dietrich@tum.de + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +import { HttpHeaders } from '@angular/common/http'; + +import { Observable } from 'rxjs'; + +import { PullRequest } from '../model/models'; + + +import { Configuration } from '../configuration'; + + + +export interface PullRequestServiceInterface { + defaultHeaders: HttpHeaders; + configuration: Configuration; + + /** + * + * + * @param id + */ + getPullRequest(id: number, extraHttpRequestParams?: any): Observable; + + /** + * + * + * @param login + */ + getPullRequestsByAuthor(login: string, extraHttpRequestParams?: any): Observable>; + +} diff --git a/webapp/src/app/core/modules/openapi/api/user.service.ts b/webapp/src/app/core/modules/openapi/api/user.service.ts new file mode 100644 index 00000000..4806a28d --- /dev/null +++ b/webapp/src/app/core/modules/openapi/api/user.service.ts @@ -0,0 +1,161 @@ +/** + * Hephaestus API + * API documentation for the Hephaestus application server. + * + * The version of the OpenAPI document: 0.0.1 + * Contact: felixtj.dietrich@tum.de + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +/* tslint:disable:no-unused-variable member-ordering */ + +import { Inject, Injectable, Optional } from '@angular/core'; +import { HttpClient, HttpHeaders, HttpParams, + HttpResponse, HttpEvent, HttpParameterCodec, HttpContext + } from '@angular/common/http'; +import { CustomHttpParameterCodec } from '../encoder'; +import { Observable } from 'rxjs'; + +// @ts-ignore +import { UserDTO } from '../model/user-dto'; + +// @ts-ignore +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; +import { + UserServiceInterface +} from './user.serviceInterface'; + + + +@Injectable({ + providedIn: 'root' +}) +export class UserService implements UserServiceInterface { + + protected basePath = 'http://localhost'; + public defaultHeaders = new HttpHeaders(); + public configuration = new Configuration(); + public encoder: HttpParameterCodec; + + constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string|string[], @Optional() configuration: Configuration) { + if (configuration) { + this.configuration = configuration; + } + if (typeof this.configuration.basePath !== 'string') { + const firstBasePath = Array.isArray(basePath) ? basePath[0] : undefined; + if (firstBasePath != undefined) { + basePath = firstBasePath; + } + + if (typeof basePath !== 'string') { + basePath = this.basePath; + } + this.configuration.basePath = basePath; + } + this.encoder = this.configuration.encoder || new CustomHttpParameterCodec(); + } + + + // @ts-ignore + private addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + if (typeof value === "object" && value instanceof Date === false) { + httpParams = this.addToHttpParamsRecursive(httpParams, value); + } else { + httpParams = this.addToHttpParamsRecursive(httpParams, value, key); + } + return httpParams; + } + + private addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + if (value == null) { + return httpParams; + } + + if (typeof value === "object") { + if (Array.isArray(value)) { + (value as any[]).forEach( elem => httpParams = this.addToHttpParamsRecursive(httpParams, elem, key)); + } else if (value instanceof Date) { + if (key != null) { + httpParams = httpParams.append(key, (value as Date).toISOString().substring(0, 10)); + } else { + throw Error("key may not be null if value is Date"); + } + } else { + Object.keys(value).forEach( k => httpParams = this.addToHttpParamsRecursive( + httpParams, value[k], key != null ? `${key}.${k}` : k)); + } + } else if (key != null) { + httpParams = httpParams.append(key, value); + } else { + throw Error("key may not be null if value is not object or array"); + } + return httpParams; + } + + /** + * @param login + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + public getUser(login: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; + public getUser(login: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getUser(login: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getUser(login: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + if (login === null || login === undefined) { + throw new Error('Required parameter login was null or undefined when calling getUser.'); + } + + let localVarHeaders = this.defaultHeaders; + + let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept; + if (localVarHttpHeaderAcceptSelected === undefined) { + // to determine the Accept header + const httpHeaderAccepts: string[] = [ + 'application/json' + ]; + localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts); + } + if (localVarHttpHeaderAcceptSelected !== undefined) { + localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); + } + + let localVarHttpContext: HttpContext | undefined = options && options.context; + if (localVarHttpContext === undefined) { + localVarHttpContext = new HttpContext(); + } + + let localVarTransferCache: boolean | undefined = options && options.transferCache; + if (localVarTransferCache === undefined) { + localVarTransferCache = true; + } + + + let responseType_: 'text' | 'json' | 'blob' = 'json'; + if (localVarHttpHeaderAcceptSelected) { + if (localVarHttpHeaderAcceptSelected.startsWith('text')) { + responseType_ = 'text'; + } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) { + responseType_ = 'json'; + } else { + responseType_ = 'blob'; + } + } + + let localVarPath = `/user/${this.configuration.encodeParam({name: "login", value: login, in: "path", style: "simple", explode: false, dataType: "string", dataFormat: undefined})}`; + return this.httpClient.request('get', `${this.configuration.basePath}${localVarPath}`, + { + context: localVarHttpContext, + responseType: responseType_, + withCredentials: this.configuration.withCredentials, + headers: localVarHeaders, + observe: observe, + transferCache: localVarTransferCache, + reportProgress: reportProgress + } + ); + } + +} diff --git a/webapp/src/app/core/modules/openapi/api/user.serviceInterface.ts b/webapp/src/app/core/modules/openapi/api/user.serviceInterface.ts new file mode 100644 index 00000000..2221661e --- /dev/null +++ b/webapp/src/app/core/modules/openapi/api/user.serviceInterface.ts @@ -0,0 +1,34 @@ +/** + * Hephaestus API + * API documentation for the Hephaestus application server. + * + * The version of the OpenAPI document: 0.0.1 + * Contact: felixtj.dietrich@tum.de + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +import { HttpHeaders } from '@angular/common/http'; + +import { Observable } from 'rxjs'; + +import { UserDTO } from '../model/models'; + + +import { Configuration } from '../configuration'; + + + +export interface UserServiceInterface { + defaultHeaders: HttpHeaders; + configuration: Configuration; + + /** + * + * + * @param login + */ + getUser(login: string, extraHttpRequestParams?: any): Observable; + +} diff --git a/webapp/src/app/core/modules/openapi/model/hello.ts b/webapp/src/app/core/modules/openapi/model/hello.ts index e7d27e77..cc49c7a0 100644 --- a/webapp/src/app/core/modules/openapi/model/hello.ts +++ b/webapp/src/app/core/modules/openapi/model/hello.ts @@ -17,7 +17,7 @@ export interface Hello { */ id?: number; /** - * Timestamp of when the Hello entity was created. This field is mandatory. + * Timestamp of when the Hello entity was created. This field is mandatory. */ timestamp?: string; } diff --git a/webapp/src/app/core/modules/openapi/model/issue-comment-dto.ts b/webapp/src/app/core/modules/openapi/model/issue-comment-dto.ts new file mode 100644 index 00000000..b1f01fb9 --- /dev/null +++ b/webapp/src/app/core/modules/openapi/model/issue-comment-dto.ts @@ -0,0 +1,24 @@ +/** + * Hephaestus API + * API documentation for the Hephaestus application server. + * + * The version of the OpenAPI document: 0.0.1 + * Contact: felixtj.dietrich@tum.de + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +import { PullRequestDTO } from './pull-request-dto'; +import { UserDTO } from './user-dto'; + + +export interface IssueCommentDTO { + id?: number; + body?: string; + createdAt?: string; + updatedAt?: string; + author?: UserDTO; + pullRequest?: PullRequestDTO; +} + diff --git a/webapp/src/app/core/modules/openapi/model/issue-comment.ts b/webapp/src/app/core/modules/openapi/model/issue-comment.ts new file mode 100644 index 00000000..5c4eaadd --- /dev/null +++ b/webapp/src/app/core/modules/openapi/model/issue-comment.ts @@ -0,0 +1,24 @@ +/** + * Hephaestus API + * API documentation for the Hephaestus application server. + * + * The version of the OpenAPI document: 0.0.1 + * Contact: felixtj.dietrich@tum.de + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +import { User } from './user'; +import { PullRequest } from './pull-request'; + + +export interface IssueComment { + id?: number; + createdAt?: string; + updatedAt?: string; + body: string; + author?: User; + pullRequest?: PullRequest; +} + diff --git a/webapp/src/app/core/modules/openapi/model/models.ts b/webapp/src/app/core/modules/openapi/model/models.ts index 3d51a59b..cea96097 100644 --- a/webapp/src/app/core/modules/openapi/model/models.ts +++ b/webapp/src/app/core/modules/openapi/model/models.ts @@ -1 +1,9 @@ export * from './hello'; +export * from './issue-comment'; +export * from './issue-comment-dto'; +export * from './pull-request'; +export * from './pull-request-dto'; +export * from './repository'; +export * from './repository-dto'; +export * from './user'; +export * from './user-dto'; diff --git a/webapp/src/app/core/modules/openapi/model/pull-request-dto.ts b/webapp/src/app/core/modules/openapi/model/pull-request-dto.ts new file mode 100644 index 00000000..4a1064f1 --- /dev/null +++ b/webapp/src/app/core/modules/openapi/model/pull-request-dto.ts @@ -0,0 +1,37 @@ +/** + * Hephaestus API + * API documentation for the Hephaestus application server. + * + * The version of the OpenAPI document: 0.0.1 + * Contact: felixtj.dietrich@tum.de + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +import { UserDTO } from './user-dto'; +import { IssueCommentDTO } from './issue-comment-dto'; +import { RepositoryDTO } from './repository-dto'; + + +export interface PullRequestDTO { + id?: number; + title?: string; + url?: string; + state?: PullRequestDTO.StateEnum; + createdAt?: string; + updatedAt?: string; + mergedAt?: string; + author?: UserDTO; + comments?: Set; + repository?: RepositoryDTO; +} +export namespace PullRequestDTO { + export type StateEnum = 'CLOSED' | 'OPEN'; + export const StateEnum = { + Closed: 'CLOSED' as StateEnum, + Open: 'OPEN' as StateEnum + }; +} + + diff --git a/webapp/src/app/core/modules/openapi/model/pull-request.ts b/webapp/src/app/core/modules/openapi/model/pull-request.ts new file mode 100644 index 00000000..c3fc78d7 --- /dev/null +++ b/webapp/src/app/core/modules/openapi/model/pull-request.ts @@ -0,0 +1,40 @@ +/** + * Hephaestus API + * API documentation for the Hephaestus application server. + * + * The version of the OpenAPI document: 0.0.1 + * Contact: felixtj.dietrich@tum.de + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +import { Repository } from './repository'; +import { User } from './user'; +import { IssueComment } from './issue-comment'; + + +export interface PullRequest { + id?: number; + createdAt?: string; + updatedAt?: string; + title: string; + url: string; + /** + * State of the PullRequest. Does not include the state of the merge. + */ + state: PullRequest.StateEnum; + mergedAt?: string; + author?: User; + comments?: Set; + repository?: Repository; +} +export namespace PullRequest { + export type StateEnum = 'CLOSED' | 'OPEN'; + export const StateEnum = { + Closed: 'CLOSED' as StateEnum, + Open: 'OPEN' as StateEnum + }; +} + + diff --git a/webapp/src/app/core/modules/openapi/model/repository-dto.ts b/webapp/src/app/core/modules/openapi/model/repository-dto.ts new file mode 100644 index 00000000..bb31547f --- /dev/null +++ b/webapp/src/app/core/modules/openapi/model/repository-dto.ts @@ -0,0 +1,20 @@ +/** + * Hephaestus API + * API documentation for the Hephaestus application server. + * + * The version of the OpenAPI document: 0.0.1 + * Contact: felixtj.dietrich@tum.de + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export interface RepositoryDTO { + name?: string; + nameWithOwner?: string; + description?: string; + url?: string; +} + diff --git a/webapp/src/app/core/modules/openapi/model/repository.ts b/webapp/src/app/core/modules/openapi/model/repository.ts new file mode 100644 index 00000000..a202a249 --- /dev/null +++ b/webapp/src/app/core/modules/openapi/model/repository.ts @@ -0,0 +1,36 @@ +/** + * Hephaestus API + * API documentation for the Hephaestus application server. + * + * The version of the OpenAPI document: 0.0.1 + * Contact: felixtj.dietrich@tum.de + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +import { PullRequest } from './pull-request'; + + +export interface Repository { + id?: number; + createdAt?: string; + updatedAt?: string; + name: string; + nameWithOwner: string; + description: string; + defaultBranch: string; + visibility: Repository.VisibilityEnum; + url: string; + homepage?: string; + pullRequests?: Set; +} +export namespace Repository { + export type VisibilityEnum = 'PUBLIC' | 'PRIVATE'; + export const VisibilityEnum = { + Public: 'PUBLIC' as VisibilityEnum, + Private: 'PRIVATE' as VisibilityEnum + }; +} + + diff --git a/webapp/src/app/core/modules/openapi/model/user-dto.ts b/webapp/src/app/core/modules/openapi/model/user-dto.ts new file mode 100644 index 00000000..aaaae01b --- /dev/null +++ b/webapp/src/app/core/modules/openapi/model/user-dto.ts @@ -0,0 +1,25 @@ +/** + * Hephaestus API + * API documentation for the Hephaestus application server. + * + * The version of the OpenAPI document: 0.0.1 + * Contact: felixtj.dietrich@tum.de + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +import { PullRequestDTO } from './pull-request-dto'; +import { IssueCommentDTO } from './issue-comment-dto'; + + +export interface UserDTO { + id?: number; + login?: string; + email?: string; + name?: string; + url?: string; + pullRequests?: Set; + comments?: Set; +} + diff --git a/webapp/src/app/core/modules/openapi/model/user.ts b/webapp/src/app/core/modules/openapi/model/user.ts new file mode 100644 index 00000000..fac7f2a3 --- /dev/null +++ b/webapp/src/app/core/modules/openapi/model/user.ts @@ -0,0 +1,40 @@ +/** + * Hephaestus API + * API documentation for the Hephaestus application server. + * + * The version of the OpenAPI document: 0.0.1 + * Contact: felixtj.dietrich@tum.de + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +import { PullRequest } from './pull-request'; +import { IssueComment } from './issue-comment'; + + +export interface User { + id?: number; + createdAt?: string; + updatedAt?: string; + /** + * Unique login identifier for a user. + */ + login: string; + email?: string; + /** + * Display name of the user. + */ + name?: string; + /** + * Unique URL to the user\'s profile. Not the website a user can set in their profile. + */ + url: string; + /** + * URL to the user\'s avatar. If unavailable, a fallback can be generated from the login, e.g. on Github: https://github.com/{login}.png + */ + avatarUrl?: string; + pullRequests?: Set; + comments?: Set; +} + From 40dfc874066d263de7b79d7df6a64e93bb45f103 Mon Sep 17 00:00:00 2001 From: GODrums Date: Mon, 2 Sep 2024 04:32:36 +0200 Subject: [PATCH 48/50] Execute generate:api --- webapp/src/app/core/modules/openapi/.openapi-generator/FILES | 1 + 1 file changed, 1 insertion(+) diff --git a/webapp/src/app/core/modules/openapi/.openapi-generator/FILES b/webapp/src/app/core/modules/openapi/.openapi-generator/FILES index 5137b882..3b9ff517 100644 --- a/webapp/src/app/core/modules/openapi/.openapi-generator/FILES +++ b/webapp/src/app/core/modules/openapi/.openapi-generator/FILES @@ -1,4 +1,5 @@ .gitignore +.openapi-generator-ignore README.md api.module.ts api/admin.service.ts From 9b6ca821b7e96c9847f7829e6e731cd5818d0f8e Mon Sep 17 00:00:00 2001 From: Armin Stanitzok Date: Mon, 2 Sep 2024 05:38:04 +0200 Subject: [PATCH 49/50] Regenerate API from Mac --- server/application-server/openapi.yaml | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/server/application-server/openapi.yaml b/server/application-server/openapi.yaml index 14b7bdf4..22c86182 100644 --- a/server/application-server/openapi.yaml +++ b/server/application-server/openapi.yaml @@ -123,8 +123,9 @@ components: format: int64 timestamp: type: string - description: "Timestamp of when the Hello entity was created.\r\n This field\ - \ is mandatory." + description: |- + Timestamp of when the Hello entity was created. + This field is mandatory. format: date-time IssueCommentDTO: type: object @@ -249,8 +250,9 @@ components: type: string state: type: string - description: "State of the PullRequest.\r\n Does not include the state of\ - \ the merge." + description: |- + State of the PullRequest. + Does not include the state of the merge. enum: - CLOSED - OPEN @@ -331,12 +333,15 @@ components: description: Display name of the user. url: type: string - description: "Unique URL to the user's profile.\r\n Not the website a user\ - \ can set in their profile." + description: |- + Unique URL to the user's profile. + Not the website a user can set in their profile. avatarUrl: type: string - description: "URL to the user's avatar.\r\n If unavailable, a fallback can\ - \ be generated from the login, e.g. on Github:\r\n https://github.com/{login}.png" + description: |- + URL to the user's avatar. + If unavailable, a fallback can be generated from the login, e.g. on Github: + https://github.com/{login}.png pullRequests: uniqueItems: true type: array From 2c822f40d602a0bd077030a0c83405f33b094986 Mon Sep 17 00:00:00 2001 From: Armin Stanitzok Date: Mon, 2 Sep 2024 06:00:38 +0200 Subject: [PATCH 50/50] Another openapi regenerate --- server/application-server/pom.xml | 2 ++ webapp/src/app/core/modules/openapi/model/hello.ts | 2 +- webapp/src/app/core/modules/openapi/model/pull-request.ts | 2 +- webapp/src/app/core/modules/openapi/model/user.ts | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/server/application-server/pom.xml b/server/application-server/pom.xml index 35ca8c00..d13c8cac 100644 --- a/server/application-server/pom.xml +++ b/server/application-server/pom.xml @@ -177,6 +177,8 @@ lombok + 500 + 100 diff --git a/webapp/src/app/core/modules/openapi/model/hello.ts b/webapp/src/app/core/modules/openapi/model/hello.ts index cc49c7a0..e7d27e77 100644 --- a/webapp/src/app/core/modules/openapi/model/hello.ts +++ b/webapp/src/app/core/modules/openapi/model/hello.ts @@ -17,7 +17,7 @@ export interface Hello { */ id?: number; /** - * Timestamp of when the Hello entity was created. This field is mandatory. + * Timestamp of when the Hello entity was created. This field is mandatory. */ timestamp?: string; } diff --git a/webapp/src/app/core/modules/openapi/model/pull-request.ts b/webapp/src/app/core/modules/openapi/model/pull-request.ts index c3fc78d7..e57a8082 100644 --- a/webapp/src/app/core/modules/openapi/model/pull-request.ts +++ b/webapp/src/app/core/modules/openapi/model/pull-request.ts @@ -21,7 +21,7 @@ export interface PullRequest { title: string; url: string; /** - * State of the PullRequest. Does not include the state of the merge. + * State of the PullRequest. Does not include the state of the merge. */ state: PullRequest.StateEnum; mergedAt?: string; diff --git a/webapp/src/app/core/modules/openapi/model/user.ts b/webapp/src/app/core/modules/openapi/model/user.ts index fac7f2a3..d156b36f 100644 --- a/webapp/src/app/core/modules/openapi/model/user.ts +++ b/webapp/src/app/core/modules/openapi/model/user.ts @@ -27,11 +27,11 @@ export interface User { */ name?: string; /** - * Unique URL to the user\'s profile. Not the website a user can set in their profile. + * Unique URL to the user\'s profile. Not the website a user can set in their profile. */ url: string; /** - * URL to the user\'s avatar. If unavailable, a fallback can be generated from the login, e.g. on Github: https://github.com/{login}.png + * URL to the user\'s avatar. If unavailable, a fallback can be generated from the login, e.g. on Github: https://github.com/{login}.png */ avatarUrl?: string; pullRequests?: Set;