generated from Bamdoliro/repository-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
93 additions
and
7 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
53 changes: 53 additions & 0 deletions
53
src/main/java/com/tomatoes/giti/global/feign/github/GithubGraphqlClient.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,53 @@ | ||
package com.tomatoes.giti.global.feign.github; | ||
|
||
import com.tomatoes.giti.global.feign.github.dto.GithubContributionResponse; | ||
import com.tomatoes.giti.global.properties.GithubProperties; | ||
import graphql.kickstart.spring.webclient.boot.GraphQLRequest; | ||
import graphql.kickstart.spring.webclient.boot.GraphQLResponse; | ||
import graphql.kickstart.spring.webclient.boot.GraphQLWebClient; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class GithubGraphqlClient { | ||
|
||
private final GraphQLWebClient graphQLWebClient; | ||
private final GithubProperties githubProperties; | ||
|
||
public int getContributions(String username) { | ||
GraphQLRequest request = GraphQLRequest.builder() | ||
.header("Authorization", "bearer " + githubProperties.getToken()) | ||
.query("query { \n" + | ||
" user(login: \"" + username + "\") {\n" + | ||
" contributionsCollection {\n" + | ||
" contributionCalendar {\n" + | ||
" totalContributions\n" + | ||
" weeks {\n" + | ||
" contributionDays {\n" + | ||
" weekday\n" + | ||
" date \n" + | ||
" contributionCount \n" + | ||
" color\n" + | ||
" }\n" + | ||
" }\n" + | ||
" months {\n" + | ||
" name\n" + | ||
" year\n" + | ||
" firstDay \n" + | ||
" totalWeeks \n" + | ||
" \n" + | ||
" }\n" + | ||
" }\n" + | ||
" }\n" + | ||
" }\n" + | ||
" \n" + | ||
"}") | ||
.build(); | ||
GraphQLResponse response = graphQLWebClient.post(request).block(); | ||
return response.get("user", GithubContributionResponse.class) | ||
.getContributionsCollection() | ||
.getContributionCalendar() | ||
.getTotalContributions(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/tomatoes/giti/global/feign/github/dto/GithubContributionResponse.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,23 @@ | ||
package com.tomatoes.giti.global.feign.github.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class GithubContributionResponse { | ||
private ContributionCollection contributionsCollection; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public static class ContributionCollection { | ||
private ContributionCalendar contributionCalendar; | ||
} | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public static class ContributionCalendar { | ||
private int totalContributions; | ||
} | ||
} |
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