diff --git a/lib/platform/github/gh-got-wrapper.js b/lib/platform/github/gh-got-wrapper.js index d25b379b9bff73efa6a76451462a23c547432e1e..ec196d7b28b928c78bb85a7035cbf147935de399 100644 --- a/lib/platform/github/gh-got-wrapper.js +++ b/lib/platform/github/gh-got-wrapper.js @@ -5,6 +5,7 @@ const parseLinkHeader = require('parse-link-header'); const endpoints = require('../../util/endpoints'); let cache = {}; +let stats = {}; async function get(path, options, retries = 5) { const { host } = URL.parse(path); @@ -19,6 +20,7 @@ async function get(path, options, retries = 5) { return cache[path]; } logger.debug(`${method.toUpperCase()} ${path}`); + stats.requestCount = (stats.requestCount || 0) + 1; try { if (appMode) { const appAccept = 'application/vnd.github.machine-man-preview+json'; @@ -37,6 +39,10 @@ async function get(path, options, retries = 5) { } } const res = await ghGot(path, opts); + if (res && res.headers) { + stats.rateLimit = res.headers['x-ratelimit-limit']; + stats.rateLimitRemaining = res.headers['x-ratelimit-remaining']; + } if (opts.paginate) { // Check if result is paginated const pageLimit = opts.pageLimit || 10; @@ -181,6 +187,11 @@ get.setAppMode = function setAppMode(val) { get.reset = function reset() { cache = null; cache = {}; + // istanbul ignore if + if (stats.requestCount) { + logger.info({ stats }, 'Request stats'); + } + stats = {}; }; module.exports = get;