Created
March 30, 2023 09:01
-
-
Save aycabas/67d3366f2ff7fd3857ca18e5bca25c68 to your computer and use it in GitHub Desktop.
an HTTP call to GitHub API
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
import { githubIssuesModel } from "../models/githubIssuesModel"; | |
import { Octokit } from "octokit"; | |
export async function getIssues(): Promise<githubIssuesModel[]> { | |
const octokit = new Octokit({ //github personal access token auth: "GITHUB_PERSONAL_ACCESS_TOKEN" }) | |
try { | |
const resp = await octokit.request('GET /repos/{owner}/{repo}/issues', { | |
//repository name and owner name | |
owner: "OWNER_NAME", | |
repo: "REPOSITORY_NAME" | |
}) | |
let issues: githubIssuesModel[] = []; | |
for (const obj of resp.data) { | |
const tmp: githubIssuesModel = {state: obj["state"], url: obj["html_url"], title: obj["title"], body: obj["body"]}; | |
issues.push(tmp); | |
} | |
return issues; | |
} | |
catch (e) { | |
throw e; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment