Github API 사용 하기
github-api.kohsuke.org/index.html
GitHub API for Java –
What is this? This library defines an object oriented representation of the GitHub API. By "object oriented" we mean there are classes that correspond to the domain model of GitHub (such as GHUser and GHRepository), operations that act on them as defined a
github-api.kohsuke.org
위 페이지를 들어가보면,
음....... 시작부터 막막하다.
시작에 앞서 Download 를 해보자
의존성 추가
<!-- https://mvnrepository.com/artifact/org.kohsuke/github-api -->
<dependency>
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
<version>1.117</version>
</dependency>
자 이제부터 시작이다.
아까 처음 봤던 영어로만 되어있는 페이지를 또 봐야한다.
위에 패스워드를 넣어서 생성하는거는 not recommended라고 적혀있으니까 하지 말고,
밑에 보니까 Personal access token을 사용해서 github을 가져올 수 있다.
그럼 Personal accsess token을 받아야 한다..
Personal access token을 발급 받는 방법은 Github - Personal Access Token 을 참조하자.
Github - Personal Access Token 받는 법
Personal Access Token Github 접속 - profile - Settings Settings / Developer settings / Personal access tokens 오른쪽 상단에 Generate new token을 클릭해준다. Note 에는 이 토큰은 무엇을 위해 사용..
iseunghan.tistory.com
Github connect
Github gitHub = new GitHubBuilder().withOAuthToken("token").build();
GHRepository
GHRepository repository = gitHub.getRepository("user/repository_Name");
Github repository를 가져와서 Issue도 가져올 수 있고, 그 issue 안에 comment 남긴 사용자의 정보도 가져올 수 있다.
public class App {
private Github github;
private GHRepository repository;
public App() throws IOException {
gitHub = new GitHubBuilder().withOAuthToken("여기에 토큰을 넣어준다").build();
repository = github.getRepository("repository name");
// Issue를 가져올 수도 있다.
GHIssue issue = repository.getIssue(i);
// Issue에 있는 comments도 가져올 수도 있다.
List<GHIssueComment> comments = issue.getComments();
// comments에 보면 User의 대한 정보를 가져올 수도 있다.
for (GHIssueComment comment : comments) {
comment.getUser();
comment.getUser().getName();
..
}
}
}
아직 여기까지 밖에 공부 못해서 공부 해가면서 내용을 채워 나가겠습니다.