Skip to content

Commit 2a11fbd

Browse files
chore(deps): update dependency @octokit/tsconfig to v4 (#646)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Oscar Dominguez <[email protected]>
1 parent b3ce19b commit 2a11fbd

File tree

5 files changed

+65
-31
lines changed

5 files changed

+65
-31
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"lint:fix": "prettier --write '{src,test,scripts}/**/*.{ts,md}' README.md *.json",
1414
"pretest": "npm run -s lint",
1515
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage",
16-
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals --esModuleInterop --strict --target es2022 --module node16 --moduleResolution node16 test/typescript-validate.ts"
16+
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals --esModuleInterop --strict --target es2022 --module node16 --moduleResolution node16 --exactOptionalPropertyTypes test/typescript-validate.ts"
1717
},
1818
"repository": "github:octokit/auth-app.js",
1919
"keywords": [
@@ -35,7 +35,7 @@
3535
"universal-user-agent": "^7.0.0"
3636
},
3737
"devDependencies": {
38-
"@octokit/tsconfig": "^3.0.0",
38+
"@octokit/tsconfig": "^4.0.0",
3939
"@types/fetch-mock": "^7.3.1",
4040
"@types/jest": "^29.0.0",
4141
"@types/node": "^20.0.0",

src/get-app-authentication.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@ export async function getAppAuthentication({
77
privateKey,
88
timeDifference,
99
}: State & {
10-
timeDifference?: number;
10+
timeDifference?: number | undefined;
1111
}): Promise<AppAuthentication> {
1212
try {
13-
const appAuthentication = await githubAppJwt({
13+
const authOptions = {
1414
id: appId,
1515
privateKey,
16-
now: timeDifference && Math.floor(Date.now() / 1000) + timeDifference,
17-
});
16+
};
17+
18+
if (timeDifference) {
19+
Object.assign(authOptions, {
20+
now: Math.floor(Date.now() / 1000) + timeDifference,
21+
});
22+
}
23+
24+
const appAuthentication = await githubAppJwt(authOptions);
1825

1926
return {
2027
type: "app",

src/get-installation-authentication.ts

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export async function getInstallationAuthentication(
4040
state.cache,
4141
optionsWithInstallationTokenFromState,
4242
);
43+
4344
if (result) {
4445
const {
4546
token,
@@ -69,6 +70,30 @@ export async function getInstallationAuthentication(
6970
const appAuthentication = await getAppAuthentication(state);
7071
const request = customRequest || state.request;
7172

73+
const payload = {
74+
installation_id: installationId,
75+
mediaType: {
76+
previews: ["machine-man"],
77+
},
78+
headers: {
79+
authorization: `bearer ${appAuthentication.token}`,
80+
},
81+
};
82+
83+
if (options.repositoryIds) {
84+
Object.assign(payload, { repository_ids: options.repositoryIds });
85+
}
86+
87+
if (options.repositoryNames) {
88+
Object.assign(payload, {
89+
repositories: options.repositoryNames,
90+
});
91+
}
92+
93+
if (options.permissions) {
94+
Object.assign(payload, { permissions: options.permissions });
95+
}
96+
7297
const {
7398
data: {
7499
token,
@@ -78,18 +103,10 @@ export async function getInstallationAuthentication(
78103
repository_selection: repositorySelectionOptional,
79104
single_file: singleFileName,
80105
},
81-
} = await request("POST /app/installations/{installation_id}/access_tokens", {
82-
installation_id: installationId,
83-
repository_ids: options.repositoryIds,
84-
repositories: options.repositoryNames,
85-
permissions: options.permissions,
86-
mediaType: {
87-
previews: ["machine-man"],
88-
},
89-
headers: {
90-
authorization: `bearer ${appAuthentication.token}`,
91-
},
92-
});
106+
} = await request(
107+
"POST /app/installations/{installation_id}/access_tokens",
108+
payload,
109+
);
93110

94111
/* istanbul ignore next - permissions are optional per OpenAPI spec, but we think that is incorrect */
95112
const permissions = permissionsOptional || {};
@@ -105,18 +122,23 @@ export async function getInstallationAuthentication(
105122
: void 0;
106123

107124
const createdAt = new Date().toISOString();
108-
await set(state.cache, optionsWithInstallationTokenFromState, {
125+
const cacheOptions = {
109126
token,
110127
createdAt,
111128
expiresAt,
112129
repositorySelection,
113130
permissions,
114131
repositoryIds,
115132
repositoryNames,
116-
singleFileName,
117-
});
133+
};
134+
135+
if (singleFileName) {
136+
Object.assign(payload, { singleFileName });
137+
}
138+
139+
await set(state.cache, optionsWithInstallationTokenFromState, cacheOptions);
118140

119-
return toTokenAuthentication({
141+
const cacheData = {
120142
installationId,
121143
token,
122144
createdAt,
@@ -125,6 +147,11 @@ export async function getInstallationAuthentication(
125147
permissions,
126148
repositoryIds,
127149
repositoryNames,
128-
singleFileName,
129-
});
150+
};
151+
152+
if (singleFileName) {
153+
Object.assign(cacheData, { singleFileName });
154+
}
155+
156+
return toTokenAuthentication(cacheData);
130157
}

src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ export type InstallationAccessTokenData = {
162162
expiresAt: UTC_TIMESTAMP;
163163
permissions: Permissions;
164164
repositorySelection: REPOSITORY_SELECTION;
165-
repositoryIds?: number[];
166-
repositoryNames?: string[];
167-
singleFileName?: string;
165+
repositoryIds?: number[] | undefined;
166+
repositoryNames?: string[] | undefined;
167+
singleFileName?: string | undefined;
168168
};
169169

170170
export type CacheData = InstallationAccessTokenData;

0 commit comments

Comments
 (0)