@preventive/triage 1.0.0-alpha.67 → 1.0.0-alpha.69
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 +3 -3
- 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-DVIYJG3F.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-FUHRMY7R.js → chunk-NA3BSFFM.js} +6 -6
- package/out/{chunk-6YGH7BJG.js → chunk-QPGM3DTI.js} +1 -1
- package/out/{chunk-A5A3LEMV.js → chunk-Y3MWMG7M.js} +1 -1
- 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 +38 -38
- 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 +15 -15
- 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 +18 -13
- package/server-managed/dependency-reviews.ts +17 -14
- package/server-managed/http.ts +93 -42
- package/server-managed/npm-patch.ts +101 -43
- package/server-managed/pull-dependencies.ts +30 -21
- package/server-managed/pull-dependency-reviews.ts +63 -26
- package/server-managed/repository-dependency-reviews.ts +4 -2
- package/server-managed/repository-issues.ts +3 -3
- package/server-managed/reviewed-dependencies.ts +44 -24
- package/server-managed/stasis-dependencies.ts +34 -16
- package/server.ts +1 -1
- package/out/chunk-6ATPGDDI.js +0 -1
|
@@ -87,8 +87,8 @@ export function touchesLockfile(paths: string[], changed: number): boolean | nul
|
|
|
87
87
|
// A package version new to a directory, as its lockfile locks it, with its
|
|
88
88
|
// integrity, which its reviews are held to; of a package its lockfiles locked
|
|
89
89
|
// before, the versions of it they did (`was`, the highest first), none of one
|
|
90
|
-
// new to it.
|
|
91
|
-
export type AddedPackage = LockedPackage & { was?: string[] }
|
|
90
|
+
// new to it; and the version the host names to review it against (`base`).
|
|
91
|
+
export type AddedPackage = LockedPackage & { was?: string[]; base?: { name: string; version: string } }
|
|
92
92
|
// A directory's lockfiles the pull request changes (`paths`, those it adds,
|
|
93
93
|
// modifies, removes or renames, by either name): the package versions they
|
|
94
94
|
// lock new to it, by name and version (as many as MAX_LOCKED, told as many
|
|
@@ -105,11 +105,14 @@ export type DirectoryDependencies = { paths: string[] } & ({ added: AddedPackage
|
|
|
105
105
|
// in; and `cut` where it changes more files than GitHub lists, or lockfiles
|
|
106
106
|
// in more directories than are read, with, where only those cut it and they
|
|
107
107
|
// are few enough, the paths of those directories' lockfiles (`omitted`), for
|
|
108
|
-
// a review holding to none of them to fail in nothing
|
|
109
|
-
|
|
108
|
+
// a review holding to none of them to fail in nothing; and whether it was
|
|
109
|
+
// read without its merge base (`baseless`), every version new to it.
|
|
110
|
+
export interface PullDependencies { base: string; head: string; lockfiles: DirectoryDependencies[]; cut: boolean; omitted?: string[]; baseless?: true }
|
|
110
111
|
const MAX_OMITTED = 1000
|
|
111
112
|
|
|
112
|
-
// What is told of a pull request, by the commits it is of, `${base}...${head}
|
|
113
|
+
// What is told of a pull request, by the commits it is of, `${base}...${head}`,
|
|
114
|
+
// read without its merge base apart (pullKey).
|
|
115
|
+
export const pullKey = (commits: string, baseless: boolean) => baseless ? `${commits}\0baseless` : commits
|
|
113
116
|
export interface PullDependencyStore {
|
|
114
117
|
read(key: string): Promise<PullDependencies | null>
|
|
115
118
|
write(key: string, value: PullDependencies): Promise<void>
|
|
@@ -148,21 +151,24 @@ const readKey = (ref: string, { path, format, sha }: { path: string; format: For
|
|
|
148
151
|
// base's moving on as it does, its head's with each push, both kept once it
|
|
149
152
|
// is merged or closed. With the branches they are of, where told: its base's
|
|
150
153
|
// (`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
|
-
|
|
154
|
+
// (`headRef`) where that is the repository's own, not a fork's; and that an
|
|
155
|
+
// open one's head is a fork's (`fork`), a commit of none of the repository's
|
|
156
|
+
// branches till it is merged, which Stasis builds nothing of.
|
|
157
|
+
export interface PullRefs { baseRef?: string; headRef?: string; fork?: true }
|
|
153
158
|
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 =>
|
|
159
|
+
// Those of `base` and `head` that are a branch's name, and `fork` where it is told.
|
|
160
|
+
export const pullRefs = (base: unknown, head: unknown, fork?: unknown): PullRefs =>
|
|
161
|
+
({ ...branchName(base) ? { baseRef: base } : {}, ...branchName(head) ? { headRef: head } : {}, ...fork === true ? { fork } : {} })
|
|
156
162
|
async function pullCommits(fullName: string, token: string, number: number, fetchImpl: typeof fetch): Promise<PullCommits> {
|
|
157
163
|
const pull = await githubJson(`${repoApi(fullName)}/pulls/${number}`, token, fetchImpl) as
|
|
158
|
-
{ number?: unknown; base?: { sha?: unknown; ref?: unknown; repo?: { full_name?: unknown } | null }
|
|
164
|
+
{ number?: unknown; state?: unknown; base?: { sha?: unknown; ref?: unknown; repo?: { full_name?: unknown } | null }
|
|
159
165
|
head?: { sha?: unknown; ref?: unknown; repo?: { full_name?: unknown } | null } } | null
|
|
160
166
|
const base = pull?.base?.sha, head = pull?.head?.sha, repo = pull?.base?.repo?.full_name
|
|
161
167
|
if (pull?.number !== number || typeof base !== 'string' || !SHA.test(base) || typeof head !== 'string' || !SHA.test(head)
|
|
162
168
|
|| typeof repo !== 'string' || repo.toLowerCase() !== fullName.toLowerCase()) throw new GithubApiError(502, 'github-malformed')
|
|
163
169
|
const from = pull.head?.repo?.full_name
|
|
164
170
|
const own = typeof from === 'string' && from.toLowerCase() === repo.toLowerCase()
|
|
165
|
-
return { base, head, ...pullRefs(pull.base?.ref, own ? pull.head?.ref : undefined) }
|
|
171
|
+
return { base, head, ...pullRefs(pull.base?.ref, own ? pull.head?.ref : undefined, pull.state === 'open' && !own) }
|
|
166
172
|
}
|
|
167
173
|
|
|
168
174
|
// The pull request's merge base and the files it changes from it: as GitHub
|
|
@@ -326,33 +332,36 @@ export async function pullDependencies(fullName: string, token: string, number:
|
|
|
326
332
|
return (await pullDependenciesAt(fullName, token, number, kept, fetchImpl)).told
|
|
327
333
|
}
|
|
328
334
|
// The same, with the commits it is kept by (`commits`), its base's and
|
|
329
|
-
// head's, by which `kept` reads it: those `given`, as a page of its
|
|
335
|
+
// head's, by which `kept` reads it (pullKey): those `given`, as a page of its
|
|
330
336
|
// repository's open pull requests read them (repository-issues.ts), else as
|
|
331
337
|
// GitHub has them now; and the branches they are of, where told (PullRefs).
|
|
332
338
|
// Commits given that its own list of its files is no longer of are read as
|
|
333
|
-
// GitHub has them now.
|
|
339
|
+
// GitHub has them now. One into branch `baselessInto` is read without its
|
|
340
|
+
// merge base's lockfiles (`baseless`).
|
|
334
341
|
export async function pullDependenciesAt(fullName: string, token: string, number: number, kept: PullDependencyStore,
|
|
335
|
-
fetchImpl: typeof fetch = globalThis.fetch, given?: PullCommits): Promise<PullRefs & { commits: string; told: PullDependencies }> {
|
|
342
|
+
fetchImpl: typeof fetch = globalThis.fetch, given?: PullCommits, baselessInto: string | null = null): Promise<PullRefs & { commits: string; told: PullDependencies }> {
|
|
336
343
|
const { base, head, ...refs } = given ?? await pullCommits(fullName, token, number, fetchImpl)
|
|
337
|
-
const
|
|
344
|
+
const baseless = baselessInto !== null && refs.baseRef === baselessInto, commits = `${base}...${head}`, key = pullKey(commits, baseless)
|
|
338
345
|
const held = await kept.read(key)
|
|
339
|
-
if (held) return { ...refs, commits
|
|
346
|
+
if (held) return { ...refs, commits, told: held }
|
|
340
347
|
const current = async () => {
|
|
341
348
|
const now = given && await pullCommits(fullName, token, number, fetchImpl)
|
|
342
349
|
return !now || (now.base === base && now.head === head)
|
|
343
350
|
}
|
|
344
351
|
const pulled = await pullFiles(fullName, token, number, base, head, fetchImpl, current)
|
|
345
|
-
if (!pulled) return pullDependenciesAt(fullName, token, number, kept, fetchImpl)
|
|
352
|
+
if (!pulled) return pullDependenciesAt(fullName, token, number, kept, fetchImpl, undefined, baselessInto)
|
|
346
353
|
const { mergeBase, files, cut: filesCut } = pulled
|
|
347
354
|
const { directories, cut, omitted } = lockfilesChanged(files)
|
|
348
|
-
const reads = directories.flatMap(({ before, after }) => [...
|
|
355
|
+
const reads = directories.flatMap(({ before, after }) => [...baseless ? [] : before.map(lockfile => [mergeBase, lockfile] as const),
|
|
356
|
+
...after.map(lockfile => [head, lockfile] as const)])
|
|
349
357
|
const read = await eachOf(reads, READ_PARALLEL, ([ref, lockfile]) => readLockfile(fullName, token, ref, lockfile))
|
|
350
358
|
let at = 0
|
|
351
359
|
const lockfiles = directories.map(({ before, after, paths }) => {
|
|
352
|
-
const readBefore = read.slice(at, at += before.length)
|
|
360
|
+
const readBefore = baseless ? [] : read.slice(at, at += before.length)
|
|
353
361
|
return addedIn([...paths].toSorted(), readBefore, read.slice(at, at += after.length))
|
|
354
362
|
})
|
|
355
|
-
const told = { base: mergeBase, head, lockfiles, cut: filesCut || cut, ...cut && !filesCut && omitted.length <= MAX_OMITTED ? { omitted } : {}
|
|
363
|
+
const told = { base: mergeBase, head, lockfiles, cut: filesCut || cut, ...cut && !filesCut && omitted.length <= MAX_OMITTED ? { omitted } : {},
|
|
364
|
+
...baseless ? { baseless: true as const } : {} }
|
|
356
365
|
await kept.write(key, told)
|
|
357
|
-
return { ...refs, commits
|
|
366
|
+
return { ...refs, commits, told }
|
|
358
367
|
}
|
|
@@ -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, or the one the host names (`base`, withBases); 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):
|
|
@@ -33,9 +34,9 @@ import { GithubApiError } from './github-errors.ts'
|
|
|
33
34
|
import type { LockedPackage } from './locked-packages.ts'
|
|
34
35
|
import { EVERY_LOCKFILE, type LockfileScope, heldTo, isEvery, reviewedIn } from './lockfile-scope.ts'
|
|
35
36
|
import { type Lru, lru } from './lru.ts'
|
|
36
|
-
import { type DirectoryDependencies, type GithubAsked, type LockfileStore, MAX_ADDED, type PullDependencies, lockedAs, lockedWith } from './pull-dependencies.ts'
|
|
37
|
+
import { type AddedPackage, type DirectoryDependencies, type GithubAsked, type LockfileStore, MAX_ADDED, type PullDependencies, lockedAs, lockedWith } from './pull-dependencies.ts'
|
|
37
38
|
import type { PublishedReview, RepoReviewState } from './repository-dependency-reviews.ts'
|
|
38
|
-
import { type ReviewedDependencies, type ReviewedDependency, askReviewed } from './reviewed-dependencies.ts'
|
|
39
|
+
import { type ReviewedBase, type ReviewedDependencies, type ReviewedDependency, askBases, askReviewed } from './reviewed-dependencies.ts'
|
|
39
40
|
|
|
40
41
|
// The other versions told unreviewed, and those told unsupported, of each
|
|
41
42
|
// directory, those past them counted.
|
|
@@ -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
|
|
@@ -179,24 +181,31 @@ function judge(pkg: LockedPackage, bases: string[] | 'any', { state, reviews, ba
|
|
|
179
181
|
// of them, and those of all that want one (`toReview`); the others its lockfiles lock that want reviews, and every one
|
|
180
182
|
// that can't be reviewed (as many of each as MAX_UNREVIEWED, how many more,
|
|
181
183
|
// once `capped`); and how many it locks past those read (`moreLocked`), which
|
|
182
|
-
// aren't checked; without `review`, what it adds alone.
|
|
183
|
-
|
|
184
|
+
// aren't checked; without `review`, what it adds alone. Read without its
|
|
185
|
+
// base (`baseless`), it tells only those it adds that pass none.
|
|
186
|
+
function reviewedDirectory(dir: DirectoryDependencies, review: Judge | null, baseless = false) {
|
|
184
187
|
if ('error' in dir) return dir
|
|
185
188
|
const { locked, moreLocked, added, ...told } = dir
|
|
186
|
-
if (!review) return { ...told, added: added.slice(0, MAX_ADDED).map(shown) }
|
|
189
|
+
if (!review) return { ...told, added: baseless ? [] : added.slice(0, MAX_ADDED).map(shown), ...baseless ? { more: 0 } : {} }
|
|
187
190
|
const adds = new Map(added.map(pkg => [lockedAs(pkg), { pkg, variants: [pkg] }]))
|
|
188
191
|
for (const pkg of locked) {
|
|
189
192
|
const of = adds.get(lockedAs(pkg))
|
|
190
193
|
if (of && lockedWith(pkg) !== lockedWith(of.pkg)) of.variants.push(pkg)
|
|
191
194
|
}
|
|
192
195
|
const own = [...adds.values()].map(({ pkg, variants }) => {
|
|
193
|
-
const judged = variants.map(variant => ({ variant, ...review(variant, pkg.
|
|
196
|
+
const judged = variants.map(variant => ({ variant, ...review(variant, basesOf(pkg, (variant as AddedPackage).base ?? null)) }))
|
|
194
197
|
const least = judged.find(one => 'unsupported' in one.review) ?? judged.find(one => one.wants) ?? judged[0]!
|
|
195
198
|
return { pkg, judged: least, wanting: judged.filter(one => one.wants).map(({ variant }) => variant) }
|
|
196
199
|
})
|
|
197
200
|
const others = locked.filter(pkg => !adds.has(lockedAs(pkg))).map(pkg => ({ pkg, judged: review(pkg, 'any') }))
|
|
198
201
|
const unsupported = locked.flatMap(pkg => { const as = reviewedAs(pkg); return as === 'version' || as === 'skip' ? [] : [{ ...shown(pkg), unsupported: as }] })
|
|
199
|
-
|
|
202
|
+
const listed = baseless ? own.filter(({ judged }) => judged.wants || 'unsupported' in judged.review) : own
|
|
203
|
+
// Each row against the base of the way it is locked that it is told by.
|
|
204
|
+
const row = ({ pkg, judged }: (typeof own)[number]) => {
|
|
205
|
+
const { base: _base, ...rest } = shown(pkg as AddedPackage), { base } = judged.variant as AddedPackage
|
|
206
|
+
return { ...rest, ...base ? { base } : {}, ...judged.review }
|
|
207
|
+
}
|
|
208
|
+
return { ...told, ...baseless ? { more: Math.max(0, listed.length - MAX_ADDED) } : {}, added: listed.slice(0, MAX_ADDED).map(row),
|
|
200
209
|
toReview: own.flatMap(({ wanting }) => wanting.map(shown)),
|
|
201
210
|
unreviewed: others.filter(({ judged }) => judged.wants).map(({ pkg, judged }) => ({ ...shown(pkg), ...judged.review })), unsupported, moreLocked }
|
|
202
211
|
}
|
|
@@ -213,6 +222,20 @@ const distinct = (lists: Shown[][], key: (pkg: Shown) => string) => new Set(list
|
|
|
213
222
|
const versionKey = (pkg: Shown) => `${pkg.name}@${pkg.version ?? ''}\0${pkg.patch?.hash ?? ''}`
|
|
214
223
|
const sourceKey = (pkg: Shown) => `${pkg.source}\0${pkg.name}@${pkg.version ?? ''}\0${pkg.from ?? ''}`
|
|
215
224
|
|
|
225
|
+
// The versions of its package an added version's reviews may be compared
|
|
226
|
+
// with: those it was, and the base the host names it (null for none).
|
|
227
|
+
export const basesOf = (pkg: AddedPackage, base: ReviewedBase | null | undefined = pkg.base) => [...pkg.was ?? [], ...base?.name === pkg.name ? [base.version] : []]
|
|
228
|
+
// `dirs`, each version of `asking` as it is locked with the version `base`
|
|
229
|
+
// names to review it against (`base`, of its package or another), its row's
|
|
230
|
+
// link and line count then against that one, and its reviews against it
|
|
231
|
+
// passing it; each named onto `named` too, by what it is asked.
|
|
232
|
+
async function withBases(dirs: DirectoryDependencies[], base: NonNullable<ReviewedDependencies['base']>, asking: Map<string, ReviewedDependency>,
|
|
233
|
+
named: Map<string, ReviewedBase>): Promise<DirectoryDependencies[]> {
|
|
234
|
+
for (const [key, one] of asking.size > 0 ? await askBases(base, asking) : []) named.set(key, one)
|
|
235
|
+
const based = <P extends LockedPackage>(pkg: P) => { const one = named.get(askedOf(pkg)[0]); return one ? { ...pkg, base: one } : pkg }
|
|
236
|
+
return dirs.map(dir => 'error' in dir ? dir : { ...dir, added: dir.added.map(based), locked: dir.locked.map(based) })
|
|
237
|
+
}
|
|
238
|
+
|
|
216
239
|
// The reviews an open pull request's comments make of `wanting`, the
|
|
217
240
|
// versions still wanting one (pull-comment-reviews.ts): those that count,
|
|
218
241
|
// and whether they couldn't be read.
|
|
@@ -230,11 +253,14 @@ export function heldDependencies<T extends PullDependencies>(told: T, scope: Loc
|
|
|
230
253
|
// A pull request's dependencies as the client is told them: without the
|
|
231
254
|
// versions its directories lock; with `state`, a repository's review in
|
|
232
255
|
// effect, each version's review (reviewedDirectory), those wanting one asked
|
|
233
|
-
// of the registered reviewed dependencies (`reviewed`),
|
|
256
|
+
// of the registered reviewed dependencies (`reviewed`), those they don't pass
|
|
257
|
+
// of their `base` (onto `namedBases`), and those still
|
|
234
258
|
// wanting one of the reviews its comments make (`commentReviews`, where the
|
|
235
259
|
// host reads them), and the review's terms (`review`), with how many
|
|
236
260
|
// reviewers' its comments count (`commentReviews`), or that they couldn't be
|
|
237
|
-
// read (`commentsFailed`), and
|
|
261
|
+
// read (`commentsFailed`), and that reviews count by comments alone, those
|
|
262
|
+
// published here not (`byComments`, where the host reads them), and that
|
|
263
|
+
// they name bases (`reviewedBases`), and how many versions across its directories want
|
|
238
264
|
// reviews, of those it adds (`toReview`) and the rest (`unreviewed`), and
|
|
239
265
|
// can't be reviewed (`unsupported`), each once; how many the reviewed dependencies failed to
|
|
240
266
|
// answer (`unasked`), and whether they are registered (`reviewedDependencies`,
|
|
@@ -247,13 +273,21 @@ export function heldDependencies<T extends PullDependencies>(told: T, scope: Loc
|
|
|
247
273
|
// lockfiles the review holds to (`lockfiles`, lockfile-scope.ts, told in its
|
|
248
274
|
// terms where not every one) are left out (heldDependencies).
|
|
249
275
|
export async function reviewedDependencies(told: PullDependencies, state: RepoReviewState | null,
|
|
250
|
-
{ baseline = null, baselineUnread = [], baselineError = null, reviewed = null, commentReviews = null }: { baseline?: Set<string> | null
|
|
251
|
-
baselineError?: string | null; reviewed?: ReviewedDependencies | null; commentReviews?: CommentReviews | null } = {}) {
|
|
276
|
+
{ baseline = null, baselineUnread = [], baselineError = null, reviewed = null, commentReviews = null, namedBases = new Map() }: { baseline?: Set<string> | null
|
|
277
|
+
baselineUnread?: string[]; baselineError?: string | null; reviewed?: ReviewedDependencies | null; commentReviews?: CommentReviews | null; namedBases?: Map<string, ReviewedBase> } = {}) {
|
|
252
278
|
const scope = state?.lockfiles ?? EVERY_LOCKFILE
|
|
253
279
|
const answered = heldDependencies(told, scope)
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
280
|
+
const baseless = told.baseless === true
|
|
281
|
+
if (!state) return { ...answered, lockfiles: answered.lockfiles.map(dir => reviewedDirectory(dir, null, baseless)) }
|
|
282
|
+
const { cut } = answered
|
|
283
|
+
let held = answered.lockfiles
|
|
284
|
+
// Reviews published here count but where the host reads those pull
|
|
285
|
+
// requests' comments make (`parseComments`): what is reviewed is then the
|
|
286
|
+
// host's to tell, by those and its `lookup`, and one published here counts
|
|
287
|
+
// for nothing, whatever it was compared with: of a pull request's versions,
|
|
288
|
+
// a default branch's or a bundle's. Its author still copies it as a comment.
|
|
289
|
+
const published = reviewed?.parseComments ? [] : state.reviews
|
|
290
|
+
let context = { state, reviews: reviewsByVersion(published), baseline: reviewed ? null : baseline }
|
|
257
291
|
// What wants a review, as `lookup` is asked of, each once.
|
|
258
292
|
const wanting = () => {
|
|
259
293
|
const asked = new Map<string, ReviewedDependency>()
|
|
@@ -274,35 +308,38 @@ export async function reviewedDependencies(told: PullDependencies, state: RepoRe
|
|
|
274
308
|
}
|
|
275
309
|
const asked = wanting()
|
|
276
310
|
await ask(asked)
|
|
311
|
+
const parsing = new Map([...asked].filter(([key]) => !passed.has(key)))
|
|
312
|
+
// Those `lookup` doesn't pass against the bases the host names them.
|
|
313
|
+
if (reviewed?.base) held = await withBases(held, reviewed.base, parsing, namedBases)
|
|
277
314
|
// Of those still wanting one, and every other one the lockfiles it holds
|
|
278
315
|
// to add that its teams' reviews pass, telling other pull requests those
|
|
279
316
|
// it reviews (`commented`), but those `lookup` passes, reviewed, the
|
|
280
317
|
// reviews its comments make, an open one's alone (pull-comment-reviews.ts),
|
|
281
318
|
// which count as its teams' do; those their rejects hold asked of `lookup`
|
|
282
319
|
// too.
|
|
283
|
-
const parsing = new Map([...asked].filter(([key]) => !passed.has(key)))
|
|
284
320
|
if (commentReviews) {
|
|
285
321
|
const others = new Map<string, ReviewedDependency>()
|
|
286
322
|
for (const pkg of held.flatMap(dir => 'added' in dir ? dir.added : [])) {
|
|
287
323
|
const [key, dependency] = askedOf(pkg)
|
|
288
|
-
if (!asked.has(key) && 'reviews' in judge(pkg, pkg
|
|
324
|
+
if (!asked.has(key) && 'reviews' in judge(pkg, basesOf(pkg), context).review) others.set(key, dependency)
|
|
289
325
|
}
|
|
290
326
|
const vouched = others.size > 0 && reviewed ? (await askReviewed(reviewed.lookup, others)).passed : new Set<string>()
|
|
291
327
|
for (const [key, dependency] of others) if (!vouched.has(key)) parsing.set(key, dependency)
|
|
292
328
|
}
|
|
293
329
|
const comments = parsing.size > 0 && commentReviews ? await commentReviews([...parsing.values()]) : { reviews: [], failed: false }
|
|
294
330
|
if (comments.reviews.length > 0) {
|
|
295
|
-
context = { ...context, reviews: reviewsByVersion([...
|
|
331
|
+
context = { ...context, reviews: reviewsByVersion([...published, ...comments.reviews.map(review => ({ ...review, comment: true as const }))]) }
|
|
296
332
|
await ask(new Map([...wanting()].filter(([key]) => !asked.has(key))))
|
|
297
333
|
}
|
|
298
334
|
const dirs = held.map(dir => reviewedDirectory(dir, (pkg, bases) => {
|
|
299
335
|
const judged = judge(pkg, bases, context)
|
|
300
336
|
return judged.wants && passed.has(askedOf(pkg)[0]) ? { review: { reviewed: true }, wants: false } : judged
|
|
301
|
-
}))
|
|
337
|
+
}, baseless))
|
|
302
338
|
const unread = baselineUnread.filter(path => heldTo(scope, path))
|
|
303
339
|
const listed = dirs.filter(dir => 'unreviewed' in dir)
|
|
304
340
|
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 } : {},
|
|
341
|
+
since: reviewed ? null : state.since, canReview: state.canReview, ...reviewed ? { reviewedDependencies: true } : {}, ...reviewed?.base ? { reviewedBases: true } : {},
|
|
342
|
+
...reviewed?.parseComments ? { byComments: true } : {},
|
|
306
343
|
toReview: distinct(listed.map(dir => dir.toReview), versionKey), unreviewed: distinct(listed.map(dir => dir.unreviewed), versionKey),
|
|
307
344
|
unsupported: distinct(listed.map(dir => dir.unsupported), sourceKey),
|
|
308
345
|
...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
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// The reviewed dependencies a host keeps beyond the app, as it registers
|
|
2
2
|
// them before the server is assembled (server.ts registerReviewedDependencies):
|
|
3
3
|
// an async method telling whether a dependency, as a lockfile locks it, is
|
|
4
|
-
// reviewed there (`lookup`), and, optionally, one
|
|
4
|
+
// reviewed there (`lookup`), and, optionally, one naming the version to
|
|
5
|
+
// review one a pull request adds against (`base`, pull-dependency-reviews.ts),
|
|
6
|
+
// one reading the reviews of
|
|
5
7
|
// dependencies an open pull request's comments make (`parseComments`,
|
|
6
8
|
// pull-comment-reviews.ts), and one formatting one's own dependency reviews
|
|
7
9
|
// as a comment, for a copy button to give (`formatDependencyReviews`,
|
|
@@ -14,9 +16,11 @@
|
|
|
14
16
|
// comments' reviews count for the pull request alone, as it is open: the
|
|
15
17
|
// host's to keep, as it is merged, among those `lookup` tells of.
|
|
16
18
|
//
|
|
17
|
-
// Each version is asked of `lookup` once a request, as many at once as
|
|
19
|
+
// Each version is asked of `lookup` (and `base`) once a request, as many at once as
|
|
18
20
|
// ASK_AT_ONCE, its answer kept in this instance KEPT_MS; one it fails to
|
|
19
|
-
// answer is unreviewed, and counted so (`unasked`).
|
|
21
|
+
// answer is unreviewed, and counted so (`unasked`), or has no base.
|
|
22
|
+
import { isExactVersion } from '@preventive/upstream/semver.js'
|
|
23
|
+
import { isNpmPackageName } from '../common/managed/npm-packages.js'
|
|
20
24
|
import { type Lru, lru } from './lru.ts'
|
|
21
25
|
|
|
22
26
|
export type ReviewedLockfile = 'npm' | 'pnpm' | 'yarn1'
|
|
@@ -87,8 +91,12 @@ export interface DependencyReviewEntry {
|
|
|
87
91
|
// What `formatDependencyReviews` formats: one's own reviews, never another's,
|
|
88
92
|
// and the pull request whose versions they are of, where its copy asks.
|
|
89
93
|
export interface FormatDependencyReviewsInput { reviews: DependencyReviewEntry[]; pullRequest?: { repository: string; number: number } }
|
|
94
|
+
// A version to review a dependency against: of its package or another.
|
|
95
|
+
export interface ReviewedBase { name: string; version: string }
|
|
90
96
|
export interface ReviewedDependencies {
|
|
91
97
|
lookup(dependency: ReviewedDependency): Promise<boolean>
|
|
98
|
+
// The reviewed version to review it against; none for its whole package.
|
|
99
|
+
base?(dependency: ReviewedDependency): Promise<ReviewedBase | null | undefined>
|
|
92
100
|
parseComments?(input: ParseCommentsInput): Promise<CommentReview[]>
|
|
93
101
|
// The comment to copy, none where it is empty, null or undefined.
|
|
94
102
|
formatDependencyReviews?(input: FormatDependencyReviewsInput): Promise<string | null | undefined>
|
|
@@ -99,19 +107,20 @@ const KEPT_MS = 60_000
|
|
|
99
107
|
|
|
100
108
|
let registered: ReviewedDependencies | null = null
|
|
101
109
|
let assembled = false
|
|
102
|
-
// Each
|
|
103
|
-
const answers = new WeakMap<
|
|
110
|
+
// Each method's answers, apart.
|
|
111
|
+
const answers = new WeakMap<object, Lru<{ at: number; value: unknown }>>()
|
|
104
112
|
|
|
105
113
|
// Registers the host's reviewed dependencies, once, before the server is
|
|
106
114
|
// assembled (init()): a server already assembled keeps what it was given.
|
|
107
115
|
export function registerReviewedDependencies(reviewed: ReviewedDependencies): void {
|
|
108
116
|
const optional = (method: unknown) => method === undefined || typeof method === 'function'
|
|
109
|
-
if (typeof reviewed?.lookup !== 'function' || !optional(reviewed.parseComments) || !optional(reviewed.formatDependencyReviews)) {
|
|
110
|
-
throw new TypeError('registerReviewedDependencies: expected { lookup, parseComments?, formatDependencyReviews? }, async methods')
|
|
117
|
+
if (typeof reviewed?.lookup !== 'function' || !optional(reviewed.base) || !optional(reviewed.parseComments) || !optional(reviewed.formatDependencyReviews)) {
|
|
118
|
+
throw new TypeError('registerReviewedDependencies: expected { lookup, base?, parseComments?, formatDependencyReviews? }, async methods')
|
|
111
119
|
}
|
|
112
120
|
if (assembled) throw new Error('registerReviewedDependencies: call it before init(), as the server takes them as it is assembled')
|
|
113
121
|
if (registered) throw new Error('registerReviewedDependencies: reviewed dependencies are registered already')
|
|
114
|
-
registered = { lookup: reviewed.lookup.bind(reviewed), ...reviewed.
|
|
122
|
+
registered = { lookup: reviewed.lookup.bind(reviewed), ...reviewed.base ? { base: reviewed.base.bind(reviewed) } : {},
|
|
123
|
+
...reviewed.parseComments ? { parseComments: reviewed.parseComments.bind(reviewed) } : {},
|
|
115
124
|
...reviewed.formatDependencyReviews ? { formatDependencyReviews: reviewed.formatDependencyReviews.bind(reviewed) } : {} }
|
|
116
125
|
}
|
|
117
126
|
|
|
@@ -122,28 +131,39 @@ export function assembledReviewedDependencies(): ReviewedDependencies | null {
|
|
|
122
131
|
return registered
|
|
123
132
|
}
|
|
124
133
|
|
|
125
|
-
//
|
|
126
|
-
//
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
let unasked = 0
|
|
134
|
+
// What `method` answers for each of `dependencies`, by their keys; one it
|
|
135
|
+
// fails to answer for left out, and logged, as failing to `what`.
|
|
136
|
+
async function askEach<T>(method: (dependency: ReviewedDependency) => Promise<T>, dependencies: Map<string, ReviewedDependency>, what: string): Promise<Map<string, T>> {
|
|
137
|
+
const told = new Map<string, T>()
|
|
130
138
|
const pending = [...dependencies]
|
|
131
|
-
const kept = answers.get(
|
|
139
|
+
const kept = answers.get(method) ?? answers.set(method, lru(100_000)).get(method)!
|
|
132
140
|
await Promise.all(Array.from({ length: Math.min(ASK_AT_ONCE, pending.length) }, async () => {
|
|
133
141
|
for (let next = pending.pop(); next; next = pending.pop()) {
|
|
134
142
|
const [key, dependency] = next
|
|
135
143
|
const known = kept.get(key)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
kept.set(key, { at: Date.now(), reviewed: answer })
|
|
144
|
+
if (known && Date.now() - known.at < KEPT_MS) { told.set(key, known.value as T); continue }
|
|
145
|
+
try {
|
|
146
|
+
const value = await method({ ...dependency })
|
|
147
|
+
kept.set(key, { at: Date.now(), value })
|
|
148
|
+
told.set(key, value)
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.warn(`reviewed dependencies: failed to ${what}`, `${dependency.name}@${dependency.version}`, error instanceof Error ? error.message : error)
|
|
144
151
|
}
|
|
145
|
-
if (answer) passed.add(key)
|
|
146
152
|
}
|
|
147
153
|
}))
|
|
148
|
-
return
|
|
154
|
+
return told
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Which of `dependencies`, by their keys, `lookup` passes, and how many it
|
|
158
|
+
// failed to answer.
|
|
159
|
+
export async function askReviewed(lookup: ReviewedDependencies['lookup'], dependencies: Map<string, ReviewedDependency>): Promise<{ passed: Set<string>; unasked: number }> {
|
|
160
|
+
const told = await askEach(lookup, dependencies, 'answer')
|
|
161
|
+
return { passed: new Set([...told].flatMap(([key, reviewed]) => reviewed === true ? [key] : [])), unasked: dependencies.size - told.size }
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// The version `base` names to review each of `dependencies` against, by
|
|
165
|
+
// their keys: none where it names no exact version of an npm package.
|
|
166
|
+
export async function askBases(base: NonNullable<ReviewedDependencies['base']>, dependencies: Map<string, ReviewedDependency>): Promise<Map<string, ReviewedBase>> {
|
|
167
|
+
return new Map([...await askEach(base, dependencies, 'name a base')].flatMap(([key, one]) => isNpmPackageName(one?.name) && typeof one?.version === 'string'
|
|
168
|
+
&& isExactVersion(one.version) ? [[key, { name: one.name, version: one.version }] as const] : []))
|
|
149
169
|
}
|
|
@@ -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
|
},
|
|
@@ -105,11 +122,12 @@ export function stasisDependencyReader({ store, build, behind, stopping }: Reade
|
|
|
105
122
|
// which can't be reviewed. Where a build is still to be made, that it is
|
|
106
123
|
// (`stasis-pending`); where the head's failed, or GitHub failed the base's,
|
|
107
124
|
// why (`stasis-failed`). A base that couldn't be built of its own, as one of
|
|
108
|
-
// no such file, reaches nothing, so every version at the head is new
|
|
125
|
+
// no such file, reaches nothing, so every version at the head is new, as
|
|
126
|
+
// where it is read without its base (`baseless`), which isn't built then.
|
|
109
127
|
export async function stasisDirectory(config: string, base: string | null, head: string, read: (commit: string) => Promise<StasisRead>,
|
|
110
|
-
locked: (commit: string, held: (path: string) => boolean) => Promise<CommitLockfiles
|
|
128
|
+
locked: (commit: string, held: (path: string) => boolean) => Promise<CommitLockfiles>, baseless = false): Promise<DirectoryDependencies> {
|
|
111
129
|
const paths = [config]
|
|
112
|
-
const [after, before] = await Promise.all([read(head), base === null || base === head ? null : read(base)])
|
|
130
|
+
const [after, before] = await Promise.all([read(head), baseless || base === null || base === head ? null : read(base)])
|
|
113
131
|
if (after.status === 'failed') return { paths, error: 'stasis-failed', detail: after.error }
|
|
114
132
|
if (before?.status === 'failed' && before.transient) return { paths, error: 'stasis-failed', detail: before.error }
|
|
115
133
|
if (after.status === 'pending' || before?.status === 'pending') return { paths, error: 'stasis-pending' }
|
|
@@ -118,7 +136,7 @@ export async function stasisDirectory(config: string, base: string | null, head:
|
|
|
118
136
|
return [...found.locked, ...found.unlocked.map(({ name, version }): LockedPackage => ({ name, version, source: 'registry', unlocked: true }))]
|
|
119
137
|
}
|
|
120
138
|
const [now, was] = await Promise.all([lockedAt(head, after.dependencies), before?.status === 'ready' ? lockedAt(base!, before.dependencies) : []])
|
|
121
|
-
return addedBetween(paths, before === null ? now : was, now)
|
|
139
|
+
return addedBetween(paths, baseless ? [] : before === null ? now : was, now)
|
|
122
140
|
}
|
|
123
141
|
|
|
124
142
|
// `answer`, a review's dependencies, each version its package manager alone
|
package/server.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { startServer } from './server-common/standalone.ts'
|
|
|
10
10
|
// reviews as a comment to copy (`formatDependencyReviews`). They replace a
|
|
11
11
|
// repository's commit its dependencies are reviewed since.
|
|
12
12
|
export { registerReviewedDependencies } from './server-managed/reviewed-dependencies.ts'
|
|
13
|
-
export type { CommentReview, DependencyReviewEntry, FormatDependencyReviewsInput, ParseCommentsInput, ReviewComment, ReviewedDependencies, ReviewedDependency,
|
|
13
|
+
export type { CommentReview, DependencyReviewEntry, FormatDependencyReviewsInput, ParseCommentsInput, ReviewComment, ReviewedBase, ReviewedDependencies, ReviewedDependency,
|
|
14
14
|
ReviewedLockfile, ReviewedVersion, ReviewVerdict } from './server-managed/reviewed-dependencies.ts'
|
|
15
15
|
|
|
16
16
|
const modes = ['e2e', 'managed', 'managed-e2e', 'e2e-managed'] as const
|