Skip to content

Commit

Permalink
fix: 레포지토리 조회 메서드가 레포지토리 링크를 받도록 수정 (#750)
Browse files Browse the repository at this point in the history
* fix: 레포지토리 조회 메서드가 적절한 값을 받도로 수정

* remove: 메서드 중복 호출 제거
  • Loading branch information
Sangwook02 authored Sep 4, 2024
1 parent e44cabc commit 920825d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 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 @@ -107,4 +108,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 920825d

Please sign in to comment.