Skip to content

Commit a94fdca

Browse files
committed
feat: new Probot({ appId }). Deprecates new Probot({ id })
1 parent 2ff5d21 commit a94fdca

3 files changed

Lines changed: 51 additions & 25 deletions

File tree

src/probot.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,16 @@ export class Probot {
101101
`[probot] "cert" option is deprecated. Use "privateKey" instead`
102102
)
103103
);
104-
options.privateKey = options.cert;
104+
options.privateKey = options.privateKey || options.cert;
105+
}
106+
107+
if (options.id) {
108+
this.log.warn(
109+
new Deprecation(
110+
`[probot] "id" option is deprecated. Use "appId" instead`
111+
)
112+
);
113+
options.appId = options.appId || options.id;
105114
}
106115

107116
if (process.env.INSTALLATION_TOKEN_TTL) {
@@ -121,7 +130,7 @@ export class Probot {
121130
const Octokit = getProbotOctokitWithDefaults({
122131
githubToken: options.githubToken,
123132
Octokit: options.Octokit || ProbotOctokit,
124-
appId: options.id,
133+
appId: Number(options.appId),
125134
privateKey: options.privateKey,
126135
cache,
127136
log: this.log,

test/deprecations.test.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe("Deprecations", () => {
5757

5858
it("new Probot({ cert })", () => {
5959
new Probot({
60-
id: 1,
60+
appId: 1,
6161
cert: "private key",
6262
log: pino(streamLogsToOutput),
6363
});
@@ -68,6 +68,19 @@ describe("Deprecations", () => {
6868
);
6969
});
7070

71+
it("new Probot({ appId })", () => {
72+
new Probot({
73+
id: 1,
74+
privateKey: "private key",
75+
log: pino(streamLogsToOutput),
76+
});
77+
78+
expect(output.length).toEqual(1);
79+
expect(output[0].msg).toContain(
80+
'[probot] "id" option is deprecated. Use "appId" instead'
81+
);
82+
});
83+
7184
it("probot.logger", () => {
7285
const probot = new Probot({ log: pino(streamLogsToOutput) });
7386
probot.logger.info("test");
@@ -150,7 +163,7 @@ describe("Deprecations", () => {
150163

151164
it("probot.webhooks.on('*', handler)", () => {
152165
const probot = new Probot({
153-
id: 1,
166+
appId: 1,
154167
privateKey: "private key",
155168
log: pino(streamLogsToOutput),
156169
});
@@ -277,7 +290,11 @@ describe("Deprecations", () => {
277290
let initialized = false;
278291

279292
process.env.APP_ID = "1";
280-
process.env.PRIVATE_KEY_PATH = join(__dirname, "test-private-key.pem");
293+
process.env.PRIVATE_KEY_PATH = join(
294+
__dirname,
295+
"fixtures",
296+
"test-private-key.pem"
297+
);
281298
process.env.WEBHOOK_PROXY_URL = "https://smee.io/EfHXC9BFfGAxbM6J";
282299
process.env.WEBHOOK_SECRET = "secret";
283300

test/probot.test.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Probot, ProbotOctokit, Context } from "../src";
99

1010
import { WebhookEvents } from "@octokit/webhooks";
1111

12-
const id = 1;
12+
const appId = 1;
1313
const privateKey = `-----BEGIN RSA PRIVATE KEY-----
1414
MIIBOQIBAAJBAIILhiN9IFpaE0pUXsesuuoaj6eeDiAqCiE49WB1tMB8ZMhC37kY
1515
Fl52NUYbUxb7JEf6pH5H9vqw1Wp69u78XeUCAwEAAQJAb88urnaXiXdmnIK71tuo
@@ -54,12 +54,12 @@ describe("Probot", () => {
5454
});
5555

5656
describe(".defaults()", () => {
57-
test.only("sets default options for constructor", async () => {
57+
test("sets default options for constructor", async () => {
5858
const mock = nock("https://api.github.com").get("/app").reply(200, {
5959
id: 1,
6060
});
6161

62-
const MyProbot = Probot.defaults({ id, privateKey });
62+
const MyProbot = Probot.defaults({ appId, privateKey });
6363
const probot = new MyProbot();
6464
const octokit = await probot.auth();
6565
await octokit.apps.getAuthenticated();
@@ -77,9 +77,9 @@ describe("Probot", () => {
7777
new Probot({ githubToken: "faketoken" });
7878
});
7979

80-
it('{ id, privateKey" }', () => {
81-
// probot with id/privateKey
82-
new Probot({ id, privateKey });
80+
it('{ appId, privateKey" }', () => {
81+
// probot with appId/privateKey
82+
new Probot({ appId, privateKey });
8383
});
8484

8585
it("shouldn't overwrite `options.throttle` passed to `{Octokit: ProbotOctokit.defaults(optiosn)}`", () => {
@@ -350,7 +350,7 @@ describe("Probot", () => {
350350
.reply(200, { id: 4 });
351351

352352
const probot = new Probot({
353-
id,
353+
appId,
354354
privateKey,
355355
});
356356

@@ -384,7 +384,7 @@ describe("Probot", () => {
384384
expect.assertions(2);
385385

386386
const probot = new Probot({
387-
id,
387+
appId,
388388
privateKey,
389389
});
390390

@@ -410,7 +410,7 @@ describe("Probot", () => {
410410

411411
it("calls callback when no action is specified", async () => {
412412
const probot = new Probot({
413-
id,
413+
appId,
414414
privateKey,
415415
});
416416

@@ -426,7 +426,7 @@ describe("Probot", () => {
426426

427427
it("calls callback with same action", async () => {
428428
const probot = new Probot({
429-
id,
429+
appId,
430430
privateKey,
431431
});
432432

@@ -439,7 +439,7 @@ describe("Probot", () => {
439439

440440
it("does not call callback with different action", async () => {
441441
const probot = new Probot({
442-
id,
442+
appId,
443443
privateKey,
444444
});
445445

@@ -452,7 +452,7 @@ describe("Probot", () => {
452452

453453
it("calls callback with *", async () => {
454454
const probot = new Probot({
455-
id,
455+
appId,
456456
privateKey,
457457
});
458458

@@ -465,7 +465,7 @@ describe("Probot", () => {
465465

466466
it("calls callback x amount of times when an array of x actions is passed", async () => {
467467
const probot = new Probot({
468-
id,
468+
appId,
469469
privateKey,
470470
});
471471

@@ -488,7 +488,7 @@ describe("Probot", () => {
488488

489489
it("adds a logger on the context", async () => {
490490
const probot = new Probot({
491-
id,
491+
appId,
492492
privateKey,
493493
log: pino(streamLogsToOutput),
494494
});
@@ -512,7 +512,7 @@ describe("Probot", () => {
512512

513513
it("returns an authenticated client for installation.created", async () => {
514514
const probot = new Probot({
515-
id,
515+
appId,
516516
privateKey,
517517
});
518518

@@ -549,7 +549,7 @@ describe("Probot", () => {
549549

550550
it("returns an unauthenticated client for installation.deleted", async () => {
551551
const probot = new Probot({
552-
id,
552+
appId,
553553
privateKey,
554554
});
555555

@@ -578,7 +578,7 @@ describe("Probot", () => {
578578

579579
it("returns an authenticated client for events without an installation", async () => {
580580
const probot = new Probot({
581-
id,
581+
appId,
582582
privateKey,
583583
});
584584

@@ -619,7 +619,7 @@ describe("Probot", () => {
619619

620620
it("delivers the event", async () => {
621621
const probot = new Probot({
622-
id,
622+
appId,
623623
privateKey,
624624
});
625625

@@ -633,7 +633,7 @@ describe("Probot", () => {
633633

634634
it("waits for async events to resolve", async () => {
635635
const probot = new Probot({
636-
id,
636+
appId,
637637
privateKey,
638638
});
639639

@@ -654,7 +654,7 @@ describe("Probot", () => {
654654

655655
it("returns a reject errors thrown in apps", async () => {
656656
const probot = new Probot({
657-
id,
657+
appId,
658658
privateKey,
659659
});
660660

0 commit comments

Comments
 (0)