Skip to content

Commit

Permalink
Additional dep (#1793)
Browse files Browse the repository at this point in the history
* Partially migrate to newer dep for GH API
* Adding some error protection, **but not all**, to the GH API deprecation of QSP's. This is probably temporary until a broader fix is implemented. GH importing may have to be disabled after May 5th, 2021... webhooks might be affected if the old (or new) Promise rejection fails. i.e. no more webhooks... but we'll see after the 5th of next month if not addressed.

Applies to #1705

NOTE(S):
* Due to the nature of the dependency with Promises it is currently contrary to the STYLEGUIDE.md See #1556 as is #1729 with ES6+ syntax.
* Doing what I can to avert this chaos but the Code is spread out all over the place.

Auto-merge
  • Loading branch information
Martii authored Apr 13, 2021
1 parent 0e6ec48 commit e843506
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ Repository | Reference | Recent Version
[toobusy-js][toobusy-jsGHUrl] <br />&#x22D4; [`harmony`][toobusy-jsGHUrlHarmonyUrl] | [Documentation][toobusy-jsDOCUrl] | [![NPM version][toobusy-jsNPMVersionImage]][toobusy-jsNPMUrl]
[underscore][underscoreGHUrl] | [Documentation][underscoreDOCUrl] | [![NPM version][underscoreNPMVersionImage]][underscoreNPMUrl]
[useragent][useragentGHUrl] | [Documentation][useragentDOCUrl] | [![NPM version][useragentNPMVersionImage]][useragentNPMUrl]
[@octokit/auth-oauth-app][auth-oauth-appUrl] | [Documentation][auth-oauth-appDOCUrl] | [![NPM version][auth-oauth-appNPMVersionImage]][auth-oauth-appNPMUrl]
[@octokit/rest ᶠᵏᵃ ᵍᶦᵗʰᵘᵇ][githubGHUrl] | [Documentation][githubDOCUrl] | [![NPM version][githubNPMVersionImage]][githubNPMUrl]


##### Static

Repository | Reference | Recent Version | Stored
Expand Down Expand Up @@ -478,6 +478,11 @@ Outdated dependencies list can also be achieved with `$ npm outdated`
[squadaOneDOCUrl]: https://github.com/google/fonts/blob/master/README.md
[squadaOneGHUrlRecent]: https://github.com/google/fonts/blob/master/ofl/squadaone/SquadaOne-Regular.ttf

[auth-oauth-appGHUrl]: https://github.com/octokit/auth-oauth-app.js
[auth-oauth-appDOCUrl]: https://github.com/octokit/auth-oauth-app.js/blob/master/README.md
[auth-oauth-appNPMUrl]: https://www.npmjs.com/package/@octokit/auth-oauth-app
[auth-oauth-appNPMVersionImage]: https://img.shields.io/npm/v/@octokit/auth-oauth-app.svg?style=flat

[githubGHUrl]: https://github.com/octokit/rest.js
[githubDOCUrl]: https://github.com/octokit/rest.js/blob/master/README.md
[githubNPMUrl]: https://www.npmjs.com/package/@octokit/rest
Expand Down
41 changes: 36 additions & 5 deletions libs/githubClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ var isDbg = require('../libs/debug').isDbg;
var uaOUJS = require('../libs/debug').uaOUJS;

//
var GitHubApi = require("github");
var _ = require("underscore");
var async = require('async');
var util = require('util');
var request = require('request');
var colors = require('ansi-colors');

var GitHubApi = require("github");
var createOAuthAppAuth = require("@octokit/auth-oauth-app").createOAuthAppAuth;

// Client
var github = new GitHubApi({
version: "3.0.0"
Expand All @@ -22,23 +24,52 @@ module.exports = github;

// Authenticate Client
var Strategy = require('../models/strategy').Strategy;
Strategy.findOne({ name: 'github' }, function (aErr, aStrat) {
Strategy.findOne({ name: 'github' }, async function (aErr, aStrat) {
var auth = null;
var appAuthentication = null;

if (aErr)
console.error(aErr);

if (aStrat) {
// This authentication authorization is currently required to authorize this app
// to have the GitHub authentication callback work when the strategy `id` and `key` is found
// and additional usage of the `id` and `key` elsewhere in the Code

auth = createOAuthAppAuth({
clientType: 'oauth-app',
clientId: aStrat.id,
clientSecret: aStrat.key
});

appAuthentication = await auth({
type: "oauth-app"
});

// TODO: Do something with `appAuthentication`

// DEPRECATED: This method will break on May 5th, 2021. See #1705
// and importing a repo will be severely hindered with possible timeouts/failures
github.authenticate({
type: 'oauth',
key: aStrat.id,
secret: aStrat.key,
secret: aStrat.key
});
console.log(colors.green('GitHub client authenticated'));

// TODO: error handler for UnhandledPromiseRejectionWarning if it crops up after deprecation

if (github.auth) {
console.log(colors.green('GitHub client (a.k.a this app) is authenticated'));
} else {
console.log(colors.yellow('GitHub client (a.k.a this app) is partially authenticated'));
}
} else {
console.warn(colors.yellow('GitHub client NOT authenticated. Will have a lower Rate Limit.'));
console.warn(colors.red('GitHub client NOT authenticated. Will have a lower Rate Limit.'));
}

});


// Util functions for the client.
github.usercontent = github.usercontent || {};

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"ace-builds": "1.4.12",
"ansi-colors": "4.1.1",
"async": "3.2.0",
"@octokit/auth-oauth-app": "4.1.2",
"aws-sdk": "2.879.0",
"base62": "2.0.1",
"body-parser": "1.19.0",
Expand Down
2 changes: 2 additions & 0 deletions routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ module.exports = function (aApp) {
aApp.route('/users/:username/comments').get(listLimiter, user.userCommentListPage);
aApp.route('/users/:username/scripts').get(listLimiter, user.userScriptListPage);
aApp.route('/users/:username/syncs').get(listLimiter, user.userSyncListPage);

aApp.route('/users/:username/github/repos').get(authentication.validateUser, user.userGitHubRepoListPage);
aApp.route('/users/:username/github/repo').get(authentication.validateUser, user.userGitHubRepoPage);
aApp.route('/users/:username/github/import').post(authentication.validateUser, user.userGitHubImportScriptPage);

aApp.route('/users/:username/profile/edit').get(authentication.validateUser, user.userEditProfilePage).post(authentication.validateUser, user.update);
aApp.route('/users/:username/update').post(authentication.validateUser, admin.adminUserUpdate);
// NOTE: Some below inconsistent with priors
Expand Down

0 comments on commit e843506

Please sign in to comment.