
์ด๋ฐ ์ปค๋ฐ ํ์คํ ๋ฆฌ๋ฅผ ๊ฐ์ ธ์์ ํฌํธํด๋ฆฌ์ค ์ฌ์ดํธ์ ๋ฟ๋ ค์ฃผ๊ณ ์ถ์๋ค.
์์ฑ ํ๋ฉด

ํด๋น ๊ธฐ๋ฅ์ GitHub API๋ก ํ์คํ ๋ฆฌ๋ฅผ ๋ถ๋ฌ์ฌ ์ ์๋ค.
ํ์ํ ๊ธฐ๋ฅ : GitHub API ์๋ํฌ์ธํธ, Access Token ๋ฐ๊ธ
1. GitHub API ์๊ฐ
- GitHub์ REST API๋ฅผ ์ ๊ณตํ๊ณ , repos ์๋ํฌ์ธํธ๋ฅผ ์ด์ฉํ๋ฉด ์ปค๋ฐ ํ์คํ ๋ฆฌ๋ฅผ ์กฐํํ ์ ์๋ค.
- ๊ธฐ๋ณธ ์ฃผ์:
https://api.github.com/repos/{owner}/{repo}/commits
2. Personal Access Token ๋ฐ๊ธ
- GitHub ๋ก๊ทธ์ธ → Settings → Developer settings → Personal access tokens
- Fine-grained token ๋๋ Classic token ๋ฐ๊ธ
- ์ต์ ๊ถํ์ repo → contents:read ์ ๋๋ฉด ์ถฉ๋ถ
์ฃผ์: ํ ํฐ์ ์ ๋ ๊ณต๊ฐ ์ ์ฅ์์ ์ฌ๋ฆฌ๋ฉด ์๋จ.
๊ฐ์ฅ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ javascript๋ก API๋ฅผ ์์ฒญํ๋ฉด ๋์ง๋ง,
์ฐ๋ฆฌ๋ ํ ํฐ์ด ์๊ธฐ ๋๋ฌธ์ ์๋น์ค๋ฅผ ๋ง๋ค์ด์ ๊ฐ์ ธ์ค๋ ค๊ณ ํฉ๋๋ค.
RestTemplate์ด๋ WebClient๋ก ๊ตฌํ ๊ฐ๋ฅํ์ง๋ง, ์ฌ๊ธฐ์๋ ๊ฐ๋จํ๊ฒ RestTemplate์ผ๋ก ํ๊ฒ ์ต๋๋ค.
1.Service ํด๋์ค
@Service
public class GitHubService {
private final RestTemplate restTemplate = new RestTemplate();
private static final String GITHUB_API_URL = "https://api.github.com/repos/{owner}/{repo}/commits";
public String getCommits(String owner, String repo, String token) {
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "token " + token);
headers.set("Accept", "application/vnd.github+json");
HttpEntity<String> entity = new HttpEntity<>(headers);
ResponseEntity<String> response = restTemplate.exchange(
GITHUB_API_URL,
HttpMethod.GET,
entity,
String.class,
owner,
repo
);
return response.getBody();
}
}
2.Controller ํด๋์ค
@RestController
@RequestMapping("/github")
public class GitHubController {
private final GitHubService gitHubService;
public GitHubController(GitHubService gitHubService) {
this.gitHubService = gitHubService;
}
@GetMapping("/commits/{owner}/{repo}")
public String getCommits(
@PathVariable String owner,
@PathVariable String repo,
@RequestHeader("Authorization") String token
) {
// token์ "Bearer xxx" ๋ง๊ณ "token xxx" ํ์์ผ๋ก ๋ณด๋ด์ผ ํจ
return gitHubService.getCommits(owner, repo, token.replace("token ", ""));
}
}
3.์ฌ์ฉ ๋ฐฉ๋ฒ
1. ์๋ฒ ์คํ
2. API ํธ์ถ (Postman์ด๋ ๋ธ๋ผ์ฐ์ ์์)
curl -H "Authorization: token {YOUR_GITHUB_TOKEN}" \
http://localhost:8080/github/commits/{owner}/{repo}
3.๊ฒฐ๊ณผ: GitHub์์ ๋ด๋ ค์ฃผ๋ JSON์ด ๊ทธ๋๋ก ์ถ๋ ฅ๋จ
[
{
"sha": "a1b2c3...",
"commit": {
"author": {
"name": "ํ๊ธธ๋",
"email": "hong@test.com",
"date": "2025-08-27T05:21:20Z"
},
"message": "Fix bug in login"
},
"html_url": "https://github.com/owner/repo/commit/a1b2c3"
}
]
๐ ์ด๋ ๊ฒ ํ๋ฉด ์น ์ฌ์ดํธ์ Spring Boot ๊ธฐ๋ฐ GitHub API ์ฐ๋์ด ๊ฐ๋ฅํ๋ค.
๋ํ ์ด ๋ฐ์ดํฐ๋ฅผ ํ๋ก ํธ์๋(React, Vue ๋ฑ)์์ ๋ฐ์์์ ํ์๋ผ์ธ ํํ๋ก ํํํ ์ ์๋ค.
ํน์ ๋ธ๋์น๋ง ์กฐํํ๊ฑฐ๋ (?sha=๋ธ๋์น๋ช ), ํน์ ํ์ผ์ ๋ํ ์ปค๋ฐ ๊ธฐ๋ก๋ง ๋ถ๋ฌ์ฌ ์๋ ์๋ค(?path=ํ์ผ๋ช )
ํฌํธํด๋ฆฌ์ค ์ฌ์ดํธ๋ฟ๋ง ์๋๋ผ, ํํ๋ก์ ํธ ๊ธฐ๋ก ๊ด๋ฆฌ, ์ต๊ทผ ์์ ํํฉ ํ์ด์ง ๊ฐ์๊ณณ์๋ ์์ฉํ ์ ์๋ค.