Skip to content

Commit 08a3c51

Browse files
committed
feat: octokit.registerEndpoints()
1 parent 0a11e0c commit 08a3c51

File tree

7 files changed

+31
-15
lines changed

7 files changed

+31
-15
lines changed

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ const factory = require('./lib/factory')
22

33
const CORE_PLUGINS = [
44
require('./plugins/authentication'),
5-
require('./plugins/endpoint-methods'),
6-
require('./plugins/pagination')
5+
require('./plugins/pagination'),
6+
require('./plugins/register-endpoints'),
7+
require('./plugins/rest-api-endpoints'),
8+
require('./plugins/validate')
79
]
810

911
module.exports = factory(CORE_PLUGINS)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = octokitRegisterEndpoints
2+
3+
const registerEndpoints = require('./register-endpoints')
4+
5+
function octokitRegisterEndpoints (octokit) {
6+
octokit.registerEndpoints = registerEndpoints.bind(null, octokit)
7+
}

plugins/endpoint-methods/index.js renamed to plugins/register-endpoints/register-endpoints.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
1-
'use strict'
1+
module.exports = registerEndpoints
22

3-
module.exports = apiPlugin
4-
5-
const validate = require('./validate')
6-
const ENDPOINT_DEFAULTS = require('./routes.json')
7-
8-
function apiPlugin (octokit) {
9-
octokit.hook.before('request', validate)
10-
11-
Object.keys(ENDPOINT_DEFAULTS).forEach(namespaceName => {
3+
function registerEndpoints (octokit, routes) {
4+
Object.keys(routes).forEach(namespaceName => {
125
octokit[namespaceName] = {}
136

14-
Object.keys(ENDPOINT_DEFAULTS[namespaceName]).forEach(apiName => {
15-
let apiOptions = ENDPOINT_DEFAULTS[namespaceName][apiName]
7+
Object.keys(routes[namespaceName]).forEach(apiName => {
8+
let apiOptions = routes[namespaceName][apiName]
169
let deprecated
1710

1811
if (apiOptions.alias) {
1912
deprecated = apiOptions.deprecated
2013
const [aliasNamespaceName, aliasApiName] = apiOptions.alias.split('.')
21-
apiOptions = ENDPOINT_DEFAULTS[aliasNamespaceName][aliasApiName]
14+
apiOptions = routes[aliasNamespaceName][aliasApiName]
2215
}
2316

2417
const endpointDefaults = ['method', 'url', 'headers'].reduce((map, key) => {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = octokitRestApiEndpoints
2+
3+
const ROUTES = require('./routes.json')
4+
5+
function octokitRestApiEndpoints (octokit) {
6+
octokit.registerEndpoints(ROUTES)
7+
}
File renamed without changes.

plugins/validate/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = octokitValidate
2+
3+
const validate = require('./validate')
4+
5+
function octokitValidate (octokit) {
6+
octokit.hook.before('request', validate)
7+
}
File renamed without changes.

0 commit comments

Comments
 (0)