Skip to content

Commit

Permalink
fix: remove deprecated { id } option
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `createAppAuth({ id, privateKey })` is no longer supported. Use `createAppAuth({ appId, privateKey })` instead
  • Loading branch information
gr2m committed Feb 19, 2021
1 parent 76115c2 commit 7cb0a8d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/get-app-authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function getAppAuthentication({
appId,
privateKey,
timeDifference,
}: State): Promise<AppAuthentication> {
}: State & { timeDifference?: number }): Promise<AppAuthentication> {
const appAuthentication = await githubAppJwt({
id: +appId,
privateKey,
Expand Down
4 changes: 2 additions & 2 deletions src/get-oauth-authentication.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
RequestInterface,
OAuthOptions,
StrategyOptionsWithDefaults,
State,
OAuthAccesTokenAuthentication,
} from "./types";
import { RequestError } from "@octokit/request-error";

export async function getOAuthAuthentication(
state: StrategyOptionsWithDefaults,
state: State,
options: OAuthOptions,
customRequest?: RequestInterface
): Promise<OAuthAccesTokenAuthentication> {
Expand Down
12 changes: 0 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getUserAgent } from "universal-user-agent";
import { request } from "@octokit/request";
import { Deprecation } from "deprecation";

import { auth } from "./auth";
import { hook } from "./hook";
Expand Down Expand Up @@ -30,14 +29,6 @@ export const createAppAuth: StrategyInterface = function createAppAuth(
options.log
);

if ("id" in options) {
log.warn(
new Deprecation(
'[@octokit/auth-app] "createAppAuth({ id })" is deprecated, use "createAppAuth({ appId })" instead'
)
);
}

const state: State = Object.assign(
{
request: request.defaults({
Expand All @@ -48,9 +39,6 @@ export const createAppAuth: StrategyInterface = function createAppAuth(
cache: getCache(),
},
options,
{
appId: Number("appId" in options ? options.appId : options.id),
},
options.installationId
? { installationId: Number(options.installationId) }
: {},
Expand Down
35 changes: 7 additions & 28 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type OAuthStrategyOptions = {
};

type CommonStrategyOptions = {
appId: number | string;
privateKey: string;
installationId?: number | string;
request?: OctokitTypes.RequestInterface;
Expand All @@ -88,34 +89,12 @@ type CommonStrategyOptions = {
};
};

type DeprecatedStrategyOptions = OAuthStrategyOptions &
CommonStrategyOptions & {
/**
* @deprecated id is deprecated, use appId instead
*/
id: number | string;
};

type CurrentStrategyOptions = OAuthStrategyOptions &
CommonStrategyOptions & {
appId: number | string;
};
export type StrategyOptions = OAuthStrategyOptions &
CommonStrategyOptions & { [key: string]: unknown };

export type StrategyOptions = (
| DeprecatedStrategyOptions
| CurrentStrategyOptions
) & { [key: string]: unknown };

export type FactoryOptions = Required<
Omit<CurrentStrategyOptions, keyof State>
> &
export type FactoryOptions = Required<Omit<StrategyOptions, keyof State>> &
State;

export type StrategyOptionsWithDefaults = CurrentStrategyOptions &
Required<
Omit<CurrentStrategyOptions, keyof OAuthStrategyOptions | "installationId">
>;

export type Permissions = {
[name: string]: string;
};
Expand Down Expand Up @@ -146,6 +125,6 @@ export type WithInstallationId = {
installationId: number;
};

export type State = StrategyOptionsWithDefaults & {
timeDifference: number;
};
export type State = Required<Omit<CommonStrategyOptions, "installationId">> & {
installationId?: number;
} & OAuthStrategyOptions;
39 changes: 20 additions & 19 deletions test/deprecations.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { Deprecation } from "deprecation";
import { createAppAuth } from "../src/index";

describe("deprecations", () => {
test("createAppAuth({ id }) - #44", () => {
const warn = jest.fn();
test("There are currently no deprecations", () => {});

// example:
//
// test("createAppAuth({ id }) - #44", () => {
// const warn = jest.fn();

createAppAuth({
id: 1,
privateKey: "...",
log: {
warn,
},
});
// createAppAuth({
// id: 1,
// privateKey: "...",
// log: {
// warn,
// },
// });

expect(warn).toHaveBeenCalledTimes(1);
expect(warn).toHaveBeenCalledWith(
new Deprecation(
'[@octokit/auth-app] "createAppAuth({ id })" is deprecated, use "createAppAuth({ appId })" instead'
)
);
});
// expect(warn).toHaveBeenCalledTimes(1);
// expect(warn).toHaveBeenCalledWith(
// new Deprecation(
// '[@octokit/auth-app] "createAppAuth({ id })" is deprecated, use "createAppAuth({ appId })" instead'
// )
// );
// });
});

0 comments on commit 7cb0a8d

Please sign in to comment.