Skip to content

Conversation

@thezz9
Copy link
Collaborator

@thezz9 thezz9 commented Jul 23, 2025

깃허브 이벤트 발행 위치 변경 및 테스트 코드 수정했습니다.

output 이 null 일 때의 방어코드도 추가했습니다

Summary by CodeRabbit

  • 신규 기능

    • 소스 코드가 새롭거나 변경된 경우에만 GitHub 저장소로 커밋 및 푸시가 이루어지도록 동작이 개선되었습니다.
  • 버그 수정

    • 테스트케이스 출력값 반환 시 null 체크가 추가되어 예외 발생 가능성이 줄었습니다.
  • 테스트

    • 소스 코드 변경이 없는 경우 푸시가 발생하지 않음을 검증하는 테스트가 추가되었습니다.
    • 기존 푸시 성공/실패 테스트가 새로운 동작 방식에 맞게 보완되었습니다.
  • 리팩터링

    • 내부 메서드 구조가 개선되어 코드의 명확성과 유지보수성이 향상되었습니다.

@thezz9 thezz9 self-assigned this Jul 23, 2025
@thezz9 thezz9 added the enhancement New feature or request label Jul 23, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 23, 2025

Walkthrough

이 변경은 SubmissionContext의 제출 카운터 증가 메서드 제거, GitHub 소스코드 변경 여부를 확인하는 메서드 추가 및 활용, 관련 서비스 로직 분기 추가, 테스트케이스 null 체크 보강, 그리고 이에 따른 테스트 코드 갱신 및 신규 테스트 추가를 포함합니다.

Changes

파일/경로 요약 변경 요약
.../submission/model/SubmissionContext.java incrementTotalSubmissions, incrementCorrectSubmissions 메서드 제거
.../submission/port/GitHubClient.java
.../infrastructure/github/GitHubClientImpl.java
isSourceCodeNewOrChanged(GitHubPushRequest req) 메서드 추가, 기존 push 로직 분리 및 정비
.../submission/service/GitHubPushService.java 소스코드 변경 여부 확인 후 push 및 이벤트 발행 분기 추가
.../problem/model/entity/Testcase.java getOutput()에서 null 체크 추가
.../submission/GitHubPushServiceTest.java 소스코드 미변경 시 push 미수행 테스트 추가 및 기존 테스트에 mock/stub 보강
.../infrastructure/github/GitHubClientTest.java 내부 mock, 검증 방식 및 변수명 정비, 메서드 호출/검증 방식 변경

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GitHubPushService
    participant GitHubClient
    participant EventPublisher

    User->>GitHubPushService: pushSolutionToRepo(ctx)
    GitHubPushService->>GitHubClient: isSourceCodeNewOrChanged(req)
    alt 코드 변경 없음
        GitHubClient-->>GitHubPushService: false
        GitHubPushService-->>User: (아무 작업 없음, 조기 종료)
    else 코드 변경 있음
        GitHubClient-->>GitHubPushService: true
        GitHubPushService->>EventPublisher: publish(GitPushStatusStarted)
        GitHubPushService->>GitHubClient: commitAndPushToRepo(req)
        GitHubClient-->>GitHubPushService: (push 완료)
        GitHubPushService->>EventPublisher: publish(GitPushStatusSucceeded)
    end
Loading

Estimated code review effort

2 (~15분)

Possibly related PRs

Suggested labels

Test, bug

Suggested reviewers

  • minjee2758
  • NCookies
  • Kimminu7
  • chat26666
  • pokerbearkr

Poem

깡총깡총 토끼가 코드를 본다,
중복된 push는 이제 안녕이라!
변경된 코드만 살짝살짝,
테스트도 꼼꼼히 챙겨봤다.
깔끔한 흐름에 토끼는 방긋,
🐰✨ 오늘도 리뷰는 순조롭다!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/main/java/org/ezcode/codetest/infrastructure/github/GitHubClientImpl.java (1)

31-44: 중복 계산 최적화를 고려해보세요.

commitAndPushToRepo에서 codeBlobSha를 다시 계산하고 있는데, isSourceCodeNewOrChanged에서 이미 계산했으므로 중복입니다. 성능상 큰 문제는 아니지만 최적화할 수 있습니다.

다음과 같이 최적화할 수 있습니다:

public void commitAndPushToRepo(GitHubPushRequest req) {
-    String codeBlobSha = blobCalculator.calculateBlobSha(req.sourceCode());
+    String codeBlobSha = blobCalculator.calculateBlobSha(req.sourceCode());
    
    List<Map<String, Object>> entries = templateBuilder.buildGitTreeEntries(req, codeBlobSha);
    // ... 나머지 로직
}

