Skip to content

Commit

Permalink
refactor: comment out code for deprecations (until we have them again)
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Jan 31, 2020
1 parent 6f85e31 commit 591a4c3
Showing 1 changed file with 56 additions and 60 deletions.
116 changes: 56 additions & 60 deletions src/endpoints-to-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ export function endpointsToMethods(

const scopeMethods = newMethods[scope] as EndpointMethods;

if (decorations) {
scopeMethods[methodName] = decorate(
octokit,
scope,
methodName,
endpointDefaults,
decorations
);
continue;
}
// if (decorations) {
// scopeMethods[methodName] = decorate(
// octokit,
// scope,
// methodName,
// endpointDefaults,
// decorations
// );
// continue;
// }

scopeMethods[methodName] = octokit.request.defaults(endpointDefaults);
}
Expand All @@ -52,53 +52,49 @@ export function endpointsToMethods(
return newMethods as RestEndpointMethods;
}

function decorate(
octokit: Octokit,
scope: string,
methodName: string,
defaults: EndpointOptions,
decorations: EndpointDecorations
) {
const requestWithDefaults = octokit.request.defaults(defaults);

function withDeprecations(
...args: [Route, RequestParameters?] | [EndpointOptions]
) {
if (decorations.renamed) {
const [newScope, newMethodName] = decorations.renamed;
octokit.log.warn(
`octokit.${scope}.${methodName}() has been renamed to octokit.${newScope}.${newMethodName}()`
);
}

if (decorations.deprecated) {
octokit.log.warn(decorations.deprecated);
}

if (decorations.renamedParameters) {
// @ts-ignore https://github.com/microsoft/TypeScript/issues/25488
const options = requestWithDefaults.endpoint.merge(...args);

for (const [name, alias] of Object.entries(
decorations.renamedParameters
)) {
if (name in options) {
octokit.log.warn(
`"${name}" parameter is deprecated for "octokit.${scope}.${methodName}()". Use "${alias}" instead`
);
if (!(alias in options)) {
options[alias] = options[name];
}
delete options[name];
}
}

return requestWithDefaults(options);
}

// @ts-ignore https://github.com/microsoft/TypeScript/issues/25488
return requestWithDefaults(...args);
}

return Object.assign(withDeprecations, requestWithDefaults);
}
// NOTE: there are currently no deprecations. But we keep the code
// below for future reference
// function decorate(
// octokit: Octokit,
// scope: string,
// methodName: string,
// defaults: EndpointOptions,
// decorations: EndpointDecorations
// ) {
// const requestWithDefaults = octokit.request.defaults(defaults);

// function withDeprecations(
// ...args: [Route, RequestParameters?] | [EndpointOptions]
// ) {
// if (decorations.renamed) {
// const [newScope, newMethodName] = decorations.renamed;
// octokit.log.warn(
// `octokit.${scope}.${methodName}() has been renamed to octokit.${newScope}.${newMethodName}()`
// );
// }
// if (decorations.deprecated) {
// octokit.log.warn(decorations.deprecated);
// }
// if (decorations.renamedParameters) {
// // @ts-ignore https://github.com/microsoft/TypeScript/issues/25488
// const options = requestWithDefaults.endpoint.merge(...args);
// for (const [name, alias] of Object.entries(
// decorations.renamedParameters
// )) {
// if (name in options) {
// octokit.log.warn(
// `"${name}" parameter is deprecated for "octokit.${scope}.${methodName}()". Use "${alias}" instead`
// );
// if (!(alias in options)) {
// options[alias] = options[name];
// }
// delete options[name];
// }
// }
// return requestWithDefaults(options);
// }
// // @ts-ignore https://github.com/microsoft/TypeScript/issues/25488
// return requestWithDefaults(...args);
// }
// return Object.assign(withDeprecations, requestWithDefaults);
// }

0 comments on commit 591a4c3

Please sign in to comment.