Skip to content

Commit 069431a

Browse files
committed
Fix: 전체 커밋을 불러올 때 연속 커밋 정보도 포함
1 parent 0a068d6 commit 069431a

File tree

2 files changed

+67
-8
lines changed

2 files changed

+67
-8
lines changed

src/main/java/cmf/commitField/domain/commit/totalCommit/service/TotalCommitService.java

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,87 @@ public class TotalCommitService {
3232
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
3333
.build();
3434

35-
// 기존 메서드
35+
// // 기존 메서드
36+
// public TotalCommitResponseDto getTotalCommitCount(String username) {
37+
// Map<String, String> requestBody = Map.of(
38+
// "query", String.format(
39+
// "query { user(login: \"%s\") { contributionsCollection { totalCommitContributions restrictedContributionsCount } } }",
40+
// username
41+
// )
42+
// );
43+
//
44+
// TotalCommitGraphQLResponse response = webClient.post()
45+
// .header("Authorization", "bearer " + PAT)
46+
// .bodyValue(requestBody)
47+
// .retrieve()
48+
// .bodyToMono(TotalCommitGraphQLResponse.class)
49+
// .block();
50+
//
51+
// TotalCommitGraphQLResponse.ContributionsCollection contributions =
52+
// response.getData().getUser().getContributionsCollection();
53+
//
54+
// return new TotalCommitResponseDto(
55+
// contributions.getTotalCommitContributions(),
56+
// contributions.getRestrictedContributionsCount()
57+
// );
58+
// // streak 계산 부분 추가
59+
// List<LocalDate> commitDates = extractCommitDates(contributions.getContributionCalendar());
60+
// StreakResult streaks = calculateStreaks(commitDates);
61+
//
62+
// return new TotalCommitResponseDto(
63+
// contributions.getTotalCommitContributions(),
64+
// contributions.getRestrictedContributionsCount(),
65+
// streaks.currentStreak,
66+
// streaks.maxStreak
67+
// );
68+
// }
69+
70+
// 연속 커밋 수 정보도 같이 반환
3671
public TotalCommitResponseDto getTotalCommitCount(String username) {
37-
Map<String, String> requestBody = Map.of(
38-
"query", String.format(
39-
"query { user(login: \"%s\") { contributionsCollection { totalCommitContributions restrictedContributionsCount } } }",
40-
username
41-
)
72+
// GraphQL 쿼리를 수정하여 contributionCalendar도 함께 요청
73+
String query = String.format(
74+
"query { user(login: \"%s\") { contributionsCollection { " +
75+
"totalCommitContributions restrictedContributionsCount " +
76+
"contributionCalendar { totalContributions weeks { contributionDays { contributionCount date } } } " +
77+
"} } }",
78+
username
4279
);
4380

81+
Map<String, String> requestBody = Map.of("query", query);
82+
4483
TotalCommitGraphQLResponse response = webClient.post()
4584
.header("Authorization", "bearer " + PAT)
4685
.bodyValue(requestBody)
4786
.retrieve()
4887
.bodyToMono(TotalCommitGraphQLResponse.class)
4988
.block();
5089

90+
if (response == null || response.getData() == null || response.getData().getUser() == null) {
91+
throw new RuntimeException("Failed to fetch GitHub data");
92+
}
93+
5194
TotalCommitGraphQLResponse.ContributionsCollection contributions =
5295
response.getData().getUser().getContributionsCollection();
5396

97+
// streak 기본값 설정
98+
int currentStreak = 0;
99+
int maxStreak = 0;
100+
101+
// contributionCalendar가 존재하는 경우에만 streak 계산
102+
if (contributions.getContributionCalendar() != null) {
103+
List<LocalDate> commitDates = extractCommitDates(contributions.getContributionCalendar());
104+
if (!commitDates.isEmpty()) {
105+
StreakResult streaks = calculateStreaks(commitDates);
106+
currentStreak = streaks.currentStreak;
107+
maxStreak = streaks.maxStreak;
108+
}
109+
}
110+
54111
return new TotalCommitResponseDto(
55112
contributions.getTotalCommitContributions(),
56-
contributions.getRestrictedContributionsCount()
113+
contributions.getRestrictedContributionsCount(),
114+
currentStreak,
115+
maxStreak
57116
);
58117
}
59118

src/main/resources/application-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ spring:
77
jpa:
88
open-in-view: false
99
hibernate:
10-
ddl-auto: create
10+
ddl-auto: update

0 commit comments

Comments
 (0)