Skip to content

Instantly share code, notes, and snippets.

@aycabas
Created March 30, 2023 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aycabas/67d3366f2ff7fd3857ca18e5bca25c68 to your computer and use it in GitHub Desktop.
Save aycabas/67d3366f2ff7fd3857ca18e5bca25c68 to your computer and use it in GitHub Desktop.
an HTTP call to GitHub API
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