From 0b6f7ffe32c69a15da2d7810e6040282a47d9d42 Mon Sep 17 00:00:00 2001 From: bendtherules Date: Fri, 31 May 2019 19:15:53 +0530 Subject: [PATCH] Add octokit with plugin throttling test --- src/MyLibrary.ts | 35 +++++++++++++++++++++++++++++++++++ src/index.ts | 9 +++++++++ src/plugin-throttling.d.ts | 1 + 3 files changed, 45 insertions(+) create mode 100644 src/MyLibrary.ts create mode 100644 src/index.ts create mode 100644 src/plugin-throttling.d.ts diff --git a/src/MyLibrary.ts b/src/MyLibrary.ts new file mode 100644 index 0000000..bf886f7 --- /dev/null +++ b/src/MyLibrary.ts @@ -0,0 +1,35 @@ +import Octokit = require('@octokit/rest'); +import pluginThrottling = require('@octokit/plugin-throttling'); + +const Octokit2 = Octokit.plugin(pluginThrottling); + +export class MyLibrary { + getRepos() { + const octokit = new Octokit2({ + throttle: { + onAbuseLimit: () => {/* ... */ }, + onRateLimit: () => {/* ... */ } + } + }); + + // Compare: https://developer.github.com/v3/repos/#list-organization-repositories + octokit.repos.listForOrg({ + org: 'octokit', + type: 'public' + }).then(({ data }) => { + console.log('All repos: ', data); + + data.forEach(async repo => { + const readmeResponse = await octokit.repos.getReadme({ + owner: 'octokit', + repo: repo.name + }); + + console.log(readmeResponse.data.html_url); + }); + + }) + } +} + +export default MyLibrary; diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..618f727 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,9 @@ +import { MyLibrary } from './MyLibrary'; + +console.log('See this in your browser console: Typescript Webpack Starter Launched'); + +const myLibrary = new MyLibrary(); +const result = myLibrary.getRepos(); + +console.log(myLibrary); +console.log(`A random number ${result}`); diff --git a/src/plugin-throttling.d.ts b/src/plugin-throttling.d.ts new file mode 100644 index 0000000..f7ed886 --- /dev/null +++ b/src/plugin-throttling.d.ts @@ -0,0 +1 @@ +declare module '@octokit/plugin-throttling'; \ No newline at end of file