-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 가장 최신 깃허브 과제 제출이력 조회 기능 구현 (#626)
* docs: 투두 추가 * chore: 로컬 환경에서 깃허브 라이브러리 로깅 설정 * refactor: 깃허브 클라이언트 패키지 변경 * feat: 깃허브 과제 경로 상수 추가 * feat: 깃허브 과제 없는 경우 예외 에러코드 추가 * feat: 가장 최신 제출이력 조회 로직 구현 * docs: 주석 추가 * feat: 응답에 커밋 해시 추가
- Loading branch information
Showing
8 changed files
with
71 additions
and
27 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
24 changes: 0 additions & 24 deletions
24
src/main/java/com/gdschongik/gdsc/infra/client/github/GithubClient.java
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
src/main/java/com/gdschongik/gdsc/infra/github/client/GithubClient.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,59 @@ | ||
package com.gdschongik.gdsc.infra.github.client; | ||
|
||
import static com.gdschongik.gdsc.global.common.constant.GithubConstant.*; | ||
|
||
import com.gdschongik.gdsc.global.exception.CustomException; | ||
import com.gdschongik.gdsc.global.exception.ErrorCode; | ||
import com.gdschongik.gdsc.infra.github.dto.response.GithubAssignmentSubmissionResponse; | ||
import java.io.IOException; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import lombok.RequiredArgsConstructor; | ||
import org.kohsuke.github.GHCommit; | ||
import org.kohsuke.github.GHContent; | ||
import org.kohsuke.github.GHRepository; | ||
import org.kohsuke.github.GitHub; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class GithubClient { | ||
|
||
private final GitHub github; | ||
|
||
public GHRepository getRepository(String ownerRepo) { | ||
try { | ||
return github.getRepository(ownerRepo); | ||
} catch (IOException e) { | ||
throw new CustomException(ErrorCode.GITHUB_REPOSITORY_NOT_FOUND); | ||
} | ||
} | ||
|
||
public GithubAssignmentSubmissionResponse getLatestAssignmentSubmission(String repo, int week) { | ||
try { | ||
GHRepository ghRepository = getRepository(repo); | ||
String assignmentPath = GITHUB_ASSIGNMENT_PATH.formatted(week); | ||
|
||
// GHContent#getSize() 의 경우 한글 문자열을 byte 단위로 계산하기 때문에, 직접 content를 읽어서 길이를 계산 | ||
GHContent ghContent = ghRepository.getFileContent(assignmentPath); | ||
String content = new String(ghContent.read().readAllBytes()); | ||
|
||
GHCommit ghLatestCommit = ghRepository | ||
.queryCommits() | ||
.path(assignmentPath) | ||
.list() | ||
.toList() | ||
.get(0); | ||
|
||
LocalDateTime committedAt = ghLatestCommit | ||
.getCommitDate() | ||
.toInstant() | ||
.atZone(ZoneId.systemDefault()) | ||
.toLocalDateTime(); | ||
|
||
return new GithubAssignmentSubmissionResponse(ghLatestCommit.getSHA1(), content.length(), committedAt); | ||
} catch (IOException e) { | ||
throw new CustomException(ErrorCode.GITHUB_ASSIGNMENT_NOT_FOUND); | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...ava/com/gdschongik/gdsc/infra/github/dto/response/GithubAssignmentSubmissionResponse.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,5 @@ | ||
package com.gdschongik.gdsc.infra.github.dto.response; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record GithubAssignmentSubmissionResponse(String commitHash, Integer size, LocalDateTime committedAt) {} |
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