Files
probot.github.io/api/6.0.0/github.js.html
2018-02-28 09:34:30 -06:00

114 lines
4.4 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>github.js - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav>
<li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading">Classes</li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Context.html">Context</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Context.html#config">config</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Context.html#issue">issue</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Context.html#repo">repo</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Robot.html">Robot</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Robot.html#on">on</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Robot.html#route">route</a></span></li><li class="nav-heading"><a href="global.html">Globals</a></li>
</nav>
<div id="main">
<h1 class="page-title">github.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>const Bottleneck = require('bottleneck')
const Octokit = require('@octokit/rest')
/**
* the [@octokit/rest Node.js module](https://github.com/octokit/rest.js),
* which wraps the [GitHub API](https://developer.github.com/v3/) and allows
* you to do almost anything programmatically that you can do through a web
* browser.
* @typedef github
* @see {@link https://github.com/octokit/rest.js}
*/
const defaultCallback = response => response
async function paginate (octokit, responsePromise, callback = defaultCallback) {
let collection = []
let getNextPage = true
let done = () => {
getNextPage = false
}
let response = await responsePromise
collection = collection.concat(await callback(response, done))
// eslint-disable-next-line no-unmodified-loop-condition
while (getNextPage &amp;&amp; octokit.hasNextPage(response)) {
response = await octokit.getNextPage(response)
collection = collection.concat(await callback(response, done))
}
return collection
}
function EnhancedGitHubClient (options) {
const octokit = Octokit(options)
const limiter = options.limiter || new Bottleneck({ maxConcurrent: 1, minTime: 1000 })
const logger = options.logger
const noop = () => Promise.resolve()
octokit.hook.before('request', limiter.schedule.bind(limiter, noop))
octokit.hook.error('request', (error, options) => {
const {method, url, headers, ...params} = options
const msg = `GitHub request: ${method} ${url} - ${error.code} ${error.status}`
logger.debug({params}, msg)
throw error
})
octokit.hook.after('request', (result, options) => {
const {method, url, headers, ...params} = options
const msg = `GitHub request: ${method} ${url} - ${result.meta.status}`
logger.debug({params}, msg)
})
octokit.paginate = paginate.bind(null, octokit)
return octokit
}
module.exports = EnhancedGitHubClient
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Feb 28 2018 09:31:56 GMT-0600 (CST) using the Minami theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>