또는 GitHubPushRequestcodeBlobSha를 캐시하는 방법도 고려할 수 있습니다.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b55eb66 and 3bb6639.

📒 Files selected for processing (7)
  • src/main/java/org/ezcode/codetest/application/submission/model/SubmissionContext.java (0 hunks)
  • src/main/java/org/ezcode/codetest/application/submission/port/GitHubClient.java (1 hunks)
  • src/main/java/org/ezcode/codetest/application/submission/service/GitHubPushService.java (1 hunks)
  • src/main/java/org/ezcode/codetest/domain/problem/model/entity/Testcase.java (1 hunks)
  • src/main/java/org/ezcode/codetest/infrastructure/github/GitHubClientImpl.java (1 hunks)
  • src/test/java/org/ezcode/codetest/application/submission/GitHubPushServiceTest.java (3 hunks)
  • src/test/java/org/ezcode/codetest/infrastructure/github/GitHubClientTest.java (2 hunks)
🧠 Learnings (1)
📓 Common learnings
Learnt from: thezz9
PR: ezcode-my/backend#114
File: src/main/java/org/ezcode/codetest/infrastructure/github/GitHubApiClient.java:159-165
Timestamp: 2025-06-28T02:03:38.693Z
Learning: User thezz9's service (ezcode) targets Korean users exclusively ("찐 한국인밖에 안 옴"), so Korean language hardcoding in commit messages and UI elements is intentional and appropriate for their use case.
Learnt from: thezz9
PR: ezcode-my/backend#36
File: src/main/java/org/ezcode/codetest/domain/submission/dto/SubmissionData.java:47-58
Timestamp: 2025-06-06T07:59:41.806Z
Learning: SubmissionData.withAggregatedStats() 메서드에서 testCaseList는 상위 프로세스(base() 메서드의 problemInfo.testcaseList())에서 이미 null 체크가 처리되어 오므로 추가적인 null 체크가 불필요함
Learnt from: thezz9
PR: ezcode-my/backend#75
File: src/main/java/org/ezcode/codetest/application/submission/aop/CodeReviewLockAspect.java:25-41
Timestamp: 2025-06-19T06:37:57.845Z
Learning: User thezz9 tends to skip validation for scenarios they consider unlikely to occur, but is willing to implement defensive programming practices when suggested for code robustness.
Learnt from: thezz9
PR: ezcode-my/backend#114
File: src/main/java/org/ezcode/codetest/infrastructure/github/GitHubApiClient.java:93-96
Timestamp: 2025-06-28T02:04:24.957Z
Learning: User thezz9 sometimes temporarily uses less secure or inconsistent exception handling (like RuntimeException with raw error bodies) for debugging purposes when error messages are being hidden in the normal application flow, but acknowledges this as technical debt and fixes it once debugging is complete.
Learnt from: thezz9
PR: ezcode-my/backend#132
File: src/main/java/org/ezcode/codetest/infrastructure/github/GitHubContentBuilder.java:72-72
Timestamp: 2025-07-02T09:39:31.485Z
Learning: User thezz9 prefers to proceed with breaking changes to path structures when it improves the organization, rather than maintaining backward compatibility or implementing migration strategies.
💤 Files with no reviewable changes (1)
  • src/main/java/org/ezcode/codetest/application/submission/model/SubmissionContext.java
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: thezz9
PR: ezcode-my/backend#114
File: src/main/java/org/ezcode/codetest/infrastructure/github/GitHubApiClient.java:159-165
Timestamp: 2025-06-28T02:03:38.693Z
Learning: User thezz9's service (ezcode) targets Korean users exclusively ("찐 한국인밖에 안 옴"), so Korean language hardcoding in commit messages and UI elements is intentional and appropriate for their use case.
Learnt from: thezz9
PR: ezcode-my/backend#36
File: src/main/java/org/ezcode/codetest/domain/submission/dto/SubmissionData.java:47-58
Timestamp: 2025-06-06T07:59:41.806Z
Learning: SubmissionData.withAggregatedStats() 메서드에서 testCaseList는 상위 프로세스(base() 메서드의 problemInfo.testcaseList())에서 이미 null 체크가 처리되어 오므로 추가적인 null 체크가 불필요함
Learnt from: thezz9
PR: ezcode-my/backend#75
File: src/main/java/org/ezcode/codetest/application/submission/aop/CodeReviewLockAspect.java:25-41
Timestamp: 2025-06-19T06:37:57.845Z
Learning: User thezz9 tends to skip validation for scenarios they consider unlikely to occur, but is willing to implement defensive programming practices when suggested for code robustness.
Learnt from: thezz9
PR: ezcode-my/backend#114
File: src/main/java/org/ezcode/codetest/infrastructure/github/GitHubApiClient.java:93-96
Timestamp: 2025-06-28T02:04:24.957Z
Learning: User thezz9 sometimes temporarily uses less secure or inconsistent exception handling (like RuntimeException with raw error bodies) for debugging purposes when error messages are being hidden in the normal application flow, but acknowledges this as technical debt and fixes it once debugging is complete.
Learnt from: thezz9
PR: ezcode-my/backend#132
File: src/main/java/org/ezcode/codetest/infrastructure/github/GitHubContentBuilder.java:72-72
Timestamp: 2025-07-02T09:39:31.485Z
Learning: User thezz9 prefers to proceed with breaking changes to path structures when it improves the organization, rather than maintaining backward compatibility or implementing migration strategies.
🔇 Additional comments (11)
src/main/java/org/ezcode/codetest/domain/problem/model/entity/Testcase.java (1)

