Skip to content

Commit dec6cdb

Browse files
committed
fix github source handling
1 parent 08bdb26 commit dec6cdb

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎apps/app/server/api/snapshot/config.put.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { kv } from '@nuxthub/kv'
22
import { z } from 'zod'
3+
import { createError } from 'evlog'
34
import { getSnapshotRepoConfig, setSnapshotRepoConfig } from '../../utils/sandbox/snapshot-config'
45
import { KV_KEYS } from '../../utils/sandbox/types'
56
import { requireAdmin } from '../../utils/admin'
@@ -23,11 +24,13 @@ export default defineEventHandler(async (event) => {
2324
const snapshotRepo = body.snapshotRepo.trim()
2425
const snapshotBranch = body.snapshotBranch?.trim() || 'main'
2526

26-
const token = await getSnapshotToken()
27+
const token = await getSnapshotToken(snapshotRepo)
2728
if (!token) {
2829
throw createError({
29-
statusCode: 400,
30+
status: 400,
3031
message: 'GitHub token not found',
32+
why: 'Could not resolve a GitHub token for this repository',
33+
fix: 'Ensure your GitHub App is installed on this repository, or set NUXT_GITHUB_TOKEN',
3134
})
3235
}
3336

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { getToken, resolveGitHubAuth } from '@savoir/github/server/utils'
22
import { getSnapshotRepoConfig } from './sandbox/snapshot-config'
33

4-
export async function getSnapshotToken(): Promise<string | undefined> {
4+
export async function getSnapshotToken(repoPath?: string): Promise<string | undefined> {
55
const config = useRuntimeConfig()
6-
const snapshotConfig = await getSnapshotRepoConfig()
76

87
const auth = resolveGitHubAuth(config.github)
98
if (!auth) return undefined
109

11-
return getToken(auth, snapshotConfig.snapshotRepo)
10+
const targetRepo = repoPath || (await getSnapshotRepoConfig()).snapshotRepo
11+
return getToken(auth, targetRepo)
1212
}

0 commit comments

Comments
 (0)