Skip to content

Commit

Permalink
refactor(get-app-authentication): allow undefined as value for timeDi…
Browse files Browse the repository at this point in the history
…fference parameter
  • Loading branch information
oscard0m committed Sep 24, 2024
1 parent fd67b16 commit 5433408
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
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

0 comments on commit 5433408

Please sign in to comment.