-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
98 changed files
with
1,919 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package corea.member.domain; | ||
|
||
public enum AuthRole { | ||
|
||
REVIEWEE, | ||
REVIEWER; | ||
|
||
public boolean isReviewer() { | ||
return this == REVIEWER; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package corea.member.domain; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import static jakarta.persistence.GenerationType.IDENTITY; | ||
|
||
@Entity | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
public class Reviewer { | ||
|
||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
private Long id; | ||
|
||
private String githubUserId; | ||
} |
11 changes: 11 additions & 0 deletions
11
backend/src/main/java/corea/member/dto/MemberRoleResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package corea.member.dto; | ||
|
||
import corea.member.domain.AuthRole; | ||
|
||
public record MemberRoleResponse(String role) { | ||
|
||
public static MemberRoleResponse from(boolean isReviewer) { | ||
AuthRole role = isReviewer ? AuthRole.REVIEWER : AuthRole.REVIEWEE; | ||
return new MemberRoleResponse(role.name()); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
backend/src/main/java/corea/member/repository/ReviewerRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package corea.member.repository; | ||
|
||
import corea.member.domain.Reviewer; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ReviewerRepository extends JpaRepository<Reviewer, Long> { | ||
|
||
boolean existsByGithubUserId(String githubUserId); | ||
} |
20 changes: 20 additions & 0 deletions
20
backend/src/main/java/corea/member/service/MemberService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package corea.member.service; | ||
|
||
import corea.member.domain.MemberReader; | ||
import corea.member.dto.MemberRoleResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class MemberService { | ||
|
||
private final MemberReader memberReader; | ||
|
||
public MemberRoleResponse getMemberRoleWithGithubUserId(String githubUserId) { | ||
boolean isReviewer = memberReader.isReviewer(githubUserId); | ||
return MemberRoleResponse.from(isReviewer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
backend/src/main/java/corea/review/infrastructure/GithubCommentClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package corea.review.infrastructure; | ||
|
||
import corea.auth.infrastructure.GithubProperties; | ||
import corea.review.dto.GithubPullRequestReview; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestClient; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Random; | ||
import java.util.stream.Stream; | ||
|
||
import static org.springframework.http.MediaType.APPLICATION_JSON; | ||
|
||
@EnableConfigurationProperties(GithubProperties.class) | ||
@Component | ||
public class GithubCommentClient { | ||
|
||
private static final Random RANDOM = new Random(); | ||
|
||
private final RestClient restClient; | ||
private final GithubPullRequestUrlExchanger githubPullRequestUrlExchanger; | ||
private final List<String> personalAccessTokens; | ||
|
||
public GithubCommentClient(RestClient restClient, GithubPullRequestUrlExchanger githubPullRequestUrlExchanger, GithubProperties githubProperties) { | ||
this.restClient = restClient; | ||
this.githubPullRequestUrlExchanger = githubPullRequestUrlExchanger; | ||
this.personalAccessTokens = githubProperties.pullRequest() | ||
.tokens(); | ||
} | ||
|
||
public List<GithubPullRequestReview> getPullRequestComments(String prLink) { | ||
String commentApiUrl = githubPullRequestUrlExchanger.pullRequestUrlToComment(prLink); | ||
|
||
return Stream.iterate(1, page -> page + 1) | ||
.map(page -> getPullRequestCommentsForPage(page, commentApiUrl)) | ||
.takeWhile(this::hasMoreComments) | ||
.flatMap(Arrays::stream) | ||
.toList(); | ||
} | ||
|
||
private GithubPullRequestReview[] getPullRequestCommentsForPage(int page, String commentApiUrl) { | ||
String url = buildPageUrl(page, commentApiUrl); | ||
|
||
return restClient.get() | ||
.uri(url) | ||
.header(HttpHeaders.AUTHORIZATION, getRandomPersonalAccessToken()) | ||
.accept(APPLICATION_JSON) | ||
.retrieve() | ||
.body(GithubPullRequestReview[].class); | ||
} | ||
|
||
private String buildPageUrl(int page, String commentApiUrl) { | ||
return commentApiUrl + "?page=" + page + "&per_page=100"; | ||
} | ||
|
||
private boolean hasMoreComments(GithubPullRequestReview[] comments) { | ||
return comments.length > 0; | ||
} | ||
|
||
private String getRandomPersonalAccessToken() { | ||
if (personalAccessTokens.isEmpty()) { | ||
return ""; | ||
} | ||
return "Bearer " + personalAccessTokens.get(RANDOM.nextInt(personalAccessTokens.size())); | ||
} | ||
} |
Oops, something went wrong.