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.
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.
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.
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.
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.
GHRequestor
A simple, resilient GitHub API client that:
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
requestlibarary 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
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
getAllwithgetAllResponsesto get back the raw responses rather than flattened array of values.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.Authentication
Authentication is handled the same as with Node’s
requestwhen using optoins and headers. You can either pass theauthorizationheader in with each call or create a request template that has theauthorizationheader set.Or
Logging
ghrequestor takes a winston-style logger as a
loggeroption. Set that option on each call or in a templateContributing
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 opencode@microsoft.com with any additional questions or comments.