Giter VIP home page Giter VIP logo

ghrequestor's Introduction

Version License Downloads

GHRequestor

A simple, resilient GitHub API client that:

  • Is great for bulk fetching of resources from the GitHub API.
  • Retries on errors and various forms of rate-limiting.
  • Backs off as you reach your API limit.
  • Automatically fetches all pages of a multi-page resource.
  • Uses etags to conserve API tokens and be kind to GitHub.
  • Reports comprehensive data on number of pages fetched, retry attempts, and length of delays.

GHRequestor is a relatively low-level facility intended for traversing large graphs of GitHub resources. Its primary usecase is GHCrawler, an engine that walks subsections of GitHub collecting related resources. This not intended to replace great modules like octonode or github.

Usage

The API is modelled after the standard node request libarary and the underlying requestretry library. It works with promises or callbacks and allows you to create pre-initialized requestor instances (with options setup) for injection into subsystems etc.

Simple GET of a single page

const ghrequestor = require('ghrequestor');
ghrequestor.get('https://api.github.com/repos/Microsoft/ghrequestor').then(response => {
  console.log(response.body);
});

GET a resource that spans multiple pages and flatten the responses into a single array. Notice the result includes an activity property detailing the requests and responses that went into getting the final result. You can swap getAll with getAllResponses to get back the raw responses rather than flattened array of values.

const ghrequestor = require('ghrequestor');
ghrequestor.getAll('https://api.github.com/repos/Microsoft/ghrequestor/commits').then(result => {
  console.log(result.length);
  console.log(result.activity.length);
  console.log(result.activity[0].attempts);
});

GET with a set of etags and a content supplier that has the etagged resources. With this you can integrate an in-memory or persistent cache of GitHub resources and let ghrequestor optimize the fetching and your use of API tokens. It's nicer on the GitHub infrastructure as well. Notice that the etag value include the "s.

const ghrequestor = require('ghrequestor');
const url = <some url>;
ghrequestor.getAllResponses(url, { etags: ['"42"']}).then(responses => {
  const supplier = url => { return yourContentLookupCode(); };
  return ghrequestor.flattenResponses(responses, supplier).then(results => {
    console.log(results.length);
  });
});

Authentication

Authentication is handled the same as with Node's request when using optoins and headers. You can either pass the authorization header in with each call or create a request template that has the authorization header set.

ghrequestor.get(url, { authorization: 'token <my token here>' });

Or

const requestorTemplate = ghrequestor.defaults({ authorization: 'token <my token here>' });
requestorTemplate.get(url);

Logging

ghrequestor takes a winston-style logger as a logger option. Set that option on each call or in a template

const winston = require('winston');
const requestorTemplate = ghrequestor.defaults({ logger: winston });
requestorTemplate.get(url);

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

ghrequestor's People

Contributors

iamwillbar avatar jeffmcaffer avatar jeffwilcox avatar maggiepint avatar microsoft-github-policy-service[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ghrequestor's Issues

GitHub API Deprecation

Hi there, we've been running the GHCrawler for our OSPO. For the last few weeks, when running it we've been getting a notification from GitHub that part of the GitHub API, used by ghrequestor, is being deprecated soon.

using the access_token query parameter is deprecated and will be removed July 1st, 2020

and we need to

use the Authorization HTTP header instead

I'm raising the issue here because the email says the problem is happening here, in ghrequestor.

Has the Microsoft OSPO been getting this issue too?

Here's a (slightly anonymized) copy of the email we're getting:

Hi @danisyellis,

On February 11th, 2020 at 00:29 (UTC) your personal access token (test - all reads and admin org_hook) using ghrequestor was used as part of a query parameter to access an endpoint through the GitHub API:

https://api.github.com/user/{userNumber}

Please use the Authorization HTTP header instead, as using the access_token query parameter is deprecated and will be removed July 1st, 2020.

Depending on your API usage, we'll be sending you this email reminder once every 3 days for each token and User-Agent used in API calls made on your behalf.
Just one URL that was accessed with a token and User-Agent combination will be listed in the email reminder, not all.

Visit https://developer.github.com/changes/2019-11-05-deprecated-passwords-and-authorizations-api/#authenticating-using-query-parameters for more information.

Thanks,
The GitHub Team

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.