Skip to content

Commit

Permalink
Fix bugs with GitHub, Blogger, Blizzard, and more.
Browse files Browse the repository at this point in the history
  • Loading branch information
roncli committed Jan 8, 2019
1 parent 0c96a29 commit bc4293d
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 88 deletions.
2 changes: 1 addition & 1 deletion roncli.com/app/controllers/home_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
life: {collection: "LifeFeatures", params: {}}
}, function(err, result) {
if (!err && result && result.blog && result.blog.models && result.blog.models[0] && result.blog.models[0].attributes && result.blog.models[0].attributes.error) {
err = result.blog.models[0].attributes;
result.blogMissing = true;
}

if (!err && result && result.songs && result.songs.models && result.songs.models[0] && result.songs.models[0].attributes && result.songs.models[0].attributes.error) {
Expand Down
14 changes: 8 additions & 6 deletions roncli.com/app/templates/home/index.hbs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<div class="col-xs-8 blog constrain-height">
<div class="btn-group-vertical">
<a class="btn btn-info" href="/blog">
<div class="panel-heading panel-title text-center"><h1>Latest Blog Post</h1></div>
</a>
{{partial "blog/post" post=blog.models.0.attributes.post header="default"}}
</div>
{{#unless blogMissing}}
<div class="btn-group-vertical">
<a class="btn btn-info" href="/blog">
<div class="panel-heading panel-title text-center"><h1>Latest Blog Post</h1></div>
</a>
{{partial "blog/post" post=blog.models.0.attributes.post header="default"}}
</div>
{{/unless}}
<div class="row">
<div class="col-sm-6">
<div class="btn-group-vertical home-panel">
Expand Down
6 changes: 5 additions & 1 deletion roncli.com/assets/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -692,4 +692,8 @@ pre.code.inline {
div.blog span.media {
font-weight: bold;
color: #808080;
}
}

label.error {
display: block;
}
4 changes: 2 additions & 2 deletions roncli.com/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"url": "https://github.com/roncli/roncli.com.git"
},
"dependencies": {
"blizzhub": "1.0.14",
"blizzhub": "1.0.15",
"body-parser": "1.18.3",
"captchagen": "1.2.0",
"compression": "1.7.3",
Expand Down Expand Up @@ -48,7 +48,7 @@
"tumblr": "0.4.1",
"twitter": "1.7.1",
"underscore": "1.9.1",
"@octokit/rest": "16.3.2"
"@octokit/rest": "16.6.0"
},
"devDependencies": {
"grunt": "1.0.3",
Expand Down
98 changes: 41 additions & 57 deletions roncli.com/server/github/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,12 @@ var config = require("../privateConfig").github,

/**
* Gets the events from GitHub.
* @param {object} [link] The link object to determine the page to retrieve. If not passed, gets the first page.
*/
getEvents = function(link) {
var processEvents = function(err, events) {
getEvents = function() {
var processEvents = function(events) {
var releaseEvents, pushEvents, allEvents;

if (err) {
console.log("Bad response from GitHub while getting events.");
console.log(err);
callback({
error: "Bad response from GitHub.",
status: 502
});
return;
}

totalEvents = [].concat.apply([], [totalEvents, events.data]);

if (client.hasNextPage(events)) {
getEvents(events);
return;
}
totalEvents = [].concat.apply([], [totalEvents, events]);

releaseEvents = totalEvents.filter(function(event) {
return event.type === "ReleaseEvent" && event.payload.action === "published" && !event.payload.release.draft;
Expand Down Expand Up @@ -95,11 +79,17 @@ var config = require("../privateConfig").github,
});
};

if (link) {
client.getNextPage(link, processEvents);
} else {
client.activity.getEventsForUser({username: "roncli", per_page: 100}, processEvents);
}
var options = client.activity.listEventsForUser.endpoint.merge({username: "roncli", per_page: 100});

client.paginate(options).then(processEvents).catch(function(err) {
console.log("Bad response from GitHub while listing events for user.");
console.log(err);
callback({
error: "Bad response from GitHub.",
status: 502
});
return;
});
};

getEvents();
Expand All @@ -118,17 +108,7 @@ var config = require("../privateConfig").github,
commitsDeferred = new Deferred(),
releasesDeferred = new Deferred();

client.repos.get({owner: user, repo: repository}, function(err, repo) {
if (err) {
console.log("Bad response from GitHub while getting a repository.");
console.log(err);
repositoryDeferred.reject({
error: "Bad response from GitHub.",
status: 502
});
return;
}

client.repos.get({owner: user, repo: repository}).then(function(repo) {
repositoryDeferred.resolve({
user: repo.data.owner.login,
repository: repo.data.name,
Expand All @@ -139,19 +119,17 @@ var config = require("../privateConfig").github,
gitUrl: repo.data.git_url,
language: repo.data.language
});
}).catch(function(err) {
console.log("Bad response from GitHub while getting a repository.");
console.log(err);
repositoryDeferred.reject({
error: "Bad response from GitHub.",
status: 502
});
return;
});

client.repos.getCommits({owner: user, repo: repository, per_page: 100}, function(err, commits) {
if (err) {
console.log("Bad response from GitHub while getting commits for a repository.");
console.log(err);
commitsDeferred.reject({
error: "Bad response from GitHub.",
status: 502
});
return;
}

client.repos.listCommits({owner: user, repo: repository, per_page: 100}).then(function(commits) {
commitsDeferred.resolve(commits.data.map(function(commit) {
var date = new Date(commit.commit.author.date).getTime();
return {
Expand All @@ -165,19 +143,17 @@ var config = require("../privateConfig").github,
}
};
}));
}).catch(function(err) {
console.log("Bad response from GitHub while getting commits for a repository.");
console.log(err);
commitsDeferred.reject({
error: "Bad response from GitHub.",
status: 502
});
return;
});

client.repos.getReleases({owner: user, repo: repository, per_page: 100}, function(err, releases) {
if (err) {
console.log("Bad response from GitHub while getting releases for a repository.");
console.log(err);
releasesDeferred.reject({
error: "Bad response from GitHub.",
status: 502
});
return;
}

client.repos.listReleases({owner: user, repo: repository, per_page: 100}).then(function(releases) {
releasesDeferred.resolve(releases.data.filter(function(release) {
return !release.draft;
}).map(function(release) {
Expand All @@ -194,6 +170,14 @@ var config = require("../privateConfig").github,
}
};
}));
}).catch(function(err) {
console.log("Bad response from GitHub while getting releases for a repository.");
console.log(err);
releasesDeferred.reject({
error: "Bad response from GitHub.",
status: 502
});
return;
});

all([repositoryDeferred.promise, commitsDeferred.promise, releasesDeferred.promise]).then(
Expand Down
14 changes: 7 additions & 7 deletions roncli.com/server/models/blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ module.exports.getLatestPostByCategory = function(category, callback) {
};

getPost(function() {
cachePosts(false, function(err) {
cachePosts(true, function(err) {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -237,7 +237,7 @@ module.exports.getPostByIndex = function(index, callback) {
};

getPost(function() {
cachePosts(false, function(err) {
cachePosts(true, function(err) {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -279,7 +279,7 @@ module.exports.getPostByUrl = function(url, callback) {
};

getPostFromUrl(url, getPost, function() {
cachePosts(false, function(err) {
cachePosts(true, function(err) {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -386,7 +386,7 @@ module.exports.getPost = function(post, callback) {
}

getIndex("roncli.com:blog:posts", rankDeferred, function() {
cachePosts(false, function(err) {
cachePosts(true, function(err) {
if (err) {
rankDeferred.reject(err);
return;
Expand Down Expand Up @@ -530,7 +530,7 @@ module.exports.getCategories = function(callback) {
};

getCategories(function() {
cachePosts(false, function(err) {
cachePosts(true, function(err) {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -632,7 +632,7 @@ module.exports.getCommentsByUrl = function(url, callback) {
};

getPostFromUrl(url, getComments, function() {
cachePosts(false, function(err) {
cachePosts(true, function(err) {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -704,7 +704,7 @@ module.exports.postComment = function(userId, url, content, callback) {
};

getPostFromUrl(url, resolve, function() {
cachePosts(false, function(err) {
cachePosts(true, function(err) {
if (err) {
callback(err);
return;
Expand Down
2 changes: 1 addition & 1 deletion roncli.com/server/models/coding.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module.exports.getLatestEvents = function(count, callback) {
};

getEvents(function() {
github.cacheEvents(false, function(err) {
github.cacheEvents(true, function(err) {
if (err) {
callback(err);
return;
Expand Down
12 changes: 6 additions & 6 deletions roncli.com/server/models/gaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ module.exports.getWowFeed = function(callback) {
};

getWowCharacter(getFeed, function() {
wow.cacheCharacter(false, function(err) {
wow.cacheCharacter(true, function(err) {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -278,7 +278,7 @@ module.exports.getLatestWowFeed = function(callback) {
};

getWowCharacter(getFeed, function() {
wow.cacheCharacter(false, function(err) {
wow.cacheCharacter(true, function(err) {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -338,7 +338,7 @@ module.exports.getDiabloHeroes = function(callback) {
};

getHeroes(function() {
d3.cacheProfile(false, function(err) {
d3.cacheProfile(true, function(err) {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -388,7 +388,7 @@ module.exports.getDiabloMain = function(callback) {
};

getProfile(function() {
d3.cacheProfile(false, function(err) {
d3.cacheProfile(true, function(err) {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -434,7 +434,7 @@ module.exports.getSteamGames = function(callback) {
};

getGames(function() {
steam.cacheGames(false, function(err) {
steam.cacheGames(true, function(err) {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -566,7 +566,7 @@ module.exports.getDclPilot = function(latest, callback) {
};

getPilot(function() {
dcl.cachePilot(false, function(err) {
dcl.cachePilot(true, function(err) {
if (err) {
callback(err);
return;
Expand Down
14 changes: 7 additions & 7 deletions roncli.com/server/models/music.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports.getLatestSongs = function(count, callback) {
};

getSongs(function() {
soundcloud.cacheTracks(false, function(err) {
soundcloud.cacheTracks(true, function(err) {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -101,7 +101,7 @@ module.exports.getLatestSongsByTag = function(tag, count, callback) {
};

getSongs(function() {
soundcloud.cacheTracks(false, function(err) {
soundcloud.cacheTracks(true, function(err) {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -144,7 +144,7 @@ module.exports.getTags = function(callback) {
};

getCategories(function() {
soundcloud.cacheTracks(false, function(err) {
soundcloud.cacheTracks(true, function(err) {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -185,7 +185,7 @@ module.exports.getSongsByTag = function(tag, callback) {
};

getSongs(function() {
soundcloud.cacheTracks(false, function(err) {
soundcloud.cacheTracks(true, function(err) {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -242,7 +242,7 @@ module.exports.getSongByUrl = function(url, callback) {
};

getSongFromUrl(url, getSong, function() {
soundcloud.cacheTracks(false, function(err) {
soundcloud.cacheTracks(true, function(err) {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -304,7 +304,7 @@ module.exports.getCommentsByUrl = function(url, callback) {
};

getSongFromUrl(url, getComments, function() {
soundcloud.cacheTracks(false, function(err) {
soundcloud.cacheTracks(true, function(err) {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -376,7 +376,7 @@ module.exports.postComment = function(userId, url, content, callback) {
};

getSongFromUrl(url, resolve, function() {
soundcloud.cacheTracks(false, function(err) {
soundcloud.cacheTracks(true, function(err) {
if (err) {
callback(err);
return;
Expand Down

0 comments on commit bc4293d

Please sign in to comment.