@preventive/triage 1.0.0-alpha.67 → 1.0.0-alpha.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/common/managed/routes.js +19 -12
- package/out/activity.js +1 -1
- package/out/{chunk-LBJVV6UB.js → chunk-2F3CYNPZ.js} +1 -1
- package/out/{chunk-U5C2TNNQ.js → chunk-2HGKTQ5Q.js} +1 -1
- package/out/chunk-4RS3NDOG.js +1 -0
- package/out/{chunk-VR3NRE5V.js → chunk-D37M7J4B.js} +1 -1
- package/out/{chunk-LDO42LAC.js → chunk-GZ46SSTF.js} +1 -1
- package/out/{chunk-R3WUYD4F.js → chunk-HETCVNO4.js} +1 -1
- package/out/{chunk-5F5FPI75.js → chunk-MPXVKVPF.js} +1 -1
- package/out/{chunk-A5A3LEMV.js → chunk-OAWY4T6R.js} +1 -1
- package/out/{chunk-6YGH7BJG.js → chunk-QPGM3DTI.js} +1 -1
- package/out/{chunk-FUHRMY7R.js → chunk-SCN2TBP2.js} +5 -5
- package/out/client-managed-import.js +1 -1
- package/out/client-managed.js +2 -2
- package/out/compare.js +8 -8
- package/out/dialogs.js +2 -2
- package/out/graph.js +1 -1
- package/out/index.html +7 -7
- package/out/scan.js +1 -1
- package/out/view.css +1 -1
- package/out/view.js +1 -1
- package/package.json +1 -1
- package/server-managed/bundle-build-worker.js +59 -7
- package/server-managed/bundle-build.ts +9 -4
- package/server-managed/db-neon.ts +4 -1
- package/server-managed/dependency-review-comments.ts +13 -10
- package/server-managed/dependency-reviews.ts +17 -14
- package/server-managed/http.ts +65 -25
- package/server-managed/npm-patch.ts +101 -43
- package/server-managed/pull-dependencies.ts +9 -6
- package/server-managed/pull-dependency-reviews.ts +20 -11
- package/server-managed/repository-dependency-reviews.ts +4 -2
- package/server-managed/repository-issues.ts +3 -3
- package/server-managed/stasis-dependencies.ts +29 -12
- package/out/chunk-6ATPGDDI.js +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// A pnpm patch of an npm package version (patchedDependencies), as its
|
|
2
2
|
// dependency review reads it (pull-dependency-reviews.ts): its file, which a
|
|
3
3
|
// lockfile names (locked-packages.ts `patchPath`), or which is found where it
|
|
4
|
-
// names it by its hash alone (withPatchFiles),
|
|
5
|
-
// commit
|
|
6
|
-
//
|
|
7
|
-
// (one pnpm 9 names by an md5 isn't read), by which it is kept
|
|
8
|
-
// read of GitHub once; and applied to the version's files as pnpm applies
|
|
4
|
+
// names it by its hash alone (withPatchFiles), or by its hash among a
|
|
5
|
+
// commit's patches (foundPatch), read of a repository at a commit, and held
|
|
6
|
+
// to the hash the lockfile names it by, as pnpm 10 and later hash it
|
|
7
|
+
// (hashOfPatch; one pnpm 9 names by an md5 isn't read), by which it is kept
|
|
8
|
+
// for good, read of GitHub once; and applied to the version's files as pnpm applies
|
|
9
9
|
// it as it installs it (patch-package's applyPatch, which pnpm 10 and 11
|
|
10
10
|
// bundle): each file it deletes, creates, renames or changes, a change's
|
|
11
11
|
// hunks each found in the file as it was, where its header says, else as
|
|
@@ -20,22 +20,25 @@ import { YamlError, parseYaml } from '@preventive/lockfile/yaml.js'
|
|
|
20
20
|
import { isGithubRepoName } from '../common/github-pr.ts'
|
|
21
21
|
import { isPatchHash, isPatchPath } from '../common/managed/npm-packages.js'
|
|
22
22
|
import { GithubApiError } from './github-errors.ts'
|
|
23
|
+
import { isStasisConfig } from '../common/managed/stasis-config.ts'
|
|
23
24
|
import { SHA, isId } from './github-values.ts'
|
|
24
25
|
import { type LockedPackage, pathFrom } from './locked-packages.ts'
|
|
25
26
|
import { type Lru, lru } from './lru.ts'
|
|
26
27
|
import type { KeptStore } from './npm-kept.ts'
|
|
27
28
|
import { plainObject } from './npm-manifest.ts'
|
|
28
29
|
import { NpmPackageError, type NpmPackageFile, npmFileText, pathOrder } from './npm-packages.ts'
|
|
29
|
-
import { type GithubAsked, type PullDependencies, repositoryFile } from './pull-dependencies.ts'
|
|
30
|
+
import { type GithubAsked, type PullDependencies, lockfileFormat, repositoryFile } from './pull-dependencies.ts'
|
|
30
31
|
import { eachOf } from './queue.ts'
|
|
31
32
|
|
|
32
33
|
// Where a patch is read: its file in a repository (by its id) at a commit,
|
|
33
34
|
// from the repository's root; and the patch, by its hash besides. A request
|
|
34
35
|
// names its repository by its id, or by its name (`owner/name`) in its place
|
|
35
|
-
// (http.ts wholeRepositoryAccess)
|
|
36
|
+
// (http.ts wholeRepositoryAccess), and may leave its path out, the patch
|
|
37
|
+
// looked for there (foundPatch); or the patch by its hash alone, which only
|
|
38
|
+
// one kept answers (keptPatch).
|
|
36
39
|
export interface PatchSource { repoId: number; commit: string; path: string }
|
|
37
40
|
export interface NpmPatch extends PatchSource { hash: string }
|
|
38
|
-
export type RequestedPatch = Omit<NpmPatch, 'repoId'> & { repoId: number | string }
|
|
41
|
+
export type RequestedPatch = (Omit<NpmPatch, 'repoId' | 'path'> & { repoId: number | string; path?: string }) | { hash: string }
|
|
39
42
|
|
|
40
43
|
// The most a patch's file may hold, and how many lines either side of where a
|
|
41
44
|
// hunk says its lines are they are looked for; and how many patches an
|
|
@@ -47,21 +50,26 @@ const FIND_AT_ONCE = 4
|
|
|
47
50
|
|
|
48
51
|
// The patch a request names, by its hash (`hash`), its repository's id
|
|
49
52
|
// (`repoId`, a number or its digits) or name, the commit and its file's
|
|
50
|
-
// path; null where it names none
|
|
51
|
-
// names one otherwise.
|
|
52
|
-
export function requestedPatch({ hash, repoId, commit, path }: { hash: unknown; repoId
|
|
53
|
-
if ([repoId, commit, path].every(field => field == null)) return null
|
|
53
|
+
// path or none, or by its hash alone; null where it names none, and
|
|
54
|
+
// 'invalid' where it names one otherwise.
|
|
55
|
+
export function requestedPatch({ hash, repoId, commit, path }: { hash: unknown; repoId?: unknown; commit?: unknown; path?: unknown }): RequestedPatch | null | 'invalid' {
|
|
56
|
+
if ([repoId, commit, path].every(field => field == null)) return hash == null ? null : isPatchHash(hash) ? { hash } : 'invalid'
|
|
54
57
|
const id = typeof repoId === 'string' && /^[1-9]\d{0,15}$/u.test(repoId) ? Number(repoId) : repoId
|
|
55
58
|
if (!isPatchHash(hash) || !(isId(id) || typeof id === 'string' && isGithubRepoName(id)) || typeof commit !== 'string' || !SHA.test(commit)
|
|
56
|
-
|| !isPatchPath(path)) return 'invalid'
|
|
57
|
-
return { hash, repoId: id, commit, path }
|
|
59
|
+
|| path != null && !isPatchPath(path)) return 'invalid'
|
|
60
|
+
return { hash, repoId: id, commit, ...typeof path === 'string' ? { path } : {} }
|
|
58
61
|
}
|
|
59
62
|
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
// The hash pnpm names a patch's text by, a sha256 in hex of it with its
|
|
64
|
+
// CRLFs as LFs, as pnpm 10 and later read a patch's file (the CRs of lines
|
|
65
|
+
// it ends otherwise kept); and whether `text` is the patch `hash` names.
|
|
66
|
+
export const hashOfPatch = (text: string) => createHash('sha256').update(text.replaceAll('\r\n', '\n')).digest('hex')
|
|
67
|
+
export const isPatchOf = (text: string, hash: string) => hashOfPatch(text) === hash
|
|
68
|
+
|
|
69
|
+
// The text of a patch's file in repository `fullName` at `commit`, read with
|
|
70
|
+
// `token`; null where GitHub has no text of it, or it is past MAX_PATCH_BYTES.
|
|
71
|
+
const patchFileAt = (fullName: string, token: string, path: string, commit: string) => repositoryFile(fullName, token, path, commit).then(text => text !== null
|
|
72
|
+
&& Buffer.byteLength(text) > MAX_PATCH_BYTES ? null : text, (err: unknown) => { if (err instanceof GithubApiError && err.message === 'github-malformed') return null; throw err })
|
|
65
73
|
|
|
66
74
|
// A change a patch makes to a file at `path` of the package: deleting it,
|
|
67
75
|
// creating it, renaming it from another (`from`), and its hunks, as
|
|
@@ -302,7 +310,8 @@ export const patchKey = (repoId: number, hash: string) => `${repoId}\0${hash}`
|
|
|
302
310
|
// Patches read lately, with where each was read, by their keys, as many as
|
|
303
311
|
// MAX_KEPT_PATCHES of the bytes they take (patchWeight); and the path each
|
|
304
312
|
// found or kept is at (`located`): '' by its key and a commit for one not
|
|
305
|
-
// found there, lest each telling look again, none for one not looked for
|
|
313
|
+
// found there, lest each telling look again, none for one not looked for;
|
|
314
|
+
// and '' by its repository's key and a commit whose patches were all kept.
|
|
306
315
|
const MAX_KEPT_PATCHES = 64 * 1024 * 1024
|
|
307
316
|
export interface ReadPatch { source: PatchSource; files: PatchedFile[] }
|
|
308
317
|
const patches: Lru<ReadPatch> = lru(MAX_KEPT_PATCHES, read => patchWeight(read.files))
|
|
@@ -334,6 +343,52 @@ export async function readPatch(fullName: string, token: string, patch: NpmPatch
|
|
|
334
343
|
return read
|
|
335
344
|
}
|
|
336
345
|
|
|
346
|
+
// The patch `hash` names as kept, of the first of repositories `repoIds`
|
|
347
|
+
// that keeps it, in this instance, else beyond it (`kept`, held to its hash
|
|
348
|
+
// again), GitHub asked for none of it; null where none does.
|
|
349
|
+
export async function keptPatch(repoIds: number[], hash: string, kept: KeptStore<KeptPatch>): Promise<ReadPatch | null> {
|
|
350
|
+
const keys = repoIds.map(repoId => patchKey(repoId, hash))
|
|
351
|
+
const known = keys.map(key => patches.get(key)).find(Boolean)
|
|
352
|
+
if (known) return known
|
|
353
|
+
const stored = keys.length > 0 ? await kept.readMany(keys) : new Map()
|
|
354
|
+
for (const [at, key] of keys.entries()) {
|
|
355
|
+
const patch = stored.get(key)?.value
|
|
356
|
+
if (typeof patch?.text !== 'string' || !isPatchOf(patch.text, hash)) continue
|
|
357
|
+
const read = { source: { repoId: repoIds[at]!, commit: patch.commit, path: patch.path }, files: parsePatch(patch.text) }
|
|
358
|
+
patches.set(key, read)
|
|
359
|
+
return read
|
|
360
|
+
}
|
|
361
|
+
return null
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// The patch `patch` names by its hash at a commit of its repository, its
|
|
365
|
+
// file unnamed: as kept by its repository and hash (keptPatch); else among
|
|
366
|
+
// the patches of the commit's files (`listed` lists them, with their bytes;
|
|
367
|
+
// null where its repository isn't looked in), each `.patch` file in a
|
|
368
|
+
// `patches` directory beside a pnpm lockfile or a stasis.config.json, where
|
|
369
|
+
// pnpm patch-commit writes them, as many as MAX_FOUND, read of repository
|
|
370
|
+
// `fullName` with `token` and each kept for good by its own hash, so a
|
|
371
|
+
// commit is looked in once; `asked` told where GitHub was. One none of them
|
|
372
|
+
// is fails as not found.
|
|
373
|
+
export async function foundPatch(fullName: string, token: string, patch: Omit<NpmPatch, 'path'>, kept: KeptStore<KeptPatch>,
|
|
374
|
+
listed: () => Promise<{ files: string[]; sizes: number[] } | null>, asked?: GithubAsked): Promise<ReadPatch> {
|
|
375
|
+
const ofIt = () => keptPatch([patch.repoId], patch.hash, kept), searched = `${patchKey(patch.repoId, '')}\0${patch.commit}`
|
|
376
|
+
let found = await ofIt()
|
|
377
|
+
const tree = found || located.get(searched) !== undefined ? null : await listed()
|
|
378
|
+
if (tree) {
|
|
379
|
+
if (asked) asked.github = true
|
|
380
|
+
const dirOf = (path: string) => path.slice(0, path.lastIndexOf('/') + 1)
|
|
381
|
+
const beside = new Set(tree.files.filter(path => lockfileFormat(path) === 'pnpm' || isStasisConfig(path)).map(path => `${dirOf(path)}patches/`))
|
|
382
|
+
const paths = tree.files.filter((path, at) => path.endsWith('.patch') && beside.has(dirOf(path)) && (tree.sizes[at] ?? 0) <= MAX_PATCH_BYTES)
|
|
383
|
+
await eachOf(paths.slice(0, MAX_FOUND), FIND_AT_ONCE, path => patchFileAt(fullName, token, path, patch.commit)
|
|
384
|
+
.then(text => text === null ? undefined : kept.write(patchKey(patch.repoId, hashOfPatch(text)), { commit: patch.commit, path, text }, Date.now())))
|
|
385
|
+
located.set(searched, '')
|
|
386
|
+
found = await ofIt()
|
|
387
|
+
}
|
|
388
|
+
if (!found) throw new NpmPackageError(404, 'patch-not-found')
|
|
389
|
+
return found
|
|
390
|
+
}
|
|
391
|
+
|
|
337
392
|
// The files a pnpm-workspace.yaml (`workspace`, its text, null for none)
|
|
338
393
|
// names its patches by, as pnpm 11 and later read their patchedDependencies
|
|
339
394
|
// there alone, by a version or a package; none where its reader refuses it.
|
|
@@ -346,48 +401,51 @@ function patchedBy(workspace: string | null): Record<string, unknown> {
|
|
|
346
401
|
return plainObject(patched) ? patched : {}
|
|
347
402
|
}
|
|
348
403
|
|
|
349
|
-
// A version pnpm patches by a patch
|
|
350
|
-
// (pnpm 11's and later),
|
|
351
|
-
|
|
352
|
-
|
|
404
|
+
// A version pnpm patches by a patch named by a sha256, with its lockfile's
|
|
405
|
+
// directory: one its lockfile names by its hash alone (pnpm 11's and later),
|
|
406
|
+
// which wants its file found; and, `keepNamed`, one whose file it names.
|
|
407
|
+
type Patched = LockedPackage & { patchHash: string; patchDir: string; version: string }
|
|
408
|
+
const patchedBy256 = (pkg: LockedPackage, keepNamed = false): pkg is Patched => (pkg.patchPath === undefined || keepNamed) && pkg.patchDir !== undefined
|
|
409
|
+
&& pkg.version !== null && isPatchHash(pkg.patchHash)
|
|
353
410
|
|
|
354
|
-
// `told`, each
|
|
355
|
-
//
|
|
356
|
-
//
|
|
357
|
-
//
|
|
358
|
-
//
|
|
359
|
-
//
|
|
360
|
-
//
|
|
361
|
-
//
|
|
411
|
+
// `told`, each version of its that pnpm patches by a patch its lockfile names
|
|
412
|
+
// by its hash alone with its patch's file (`patchPath`), as a lockfile naming
|
|
413
|
+
// one tells it: as kept by its repository and hash, else the file the
|
|
414
|
+
// pnpm-workspace.yaml beside its lockfile names of it (patchedBy: its
|
|
415
|
+
// version's, else its package's) at `told.head`, held to its hash and kept
|
|
416
|
+
// for good, so each is found once, as many an answer as MAX_FOUND; one not
|
|
417
|
+
// found left with none. With `keepNamed`, as a default branch's are told,
|
|
418
|
+
// each patch whose file a lockfile names is read there and kept as well, so
|
|
419
|
+
// that a link naming it by its hash alone finds it later (keptPatch).
|
|
420
|
+
// `asked` told where GitHub was. A file GitHub has no text of, or past
|
|
421
|
+
// MAX_PATCH_BYTES, is none; any other failure of GitHub's is the whole
|
|
422
|
+
// answer's, as a lockfile's is.
|
|
362
423
|
export async function withPatchFiles<T extends PullDependencies>(told: T, repoId: number, fullName: string, token: string, kept: KeptStore<KeptPatch>,
|
|
363
|
-
asked?: GithubAsked): Promise<T> {
|
|
364
|
-
const wanted = new Map<string,
|
|
424
|
+
asked?: GithubAsked, { keepNamed = false } = {}): Promise<T> {
|
|
425
|
+
const wanted = new Map<string, Patched>()
|
|
365
426
|
for (const dir of told.lockfiles) {
|
|
366
|
-
for (const pkg of 'error' in dir ? [] : [...dir.added, ...dir.locked]) if (
|
|
427
|
+
for (const pkg of 'error' in dir ? [] : [...dir.added, ...dir.locked]) if (patchedBy256(pkg, keepNamed)) wanted.set(patchKey(repoId, pkg.patchHash), pkg)
|
|
367
428
|
}
|
|
368
429
|
if (wanted.size === 0) return told
|
|
369
430
|
const at = (key: string) => located.get(key) ?? located.get(`${key}\0${told.head}`)
|
|
370
431
|
const unknown = [...wanted.keys()].filter(key => at(key) === undefined)
|
|
371
432
|
for (const [key, { value }] of unknown.length > 0 ? await kept.readMany(unknown) : []) if (typeof value?.path === 'string') located.set(key, value.path)
|
|
372
|
-
const files = new Map<string, Promise<string | null>>()
|
|
373
|
-
const read = (path: string) => files.get(path) ?? files.set(path, repositoryFile(fullName, token, path, told.head).then(
|
|
374
|
-
text => text !== null && Buffer.byteLength(text) > MAX_PATCH_BYTES ? null : text,
|
|
375
|
-
(err: unknown) => { if (err instanceof GithubApiError && err.message === 'github-malformed') return null; throw err })).get(path)!
|
|
433
|
+
const files = new Map<string, Promise<string | null>>(), read = (path: string) => files.get(path) ?? files.set(path, patchFileAt(fullName, token, path, told.head)).get(path)!
|
|
376
434
|
const workspaces = new Map<string, Promise<Record<string, unknown>>>()
|
|
377
435
|
const namedIn = (dir: string) => workspaces.get(dir) ?? workspaces.set(dir, read(pathFrom(dir, 'pnpm-workspace.yaml')!).then(patchedBy)).get(dir)!
|
|
378
436
|
await eachOf(unknown.filter(key => at(key) === undefined).slice(0, MAX_FOUND), FIND_AT_ONCE, async key => {
|
|
379
437
|
const pkg = wanted.get(key)!
|
|
380
438
|
if (asked) asked.github = true
|
|
381
|
-
const patched = await namedIn(pkg.patchDir)
|
|
382
|
-
const file = patched[`${pkg.name}@${pkg.version}`] ?? patched[pkg.name]
|
|
383
|
-
const path = typeof file === 'string' ? pathFrom(pkg.patchDir, file) : null
|
|
439
|
+
const patched = pkg.patchPath === undefined ? await namedIn(pkg.patchDir) : {}
|
|
440
|
+
const file = pkg.patchPath ?? patched[`${pkg.name}@${pkg.version}`] ?? patched[pkg.name]
|
|
441
|
+
const path = typeof file === 'string' ? pkg.patchPath ?? pathFrom(pkg.patchDir, file) : null
|
|
384
442
|
const text = path === null ? null : await read(path)
|
|
385
443
|
if (path === null || text === null || !isPatchOf(text, pkg.patchHash)) { located.set(`${key}\0${told.head}`, ''); return }
|
|
386
444
|
await kept.write(key, { commit: told.head, path, text }, Date.now())
|
|
387
445
|
located.set(key, path)
|
|
388
446
|
})
|
|
389
447
|
const named = <P extends LockedPackage>(pkg: P): P => {
|
|
390
|
-
const patchPath =
|
|
448
|
+
const patchPath = patchedBy256(pkg) && at(patchKey(repoId, pkg.patchHash))
|
|
391
449
|
return patchPath ? { ...pkg, patchPath } : pkg
|
|
392
450
|
}
|
|
393
451
|
return { ...told, lockfiles: told.lockfiles.map(dir => 'error' in dir ? dir : { ...dir, added: dir.added.map(named), locked: dir.locked.map(named) }) }
|
|
@@ -148,21 +148,24 @@ const readKey = (ref: string, { path, format, sha }: { path: string; format: For
|
|
|
148
148
|
// base's moving on as it does, its head's with each push, both kept once it
|
|
149
149
|
// is merged or closed. With the branches they are of, where told: its base's
|
|
150
150
|
// (`baseRef`), whose history holds its merge base, and its head's
|
|
151
|
-
// (`headRef`) where that is the repository's own, not a fork's
|
|
152
|
-
|
|
151
|
+
// (`headRef`) where that is the repository's own, not a fork's; and that an
|
|
152
|
+
// open one's head is a fork's (`fork`), a commit of none of the repository's
|
|
153
|
+
// branches till it is merged, which Stasis builds nothing of.
|
|
154
|
+
export interface PullRefs { baseRef?: string; headRef?: string; fork?: true }
|
|
153
155
|
export interface PullCommits extends PullRefs { base: string; head: string }
|
|
154
|
-
// Those of `base` and `head` that are a branch's name.
|
|
155
|
-
export const pullRefs = (base: unknown, head: unknown): PullRefs =>
|
|
156
|
+
// Those of `base` and `head` that are a branch's name, and `fork` where it is told.
|
|
157
|
+
export const pullRefs = (base: unknown, head: unknown, fork?: unknown): PullRefs =>
|
|
158
|
+
({ ...branchName(base) ? { baseRef: base } : {}, ...branchName(head) ? { headRef: head } : {}, ...fork === true ? { fork } : {} })
|
|
156
159
|
async function pullCommits(fullName: string, token: string, number: number, fetchImpl: typeof fetch): Promise<PullCommits> {
|
|
157
160
|
const pull = await githubJson(`${repoApi(fullName)}/pulls/${number}`, token, fetchImpl) as
|
|
158
|
-
{ number?: unknown; base?: { sha?: unknown; ref?: unknown; repo?: { full_name?: unknown } | null }
|
|
161
|
+
{ number?: unknown; state?: unknown; base?: { sha?: unknown; ref?: unknown; repo?: { full_name?: unknown } | null }
|
|
159
162
|
head?: { sha?: unknown; ref?: unknown; repo?: { full_name?: unknown } | null } } | null
|
|
160
163
|
const base = pull?.base?.sha, head = pull?.head?.sha, repo = pull?.base?.repo?.full_name
|
|
161
164
|
if (pull?.number !== number || typeof base !== 'string' || !SHA.test(base) || typeof head !== 'string' || !SHA.test(head)
|
|
162
165
|
|| typeof repo !== 'string' || repo.toLowerCase() !== fullName.toLowerCase()) throw new GithubApiError(502, 'github-malformed')
|
|
163
166
|
const from = pull.head?.repo?.full_name
|
|
164
167
|
const own = typeof from === 'string' && from.toLowerCase() === repo.toLowerCase()
|
|
165
|
-
return { base, head, ...pullRefs(pull.base?.ref, own ? pull.head?.ref : undefined) }
|
|
168
|
+
return { base, head, ...pullRefs(pull.base?.ref, own ? pull.head?.ref : undefined, pull.state === 'open' && !own) }
|
|
166
169
|
}
|
|
167
170
|
|
|
168
171
|
// The pull request's merge base and the files it changes from it: as GitHub
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
// tarball (locked-packages.ts), with an integrity. One from git, another
|
|
17
17
|
// tarball (a mirror's too), or with no integrity can't be; a file of the
|
|
18
18
|
// project's isn't. Its reviews are those of it, of an integrity it is locked
|
|
19
|
-
// with, either whole,
|
|
20
|
-
//
|
|
19
|
+
// with, either whole, compared with any version of another package, or
|
|
20
|
+
// compared with a version of its own: for a version the pull request adds,
|
|
21
|
+
// one it was; for another, any. A patched
|
|
21
22
|
// one's (`patch`) are of it as patched, by its patch's hash, its patch read
|
|
22
23
|
// of the repository at its file, which its lockfile names, or which is found
|
|
23
24
|
// where it names it by its hash alone (npm-patch.ts withPatchFiles):
|
|
@@ -99,18 +100,19 @@ export function reviewsOf(pkg: LockedPackage, reviews: ReviewsOf): PublishedRevi
|
|
|
99
100
|
const hashes = hashesOf(pkg)
|
|
100
101
|
return (reviews.get(`${pkg.name}@${pkg.version}`) ?? []).filter(review => hashes.includes(review.integrity) && (review.patchHash ?? '') === (pkg.patchHash ?? ''))
|
|
101
102
|
}
|
|
102
|
-
// Whether `review` is of `pkg` whole,
|
|
103
|
-
// package (any,
|
|
103
|
+
// Whether `review` is of `pkg` whole, compared with a version of another
|
|
104
|
+
// package (any), or compared with one of `bases` of its own package (any,
|
|
105
|
+
// for `any`).
|
|
104
106
|
export const comparedWith = (review: PublishedReview, pkg: LockedPackage, bases: string[] | 'any') => review.basePackage === null
|
|
105
|
-
||
|
|
107
|
+
|| review.basePackage !== pkg.name || bases === 'any' || bases.includes(review.baseVersion ?? '')
|
|
106
108
|
|
|
107
109
|
const ACCEPTING = new Set(['accept', 'accept-with-nits'])
|
|
108
110
|
// Where `pkg`'s reviewers stand on it among `reviews`, those of its version,
|
|
109
111
|
// of an integrity it is locked with, and of its patch: each one's latest
|
|
110
112
|
// telling it, any rejecting it holding it unreviewed (`rejected`); those
|
|
111
113
|
// accepting it passing it (`passing`), each once, by a full, accepting
|
|
112
|
-
// review of theirs, whole
|
|
113
|
-
// (any, for `any`); and how many review it in its pull request's comments
|
|
114
|
+
// review of theirs, whole, compared with another package's version, or
|
|
115
|
+
// compared with one of `bases` of its own (any, for `any`); and how many review it in its pull request's comments
|
|
114
116
|
// alone (`commented`), which count for it alone: whose reviews passing it,
|
|
115
117
|
// else whose latest, are its comments'. Each reviewer too (`reviewers`), by
|
|
116
118
|
// their login, their latest verdict, whether they pass it, and whether that
|
|
@@ -234,7 +236,8 @@ export function heldDependencies<T extends PullDependencies>(told: T, scope: Loc
|
|
|
234
236
|
// wanting one of the reviews its comments make (`commentReviews`, where the
|
|
235
237
|
// host reads them), and the review's terms (`review`), with how many
|
|
236
238
|
// reviewers' its comments count (`commentReviews`), or that they couldn't be
|
|
237
|
-
// read (`commentsFailed`), and
|
|
239
|
+
// read (`commentsFailed`), and that reviews count by comments alone, those
|
|
240
|
+
// published here not (`byComments`, where the host reads them), and how many versions across its directories want
|
|
238
241
|
// reviews, of those it adds (`toReview`) and the rest (`unreviewed`), and
|
|
239
242
|
// can't be reviewed (`unsupported`), each once; how many the reviewed dependencies failed to
|
|
240
243
|
// answer (`unasked`), and whether they are registered (`reviewedDependencies`,
|
|
@@ -253,7 +256,13 @@ export async function reviewedDependencies(told: PullDependencies, state: RepoRe
|
|
|
253
256
|
const answered = heldDependencies(told, scope)
|
|
254
257
|
if (!state) return { ...answered, lockfiles: answered.lockfiles.map(dir => reviewedDirectory(dir, null)) }
|
|
255
258
|
const { cut, lockfiles: held } = answered
|
|
256
|
-
|
|
259
|
+
// Reviews published here count but where the host reads those pull
|
|
260
|
+
// requests' comments make (`parseComments`): what is reviewed is then the
|
|
261
|
+
// host's to tell, by those and its `lookup`, and one published here counts
|
|
262
|
+
// for nothing, whatever it was compared with: of a pull request's versions,
|
|
263
|
+
// a default branch's or a bundle's. Its author still copies it as a comment.
|
|
264
|
+
const published = reviewed?.parseComments ? [] : state.reviews
|
|
265
|
+
let context = { state, reviews: reviewsByVersion(published), baseline: reviewed ? null : baseline }
|
|
257
266
|
// What wants a review, as `lookup` is asked of, each once.
|
|
258
267
|
const wanting = () => {
|
|
259
268
|
const asked = new Map<string, ReviewedDependency>()
|
|
@@ -292,7 +301,7 @@ export async function reviewedDependencies(told: PullDependencies, state: RepoRe
|
|
|
292
301
|
}
|
|
293
302
|
const comments = parsing.size > 0 && commentReviews ? await commentReviews([...parsing.values()]) : { reviews: [], failed: false }
|
|
294
303
|
if (comments.reviews.length > 0) {
|
|
295
|
-
context = { ...context, reviews: reviewsByVersion([...
|
|
304
|
+
context = { ...context, reviews: reviewsByVersion([...published, ...comments.reviews.map(review => ({ ...review, comment: true as const }))]) }
|
|
296
305
|
await ask(new Map([...wanting()].filter(([key]) => !asked.has(key))))
|
|
297
306
|
}
|
|
298
307
|
const dirs = held.map(dir => reviewedDirectory(dir, (pkg, bases) => {
|
|
@@ -302,7 +311,7 @@ export async function reviewedDependencies(told: PullDependencies, state: RepoRe
|
|
|
302
311
|
const unread = baselineUnread.filter(path => heldTo(scope, path))
|
|
303
312
|
const listed = dirs.filter(dir => 'unreviewed' in dir)
|
|
304
313
|
return { ...answered, cut, lockfiles: dirs.map(dir => 'unreviewed' in dir ? capped(dir) : dir), review: { required: state.required,
|
|
305
|
-
since: reviewed ? null : state.since, canReview: state.canReview, ...reviewed ? { reviewedDependencies: true } : {},
|
|
314
|
+
since: reviewed ? null : state.since, canReview: state.canReview, ...reviewed ? { reviewedDependencies: true } : {}, ...reviewed?.parseComments ? { byComments: true } : {},
|
|
306
315
|
toReview: distinct(listed.map(dir => dir.toReview), versionKey), unreviewed: distinct(listed.map(dir => dir.unreviewed), versionKey),
|
|
307
316
|
unsupported: distinct(listed.map(dir => dir.unsupported), sourceKey),
|
|
308
317
|
...unasked > 0 ? { unasked } : {}, ...baselineError && !reviewed ? { baselineError } : {},
|
|
@@ -26,7 +26,9 @@ export interface RepoDependencyReview { enabled: boolean; required: number; sinc
|
|
|
26
26
|
// lockfile names it), the version it was compared with (none for a whole package's),
|
|
27
27
|
// who wrote it (`reviewer`, their id, else their login then), their login
|
|
28
28
|
// as it was then (`login`), its verdict, whether it checked every file
|
|
29
|
-
// (`full`), and when it was published.
|
|
29
|
+
// (`full`), and when it was published. One compared with a version as a patch
|
|
30
|
+
// changes it counts for none: what a pull request replaced isn't told by its
|
|
31
|
+
// patch.
|
|
30
32
|
// One made in a pull request's comments (`comment`) counts for it alone;
|
|
31
33
|
// one published here has its `id`.
|
|
32
34
|
export interface PublishedReview {
|
|
@@ -83,7 +85,7 @@ async function publishedReviews(db: ManagedSql, repoId: number, versions: Review
|
|
|
83
85
|
const rows = (await db.prepare(`SELECT r.id, r.user_id AS userId, r.user_login AS userLogin, r.package, r.version, r.integrity, r.patch_hash AS patchHash,
|
|
84
86
|
NULLIF(r.base_package, '') AS basePackage, NULLIF(r.base_version, '') AS baseVersion, r.files, r.status, r.published_at AS publishedAt
|
|
85
87
|
FROM managed_dependency_review r
|
|
86
|
-
WHERE r.ecosystem = 'npm' AND r.published_at IS NOT NULL AND r.revoked_at IS NULL AND r.status IS NOT NULL
|
|
88
|
+
WHERE r.ecosystem = 'npm' AND r.published_at IS NOT NULL AND r.revoked_at IS NULL AND r.status IS NOT NULL AND r.base_patch_hash = ''
|
|
87
89
|
AND r.package IN (${names.map(() => '?').join(',')}) AND r.version IN (${numbers.map(() => '?').join(',')})
|
|
88
90
|
AND EXISTS (SELECT 1 FROM managed_dependency_review_team rt JOIN managed_team t ON t.id = rt.team_id
|
|
89
91
|
WHERE rt.review_id = r.id AND ${COUNTING_TEAM})`).all(...names, ...numbers, repoId) as
|
|
@@ -179,11 +179,11 @@ export async function repositoryItem(fullName: string, token: string, number: nu
|
|
|
179
179
|
// An open pull request's base's and head's commits, by its number, as GitHub
|
|
180
180
|
// has them now: those its REST API names `base.sha` and `head.sha`
|
|
181
181
|
// (pull-dependencies.ts pullCommits), with the branches they are of
|
|
182
|
-
// (pullRefs), its head's where it is no fork's
|
|
183
|
-
// commit's id.
|
|
182
|
+
// (pullRefs), its head's where it is no fork's, and that it is one's where
|
|
183
|
+
// it is. None where either isn't a commit's id.
|
|
184
184
|
const commitsOf = (number: number, { baseRefOid: base, headRefOid: head, baseRefName, headRefName, isCrossRepository }: Node) =>
|
|
185
185
|
typeof base === 'string' && SHA.test(base) && typeof head === 'string' && SHA.test(head)
|
|
186
|
-
? [{ number, base, head, ...pullRefs(baseRefName, isCrossRepository === false ? headRefName : undefined) }] : []
|
|
186
|
+
? [{ number, base, head, ...pullRefs(baseRefName, isCrossRepository === false ? headRefName : undefined, isCrossRepository) }] : []
|
|
187
187
|
|
|
188
188
|
// The label the pull requests changing a repository's dependencies carry,
|
|
189
189
|
// as Dependabot's do: where it has one, a team's Dependencies reads its open
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
// commit and the file's path, which never change, in this instance and in
|
|
6
6
|
// the database, the versions alone. A build takes minutes, so none is waited
|
|
7
7
|
// for: one not kept is told as pending and built behind the answer, one at a
|
|
8
|
-
// time
|
|
9
|
-
//
|
|
8
|
+
// time, the one asked for last meanwhile following a quick one at once; any
|
|
9
|
+
// other is built when asked for again, as its page asks. A failed one is
|
|
10
|
+
// held in this instance, then built again as asked.
|
|
10
11
|
import { BundleBuildError, type LockfileInput, type StasisDependency } from './bundle-build.ts'
|
|
11
12
|
import { directoryOf, installsBundle, lockedVersions } from './bundle-dependency-reviews.ts'
|
|
12
13
|
import type { CommitLockfiles } from './commit-lockfiles.ts'
|
|
@@ -26,6 +27,10 @@ const FAILED_HELD_MS = 60 * 60_000
|
|
|
26
27
|
const TRANSIENT = new Set(['github-rate-limited', 'github-build-failed'])
|
|
27
28
|
// How long no build is tried again once one found its slot busy.
|
|
28
29
|
const BUSY_MS = 10_000
|
|
30
|
+
// How long after the first of them began builds follow one another at once:
|
|
31
|
+
// later, the next is built when asked for again, lest they outlast the
|
|
32
|
+
// invocation they run behind (serverless).
|
|
33
|
+
const FOLLOWED_WITHIN_MS = 60_000
|
|
29
34
|
// How often a build under way looks whether the server is stopping.
|
|
30
35
|
const STOPPING_EVERY_MS = 1000
|
|
31
36
|
|
|
@@ -46,6 +51,7 @@ interface ReaderOptions {
|
|
|
46
51
|
stopping(): boolean
|
|
47
52
|
}
|
|
48
53
|
|
|
54
|
+
type Job = { key: string; input: LockfileInput; github: string; token: string }
|
|
49
55
|
const optional = (value: unknown) => value === undefined || typeof value === 'string'
|
|
50
56
|
const dependenciesOf = (value: unknown) => Array.isArray(value) && value.every(one => plainObject(one) && typeof one['name'] === 'string'
|
|
51
57
|
&& typeof one['version'] === 'string' && optional(one['integrity']) && optional(one['patch'])) ? value as StasisDependency[] : null
|
|
@@ -53,10 +59,10 @@ const dependenciesOf = (value: unknown) => Array.isArray(value) && value.every(o
|
|
|
53
59
|
export function stasisDependencyReader({ store, build, behind, stopping }: ReaderOptions): StasisDependencyReader {
|
|
54
60
|
const known: Lru<{ read: StasisRead; until: number }> = lru(500_000, ({ read }) => read.status === 'ready' ? read.dependencies.length + 1 : 1)
|
|
55
61
|
const hold = (key: string, read: StasisRead, until = Infinity) => { known.set(key, { read, until }); return read }
|
|
56
|
-
//
|
|
57
|
-
let building =
|
|
62
|
+
// The one being built here, till when none is tried after one found its slot busy, and the one asked for last meanwhile.
|
|
63
|
+
let building: string | null = null, busyTill = 0, next: Job | null = null
|
|
58
64
|
|
|
59
|
-
async function built(key
|
|
65
|
+
async function built({ key, input, github, token }: Job) {
|
|
60
66
|
const stop = new AbortController()
|
|
61
67
|
const watching = setInterval(() => { if (stopping()) stop.abort() }, STOPPING_EVERY_MS)
|
|
62
68
|
watching.unref()
|
|
@@ -73,10 +79,19 @@ export function stasisDependencyReader({ store, build, behind, stopping }: Reade
|
|
|
73
79
|
if (!refused) console.warn('managed: stasis dependencies build failed:', err)
|
|
74
80
|
const transient = !refused || TRANSIENT.has(code)
|
|
75
81
|
hold(key, { status: 'failed', error: code, transient }, Date.now() + (transient ? TRANSIENT_HELD_MS : FAILED_HELD_MS))
|
|
76
|
-
} finally {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
} finally { clearInterval(watching) }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// `first` built, then the one asked for last meanwhile, and so on while the first began FOLLOWED_WITHIN_MS ago or less.
|
|
86
|
+
async function run(first: Job) {
|
|
87
|
+
const began = Date.now()
|
|
88
|
+
try {
|
|
89
|
+
for (let job: Job | null = first; job; job = Date.now() - began < FOLLOWED_WITHIN_MS && Date.now() >= busyTill && !stopping() ? next : null) {
|
|
90
|
+
building = job.key
|
|
91
|
+
next = null
|
|
92
|
+
await built(job)
|
|
93
|
+
}
|
|
94
|
+
} finally { building = next = null }
|
|
80
95
|
}
|
|
81
96
|
|
|
82
97
|
return {
|
|
@@ -86,9 +101,11 @@ export function stasisDependencyReader({ store, build, behind, stopping }: Reade
|
|
|
86
101
|
if (held && Date.now() < held.until) return held.read
|
|
87
102
|
const kept = dependenciesOf((await store.read(key))?.value)
|
|
88
103
|
if (kept) return hold(key, { status: 'ready', dependencies: kept })
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
104
|
+
const job = { key, input: { repoId, commit, config, ...branch !== undefined && { branch } }, github: fullName, token }
|
|
105
|
+
if (building !== null) next = building === key ? next : job
|
|
106
|
+
else if (Date.now() >= busyTill && !stopping()) {
|
|
107
|
+
building = key
|
|
108
|
+
behind(run(job))
|
|
92
109
|
}
|
|
93
110
|
return { status: 'pending' }
|
|
94
111
|
},
|
package/out/chunk-6ATPGDDI.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./chunk-QRKFPLA4.js";var t=new Set([`overview`,`graph`,`treemap`,`compare`,`advisories`,`issues`,`code`,`search`,`terminal`]),n=/^\d+$/u;function r(e){for(let t=0;t<e.length;t++){let n=e.codePointAt(t);if(n<32||n===127)return!0}return!1}var i=512;function a(e){return typeof e==`string`&&e.length>0&&e.length<=i&&!r(e)}function o(e){return a(e)&&!n.test(e)}function s(e){return e===`completed`||e===`not_planned`||e===`duplicate`?e:`unknown`}function c(e){let[t,n,r]=e.split(`/`);return r===void 0&&t!==void 0&&n!==void 0&&t.length<=39&&/^[a-zA-Z\d](?:-?[a-zA-Z\d])*$/u.test(t)&&n.length<=100&&n!==`.`&&n!==`..`&&/^[a-zA-Z\d._-]+$/u.test(n)}function l(e,t){if(typeof e!=`string`||e.length>2048)return null;let n;try{n=new URL(e)}catch{return null}if(n.href!==e||n.origin!==`https://github.com`||n.username||n.password)return null;let r=t.exec(n.pathname);if(!r)return null;let i=`${r[1]}/${r[2]}`,a=Number(r[3]);return!c(i)||!Number.isSafeInteger(a)||a<=0?null:{repo:i,number:a}}function u(e){return l(e,/^\/([^/]+)\/([^/]+)\/pull\/(\d+)(?:\/(?:files|commits|checks))?\/?$/u)}function d(e){return l(e,/^\/([^/]+)\/([^/]+)\/issues\/(\d+)\/?$/u)}function f(e){let t=u(e);if(t)return{...t,kind:`pull`};let n=d(e);return n?{...n,kind:`issue`}:null}function p(e){return`${e.repo.toLowerCase()}#${e.kind}:${e.number}`}var m=/^(?=.{1,214}$)(?:@[\w.-]+\/[\w-]|[\dA-Za-z])[\w.-]*$/u,h=/^(?=.{1,256}$)[\dA-Za-z][\w.+-]*$/u,g=/^@[\da-z~-][\w.~-]*$/u,ee=/^[\da-f]{64}$/u;function _(e){return typeof e==`string`&&m.test(e)}function v(e){return typeof e==`string`&&h.test(e)}function y(e){return typeof e==`string`&&ee.test(e)}function b(e){return typeof e==`string`&&e.length>0&&e.length<=1024&&!/[\p{Cc}\\]/u.test(e)&&e.split(`/`).every(e=>e!==``&&e!==`.`&&e!==`..`)}function x(e){if(typeof e!=`string`)return null;let t=e.trim().toLowerCase(),n=t.startsWith(`@`)?t:`@${t}`;return n.length<=214&&g.test(n)?n:null}var S=e=>typeof e==`string`&&e.length>0&&e.length<=256&&!/[\p{Cc}]/u.test(e);function C(t){let n=t.get(`repo`),r=new Set((t.get(`severity`)??``).split(`,`)),i=e.filter(e=>r.has(e)),a={...S(n)?{repo:n}:{},...i.length>0?{severities:i}:{}};return Object.keys(a).length>0?{filters:a}:{}}function w(t){let n=e.filter(e=>t?.severities?.includes(e)),r=[...S(t?.repo)?[`repo=${encodeURIComponent(t.repo).replaceAll(`%2F`,`/`)}`]:[],...n.length>0?[`severity=${n.join(`,`)}`]:[]];return r.length>0?`?${r.join(`&`)}`:``}var T=new Set([`code`,`diff`]),E=e=>T.has(e)?`code`:`overview`,D=e=>T.has(e)?{compareMode:`code`}:{},O=e=>T.has(e)?`/code`:``,k=Object.freeze({manage:`/manage`,"manage-bundles":`/manage/bundle`,"manage-scans":`/manage/scans`,"manage-reports":`/manage/report`,"manage-repos":`/manage/repositories`,"manage-repo-risk":`/manage/repositories/risk`,"admin-users":`/manage/users`,"manage-teams":`/manage/team`,"manage-import":`/manage/import`,"manage-links":`/manage/links`,"manage-deduplication":`/manage/deduplication`,"manage-history":`/manage/history`}),A=new Set([`workspace-reports`,`workspace-bundles`,`workspace-repositories`,`workspace-dependencies`]),j=new Set([`pulls`,`versions`,`branch`,`reviews`]),M=e=>e.view===`workspace-dependencies`&&e.dependencyTab!=null?{dependencyTab:e.dependencyTab}:{};function N(e){if(!o(e)||e===`.`||e===`..`)return null;try{return`/finding/${encodeURIComponent(e)}`}catch{return null}}function P(e){if(!e)return null;if(e.view===`home`)return`/`;if(e.view===`reviews`)return`/my/reviews`;if(e.view===`profile`)return`/my/profile`;if(e.view===`npm`)return L(e);if(e.view===`repository-code`)return J(e);if(A.has(e.view)){let t=M(e).dependencyTab??`pulls`;return!/^[A-Za-z0-9_-]+$/u.test(e.teamSlug??``)||!j.has(t)?null:`/team/${e.teamSlug}/${e.view.slice(10)}${t===`pulls`?``:`/${t}`}`}if(e.view===`bundles`){if(!/^[A-Za-z0-9_-]+$/u.test(e.bundleSlug??``)||[e.teamSlug,e.compareSlug].some(e=>e!=null&&!/^[A-Za-z0-9_-]+$/u.test(e)))return null;let n=e.bundleTab??`overview`;if(!t.has(n))return null;let r=e.teamSlug?`/team/${e.teamSlug}`:`/manage`,i=n===`code`&&X(e.file)?`/${e.file}`:``,a=i&&X(e.line)?`#L${e.line}${X(e.endLine)&&e.endLine>e.line?`-L${e.endLine}`:``}`:``,o=n===`compare`&&e.compareSlug!=null?`/${e.compareSlug}${O(e.compareMode)}`:``;return`${r}/bundle/${e.bundleSlug}${n===`overview`?``:`/${n}`}${i}${o}${a}`}if(Object.hasOwn(k,e.view)){let t=k[e.view];return e.view===`manage-deduplication`&&e.linkId?`${t}?report=${encodeURIComponent(e.linkId)}`:e.view===`manage-bundles`&&Number.isSafeInteger(e.createRepoId)&&e.createRepoId>0?`${t}?createRepo=${e.createRepoId}`:e.view===`manage-scans`&&e.scanMode===`link`?`${t}?mode=link`:e.view===`manage-scans`&&e.bundleId?`${t}?bundle=${encodeURIComponent(e.bundleId)}${e.scanMode===`dependencies`?`&mode=dependencies`:``}`:e.view===`manage-history`&&e.actor?`${t}?actor=${encodeURIComponent(e.actor)}`:t}if(![`findings`,`files`].includes(e.view)||!e.teamSlug||[e.teamSlug,e.reportSlug].some(e=>e!=null&&!/^[A-Za-z0-9_-]+$/u.test(e)))return null;let n=`/team/${encodeURIComponent(e.teamSlug)}`,r=e.reportSlug?`/report/${encodeURIComponent(e.reportSlug)}`:``;if(e.finding){let t=N(e.finding.id);return e.view===`findings`&&t?`${n}${r}${t}`:null}return e.view===`files`?`${n}${r}/files`:`${n}${r}${r?``:w(e.filters)}`}var F=new Set([`overview`,`code`,`search`,`compare`,`review`,`treemap`]),I=e=>y(e?.hash)&&(K(e.repoId)||typeof e.repoId==`string`&&c(e.repoId))&&W.test(e.commit??``)&&b(e.path);function L(e){if(e.packageName==null)return`/npm`;let t=e.bundleTab??`overview`;if(!_(e.packageName)||e.packageSpec!=null&&!v(e.packageSpec)||!F.has(t)||e.compareSpec!=null&&!v(e.compareSpec))return null;if(t===`review`){if(e.reviewPackage!=null&&!_(e.reviewPackage)||e.reviewSpec!=null&&!v(e.reviewSpec)||e.patch!=null&&!I(e.patch))return null;let t=e.reviewPackage==null?``:`/${e.reviewPackage}${e.reviewSpec==null?``:`@${e.reviewSpec}`}`,n=e.patch==null?``:`?patch=${e.patch.hash}&repo=${e.patch.repoId}&commit=${e.patch.commit}&path=${e.patch.path.split(`/`).map(encodeURIComponent).join(`/`)}`;return`/npm/${e.packageName}${e.packageSpec==null?``:`@${e.packageSpec}`}/review${t}${n}`}let n=t===`code`&&X(e.file)?`/${e.file}`:``,r=n&&X(e.line)?`#L${e.line}${X(e.endLine)&&e.endLine>e.line?`-L${e.endLine}`:``}`:``,i=t===`compare`&&e.compareSpec!=null?`/${e.compareSpec}${O(e.compareMode)}`:``;return`/npm/${e.packageName}${e.packageSpec==null?``:`@${e.packageSpec}`}${t===`overview`?``:`/${t}`}${n}${i}${r}`}function R(e,t,n){let r=/^\/npm\/((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+))?\/review(?:\/((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+))?)?$/u.exec(e);if(r){if(!_(r[1])||r[2]!=null&&!v(r[2])||r[3]!=null&&!_(r[3])||r[4]!=null&&!v(r[4]))return null;let e=r[3]&&/^\d+\.\d+\.\d+(?:[-+].*)?$/u.test(r[3])&&r[4]==null,t=n.has(`patch`)?{hash:n.get(`patch`),repoId:/^[1-9]\d*$/u.test(n.get(`repo`)??``)?Number(n.get(`repo`)):n.get(`repo`),commit:n.get(`commit`),path:n.get(`path`)}:null;return t&&!I(t)?null:{view:`npm`,packageName:r[1],packageSpec:r[2]??null,bundleTab:`review`,...r[3]?{reviewPackage:e?r[1]:r[3],reviewSpec:e?r[3]:r[4]??null}:{},...t?{patch:t}:{}}}let i=/^\/npm(?:\/((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+))?(?:\/(code|search|compare|treemap)(?:\/([^/]+)(?:\/([a-z]+))?)?)?)?$/u.exec(e);if(!i)return;if(i[1]==null)return{view:`npm`};if(!_(i[1])||i[2]!=null&&!v(i[2]))return null;let a={view:`npm`,packageName:i[1],packageSpec:i[2]??null,bundleTab:i[3]??`overview`};if(i[4]==null)return a;if(a.bundleTab===`compare`)return v(i[4])&&(i[5]==null||T.has(i[5]))?{...a,compareSpec:i[4],...D(i[5])}:null;if(a.bundleTab!==`code`)return null;let o=Number(i[4]);return!i[5]&&/^[1-9]\d*$/u.test(i[4])&&Number.isSafeInteger(o)?{...a,file:o,...Z(t)}:null}var z=new Set([`code`,`search`,`treemap`,`compare`,`commits`,`issues`,`pulls`,`agents`,`pulse`,`replay`]),B=new Set([`commits`,`issues`,`pulls`,`agents`,`pulse`,`replay`]),V=new Map([[`issues`,new Set([`closed`])],[`pulls`,new Set([`closed`])],[`pulse`,new Set([`week`,`quarter`,`year`])],[`replay`,new Set([`100`,`1000`])]]),H=/^[a-z][a-z\d-]{0,31}$/u,U=(e,t)=>e===`agents`?typeof t==`string`&&H.test(t)&&t!==`all`:V.get(e)?.has(t)===!0,W=/^[a-f\d]{40}$/u,G=500,K=e=>Number.isSafeInteger(e)&&e>0;function q(e){return typeof e==`string`&&(e===``||e.length<=G&&!/[\p{Cc}\\]/u.test(e)&&e.split(`/`).every(e=>e!==``&&e!==`.`&&e!==`..`&&e===e.trim()))}function J(e){let t=e.bundleTab??`code`,n=e.path??``;if(!K(e.repoId)||e.commit!=null&&!W.test(e.commit)||!q(n)||!z.has(t)||e.compareCommit!=null&&!W.test(e.compareCommit))return null;let r=n?`?path=${n.split(`/`).map(encodeURIComponent).join(`/`)}`:``;if(e.commit==null)return`/repo/${e.repoId}${r}`;let i=t===`code`&&X(e.file)?`/code/${e.file}`:t===`code`?``:`/${t}`,a=t===`compare`&&e.compareCommit!=null?`/${e.compareCommit}${O(e.compareMode)}`:``,o=U(t,e.subtab)?`/${e.subtab}`:``,s=t===`code`&&X(e.file)&&X(e.line)?`#L${e.line}${X(e.endLine)&&e.endLine>e.line?`-L${e.endLine}`:``}`:``;return`/repo/${e.repoId}/${e.commit}${i}${a}${o}${r}${s}`}function Y(e){let t=/^\/(?:repo|manage\/code)\/([1-9]\d*)(?:\/([a-f\d]{40})(?:\/(code|search|treemap|compare|commits|history|issues|pulls|agents|pulse|replay)(?:\/([^/]+)(?:\/([a-z]+))?)?)?)?$/u.exec(e.pathname.replace(/\/$/u,``));if(!t)return;let n=Number(t[1]),r=e.searchParams.get(`path`)??``,i=t[3]===`history`?`commits`:t[3]??`code`;if(!K(n)||!q(r))return null;let a={view:`repository-code`,repoId:n,commit:t[2]??null,path:r,bundleTab:i};if(t[4]==null)return a;if(i===`compare`)return W.test(t[4])&&(t[5]==null||T.has(t[5]))?{...a,compareCommit:t[4],...D(t[5])}:null;if(B.has(i))return t[5]==null&&U(i,t[4])?{...a,subtab:t[4]}:null;let o=Number(t[4]);return i===`code`&&t[5]==null&&/^[1-9]\d*$/u.test(t[4])&&Number.isSafeInteger(o)?{...a,file:o,...Z(e.hash)}:null}function X(e){return Number.isSafeInteger(e)&&e>0}function Z(e){let t=/^#L([1-9]\d*)(?:-L([1-9]\d*))?$/u.exec(e),[n,r]=t?[Number(t[1]),Number(t[2]??t[1])]:[];return!X(n)||!X(r)?{}:n===r?{line:n}:{line:Math.min(n,r),endLine:Math.max(n,r)}}function Q(e){let n=e.pathname.replace(/\/$/u,``)||`/`;if(n===`/`||n===`/index.html`)return{view:`home`};if(n===`/my/reviews`)return{view:`reviews`};if(n===`/my/profile`){let t=e.searchParams.get(`link-error`);return{view:`profile`,...t&&/^[a-z-]{1,64}$/u.test(t)?{linkError:t}:{}}}let r=Object.keys(k).find(e=>k[e]===n);if(r){let t=Number(e.searchParams.get(`createRepo`));return{view:r,...r===`manage-deduplication`&&e.searchParams.get(`report`)?{linkId:e.searchParams.get(`report`)}:{},...r===`manage-bundles`&&Number.isSafeInteger(t)&&t>0?{createRepoId:t}:{},...r===`manage-history`&&e.searchParams.get(`actor`)?{actor:e.searchParams.get(`actor`)}:{},...r===`manage-scans`?e.searchParams.get(`mode`)===`link`?{scanMode:`link`}:e.searchParams.get(`bundle`)?{bundleId:e.searchParams.get(`bundle`),...e.searchParams.get(`mode`)===`dependencies`?{scanMode:`dependencies`}:{}}:{}:{}}}let a=/^(?:\/team\/([A-Za-z0-9_-]+)|\/manage)\/bundle\/([A-Za-z0-9_-]+)(?:\/([a-z]+)(?:\/([A-Za-z0-9_-]+)(?:\/([a-z]+))?)?)?$/u.exec(n);if(a){let n=a[3]??`overview`;if(!t.has(n))return null;let r={view:`bundles`,teamSlug:a[1]??null,bundleSlug:a[2],bundleTab:n};if(a[4]==null)return r;if(n===`compare`)return a[5]==null||T.has(a[5])?{...r,compareSlug:a[4],...D(a[5])}:null;let i=Number(a[4]);return n!==`code`||a[5]||!/^[1-9]\d*$/u.test(a[4])||!Number.isSafeInteger(i)?null:{...r,file:i,...Z(e.hash)}}let o=R(n,e.hash,e.searchParams);if(o!==void 0)return o;let s=Y(e);if(s!==void 0)return s;let c=/^\/team\/([A-Za-z0-9_-]+)\/(reports|bundles|repositories|dependencies)$/u.exec(n);if(c)return{view:`workspace-${c[2]}`,teamSlug:c[1]};let l=/^\/team\/([A-Za-z0-9_-]+)\/dependencies\/([a-z]+)$/u.exec(n);if(l)return j.has(l[2])?{view:`workspace-dependencies`,teamSlug:l[1],dependencyTab:l[2]}:null;let u=/^\/team\/([^/]+)(?:\/report\/([^/]+))?(?:\/(files)|\/finding\/([^/]+))?$/u.exec(n);if(!u)return null;try{let t=decodeURIComponent(u[1]),n=u[2]?decodeURIComponent(u[2]):null;if([t,n].some(e=>e!=null&&!/^[A-Za-z0-9_-]+$/u.test(e))||u[4]?.length>i*9)return null;let r=u[4]?decodeURIComponent(u[4]):null;return r!=null&&!N(r)?null:u[3]?{view:`files`,teamSlug:t,reportSlug:n}:r==null?{view:`findings`,teamSlug:t,reportSlug:n,...n==null?C(e.searchParams):{}}:{view:`findings`,teamSlug:t,reportSlug:n,finding:{id:r}}}catch{return null}}function $(e,t,n=[]){if(A.has(e.view)){let n=t.filter(t=>t.slug===e.teamSlug);return n.length===1?{view:e.view,teamId:n[0].id,...M(e)}:null}if(e.view===`bundles`){let{teamSlug:r,bundleSlug:i,compareSlug:a,compareMode:o,...s}=e,c=r==null?[]:t.filter(e=>e.slug===r);if(r!=null&&c.length!==1)return null;let l=c[0],u=r==null?n:t.flatMap(e=>e.bundles??[]),d=e=>new Set(u.filter(t=>t.slug===e).map(e=>e.id)),f=d(i),p=(l?.bundles??n).find(e=>e.slug===i);if(!i||!p||f.size!==1)return null;let m=a==null?null:d(a),h=m?.size===1?{compareId:[...m][0],...D(o)}:{};return{...s,teamId:l?.id??null,bundleId:p.id,...h}}if(![`findings`,`files`].includes(e.view))return e;let{teamSlug:r,reportSlug:i,...a}=e,o=t.filter(e=>e.slug===r),s=r&&o.length===1?o[0]:null,c=new Set(t.flatMap(e=>e.reports??[]).filter(e=>e.slug===i).map(e=>e.id)),l=i!=null&&c.size===1?[...c][0]:null;return a.finding?{...a,teamId:s?.id??null,reportId:l,teamOnly:i==null}:s?i==null?{...a,teamId:s.id,reportId:null}:(s.reports??[]).some(e=>e.id===l)?{...a,teamId:s.id,reportId:l}:null:null}function te(e,t,n=[]){if(A.has(e.view)){let n=t.find(t=>t.id===e.teamId),r={view:e.view,teamSlug:n?.slug,...M(e)};return n?.slug&&$(r,t)?r:null}if(e.view===`bundles`){let{teamId:r,bundleId:i,compareId:a,compareMode:o,...s}=e,c=t.find(e=>e.id===r);if(r!=null&&!c?.slug)return null;let l=(c?.bundles??n).find(e=>e.id===i);if(!l?.slug)return null;let u=a==null?null:(r==null?n:t.flatMap(e=>e.bundles??[])).find(e=>e.id===a),d={...s,teamSlug:c?.slug??null,bundleSlug:l.slug,...u?.slug?{compareSlug:u.slug,...D(o)}:{}},f=$(d,t,n);if(!f)return null;if(d.compareSlug!=null&&f.compareId!==a){let{compareSlug:e,compareMode:t,...n}=d;return n}return d}if(![`findings`,`files`].includes(e.view))return e;let{teamId:r,reportId:i,...a}=e,o=t.find(e=>e.id===r),s=i==null?null:o?.reports?.find(e=>e.id===i);if(!o?.slug||i!=null&&!s?.slug)return null;let c={...a,teamSlug:o.slug,reportSlug:s?.slug??null},l=$(c,t);return l?.teamId===o.id&&l.reportId===(s?.id??null)?c:null}export{t as a,i as b,o as c,s as d,u as e,d as f,f as g,p as h,_ as i,v as j,y as k,b as l,x as m,E as n,D as o,k as p,j as q,P as r,F as s,z as t,B as u,U as v,Q as w,$ as x,te as y};
|