Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create activity endpoint returning pull requests with bad practices(#… #200

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 150 additions & 65 deletions server/application-server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,24 @@ paths:
type: array
items:
$ref: "#/components/schemas/LeaderboardEntry"
/activity/{login}:
get:
tags:
- activity
operationId: getActivityByUser
parameters:
- name: login
in: path
required: true
schema:
type: string
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Activity"
/workspace/team/{teamId}:
delete:
tags:
Expand Down Expand Up @@ -434,22 +452,6 @@ components:
updatedAt:
type: string
format: date-time
LabelInfo:
required:
- color
- id
- name
type: object
properties:
id:
type: integer
format: int64
name:
type: string
color:
type: string
repository:
$ref: "#/components/schemas/RepositoryInfo"
UserProfile:
required:
- contributedRepositories
Expand Down Expand Up @@ -493,81 +495,80 @@ components:
type: string
htmlUrl:
type: string
PullRequestReviewInfo:
UserTeams:
required:
- codeComments
- htmlUrl
- id
- isDismissed
- score
- state
- login
- name
- teams
- url
type: object
properties:
id:
type: integer
format: int64
isDismissed:
type: boolean
state:
login:
type: string
enum:
- COMMENTED
- APPROVED
- CHANGES_REQUESTED
- UNKNOWN
codeComments:
type: integer
format: int32
author:
$ref: "#/components/schemas/UserInfo"
pullRequest:
$ref: "#/components/schemas/PullRequestBaseInfo"
htmlUrl:
name:
type: string
score:
type: integer
format: int32
submittedAt:
url:
type: string
format: date-time
MetaData:
required:
- scheduledDay
- scheduledTime
- teams
type: object
properties:
teams:
uniqueItems: true
type: array
items:
$ref: "#/components/schemas/TeamInfo"
scheduledDay:
type: string
scheduledTime:
type: string
UserTeams:
PullRequestWithBadPractices:
required:
- additions
- deletions
- htmlUrl
- id
- login
- name
- teams
- url
- isDraft
- isMerged
- number
- state
- title
type: object
properties:
id:
type: integer
format: int64
login:
number:
type: integer
format: int32
title:
type: string
name:
state:
type: string
url:
enum:
- OPEN
- CLOSED
isDraft:
type: boolean
isMerged:
type: boolean
labels:
type: array
items:
$ref: "#/components/schemas/LabelInfo"
repository:
$ref: "#/components/schemas/RepositoryInfo"
additions:
type: integer
format: int32
deletions:
type: integer
format: int32
htmlUrl:
type: string
teams:
uniqueItems: true
createdAt:
type: string
format: date-time
badPractices:
type: array
items:
$ref: "#/components/schemas/TeamInfo"
$ref: "#/components/schemas/PullRequestBadPractice"
PullRequestBaseInfo:
required:
- htmlUrl
Expand Down Expand Up @@ -600,6 +601,15 @@ components:
$ref: "#/components/schemas/RepositoryInfo"
htmlUrl:
type: string
Activity:
required:
- pullRequests
type: object
properties:
pullRequests:
type: array
items:
$ref: "#/components/schemas/PullRequestWithBadPractices"
UserInfo:
required:
- avatarUrl
Expand Down Expand Up @@ -646,6 +656,81 @@ components:
type: array
items:
$ref: "#/components/schemas/LabelInfo"
PullRequestBadPractice:
type: object
properties:
title:
type: string
description:
type: string
LabelInfo:
required:
- color
- id
- name
type: object
properties:
id:
type: integer
format: int64
name:
type: string
color:
type: string
repository:
$ref: "#/components/schemas/RepositoryInfo"
PullRequestReviewInfo:
required:
- codeComments
- htmlUrl
- id
- isDismissed
- score
- state
type: object
properties:
id:
type: integer
format: int64
isDismissed:
type: boolean
state:
type: string
enum:
- COMMENTED
- APPROVED
- CHANGES_REQUESTED
- UNKNOWN
codeComments:
type: integer
format: int32
author:
$ref: "#/components/schemas/UserInfo"
pullRequest:
$ref: "#/components/schemas/PullRequestBaseInfo"
htmlUrl:
type: string
score:
type: integer
format: int32
submittedAt:
type: string
format: date-time
MetaData:
required:
- scheduledDay
- scheduledTime
- teams
type: object
properties:
teams:
type: array
items:
$ref: "#/components/schemas/TeamInfo"
scheduledDay:
type: string
scheduledTime:
type: string
LeaderboardEntry:
required:
- numberOfApprovals
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package de.tum.in.www1.hephaestus.activity;

import org.springframework.beans.factory.annotation.Autowired;
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;

@RestController
@RequestMapping("/activity")
public class ActivityController {

@Autowired
private ActivityService activityService;

@GetMapping("/{login}")
public ResponseEntity<ActivityDTO> getActivityByUser(@PathVariable String login) {
ActivityDTO activity = activityService.getActivity(login);
return ResponseEntity.ok(activity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package de.tum.in.www1.hephaestus.activity;

import io.micrometer.common.lang.NonNull;

import java.util.List;

public record ActivityDTO(
@NonNull List<PullRequestWithBadPracticesDTO> pullRequests) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package de.tum.in.www1.hephaestus.activity;

import de.tum.in.www1.hephaestus.gitprovider.issue.Issue;
import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequest;
import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequestRepository;
import jakarta.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class ActivityService {

@Autowired
private PullRequestRepository pullRequestRepository;

@Autowired
private PullRequestBadPracticeRepository pullRequestBadPracticeRepository;

@Transactional
public ActivityDTO getActivity(String login) {

List<PullRequest> pullRequests = pullRequestRepository
.findAssignedByLoginAndStates(login, Set.of(Issue.State.OPEN));

List<PullRequestBadPractice> openPulLRequestBadPractices = pullRequestBadPracticeRepository.findByLogin(login);

Map<PullRequest, List<PullRequestBadPracticeDTO>> pullRequestBadPracticesMap = openPulLRequestBadPractices.stream()
.collect(Collectors.groupingBy(
PullRequestBadPractice::getPullrequest,
Collectors.collectingAndThen(
Collectors.toList(),
list -> list.stream()
.map(PullRequestBadPractice::getType)
.distinct()
.map(PullRequestBadPracticeDTO::fromPullRequestBadPracticeType)
.collect(Collectors.toList())
)
));

List<PullRequestWithBadPracticesDTO> openPullRequestsWithBadPractices = pullRequests.stream()
.map(pullRequest -> PullRequestWithBadPracticesDTO.fromPullRequest(pullRequest,
pullRequestBadPracticesMap.getOrDefault(pullRequest, List.of()))
)
.collect(Collectors.toList());

return new ActivityDTO(openPullRequestsWithBadPractices);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.tum.in.www1.hephaestus.activity;

import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequest;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Entity
@Getter
@Setter
@NoArgsConstructor
@ToString
public class PullRequestBadPractice {

@Id
private Long id;

private PullRequestBadPracticeType type;

@ManyToOne
@JoinColumn(name = "pullrequest_id")
private PullRequest pullrequest;
}
Loading
Loading