Skip to content

Commit 9f350d3

Browse files
committed
refactor
1 parent c0815ed commit 9f350d3

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

server/src/app.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ import process from 'process'
3232

3333
// --- Initialization ------------------------------------------------------------------------------------------------
3434

35-
log.debug({appId: config.githubAppAuth.appId}, 'GitHub app')
36-
const GITHUB_ACTIONS_ACCESS_MANAGER = await accessTokenManager(config.githubAppAuth)
35+
const GITHUB_ACTIONS_ACCESS_MANAGER = await accessTokenManager(config)
3736

3837
// --- Server Setup --------------------------------------------------------------------------------------------------
3938
export const app = new Hono<{ Variables: { log: Logger, id: string } }>()

server/src/github-actions-access-manager.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,24 @@ import {Status} from './common/http-utils.js'
3030
import {components} from '@octokit/openapi-types'
3131
import {createAppAuth} from '@octokit/auth-app'
3232
import limit from 'p-limit'
33-
import {config} from './config.js'
3433
import log from './logger.js'
3534
import type {
3635
RestEndpointMethodTypes,
3736
} from '@octokit/plugin-rest-endpoint-methods/dist-types/generated/parameters-and-response-types'
3837

3938
/**
4039
* GitHub Access Manager
41-
* @param appAuth - GitHub App authentication
40+
* @param options - options
4241
* @returns access token manager
4342
*/
44-
export async function accessTokenManager(appAuth: {
45-
appId: string,
46-
privateKey: string,
47-
}) {
48-
const GITHUB_APP_CLIENT = new Octokit({authStrategy: createAppAuth, auth: appAuth})
43+
export async function accessTokenManager(options: {
44+
githubAppAuth: { appId: string, privateKey: string, },
45+
accessPolicyLocation: {
46+
owner: { repo: string, path: string,},
47+
repo: { path: string}
48+
}}) {
49+
log.debug({appId: options.githubAppAuth.appId}, 'GitHub app')
50+
const GITHUB_APP_CLIENT = new Octokit({authStrategy: createAppAuth, auth: options.githubAppAuth})
4951
const GITHUB_APP = await GITHUB_APP_CLIENT.apps.getAuthenticated()
5052
.then((res) => res.data!)
5153

@@ -106,8 +108,8 @@ export async function accessTokenManager(appAuth: {
106108

107109
// --- load owner access policy ----------------------------------------------------------------------------------
108110
const ownerAccessPolicy = await getOwnerAccessPolicy(appInstallationClient, {
109-
owner: tokenRequest.owner, repo: config.accessPolicyLocation.owner.repo,
110-
path: config.accessPolicyLocation.owner.path,
111+
owner: tokenRequest.owner, repo: options.accessPolicyLocation.owner.repo,
112+
path: options.accessPolicyLocation.owner.path,
111113
strict: false, // ignore invalid access policy entries
112114
})
113115
log.debug({ownerAccessPolicy}, `${tokenRequest.owner} access policy:`)
@@ -196,7 +198,7 @@ export async function accessTokenManager(appAuth: {
196198
tokenRequest.repositories.map((repo) => limitRepoPermissionRequests(async () => {
197199
const repoAccessPolicy = await getRepoAccessPolicy(appInstallationClient, {
198200
owner: tokenRequest.owner, repo,
199-
path: config.accessPolicyLocation.repo.path,
201+
path: options.accessPolicyLocation.repo.path,
200202
strict: false, // ignore invalid access policy entries
201203
})
202204
log.debug({repoAccessPolicy}, `${tokenRequest.owner}/${repo} access policy`)

0 commit comments

Comments
 (0)