61-62: 방어적 프로그래밍 개선이 잘 적용되었습니다.

getInput() 메서드와 동일한 패턴으로 null 체크를 추가하여 NullPointerException 발생을 방지했습니다. 일관성 있고 안전한 구현입니다.

src/main/java/org/ezcode/codetest/application/submission/port/GitHubClient.java (1)

7-7: 인터페이스 개선이 잘 구현되었습니다.

소스코드 변경 여부 확인 로직을 별도 메서드로 분리하여 단일 책임 원칙을 준수하고, 불필요한 푸시 작업을 방지할 수 있게 되었습니다.

src/main/java/org/ezcode/codetest/application/submission/service/GitHubPushService.java (1)

32-41: GitHub 이벤트 발행 위치 변경이 적절히 구현되었습니다.

소스코드 변경 여부를 먼저 확인한 후 실제 푸시가 필요한 경우에만 이벤트를 발행하도록 최적화되었습니다. 불필요한 GitHub API 호출과 이벤트 발행을 방지하는 효율적인 구조입니다.

src/test/java/org/ezcode/codetest/application/submission/GitHubPushServiceTest.java (2)

108-138: 새로운 테스트 케이스가 잘 구현되었습니다.

코드 변경이 없을 때의 동작을 정확히 검증하고 있습니다. 푸시 작업과 이벤트 발행이 모두 생략되는지 확인하는 적절한 테스트입니다.


159-159: 기존 테스트 업데이트가 적절합니다.

새로 추가된 isSourceCodeNewOrChanged 메서드를 true로 모킹하여 기존 테스트의 의도된 동작을 유지하도록 잘 수정되었습니다.

Also applies to: 195-195

src/main/java/org/ezcode/codetest/infrastructure/github/GitHubClientImpl.java (1)

23-28: 소스코드 변경 검증 메서드가 잘 구현되었습니다.

기존 commitAndPushToRepo에서 초기 반환 로직을 적절히 분리했습니다. 메서드명과 반환값이 명확하고 로직도 정확합니다.

src/test/java/org/ezcode/codetest/infrastructure/github/GitHubClientTest.java (5)

59-62: 리팩터링에 맞춰 테스트가 잘 개선되었습니다.

isSourceCodeNewOrChanged 메서드 분리에 따라 테스트도 해당 메서드를 직접 호출하여 검증하도록 변경되어 테스트 의도가 더 명확해졌습니다.


79-79: mock 설정 순서 개선이 적절합니다.

실행 순서에 맞게 mock 설정을 재배치한 것으로 보이며, 테스트 가독성 향상에 도움이 됩니다.


97-99: 변수 도입으로 테스트 가독성이 향상되었습니다.

하드코딩된 문자열 대신 의미있는 변수명을 사용하여 테스트의 의도가 더 명확해졌습니다.


103-104: sourceCode 변수 활용으로 일관성이 개선되었습니다.

setup에서 정의한 sourceCode 변수를 일관되게 사용하여 테스트의 통일성이 향상되었습니다.


107-117: mock 설정과 검증 로직이 체계적으로 개선되었습니다.

변수를 활용한 mock 설정과 검증으로 테스트의 추적성과 유지보수성이 향상되었습니다.

@thezz9 thezz9 merged commit 5060b18 into dev Jul 24, 2025
2 checks passed
@thezz9 thezz9 deleted the refactor/submission branch July 24, 2025 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants