Skip to content

Commit

Permalink
feat: octokit.registerEndpoints()
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Nov 17, 2018
1 parent 0a11e0c commit 08a3c51
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ const factory = require('./lib/factory')

const CORE_PLUGINS = [
require('./plugins/authentication'),
require('./plugins/endpoint-methods'),
require('./plugins/pagination')
require('./plugins/pagination'),
require('./plugins/register-endpoints'),
require('./plugins/rest-api-endpoints'),
require('./plugins/validate')
]

module.exports = factory(CORE_PLUGINS)
7 changes: 7 additions & 0 deletions plugins/register-endpoints/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = octokitRegisterEndpoints

const registerEndpoints = require('./register-endpoints')

function octokitRegisterEndpoints (octokit) {
octokit.registerEndpoints = registerEndpoints.bind(null, octokit)
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
'use strict'
module.exports = registerEndpoints

module.exports = apiPlugin

const validate = require('./validate')
const ENDPOINT_DEFAULTS = require('./routes.json')

function apiPlugin (octokit) {
octokit.hook.before('request', validate)

Object.keys(ENDPOINT_DEFAULTS).forEach(namespaceName => {
function registerEndpoints (octokit, routes) {
Object.keys(routes).forEach(namespaceName => {
octokit[namespaceName] = {}

Object.keys(ENDPOINT_DEFAULTS[namespaceName]).forEach(apiName => {
let apiOptions = ENDPOINT_DEFAULTS[namespaceName][apiName]
Object.keys(routes[namespaceName]).forEach(apiName => {
let apiOptions = routes[namespaceName][apiName]
let deprecated

if (apiOptions.alias) {
deprecated = apiOptions.deprecated
const [aliasNamespaceName, aliasApiName] = apiOptions.alias.split('.')
apiOptions = ENDPOINT_DEFAULTS[aliasNamespaceName][aliasApiName]
apiOptions = routes[aliasNamespaceName][aliasApiName]
}

const endpointDefaults = ['method', 'url', 'headers'].reduce((map, key) => {
Expand Down
7 changes: 7 additions & 0 deletions plugins/rest-api-endpoints/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = octokitRestApiEndpoints

const ROUTES = require('./routes.json')

function octokitRestApiEndpoints (octokit) {
octokit.registerEndpoints(ROUTES)
}
File renamed without changes.
7 changes: 7 additions & 0 deletions plugins/validate/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = octokitValidate

const validate = require('./validate')

function octokitValidate (octokit) {
octokit.hook.before('request', validate)
}
File renamed without changes.

0 comments on commit 08a3c51

Please sign in to comment.