mirror of
https://github.com/zhigang1992/probot.github.io.git
synced 2026-01-12 22:49:53 +08:00
121 lines
4.4 KiB
HTML
121 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 GitHubApi = require('github')
|
|
|
|
/**
|
|
* the [github Node.js module](https://github.com/octokit/node-github),
|
|
* 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/node-github}
|
|
*/
|
|
|
|
// Default callback should just return the response passed to it.
|
|
const defaultCallback = response => response
|
|
|
|
class EnhancedGitHubClient extends GitHubApi {
|
|
constructor (options) {
|
|
super(options)
|
|
this.limiter = new Bottleneck(1, 1000)
|
|
this.logger = options.logger
|
|
}
|
|
|
|
handler (params, block, callback) {
|
|
// Only allow one request at a time with a 1s delay
|
|
// https://github.com/octokit/node-github/issues/526
|
|
this.limiter.submit(super.handler.bind(this), params, block, (err, res) => {
|
|
let msg = `GitHub request: ${block.method} ${block.url}`
|
|
if (res) {
|
|
msg += ` - ${res.meta.status}`
|
|
} else if (err) {
|
|
msg += ` - ${err.code} ${err.status}`
|
|
}
|
|
this.logger.debug({params}, msg)
|
|
|
|
if (res) {
|
|
this.logger.trace(res, 'GitHub response:')
|
|
}
|
|
|
|
callback(err, res)
|
|
})
|
|
}
|
|
|
|
async paginate (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 && this.hasNextPage(response)) {
|
|
response = await this.getNextPage(response)
|
|
collection = collection.concat(await callback(response, done))
|
|
}
|
|
return collection
|
|
}
|
|
}
|
|
|
|
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 Thu Jan 18 2018 08:17:45 GMT-0600 (CST) using the Minami theme.
|
|
</footer>
|
|
|
|
<script>prettyPrint();</script>
|
|
<script src="scripts/linenumber.js"></script>
|
|
</body>
|
|
</html>
|