Github API calls
This commit is contained in:
parent
da6f6162dc
commit
9c6038bfb4
|
@ -0,0 +1,37 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const https = require('https');
|
||||||
|
const config = require('../config');
|
||||||
|
|
||||||
|
// Returns the url for getting the labels of a request (Github v3)
|
||||||
|
// req has req.issue.labels_url
|
||||||
|
const getLabelsURL = function(req) {
|
||||||
|
let url = req.issue.labels_url;
|
||||||
|
// Make the URL generic removing the name of the label
|
||||||
|
return url.replace('{/name}', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
const getLabels = function(req) {
|
||||||
|
let url = getLabelsURL(req);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const request = https.get(url, (response) => {
|
||||||
|
// handle http errors
|
||||||
|
if (response.statusCode < 200 || response.statusCode > 299) {
|
||||||
|
reject(new Error('Failed to load page, status code: ' + response.statusCode));
|
||||||
|
}
|
||||||
|
// temporary data holder
|
||||||
|
const body = [];
|
||||||
|
// on every content chunk, push it to the data array
|
||||||
|
response.on('data', (chunk) => body.push(chunk));
|
||||||
|
// we are done, resolve promise with those joined chunks
|
||||||
|
response.on('end', () => {
|
||||||
|
let labels = JSON.parse(body.join('')).map(lableObj => lableObj.name);
|
||||||
|
let bountyLabels = labels.filter(name => config.BOUNTY_LABELS.hasOwnProperty(name));
|
||||||
|
|
||||||
|
resolve(bountyLabels);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// handle connection errors of the request
|
||||||
|
request.on('error', (err) => reject(err))
|
||||||
|
});
|
||||||
|
}
|
|
@ -1,3 +1,15 @@
|
||||||
|
|
||||||
|
|
||||||
|
const BOUNTY_LABELS = {
|
||||||
|
'bounty-xs': 1,
|
||||||
|
'bounty-s': 10,
|
||||||
|
'bounty-m': 100,
|
||||||
|
'bounty-l': 1000,
|
||||||
|
'bounty-xl': 10000
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
urlEndpoint: "/autobounty/fund",
|
urlEndpoint: "/autobounty/fund",
|
||||||
signerPath: "https://ropsten.infura.io",
|
signerPath: "https://ropsten.infura.io",
|
||||||
|
|
Loading…
Reference in New Issue