Skip to content

Commit 7dc08e5

Browse files
authoredMay 9, 2024··
feat: appId argument can be set to Client ID string (#606)
1 parent 81ac6ec commit 7dc08e5

8 files changed

+58
-29
lines changed
 

‎.github/workflows/release.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ name: Release
88
- "*.x"
99
# These are recommended by the semantic-release docs: https://github.com/semantic-release/npm#npm-provenance
1010
permissions:
11-
contents: write # to be able to publish a GitHub release
12-
issues: write # to be able to comment on released issues
13-
pull-requests: write # to be able to comment on released pull requests
14-
id-token: write # to enable use of OIDC for npm provenance
11+
contents: write # to be able to publish a GitHub release
12+
issues: write # to be able to comment on released issues
13+
pull-requests: write # to be able to comment on released pull requests
14+
id-token: write # to enable use of OIDC for npm provenance
1515

1616
jobs:
1717
release:
@@ -25,7 +25,7 @@ jobs:
2525
cache: npm
2626
- run: npm ci
2727
- run: npm run build
28-
- run: npx semantic-release
28+
- run: npx semantic-release@beta
2929
env:
3030
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3131
NPM_TOKEN: ${{ secrets.OCTOKITBOT_NPM_TOKEN }}

‎package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-10
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"@octokit/request-error": "^6.1.1",
3232
"@octokit/types": "^13.4.1",
3333
"lru-cache": "^10.0.0",
34-
"universal-github-app-jwt": "^2.0.6",
34+
"universal-github-app-jwt": "^2.2.0",
3535
"universal-user-agent": "^7.0.0"
3636
},
3737
"devDependencies": {
@@ -74,15 +74,6 @@
7474
}
7575
},
7676
"release": {
77-
"branches": [
78-
"+([0-9]).x",
79-
"main",
80-
"next",
81-
{
82-
"name": "beta",
83-
"prerelease": true
84-
}
85-
],
8677
"plugins": [
8778
"@semantic-release/commit-analyzer",
8879
"@semantic-release/release-notes-generator",

‎src/get-app-authentication.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ export async function getAppAuthentication({
66
appId,
77
privateKey,
88
timeDifference,
9-
}: State & { timeDifference?: number }): Promise<AppAuthentication> {
9+
}: State & {
10+
timeDifference?: number;
11+
}): Promise<AppAuthentication> {
1012
try {
1113
const appAuthentication = await githubAppJwt({
12-
id: +appId,
14+
id: appId,
1315
privateKey,
1416
now: timeDifference && Math.floor(Date.now() / 1000) + timeDifference,
1517
});

‎src/index.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ export function createAppAuth(options: StrategyOptions): AuthInterface {
3131
if (!options.appId) {
3232
throw new Error("[@octokit/auth-app] appId option is required");
3333
}
34-
if (!Number.isFinite(+options.appId)) {
35-
throw new Error(
36-
"[@octokit/auth-app] appId option must be a number or numeric string",
37-
);
38-
}
34+
3935
if (!options.privateKey) {
4036
throw new Error("[@octokit/auth-app] privateKey option is required");
4137
}

‎src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export type UTC_TIMESTAMP = string;
152152
export type AppAuthentication = {
153153
type: APP_TYPE;
154154
token: JWT;
155-
appId: number;
155+
appId: number | string;
156156
expiresAt: string;
157157
};
158158

‎test/index.test.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -2308,15 +2308,13 @@ it("throws helpful error if `appId` is not set (#184)", async () => {
23082308
}).toThrowError("[@octokit/auth-app] appId option is required");
23092309
});
23102310

2311-
it("throws helpful error if `appId` is not set to a numeric value", async () => {
2311+
it("allows passing an `appId` as a non numeric value", async () => {
23122312
expect(() => {
23132313
createAppAuth({
2314-
appId: "not-a-number",
2314+
appId: "Iv1.0123456789abcdef",
23152315
privateKey: PRIVATE_KEY,
23162316
});
2317-
}).toThrowError(
2318-
"[@octokit/auth-app] appId option must be a number or numeric string",
2319-
);
2317+
}).not.toThrow();
23202318
});
23212319

23222320
it("throws helpful error if `privateKey` is not set properly (#184)", async () => {

‎test/typescript-validate.ts

+42
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
// THIS CODE IS NOT EXECUTED. IT IS JUST FOR TYPECHECKING
33
// ************************************************************
44

5+
import { getAppAuthentication } from "../src/get-app-authentication.js";
6+
import { request } from "@octokit/request";
57
import { createAppAuth } from "../src/index.js";
8+
import { State, StrategyOptions } from "../src/types.js";
9+
import { getCache } from "../src/cache.js";
10+
import { createOAuthAppAuth } from "@octokit/auth-oauth-app";
611
function isString(what: string) {}
712

813
export async function readmeExample() {
@@ -31,3 +36,40 @@ export async function issue282() {
3136

3237
isString(authentication.token);
3338
}
39+
40+
// https://github.com/octokit/auth-app.js/issues/603
41+
export async function issue603() {
42+
createAppAuth({
43+
appId: "Iv1.0123456789abcdef",
44+
privateKey: "",
45+
});
46+
47+
const options: StrategyOptions = {
48+
appId: "Iv1.0123456789abcdef",
49+
privateKey: "",
50+
};
51+
52+
const state: State = Object.assign(
53+
{
54+
request,
55+
cache: getCache(),
56+
},
57+
options,
58+
options.installationId
59+
? { installationId: Number(options.installationId) }
60+
: {},
61+
{
62+
log: {
63+
warn: console.warn.bind(console),
64+
},
65+
oauthApp: createOAuthAppAuth({
66+
clientType: "github-app",
67+
clientId: options.clientId || "",
68+
clientSecret: options.clientSecret || "",
69+
request,
70+
}),
71+
},
72+
);
73+
74+
getAppAuthentication(state);
75+
}

0 commit comments

Comments
 (0)
Please sign in to comment.