Skip to content

Commit

Permalink
fix: 레포지토리 조회 메서드가 적절한 값을 받도로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangwook02 committed Sep 4, 2024
1 parent e44cabc commit 42a6e42
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gdschongik.gdsc.domain.study.application;

import static com.gdschongik.gdsc.global.common.constant.GithubConstant.*;
import static com.gdschongik.gdsc.global.exception.ErrorCode.*;

import com.gdschongik.gdsc.domain.member.domain.Member;
Expand Down Expand Up @@ -56,8 +55,7 @@ public void updateRepository(Long studyId, RepositoryUpdateRequest request) thro

boolean isAnyAssignmentSubmitted =
assignmentHistoryRepository.existsSubmittedAssignmentByMemberAndStudy(currentMember, study);
String ownerRepo = getOwnerRepo(request.repositoryLink());
GHRepository repository = githubClient.getRepository(ownerRepo);
GHRepository repository = githubClient.getRepository(request.repositoryLink());
// TODO: GHRepository 등을 wrapper로 감싸서 테스트 가능하도록 변경
studyHistoryValidator.validateUpdateRepository(
isAnyAssignmentSubmitted, String.valueOf(repository.getOwner().getId()), currentMember.getOauthId());
Expand All @@ -71,11 +69,6 @@ public void updateRepository(Long studyId, RepositoryUpdateRequest request) thro
request.repositoryLink());
}

private String getOwnerRepo(String repositoryLink) {
int startIndex = repositoryLink.indexOf(GITHUB_DOMAIN) + GITHUB_DOMAIN.length();
return repositoryLink.substring(startIndex);
}

@Transactional(readOnly = true)
public List<AssignmentHistoryResponse> getAllAssignmentHistories(Long studyId) {
Member currentMember = memberUtil.getCurrentMember();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public class GithubClient {
private final GitHub github;
private final GitHubConnector gitHubConnector = GitHubConnector.DEFAULT;

public GHRepository getRepository(String ownerRepo) {
public GHRepository getRepository(String repo) {
try {
String ownerRepo = getOwnerRepo(repo);
return github.getRepository(ownerRepo);
} catch (IOException e) {
throw new CustomException(GITHUB_REPOSITORY_NOT_FOUND);
Expand Down Expand Up @@ -59,7 +60,8 @@ public AssignmentSubmissionFetcher getLatestAssignmentSubmissionFetcher(String r
}

private AssignmentSubmission getLatestAssignmentSubmission(String repo, int week) {
GHRepository ghRepository = getRepository(repo);
String ownerRepo = getOwnerRepo(repo);
GHRepository ghRepository = getRepository(ownerRepo);
String assignmentPath = GITHUB_ASSIGNMENT_PATH.formatted(week);

// GHContent#getSize() 의 경우 한글 문자열을 byte 단위로 계산하기 때문에, 직접 content를 읽어서 길이를 계산
Expand Down Expand Up @@ -107,4 +109,9 @@ private LocalDateTime getCommitDate(GHCommit ghLatestCommit) {
throw new CustomException(GITHUB_COMMIT_DATE_FETCH_FAILED);
}
}

private String getOwnerRepo(String repositoryLink) {
int startIndex = repositoryLink.indexOf(GITHUB_DOMAIN) + GITHUB_DOMAIN.length();
return repositoryLink.substring(startIndex);
}
}

0 comments on commit 42a6e42

Please sign in to comment.