add ajax for github calls

This commit is contained in:
Michael Q Larson
2015-02-17 13:31:59 -08:00
parent bc57bbdc37
commit 449589827c
5 changed files with 17 additions and 12 deletions

View File

@ -99,7 +99,7 @@ module.exports = {
githubCalls: function(req, res) { githubCalls: function(req, res) {
var githubHeaders = {headers: {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1521.3 Safari/537.36'}, port:80 }; var githubHeaders = {headers: {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1521.3 Safari/537.36'}, port:80 };
client.get('https://api.github.com/repos/freecodecamp/freecodecamp/pulls?client_id=' + secrets.github.clientID + '&client_secret=' + secrets.github.clientSecret, githubHeaders, function(pulls, res3) { client.get('https://api.github.com/repos/freecodecamp/freecodecamp/pulls?client_id=' + secrets.github.clientID + '&client_secret=' + secrets.github.clientSecret, githubHeaders, function(pulls, res3) {
pulls = Object.keys(JSON.parse(pulls)).length || "Can't connect to github"; pulls = pulls ? Object.keys(JSON.parse(pulls)).length : "Can't connect to github";
client.get('https://api.github.com/repos/freecodecamp/freecodecamp/issues?client_id=' + secrets.github.clientID + '&client_secret=' + secrets.github.clientSecret, githubHeaders, function (issues, res4) { client.get('https://api.github.com/repos/freecodecamp/freecodecamp/issues?client_id=' + secrets.github.clientID + '&client_secret=' + secrets.github.clientSecret, githubHeaders, function (issues, res4) {
issues = ((pulls === parseInt(pulls)) && issues) ? Object.keys(JSON.parse(issues)).length - pulls : "Can't connect to GitHub"; issues = ((pulls === parseInt(pulls)) && issues) ? Object.keys(JSON.parse(issues)).length - pulls : "Can't connect to GitHub";
res.send({"issues": issues, "pulls" : pulls}); res.send({"issues": issues, "pulls" : pulls});

View File

@ -0,0 +1,14 @@
#github
script.
(function() {
$.ajax({
url: 'http://localhost:3001/api/github',
type: 'GET'
}).done(
function(data) {
var github = document.createElement('div');
console.log(data);
$(github).html('<div class="row"><div class="col-xs-6 text-right">Open Issues:</div><div class="col-xs-6 text-left">' + data.issues + ' <a href="https://github.com/freecodecamp/freecodecamp/issues">(create one)</a></div></div><div class="row"><div class="col-xs-6 text-right">Open Pull Requests:</div><div class="col-xs-6 text-left">' + data.pulls + ' <a href="https://github.com/freecodecamp/freecodecamp/pulls">(create one)</a></div></div>').prependTo($('#github'))
}
);
})();

View File

@ -6,16 +6,7 @@ h2.stats-text
.col-xs-6.text-right Nonprofit Projects: .col-xs-6.text-right Nonprofit Projects:
.col-xs-6.text-left .col-xs-6.text-left
include ../partials/trello include ../partials/trello
//.row include ../partials/github
// .col-xs-6.text-right Open Issues:
// .col-xs-6.text-left= issues
// | &nbsp
// a(href="https://github.com/freecodecamp/freecodecamp/issues") (create one)
//.row
// .col-xs-6.text-right Pull Requests:
// .col-xs-6.text-left= pulls
// | &nbsp
// a(href="https://github.com/freecodecamp/freecodecamp/pulls") (create one)
.row .row
.col-xs-6.text-right Campers with at least... .col-xs-6.text-right Campers with at least...
.col-xs-4 .col-xs-4

View File

@ -29,7 +29,7 @@ block content
.panel-heading.landing-panel-heading.text-center Blog .panel-heading.landing-panel-heading.text-center Blog
.panel-body .panel-body
.landing-panel-body.text-center .landing-panel-body.text-center
include ../partials/blog include ../partials/blogger
.panel.panel-info .panel.panel-info
.panel-heading.landing-panel-heading.text-center Tweets .panel-heading.landing-panel-heading.text-center Tweets
.panel-body .panel-body