Skip to content

Commit

Permalink
Profile Pages with User Activity and PRs (#115)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Felix T.J. Dietrich <[email protected]>
Co-authored-by: Felix T.J. Dietrich <[email protected]>
  • Loading branch information
4 people authored Oct 18, 2024
1 parent d08c7f4 commit 511c515
Show file tree
Hide file tree
Showing 45 changed files with 1,256 additions and 187 deletions.
153 changes: 124 additions & 29 deletions server/application-server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/UserDTO"
/user/{login}/profile:
get:
tags:
- user
operationId: getUserProfile
parameters:
- name: login
in: path
required: true
schema:
type: string
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/UserProfileDTO"
/user/{login}/full:
get:
tags:
Expand Down Expand Up @@ -176,36 +194,74 @@ components:
pullRequest:
$ref: "#/components/schemas/PullRequestDTO"
PullRequestDTO:
required:
- additions
- createdAt
- deletions
- id
- number
- state
- title
- updatedAt
- url
type: object
properties:
id:
type: integer
format: int64
title:
type: string
number:
type: integer
format: int32
url:
type: string
state:
type: string
enum:
- CLOSED
- OPEN
additions:
type: integer
format: int32
deletions:
type: integer
format: int32
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
mergedAt:
type: string
format: date-time
author:
$ref: "#/components/schemas/UserDTO"
comments:
uniqueItems: true
type: array
items:
$ref: "#/components/schemas/IssueCommentDTO"
labels:
uniqueItems: true
type: array
items:
$ref: "#/components/schemas/PullRequestLabel"
repository:
$ref: "#/components/schemas/RepositoryDTO"
PullRequestLabel:
type: object
properties:
name:
type: string
color:
type: string
RepositoryDTO:
required:
- name
- nameWithOwner
- url
type: object
properties:
name:
Expand Down Expand Up @@ -240,6 +296,72 @@ components:
type: array
items:
$ref: "#/components/schemas/IssueCommentDTO"
PullRequestReviewDTO:
required:
- createdAt
- id
- state
- submittedAt
- updatedAt
type: object
properties:
id:
type: integer
format: int64
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
submittedAt:
type: string
format: date-time
state:
type: string
enum:
- COMMENTED
- APPROVED
- CHANGES_REQUESTED
- DISMISSED
url:
type: string
pullRequest:
$ref: "#/components/schemas/PullRequestDTO"
UserProfileDTO:
required:
- avatarUrl
- firstContribution
- id
- login
- repositories
type: object
properties:
id:
type: integer
format: int64
login:
type: string
avatarUrl:
type: string
firstContribution:
type: string
format: date-time
repositories:
uniqueItems: true
type: array
items:
type: string
activity:
uniqueItems: true
type: array
items:
$ref: "#/components/schemas/PullRequestReviewDTO"
pullRequests:
uniqueItems: true
type: array
items:
$ref: "#/components/schemas/PullRequestDTO"
IssueComment:
type: object
properties:
Expand Down Expand Up @@ -323,13 +445,6 @@ components:
type: array
items:
$ref: "#/components/schemas/PullRequestLabel"
PullRequestLabel:
type: object
properties:
name:
type: string
color:
type: string
PullRequestReview:
required:
- state
Expand All @@ -356,6 +471,8 @@ components:
submittedAt:
type: string
format: date-time
url:
type: string
comments:
uniqueItems: true
type: array
Expand Down Expand Up @@ -528,28 +645,6 @@ components:
type: array
items:
$ref: "#/components/schemas/PullRequestReviewDTO"
PullRequestReviewDTO:
type: object
properties:
id:
type: integer
format: int64
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
submittedAt:
type: string
format: date-time
state:
type: string
enum:
- COMMENTED
- APPROVED
- CHANGES_REQUESTED
- DISMISSED
UserInfoDto:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,12 @@ public void addComment(IssueComment comment) {
public void addReview(PullRequestReview review) {
reviews.add(review);
}

public Integer getAdditions() {
return additions;
}

public Integer getDeletions() {
return deletions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ private IssueState convertState(org.kohsuke.github.GHIssueState state) {
private Set<PullRequestLabel> convertLabels(Collection<GHLabel> labels) {
Set<PullRequestLabel> pullRequestLabels = new HashSet<>();
for (GHLabel label : labels) {
PullRequestLabel pullRequestLabel = new PullRequestLabel();
pullRequestLabel.setName(label.getName());
pullRequestLabel.setColor(label.getColor());
PullRequestLabel pullRequestLabel = new PullRequestLabel(label.getName(), label.getColor());
pullRequestLabels.add(pullRequestLabel);
}
return pullRequestLabels;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
package de.tum.in.www1.hephaestus.codereview.pullrequest;

import java.time.OffsetDateTime;
import java.util.Set;

import org.springframework.lang.NonNull;

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(Long id, String title, String url, IssueState state, String createdAt, String updatedAt,
String mergedAt, UserDTO author, Set<IssueCommentDTO> comments, RepositoryDTO repository) {
public PullRequestDTO(Long id, String title, String url, IssueState state, String createdAt, String updatedAt,
String mergedAt) {
this(id, title, url, state, createdAt, updatedAt, mergedAt, null, null, null);
public record PullRequestDTO(@NonNull Long id, @NonNull String title, @NonNull Integer number, @NonNull String url,
@NonNull IssueState state, @NonNull Integer additions, @NonNull Integer deletions,
@NonNull OffsetDateTime createdAt, @NonNull OffsetDateTime updatedAt, OffsetDateTime mergedAt,
UserDTO author, Set<IssueCommentDTO> comments, Set<PullRequestLabel> labels, RepositoryDTO repository) {
public PullRequestDTO(@NonNull Long id, @NonNull String title, @NonNull Integer number, @NonNull String url,
@NonNull IssueState state, @NonNull Integer additions, @NonNull Integer deletions,
@NonNull OffsetDateTime createdAt, @NonNull OffsetDateTime updatedAt, OffsetDateTime mergedAt) {
this(id, title, number, url, state, additions, deletions, createdAt, updatedAt, mergedAt, null, null,
null,
null);
}

public PullRequestDTO(@NonNull Long id, @NonNull String title, @NonNull Integer number, @NonNull String url,
@NonNull IssueState state, @NonNull Integer additions,
@NonNull Integer deletions, @NonNull OffsetDateTime createdAt,
@NonNull OffsetDateTime updatedAt, OffsetDateTime mergedAt,
@NonNull Set<PullRequestLabel> labels,
@NonNull RepositoryDTO repository) {
this(id, title, number, url, state, additions, deletions, createdAt, updatedAt, mergedAt, null, null,
labels, repository);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package de.tum.in.www1.hephaestus.codereview.pullrequest;

import jakarta.persistence.Embeddable;
import lombok.Getter;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;

@Embeddable
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class PullRequestLabel {
@NonNull
private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class PullRequestReview extends BaseGitServiceEntity {

private OffsetDateTime submittedAt;

private String url;

@OneToMany(cascade = CascadeType.REFRESH, mappedBy = "review")
@ToString.Exclude
private Set<PullRequestReviewComment> comments = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public PullRequestReview convert(@NonNull GHPullRequestReview source) {
public PullRequestReview update(@NonNull GHPullRequestReview source, @NonNull PullRequestReview review) {
convertBaseFields(source, review);
review.setState(convertState(source.getState()));
review.setUrl(source.getHtmlUrl().toString());
try {
review.setSubmittedAt(convertToOffsetDateTime(source.getSubmittedAt()));
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,25 @@

import java.time.OffsetDateTime;

import org.springframework.lang.NonNull;

import com.fasterxml.jackson.annotation.JsonInclude;

import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequestDTO;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public record PullRequestReviewDTO(Long id, OffsetDateTime createdAt, OffsetDateTime updatedAt,
OffsetDateTime submittedAt, PullRequestReviewState state) {
public record PullRequestReviewDTO(@NonNull Long id, @NonNull OffsetDateTime createdAt,
@NonNull OffsetDateTime updatedAt, @NonNull OffsetDateTime submittedAt,
@NonNull PullRequestReviewState state, String url, PullRequestDTO pullRequest) {
public PullRequestReviewDTO(@NonNull Long id, @NonNull OffsetDateTime createdAt,
@NonNull OffsetDateTime updatedAt, @NonNull OffsetDateTime submittedAt,
@NonNull PullRequestReviewState state) {
this(id, createdAt, updatedAt, submittedAt, state, null, null);
}

public PullRequestReviewDTO(@NonNull Long id, @NonNull OffsetDateTime createdAt,
@NonNull OffsetDateTime updatedAt, @NonNull OffsetDateTime submittedAt,
@NonNull PullRequestReviewState state, String url) {
this(id, createdAt, updatedAt, submittedAt, state, url, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

import java.util.Set;

import org.springframework.lang.NonNull;

import com.fasterxml.jackson.annotation.JsonInclude;

import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequestDTO;

public record RepositoryDTO(String name, String nameWithOwner, String description, String url,
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public record RepositoryDTO(@NonNull String name, @NonNull String nameWithOwner, String description,
@NonNull String url,
Set<PullRequestDTO> pullRequests) {
public RepositoryDTO(String name, String nameWithOwner, String description, String url) {
public RepositoryDTO(@NonNull String name, @NonNull String nameWithOwner, String description, @NonNull String url) {
this(name, nameWithOwner, description, url, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ public ResponseEntity<User> getFullUser(@PathVariable String login) {
System.out.println(user);
return user.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
}

@GetMapping("/{login}/profile")
public ResponseEntity<UserProfileDTO> getUserProfile(@PathVariable String login) {
Optional<UserProfileDTO> userProfile = userService.getUserProfileDTO(login);
return userProfile.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public User update(@NonNull GHUser source, @NonNull User user) {
logger.error("Failed to convert user email field for source {}: {}", source.getId(), e.getMessage());
}
try {
user.setName(source.getName());
user.setName(source.getName() != null ? source.getName() : source.getLogin());
} catch (IOException e) {
logger.error("Failed to convert user name field for source {}: {}", source.getId(), e.getMessage());
}
Expand Down
Loading

0 comments on commit 511c515

Please sign in to comment.