github issue 가져오기 / fetching / download / crawling / crawl / 이슈
ocktokit.js 를 이용해서 github issue 가져오기
- Getting started with the REST API - GitHub Docs –> JavaScript tab
간략한 절차
- Personal Access Token(PAT) 만들기
- octokit.js 를 이용해서 issue 가져오기
예시
아래 간략한 code 가 있다. auth 를 하고, issue #10 을 가져오는 code 이다.
import { Octokit, App } from "octokit";
(async () => {
// Create a personal access token at https://github.com/settings/tokens/new?scopes=repo
const octokit = new Octokit({ auth: `my-personal-access-token` });
// Compare: https://docs.github.com/en/rest/reference/users#get-the-authenticated-user
const {data: {login}} = await octokit.rest.users.getAuthenticated();
// --------------------------------------------
// 모든 이슈를 가져올때
const iterator = octokit.paginate.iterator(octokit.rest.issues.listForRepo, {
owner: login,
repo: "my_repo",
per_page: 100,
state: "all",
});
// iterate through each response
// iterate through each response
for await (const { data: issues } of iterator) {
for (const issue of issues) {
console.log("Issue #%d: %s", issue.number, issue.title);
console.log("Issue Body: %s", issue.body);
// comments
const {data: commentsList} = await octokit.rest.issues.listComments({
owner: login,
repo: "my_repo",
issue_number: issue.number,
})
for (const comment of commentsList) {
console.log(`url=${comment.html_url}`)
console.log(`created_at:${comment.created_at}, updated_at:${comment.updated_at}`)
console.log(`body=${comment.body}`)
}
}
}
// --------------------------------------------
// 특정 이슈를 가져올 때
// gh api repos/mygitid/my_repo/issues/10
console.log("Hello, %s", login);
octokit.rest.users.getAuthenticated();
const resp = await octokit.rest.issues.get({
owner: login,
repo: "my_repo",
issue_number: 10,
})
console.log(`issue body=${resp.data.body}`)
})()
댓글 없음:
댓글 쓰기