Skip to content

Commit

Permalink
Create GraphQL connection relations
Browse files Browse the repository at this point in the history
  • Loading branch information
GODrums committed Aug 18, 2024
1 parent 8df40a6 commit 5ff5a8b
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<Comment> nodes;

@OneToOne(mappedBy = "comments", fetch = FetchType.LAZY)
private Pullrequest pullrequest;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -83,13 +84,14 @@ public class Pullrequest {
/**
* The comments of the Pullrequest entity.
*/
@OneToMany(mappedBy = "pullrequest", fetch = FetchType.LAZY)
private List<Comment> 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;
}
Original file line number Diff line number Diff line change
@@ -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<Pullrequest> nodes;

@OneToOne(mappedBy = "pullRequests", fetch = FetchType.LAZY)
private Repository repository;
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<Pullrequest> 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 + "]";
}
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
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
createdAt
updatedAt
mergedAt
author {
avatarUrl
login
url
...authorFields
}
comments(last: 100) {
nodes {
id
githubId: id
body
createdAt
updatedAt
author {
avatarUrl
login
url
...authorFields
}
}
}
}
}
}
}

fragment authorFields on Actor {
avatarUrl
login
url
}

0 comments on commit 5ff5a8b

Please sign in to comment.