mirror of
https://github.com/status-im/burnchart.git
synced 2025-01-20 15:38:52 +00:00
closes #32
This commit is contained in:
parent
eeb5a37423
commit
9f1cb89d01
@ -20427,7 +20427,7 @@ if (typeof exports == "object") {
|
||||
// request.coffee
|
||||
root.require.register('ghbc/src/modules/request.js', function(exports, require, module) {
|
||||
|
||||
var request, respond, superagent, _, _ref;
|
||||
var error, headers, request, response, superagent, _, _ref;
|
||||
|
||||
_ref = require('./require'), superagent = _ref.superagent, _ = _ref._;
|
||||
|
||||
@ -20445,38 +20445,59 @@ if (typeof exports == "object") {
|
||||
|
||||
module.exports = {
|
||||
'all_milestones': function(repo, cb) {
|
||||
var query;
|
||||
query = {
|
||||
'state': 'open',
|
||||
'sort': 'due_date',
|
||||
'direction': 'asc'
|
||||
};
|
||||
return request(repo, query, 'milestones', cb);
|
||||
return request({
|
||||
'protocol': repo.protocol,
|
||||
'host': repo.host,
|
||||
'path': "/repos/" + repo.path + "/milestones",
|
||||
'query': {
|
||||
'state': 'open',
|
||||
'sort': 'due_date',
|
||||
'direction': 'asc'
|
||||
},
|
||||
'headers': headers(repo.token)
|
||||
}, cb);
|
||||
},
|
||||
'one_milestone': function(repo, number, cb) {
|
||||
var query;
|
||||
query = {
|
||||
'state': 'open',
|
||||
'sort': 'due_date',
|
||||
'direction': 'asc'
|
||||
};
|
||||
return request(repo, query, "milestones/" + number, cb);
|
||||
return request({
|
||||
'protocol': repo.protocol,
|
||||
'host': repo.host,
|
||||
'path': "/repos/" + repo.path + "/milestones/" + number,
|
||||
'query': {
|
||||
'state': 'open',
|
||||
'sort': 'due_date',
|
||||
'direction': 'asc'
|
||||
},
|
||||
'headers': headers(repo.token)
|
||||
}, cb);
|
||||
},
|
||||
'all_issues': function(repo, query, cb) {
|
||||
_.extend(query, {
|
||||
'per_page': '100'
|
||||
});
|
||||
return request(repo, query, 'issues', cb);
|
||||
return request({
|
||||
'protocol': repo.protocol,
|
||||
'host': repo.host,
|
||||
'path': "/repos/" + repo.path + "/issues",
|
||||
'query': _.extend(query, {
|
||||
'per_page': '100'
|
||||
}),
|
||||
'headers': headers(repo.token)
|
||||
}, cb);
|
||||
},
|
||||
'config': function(cb) {
|
||||
return superagent.get("http://" + (window.location.host + window.location.pathname) + "config.json").set('Content-Type', 'application/json').end(_.partialRight(respond, cb));
|
||||
return request({
|
||||
'protocol': 'http',
|
||||
'host': window.location.host,
|
||||
'path': "" + window.location.pathname + "config.json",
|
||||
'headers': _.extend(headers(), {
|
||||
'Accept': 'application/json'
|
||||
})
|
||||
}, cb);
|
||||
}
|
||||
};
|
||||
|
||||
request = function(_arg, query, noun, cb) {
|
||||
var host, k, path, protocol, q, req, token, v;
|
||||
protocol = _arg.protocol, host = _arg.host, token = _arg.token, path = _arg.path;
|
||||
q = ((function() {
|
||||
request = function(_arg, cb) {
|
||||
var exited, headers, host, k, path, protocol, q, query, req, timeout, v;
|
||||
protocol = _arg.protocol, host = _arg.host, path = _arg.path, query = _arg.query, headers = _arg.headers;
|
||||
exited = false;
|
||||
q = query ? '?' + ((function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
for (k in query) {
|
||||
@ -20484,16 +20505,31 @@ if (typeof exports == "object") {
|
||||
_results.push("" + k + "=" + v);
|
||||
}
|
||||
return _results;
|
||||
})()).join('&');
|
||||
req = superagent.get("" + protocol + "://" + host + "/repos/" + path + "/" + noun + "?" + q).set('Content-Type', 'application/json').set('Accept', 'application/vnd.github.v3');
|
||||
if (token) {
|
||||
req = req.set('Authorization', "token " + token);
|
||||
})()).join('&') : '';
|
||||
req = superagent.get("" + protocol + "://" + host + path + q);
|
||||
for (k in headers) {
|
||||
v = headers[k];
|
||||
req.set(k, v);
|
||||
}
|
||||
return req.end(_.partialRight(respond, cb));
|
||||
timeout = setTimeout(function() {
|
||||
exited = true;
|
||||
return cb('Request has timed out');
|
||||
}, 3e3);
|
||||
return req.end(function(err, data) {
|
||||
if (exited) {
|
||||
return;
|
||||
}
|
||||
exited = true;
|
||||
clearTimeout(timeout);
|
||||
return response(err, data, cb);
|
||||
});
|
||||
};
|
||||
|
||||
respond = function(data, cb) {
|
||||
response = function(err, data, cb) {
|
||||
var _ref1;
|
||||
if (err) {
|
||||
return cb(error(err));
|
||||
}
|
||||
if (data.statusType !== 2) {
|
||||
if ((data != null ? (_ref1 = data.body) != null ? _ref1.message : void 0 : void 0) != null) {
|
||||
return cb(data.body.message);
|
||||
@ -20503,6 +20539,40 @@ if (typeof exports == "object") {
|
||||
return cb(null, data.body);
|
||||
};
|
||||
|
||||
headers = function(token) {
|
||||
var h;
|
||||
h = _.extend({}, {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/vnd.github.v3'
|
||||
});
|
||||
if (token != null) {
|
||||
h.Authorization = "token " + token;
|
||||
}
|
||||
return h;
|
||||
};
|
||||
|
||||
error = function(err) {
|
||||
var message;
|
||||
switch (false) {
|
||||
case !_.isString(err):
|
||||
message = err;
|
||||
break;
|
||||
case !_.isArray(err):
|
||||
message = err[1];
|
||||
break;
|
||||
case !(_.isObject(err) && _.isString(err.message)):
|
||||
message = err.message;
|
||||
}
|
||||
if (!message) {
|
||||
try {
|
||||
message = JSON.stringify(err);
|
||||
} catch (_error) {
|
||||
message = err.toString();
|
||||
}
|
||||
}
|
||||
return message;
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
8
build/app.bundle.min.js
vendored
8
build/app.bundle.min.js
vendored
File diff suppressed because one or more lines are too long
130
build/app.js
130
build/app.js
@ -785,7 +785,7 @@
|
||||
// request.coffee
|
||||
root.require.register('ghbc/src/modules/request.js', function(exports, require, module) {
|
||||
|
||||
var request, respond, superagent, _, _ref;
|
||||
var error, headers, request, response, superagent, _, _ref;
|
||||
|
||||
_ref = require('./require'), superagent = _ref.superagent, _ = _ref._;
|
||||
|
||||
@ -803,38 +803,59 @@
|
||||
|
||||
module.exports = {
|
||||
'all_milestones': function(repo, cb) {
|
||||
var query;
|
||||
query = {
|
||||
'state': 'open',
|
||||
'sort': 'due_date',
|
||||
'direction': 'asc'
|
||||
};
|
||||
return request(repo, query, 'milestones', cb);
|
||||
return request({
|
||||
'protocol': repo.protocol,
|
||||
'host': repo.host,
|
||||
'path': "/repos/" + repo.path + "/milestones",
|
||||
'query': {
|
||||
'state': 'open',
|
||||
'sort': 'due_date',
|
||||
'direction': 'asc'
|
||||
},
|
||||
'headers': headers(repo.token)
|
||||
}, cb);
|
||||
},
|
||||
'one_milestone': function(repo, number, cb) {
|
||||
var query;
|
||||
query = {
|
||||
'state': 'open',
|
||||
'sort': 'due_date',
|
||||
'direction': 'asc'
|
||||
};
|
||||
return request(repo, query, "milestones/" + number, cb);
|
||||
return request({
|
||||
'protocol': repo.protocol,
|
||||
'host': repo.host,
|
||||
'path': "/repos/" + repo.path + "/milestones/" + number,
|
||||
'query': {
|
||||
'state': 'open',
|
||||
'sort': 'due_date',
|
||||
'direction': 'asc'
|
||||
},
|
||||
'headers': headers(repo.token)
|
||||
}, cb);
|
||||
},
|
||||
'all_issues': function(repo, query, cb) {
|
||||
_.extend(query, {
|
||||
'per_page': '100'
|
||||
});
|
||||
return request(repo, query, 'issues', cb);
|
||||
return request({
|
||||
'protocol': repo.protocol,
|
||||
'host': repo.host,
|
||||
'path': "/repos/" + repo.path + "/issues",
|
||||
'query': _.extend(query, {
|
||||
'per_page': '100'
|
||||
}),
|
||||
'headers': headers(repo.token)
|
||||
}, cb);
|
||||
},
|
||||
'config': function(cb) {
|
||||
return superagent.get("http://" + (window.location.host + window.location.pathname) + "config.json").set('Content-Type', 'application/json').end(_.partialRight(respond, cb));
|
||||
return request({
|
||||
'protocol': 'http',
|
||||
'host': window.location.host,
|
||||
'path': "" + window.location.pathname + "config.json",
|
||||
'headers': _.extend(headers(), {
|
||||
'Accept': 'application/json'
|
||||
})
|
||||
}, cb);
|
||||
}
|
||||
};
|
||||
|
||||
request = function(_arg, query, noun, cb) {
|
||||
var host, k, path, protocol, q, req, token, v;
|
||||
protocol = _arg.protocol, host = _arg.host, token = _arg.token, path = _arg.path;
|
||||
q = ((function() {
|
||||
request = function(_arg, cb) {
|
||||
var exited, headers, host, k, path, protocol, q, query, req, timeout, v;
|
||||
protocol = _arg.protocol, host = _arg.host, path = _arg.path, query = _arg.query, headers = _arg.headers;
|
||||
exited = false;
|
||||
q = query ? '?' + ((function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
for (k in query) {
|
||||
@ -842,16 +863,31 @@
|
||||
_results.push("" + k + "=" + v);
|
||||
}
|
||||
return _results;
|
||||
})()).join('&');
|
||||
req = superagent.get("" + protocol + "://" + host + "/repos/" + path + "/" + noun + "?" + q).set('Content-Type', 'application/json').set('Accept', 'application/vnd.github.v3');
|
||||
if (token) {
|
||||
req = req.set('Authorization', "token " + token);
|
||||
})()).join('&') : '';
|
||||
req = superagent.get("" + protocol + "://" + host + path + q);
|
||||
for (k in headers) {
|
||||
v = headers[k];
|
||||
req.set(k, v);
|
||||
}
|
||||
return req.end(_.partialRight(respond, cb));
|
||||
timeout = setTimeout(function() {
|
||||
exited = true;
|
||||
return cb('Request has timed out');
|
||||
}, 3e3);
|
||||
return req.end(function(err, data) {
|
||||
if (exited) {
|
||||
return;
|
||||
}
|
||||
exited = true;
|
||||
clearTimeout(timeout);
|
||||
return response(err, data, cb);
|
||||
});
|
||||
};
|
||||
|
||||
respond = function(data, cb) {
|
||||
response = function(err, data, cb) {
|
||||
var _ref1;
|
||||
if (err) {
|
||||
return cb(error(err));
|
||||
}
|
||||
if (data.statusType !== 2) {
|
||||
if ((data != null ? (_ref1 = data.body) != null ? _ref1.message : void 0 : void 0) != null) {
|
||||
return cb(data.body.message);
|
||||
@ -861,6 +897,40 @@
|
||||
return cb(null, data.body);
|
||||
};
|
||||
|
||||
headers = function(token) {
|
||||
var h;
|
||||
h = _.extend({}, {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/vnd.github.v3'
|
||||
});
|
||||
if (token != null) {
|
||||
h.Authorization = "token " + token;
|
||||
}
|
||||
return h;
|
||||
};
|
||||
|
||||
error = function(err) {
|
||||
var message;
|
||||
switch (false) {
|
||||
case !_.isString(err):
|
||||
message = err;
|
||||
break;
|
||||
case !_.isArray(err):
|
||||
message = err[1];
|
||||
break;
|
||||
case !(_.isObject(err) && _.isString(err.message)):
|
||||
message = err.message;
|
||||
}
|
||||
if (!message) {
|
||||
try {
|
||||
message = JSON.stringify(err);
|
||||
} catch (_error) {
|
||||
message = err.toString();
|
||||
}
|
||||
}
|
||||
return message;
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
2
build/app.min.js
vendored
2
build/app.min.js
vendored
File diff suppressed because one or more lines are too long
1
public/app.bundle.js
Symbolic link
1
public/app.bundle.js
Symbolic link
@ -0,0 +1 @@
|
||||
../build/app.bundle.js
|
@ -24,7 +24,7 @@ route = ->
|
||||
, (conf, cb) ->
|
||||
repo _.extend(opts, conf), cb
|
||||
], (err) ->
|
||||
render 'body', 'error', { 'text': err.toString() } if err
|
||||
render 'body', 'error', { 'text': do err.toString } if err
|
||||
|
||||
# Info notice for you.
|
||||
render 'body', 'info'
|
||||
|
@ -12,48 +12,75 @@ superagent.parse =
|
||||
module.exports =
|
||||
|
||||
# Get all milestones.
|
||||
'all_milestones': (repo, cb) ->
|
||||
query = { 'state': 'open', 'sort': 'due_date', 'direction': 'asc' }
|
||||
request repo, query, 'milestones', cb
|
||||
'all_milestones': (repo, cb) ->
|
||||
request
|
||||
'protocol': repo.protocol
|
||||
'host': repo.host
|
||||
'path': "/repos/#{repo.path}/milestones"
|
||||
'query': { 'state': 'open', 'sort': 'due_date', 'direction': 'asc' }
|
||||
'headers': headers repo.token
|
||||
, cb
|
||||
|
||||
# Get one milestone.
|
||||
'one_milestone': (repo, number, cb) ->
|
||||
query = { 'state': 'open', 'sort': 'due_date', 'direction': 'asc' }
|
||||
request repo, query, "milestones/#{number}", cb
|
||||
'one_milestone': (repo, number, cb) ->
|
||||
request
|
||||
'protocol': repo.protocol
|
||||
'host': repo.host
|
||||
'path': "/repos/#{repo.path}/milestones/#{number}"
|
||||
'query': { 'state': 'open', 'sort': 'due_date', 'direction': 'asc' }
|
||||
'headers': headers repo.token
|
||||
, cb
|
||||
|
||||
# Get all issues for a state.
|
||||
'all_issues': (repo, query, cb) ->
|
||||
_.extend query, { 'per_page': '100' }
|
||||
request repo, query, 'issues', cb
|
||||
'all_issues': (repo, query, cb) ->
|
||||
request
|
||||
'protocol': repo.protocol
|
||||
'host': repo.host
|
||||
'path': "/repos/#{repo.path}/issues"
|
||||
'query': _.extend query, { 'per_page': '100' }
|
||||
'headers': headers repo.token
|
||||
, cb
|
||||
|
||||
# Get config from our host always.
|
||||
'config': (cb) ->
|
||||
superagent
|
||||
.get("http://#{window.location.host + window.location.pathname}config.json")
|
||||
.set('Content-Type', 'application/json')
|
||||
.end _.partialRight respond, cb
|
||||
'config': (cb) ->
|
||||
request
|
||||
'protocol': 'http'
|
||||
'host': window.location.host
|
||||
'path': "#{window.location.pathname}config.json"
|
||||
'headers': _.extend headers(), { 'Accept': 'application/json' }
|
||||
, cb
|
||||
|
||||
# Make a request using SuperAgent.
|
||||
request = ({ protocol, host, path, query, headers }, cb) ->
|
||||
exited = no
|
||||
|
||||
# Make a request using SuperAgent to GitHub.
|
||||
request = ({ protocol, host, token, path }, query, noun, cb) ->
|
||||
# Make the query params.
|
||||
q = ( "#{k}=#{v}" for k, v of query ).join('&')
|
||||
q = if query then '?' + ( "#{k}=#{v}" for k, v of query ).join('&') else ''
|
||||
|
||||
req = superagent
|
||||
# The URI.
|
||||
.get("#{protocol}://#{host}/repos/#{path}/#{noun}?#{q}")
|
||||
# The content type.
|
||||
.set('Content-Type', 'application/json')
|
||||
# The media type.
|
||||
.set('Accept', 'application/vnd.github.v3')
|
||||
|
||||
# Auth token?
|
||||
req = req.set('Authorization', "token #{token}") if token
|
||||
req = superagent.get("#{protocol}://#{host}#{path}#{q}")
|
||||
# Add headers.
|
||||
( req.set(k, v) for k, v of headers )
|
||||
|
||||
# Timeout for requests that do not finish... see #32.
|
||||
timeout = setTimeout ->
|
||||
exited = yes
|
||||
cb 'Request has timed out'
|
||||
, 3e3
|
||||
|
||||
# Send.
|
||||
req.end _.partialRight respond, cb
|
||||
req.end (err, data) ->
|
||||
# Arrived too late.
|
||||
return if exited
|
||||
# All fine.
|
||||
exited = yes
|
||||
clearTimeout timeout
|
||||
# Actually process the response.
|
||||
response err, data, cb
|
||||
|
||||
# How do we respond to a response?
|
||||
respond = (data, cb) ->
|
||||
response = (err, data, cb) ->
|
||||
return cb error err if err
|
||||
# 2xx?
|
||||
if data.statusType isnt 2
|
||||
# Do we have a message from GitHub?
|
||||
@ -61,4 +88,32 @@ respond = (data, cb) ->
|
||||
# Use SA one.
|
||||
return cb data.error.message
|
||||
# All good.
|
||||
cb null, data.body
|
||||
cb null, data.body
|
||||
|
||||
# Give us headers.
|
||||
headers = (token) ->
|
||||
# The defaults.
|
||||
h = _.extend {},
|
||||
'Content-Type': 'application/json'
|
||||
'Accept': 'application/vnd.github.v3'
|
||||
# Add token?
|
||||
h.Authorization = "token #{token}" if token?
|
||||
h
|
||||
|
||||
# Parse an error.
|
||||
error = (err) ->
|
||||
switch
|
||||
when _.isString err
|
||||
message = err
|
||||
when _.isArray err
|
||||
message = err[1]
|
||||
when _.isObject(err) and _.isString(err.message)
|
||||
message = err.message
|
||||
|
||||
unless message
|
||||
try
|
||||
message = JSON.stringify err
|
||||
catch
|
||||
message = do err.toString
|
||||
|
||||
message
|
@ -2,12 +2,17 @@
|
||||
proxy = do require('proxyquire').noCallThru
|
||||
assert = require 'assert'
|
||||
path = require 'path'
|
||||
_ = require 'lodash'
|
||||
|
||||
class Superagent
|
||||
|
||||
get: -> @
|
||||
set: -> @
|
||||
end: (cb) -> cb @response
|
||||
get: (uri) ->
|
||||
@params = { uri }
|
||||
@
|
||||
set: (key, value) ->
|
||||
@params[key] = value
|
||||
@
|
||||
end: (cb) -> cb null, @response
|
||||
|
||||
request = proxy path.resolve(__dirname, '../src/modules/request.coffee'),
|
||||
'./require':
|
||||
@ -25,10 +30,30 @@ module.exports =
|
||||
'error': no
|
||||
'body': [ null ]
|
||||
|
||||
request.all_milestones {}, (err) ->
|
||||
request.all_milestones {}, (err, data) ->
|
||||
assert.ifError err
|
||||
assert.deepEqual sa.params,
|
||||
'uri': 'undefined://undefined/repos/undefined/milestones?state=open&sort=due_date&direction=asc'
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/vnd.github.v3'
|
||||
assert.deepEqual data, [ null ]
|
||||
do done
|
||||
|
||||
'request - one milestone (ok)': (done) ->
|
||||
sa.response =
|
||||
'statusType': 2
|
||||
'error': no
|
||||
'body': [ null ]
|
||||
|
||||
request.one_milestone {}, 1, (err, data) ->
|
||||
assert.ifError err
|
||||
assert.deepEqual sa.params,
|
||||
'uri': 'undefined://undefined/repos/undefined/milestones/1?state=open&sort=due_date&direction=asc'
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/vnd.github.v3'
|
||||
assert.deepEqual data, [ null ]
|
||||
do done
|
||||
|
||||
'request - one milestone (404)': (done) ->
|
||||
sa.response =
|
||||
'statusType': 4
|
||||
@ -49,4 +74,19 @@ module.exports =
|
||||
|
||||
request.one_milestone {}, 9, (err) ->
|
||||
assert.equal err, 'Error'
|
||||
do done
|
||||
|
||||
'request - all issues (ok)': (done) ->
|
||||
sa.response =
|
||||
'statusType': 2
|
||||
'error': no
|
||||
'body': [ null ]
|
||||
|
||||
request.all_issues {}, {}, (err, data) ->
|
||||
assert.ifError err
|
||||
assert.deepEqual sa.params,
|
||||
'uri': 'undefined://undefined/repos/undefined/issues?per_page=100'
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/vnd.github.v3'
|
||||
assert.deepEqual data, [ null ]
|
||||
do done
|
Loading…
x
Reference in New Issue
Block a user