Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(get-app-authentication): allow undefined as value for timeDi…
…fference parameter
  • Loading branch information
oscard0m committed Sep 24, 2024
commit 5433408310e65feab1e854bb3349f84b8fb2a06a
24 changes: 13 additions & 11 deletions src/get-app-authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ export async function getAppAuthentication({
privateKey,
timeDifference,
}: State & {
timeDifference?: number;
timeDifference?: number | undefined;
}): Promise<AppAuthentication> {
try {
const appAuthentication = timeDifference
? await githubAppJwt({
id: appId,
privateKey,
now: timeDifference && Math.floor(Date.now() / 1000) + timeDifference,
})
: await githubAppJwt({
id: appId,
privateKey,
});
const authOptions = {
id: appId,
privateKey,
};

if (timeDifference) {
Object.assign(authOptions, {
now: Math.floor(Date.now() / 1000) + timeDifference,
});
}

const appAuthentication = await githubAppJwt(authOptions);

return {
type: "app",
Expand Down
14 changes: 4 additions & 10 deletions src/get-installation-authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export async function getInstallationAuthentication(
state.cache,
optionsWithInstallationTokenFromState,
);

if (result) {
const {
token,
Expand All @@ -52,7 +53,7 @@ export async function getInstallationAuthentication(
repositorySelection,
} = result;

const authParams = {
return toTokenAuthentication({
installationId,
token,
createdAt,
Expand All @@ -61,15 +62,8 @@ export async function getInstallationAuthentication(
repositorySelection,
repositoryIds,
repositoryNames,
};

if (singleFileName) {
Object.assign(authParams, {
singleFileName,
});
}

return toTokenAuthentication(authParams);
singleFileName,
});
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ export type InstallationAccessTokenData = {
expiresAt: UTC_TIMESTAMP;
permissions: Permissions;
repositorySelection: REPOSITORY_SELECTION;
repositoryIds: number[] | undefined;
repositoryNames: string[] | undefined;
singleFileName?: string;
repositoryIds?: number[] | undefined;
repositoryNames?: string[] | undefined;
singleFileName?: string | undefined;
};

export type CacheData = InstallationAccessTokenData;
Expand Down