@preventive/triage 1.0.0-alpha.70 → 1.0.0-alpha.72
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/directory-packages.ts +28 -0
- package/out/activity.js +4 -4
- package/out/{chunk-GTMTGYPT.js → chunk-27Y75UQR.js} +1 -1
- package/out/chunk-4LZK6C6N.js +11 -0
- package/out/chunk-4XSH6ZLT.js +1 -0
- package/out/{chunk-QPGM3DTI.js → chunk-7CHIFYQW.js} +1 -1
- package/out/chunk-7YFJUT2P.js +1 -0
- package/out/chunk-CZ3U2LI4.js +2 -0
- package/out/chunk-ETL5ZPPR.js +259 -0
- package/out/{chunk-45J7357T.js → chunk-L6VIWL2Y.js} +1 -1
- package/out/{chunk-MPXVKVPF.js → chunk-OSHR3N4S.js} +1 -1
- package/out/chunk-PQPKHAI5.js +15 -0
- package/out/chunk-UD33S2MG.js +52 -0
- package/out/{chunk-GZ46SSTF.js → chunk-WKFBZYJX.js} +1 -1
- package/out/client-managed.js +28 -27
- package/out/compare.js +13 -15
- package/out/dialogs.js +28 -28
- package/out/graph.js +1 -1
- package/out/index.html +6 -6
- package/out/scan.js +2 -2
- package/out/terminal.js +1 -1
- package/out/view.css +1 -1
- package/out/view.js +11 -11
- package/package.json +3 -1
- package/risk/actions/resolve.js +9 -3
- package/risk/files/characters.js +11 -0
- package/risk/files/source-map-link.js +43 -0
- package/risk/npm/compare.js +4 -26
- package/server-managed/bundle-advisory-inventory.ts +9 -1
- package/server-managed/bundle-build-worker.js +5 -2
- package/server-managed/bundle-cache.ts +1 -1
- package/server-managed/bundle-dependency-reviews.ts +11 -4
- package/server-managed/http.ts +111 -57
- package/server-managed/locked-packages.ts +9 -4
- package/server-managed/npm-delta.ts +16 -1
- package/server-managed/npm-kept.ts +6 -0
- package/server-managed/pull-dependencies.ts +5 -2
- package/server-managed/pull-dependency-reviews.ts +22 -8
- package/server-managed/repository-issues.ts +15 -9
- package/server-managed/stasis-dependencies.ts +7 -4
- package/out/chunk-2HGKTQ5Q.js +0 -52
- package/out/chunk-7GJNLCXF.js +0 -15
- package/out/chunk-CGRIZ5M5.js +0 -1
- package/out/chunk-D6NVKGGG.js +0 -10
- package/out/chunk-MQ4HT75S.js +0 -247
- package/out/chunk-NB4JBTKK.js +0 -2
- package/out/chunk-VFWMQ3LG.js +0 -2
package/server-managed/http.ts
CHANGED
|
@@ -148,10 +148,10 @@ import { pipeline } from 'node:stream/promises'
|
|
|
148
148
|
import { setTimeout as delay } from 'node:timers/promises'
|
|
149
149
|
import { type KeptStore, REPOSITORY_READ_KEPT_MS, authoredCommitStore, branchTipStore, bundleValidationStore, codeHeadStore, codeTreeStore, commitPullStore, githubTagStore, historyChangeStore, historyPageStore, historySquashStore, historyTreeStore,
|
|
150
150
|
issueListStore, lockfileReadStore,
|
|
151
|
-
npmDeltaStore, npmPublishTimeStore, npmVersionStore, ownKeptPrunes, patchStore, pullDependencyStore, pullListStore, repositoryReadStore, reviewBaselineStore, riskLineStore,
|
|
151
|
+
npmDeltaStore, npmPublishTimeStore, npmVersionDeltaStore, npmVersionStore, ownKeptPrunes, patchStore, pullDependencyStore, pullListStore, repositoryReadStore, reviewBaselineStore, riskLineStore,
|
|
152
152
|
scanReadStore, stasisDependencyStore } from './npm-kept.ts'
|
|
153
153
|
import { plainObject } from './npm-manifest.ts'
|
|
154
|
-
import { type NpmDelta, deltaKey, keptNpmDeltas, npmDelta } from './npm-delta.ts'
|
|
154
|
+
import { type NpmDelta, deltaKey, keptNpmDeltas, keptVersionDeltas, npmDelta, versionDeltaKey } from './npm-delta.ts'
|
|
155
155
|
import { ADVISORIES_TIMEOUT_MS, fetchBundleAdvisories } from './bundle-advisories.ts'
|
|
156
156
|
import { auditCache, auditedKeys, lastListing } from './upstream-cache.ts'
|
|
157
157
|
import type { BundleAdvisoryInventory } from './bundle-advisory-inventory.ts'
|
|
@@ -179,6 +179,7 @@ import { filterReportData } from '../common/managed/report-filter.ts'
|
|
|
179
179
|
import { ourRepoSlugs, withoutStrayRepos } from '../common/finding-repo.js'
|
|
180
180
|
import type { TriageEntryPatch } from '../common/managed/triage.ts'
|
|
181
181
|
import { GITHUB_AGENTS } from '../common/managed/github-agents.ts'
|
|
182
|
+
import { isDirectoryEcosystem } from '../common/managed/directory-packages.ts'
|
|
182
183
|
import { MAX_FINDING_ID, MAX_TRIAGE_BODY_BYTES, MAX_TRIAGE_ENTRIES, MAX_TRIAGE_HISTORY, parseTriageEntryPatch } from '../common/managed/triage.ts'
|
|
183
184
|
import { reportRepoGithub, repoDirectory as stampedDirectory } from '@preventive/report'
|
|
184
185
|
import { findingsRepository, loadManagedFindings, ownFileDirectory, readManagedReport } from '../common/managed/report-content.ts'
|
|
@@ -2561,7 +2562,9 @@ function itemNumber(text: string | null): number | null {
|
|
|
2561
2562
|
// Up to MAX_ASKED_PULLS pull requests asked together (`numbers=1,2,3`) are
|
|
2562
2563
|
// answered together, as many read at once as PULLS_AT_ONCE, `{ pulls }`,
|
|
2563
2564
|
// each's answer, else `{ number, error }` where GitHub fails it, with one
|
|
2564
|
-
// check of its access before and one after, but where each was kept.
|
|
2565
|
+
// check of its access before and one after, but where each was kept. With
|
|
2566
|
+
// `review=1`, the lines its versions wanting reviews change, where they are
|
|
2567
|
+
// counted already (`deltas`, teamDeltas), as a team's Dependencies tells them.
|
|
2565
2568
|
const MAX_ASKED_PULLS = 20
|
|
2566
2569
|
const PULLS_AT_ONCE = 3
|
|
2567
2570
|
async function handleRepositoryPullDependencies(res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined, query: URLSearchParams): Promise<void> {
|
|
@@ -2577,9 +2580,12 @@ async function handleRepositoryPullDependencies(res: ServerResponse, deps: Manag
|
|
|
2577
2580
|
|| !['1', null].includes(query.get('review')) || !['1', null].includes(query.get('listed'))) { sendJson(res, 400, { error: 'bad-request' }); return }
|
|
2578
2581
|
await answerWholeRepository(res, deps, cookie, repoId, async (fullName, token, user) => {
|
|
2579
2582
|
const commits = tiles ? await keptPullCommits(deps, repoId, numbers as number[]) : new Map<number, PullCommits>()
|
|
2580
|
-
if (listed === null)
|
|
2583
|
+
if (listed === null) {
|
|
2584
|
+
const answer = await pullDependencyAnswer(deps, fullName, token, user, repoId, numbers[0]!, review, commits.get(numbers[0]!))
|
|
2585
|
+
return review ? { ...answer, value: { ...answer.value, ...await withDeltas(deps, [answer.value]) } } : answer
|
|
2586
|
+
}
|
|
2581
2587
|
const answers = await pullDependencyAnswers(deps, fullName, token, user, repoId, numbers as number[], review, commits)
|
|
2582
|
-
return { value: { pulls: answers.value }, kept: answers.kept }
|
|
2588
|
+
return { value: { pulls: answers.value, ...review ? await withDeltas(deps, answers.value) : {} }, kept: answers.kept }
|
|
2583
2589
|
})
|
|
2584
2590
|
}
|
|
2585
2591
|
|
|
@@ -2661,7 +2667,7 @@ async function pullDependencyAnswer(deps: ManagedHttpDeps, fullName: string, tok
|
|
|
2661
2667
|
// Each patch its lockfiles name by its hash alone with its file (npm-patch.ts), where its review is in effect.
|
|
2662
2668
|
const patched = state ? await withPatchFiles(told, repoId, fullName, token, patchStore(deps.db, deps.config.debug), asked) : told
|
|
2663
2669
|
const bases = new Map<string, ReviewedBase>(), wantedIn = new Map<string[], number>()
|
|
2664
|
-
const dependencies = await reviewedDependencies(patched, state, { baseline, baselineUnread: unread, baselineError: error, reviewed, commentReviews: noting, namedBases: bases,
|
|
2670
|
+
const dependencies = await reviewedDependencies(patched, state, { baseline, baselineUnread: unread, baselineError: error, reviewed, commentReviews: noting, namedBases: bases, user: user.id,
|
|
2665
2671
|
wantedIn })
|
|
2666
2672
|
askBuilds(deps, wanted, wantedIn, wants)
|
|
2667
2673
|
// The comment the host formats of the reader's reviews of its versions, for
|
|
@@ -2774,7 +2780,7 @@ async function branchDependencyAnswer(deps: ManagedHttpDeps, fullName: string, t
|
|
|
2774
2780
|
const reviewed = deps.reviewedDependencies ?? null
|
|
2775
2781
|
const { baseline, unread: baselineUnread, error } = reviewed ? { baseline: null, unread: [], error: null }
|
|
2776
2782
|
: await baselineFor(fullName, token, repoId, state, baselineKept(deps), reads, asked)
|
|
2777
|
-
return { value: await reviewedDependencies(told, state, { baseline, baselineUnread, baselineError: error, reviewed }), kept: !asked.github }
|
|
2783
|
+
return { value: await reviewedDependencies(told, state, { baseline, baselineUnread, baselineError: error, reviewed, user: user.id }), kept: !asked.github }
|
|
2778
2784
|
}
|
|
2779
2785
|
|
|
2780
2786
|
// GET /api/admin/repositories/lockfiles: the lockfiles of the repository's
|
|
@@ -2828,10 +2834,23 @@ const TEAM_PULL_READS = TEAM_PULLS / OPEN_PULLS_SIZES.at(-1)!
|
|
|
2828
2834
|
const TEAM_PULLS_TOGETHER = 20
|
|
2829
2835
|
const PARTIAL_ACCESS = new Set(['no-directory', 'no-repository'])
|
|
2830
2836
|
type TeamDependencyLine = Record<string, unknown> & { repoId?: number }
|
|
2831
|
-
type TeamPull = { number: number; touchesLockfile?: boolean | null }
|
|
2837
|
+
type TeamPull = { number: number; touchesLockfile?: boolean | null; base?: string; draft?: boolean }
|
|
2838
|
+
// Whether a pull request is to merge into its repository's default branch
|
|
2839
|
+
// (`defaultBranch`), as a team's Dependencies reads those alone unless
|
|
2840
|
+
// asked for every branch's: one whose branch, or the default, isn't told is.
|
|
2841
|
+
const ontoDefault = (item: TeamPull, defaultBranch: string | null) => !defaultBranch || !item.base || item.base === defaultBranch
|
|
2842
|
+
// Whether a team's read tells the dependencies of every branch's pull
|
|
2843
|
+
// requests (`branch`), and of drafts (`draft`), else of its default
|
|
2844
|
+
// branch's alone, and not of drafts.
|
|
2845
|
+
type TeamEvery = { branch: boolean; draft: boolean }
|
|
2846
|
+
const DEFAULT_ONLY: TeamEvery = { branch: false, draft: false }
|
|
2832
2847
|
async function handleTeamDependencies(res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined, s: { session: ManagedSession; user: StoredUser },
|
|
2833
2848
|
teamId: string, query: URLSearchParams): Promise<void> {
|
|
2834
2849
|
const deadline = Date.now() + TEAM_DEPENDENCIES_MS
|
|
2850
|
+
// The dependencies of the pull requests to merge into other branches than
|
|
2851
|
+
// their repository's default too, where asked (`branches=all`); and of
|
|
2852
|
+
// drafts too, where asked (`drafts=all`).
|
|
2853
|
+
const every = { branch: query.get('branches') === 'all', draft: query.get('drafts') === 'all' }
|
|
2835
2854
|
const named = query.get('repoIds')
|
|
2836
2855
|
const only = named === null ? null : new Set(named.split(',').map(Number))
|
|
2837
2856
|
if (only && (only.size === 0 || only.size > 1000 || [...only].some(id => !Number.isSafeInteger(id) || id <= 0))) { sendJson(res, 400, { error: 'bad-request' }); return }
|
|
@@ -2875,7 +2894,7 @@ async function handleTeamDependencies(res: ServerResponse, deps: ManagedHttpDeps
|
|
|
2875
2894
|
}
|
|
2876
2895
|
if (answered.length > 0 && !await send(...answered)) return
|
|
2877
2896
|
const done = await eachOf(reading, TEAM_REPOSITORIES_AT_ONCE, ({ access, setting }) => stopped || Date.now() > deadline ? Promise.resolve(false)
|
|
2878
|
-
: teamRepositoryDependencies(deps, access, setting, deadline, send, () => wholeRepositoryAccess(deps, cookie, access.repo.repoId)))
|
|
2897
|
+
: teamRepositoryDependencies(deps, access, setting, deadline, send, () => wholeRepositoryAccess(deps, cookie, access.repo.repoId), every))
|
|
2879
2898
|
if (stopped) return
|
|
2880
2899
|
const unread = reading.filter((_, at) => !done[at]).map(({ access }) => access.repo.repoId)
|
|
2881
2900
|
if (!await send(unread.length === 0 ? { done: true } : { done: false, unread })) return
|
|
@@ -2885,20 +2904,21 @@ async function handleTeamDependencies(res: ServerResponse, deps: ManagedHttpDeps
|
|
|
2885
2904
|
// A repository's lines of its team's Dependencies, as handleTeamDependencies
|
|
2886
2905
|
// tells them; whether all were written, none left for its time.
|
|
2887
2906
|
async function teamRepositoryDependencies(deps: ManagedHttpDeps, access: WholeAccess, setting: RepoDependencyReview, deadline: number,
|
|
2888
|
-
send: (...lines: TeamDependencyLine[]) => Promise<boolean>, reauthorize: () => Promise<WholeAccess | Refusal
|
|
2907
|
+
send: (...lines: TeamDependencyLine[]) => Promise<boolean>, reauthorize: () => Promise<WholeAccess | Refusal>, every: TeamEvery = DEFAULT_ONLY): Promise<boolean> {
|
|
2889
2908
|
// The Stasis builds its answers want, asked for a batch of pull requests at a time, its default branch's with the first.
|
|
2890
2909
|
const wants: StasisWant[] = []
|
|
2891
|
-
try { return await teamRepositoryLines(deps, access, setting, deadline, send, reauthorize, wants) } finally { stasisReader(deps).build(wants) }
|
|
2910
|
+
try { return await teamRepositoryLines(deps, access, setting, deadline, send, reauthorize, wants, every) } finally { stasisReader(deps).build(wants) }
|
|
2892
2911
|
}
|
|
2893
2912
|
async function teamRepositoryLines(deps: ManagedHttpDeps, access: WholeAccess, setting: RepoDependencyReview, deadline: number,
|
|
2894
|
-
send: (...lines: TeamDependencyLine[]) => Promise<boolean>, reauthorize: () => Promise<WholeAccess | Refusal>, wants: StasisWant[]): Promise<boolean> {
|
|
2913
|
+
send: (...lines: TeamDependencyLine[]) => Promise<boolean>, reauthorize: () => Promise<WholeAccess | Refusal>, wants: StasisWant[], every: TeamEvery): Promise<boolean> {
|
|
2895
2914
|
const repoId = access.repo.repoId
|
|
2896
|
-
type Read = { branch: object | null; pulls?: { items: TeamPull[]; more: boolean; error?: string }; commits?: Map<number, PullCommits> }
|
|
2915
|
+
type Read = { branch: object | null; pulls?: { items: TeamPull[]; more: boolean; error?: string; defaultBranch?: string }; commits?: Map<number, PullCommits> }
|
|
2897
2916
|
const read = await readWholeRepositoryOf<Read>(deps, access, async (fullName, token, user) => {
|
|
2898
2917
|
const branch = await branchDependencyAnswer(deps, fullName, token, user, repoId, setting, wants)
|
|
2899
2918
|
if (!(branch.value as { review?: unknown }).review) return { value: { branch: null }, kept: branch.kept }
|
|
2900
2919
|
const pulls = await teamOpenPulls(deps, repoId, fullName, token, deadline)
|
|
2901
|
-
return { value: { branch: branch.value, pulls: { items: pulls.items, more: pulls.more, ...pulls.failed === null ? {} : { error: pulls.failed }
|
|
2920
|
+
return { value: { branch: branch.value, pulls: { items: pulls.items, more: pulls.more, ...pulls.failed === null ? {} : { error: pulls.failed },
|
|
2921
|
+
...pulls.defaultBranch ? { defaultBranch: pulls.defaultBranch } : {} }, commits: pulls.commits },
|
|
2902
2922
|
kept: branch.kept && pulls.kept }
|
|
2903
2923
|
}, reauthorize)
|
|
2904
2924
|
if ('error' in read) return send({ repoId, ...PARTIAL_ACCESS.has(read.error) ? { branch: null } : { error: read.error, status: read.status } })
|
|
@@ -2906,8 +2926,12 @@ async function teamRepositoryLines(deps: ManagedHttpDeps, access: WholeAccess, s
|
|
|
2906
2926
|
if (!branch) return send({ repoId, branch: null })
|
|
2907
2927
|
if (!await send({ repoId, branch, pulls, ...await withDeltas(deps, [branch]) })) return false
|
|
2908
2928
|
// Each by the commits its page names, where it names them, GitHub not asked
|
|
2909
|
-
// for them (pullDependencyAnswer); never told.
|
|
2910
|
-
|
|
2929
|
+
// for them (pullDependencyAnswer); never told. Those to merge into another
|
|
2930
|
+
// branch than the default, and drafts, but where asked, as the tab hides
|
|
2931
|
+
// them unless asked, and reads them alone once it shows them, their Stasis
|
|
2932
|
+
// builds none.
|
|
2933
|
+
const numbers = pulls!.items.filter(item => (item.touchesLockfile === true || item.touchesLockfile === null)
|
|
2934
|
+
&& (every.branch || ontoDefault(item, pulls!.defaultBranch ?? null)) && (every.draft || item.draft !== true)).map(item => item.number)
|
|
2911
2935
|
for (let at = 0; at < numbers.length; at += TEAM_PULLS_TOGETHER) {
|
|
2912
2936
|
if (Date.now() > deadline) return false
|
|
2913
2937
|
const batch = numbers.slice(at, at + TEAM_PULLS_TOGETHER)
|
|
@@ -2927,7 +2951,8 @@ const withDeltas = async (deps: ManagedHttpDeps, answers: object[]) => {
|
|
|
2927
2951
|
// A repository's open pull requests, the TEAM_PULLS updated latest, a page
|
|
2928
2952
|
// at a time (repository-issues.ts repositoryOpenPulls), each kept; each's
|
|
2929
2953
|
// base's and head's commits as its page has them (`commits`, by its number),
|
|
2930
|
-
// where it has them;
|
|
2954
|
+
// where it has them; the repository's default branch, by its name
|
|
2955
|
+
// (`defaultBranch`), where told; whether it has more, and whether all were kept. Where
|
|
2931
2956
|
// the repository has a label named DEPENDENCIES_LABEL (kept as a page is),
|
|
2932
2957
|
// those carrying it alone, by its name as the repository has it: a
|
|
2933
2958
|
// repository of many open pull requests, few of them its dependencies', read
|
|
@@ -2943,8 +2968,9 @@ async function teamOpenPulls(deps: ManagedHttpDeps, repoId: number, fullName: st
|
|
|
2943
2968
|
const items: TeamPull[] = []
|
|
2944
2969
|
const commits = new Map<number, PullCommits>()
|
|
2945
2970
|
let after: string | null = null, kept = labelled.kept, size = OPEN_PULLS_SIZES[0]!
|
|
2971
|
+
let defaultBranch: string | null = null
|
|
2946
2972
|
for (let page = 0; page < TEAM_PULL_READS && items.length < TEAM_PULLS; page++) {
|
|
2947
|
-
if (Date.now() > deadline) return { items, commits, more: true, kept: false, failed: 'time-up' }
|
|
2973
|
+
if (Date.now() > deadline) return { items, commits, more: true, kept: false, failed: 'time-up', defaultBranch }
|
|
2948
2974
|
const asked = size, cursor = after
|
|
2949
2975
|
let answer
|
|
2950
2976
|
try {
|
|
@@ -2952,19 +2978,20 @@ async function teamOpenPulls(deps: ManagedHttpDeps, repoId: number, fullName: st
|
|
|
2952
2978
|
} catch (err) {
|
|
2953
2979
|
if (!(err instanceof GithubApiError) || refusedRead(err)) throw err
|
|
2954
2980
|
console.warn('managed: open pull requests read failed:', err)
|
|
2955
|
-
return { items, commits, more: true, kept: false, failed: err.message }
|
|
2981
|
+
return { items, commits, more: true, kept: false, failed: err.message, defaultBranch }
|
|
2956
2982
|
}
|
|
2957
2983
|
kept &&= answer.kept
|
|
2958
2984
|
const value = answer.value as OpenPullsPage
|
|
2959
2985
|
if (typeof value.size === 'number' && value.size > 0) size = Math.min(size, value.size)
|
|
2986
|
+
if (typeof value.defaultBranch === 'string' && value.defaultBranch) defaultBranch ??= value.defaultBranch
|
|
2960
2987
|
items.push(...(Array.isArray(value.items) ? value.items : []).filter(item => Number.isSafeInteger(item?.number) && item.number > 0))
|
|
2961
2988
|
pageCommits(value, commits)
|
|
2962
|
-
if (value.more !== true || typeof value.after !== 'string') return { items, commits, more: false, kept, failed: null }
|
|
2989
|
+
if (value.more !== true || typeof value.after !== 'string') return { items, commits, more: false, kept, failed: null, defaultBranch }
|
|
2963
2990
|
after = value.after
|
|
2964
2991
|
}
|
|
2965
|
-
return { items, commits, more: true, kept, failed: null }
|
|
2992
|
+
return { items, commits, more: true, kept, failed: null, defaultBranch }
|
|
2966
2993
|
}
|
|
2967
|
-
type OpenPullsPage = { items?: unknown; more?: unknown; after?: unknown; commits?: unknown; size?: unknown }
|
|
2994
|
+
type OpenPullsPage = { items?: unknown; more?: unknown; after?: unknown; commits?: unknown; size?: unknown; defaultBranch?: unknown }
|
|
2968
2995
|
// Each open pull request's base's and head's commits a page of them names,
|
|
2969
2996
|
// into `commits` by its number.
|
|
2970
2997
|
function pageCommits(page: OpenPullsPage, commits: Map<number, PullCommits>) {
|
|
@@ -2998,9 +3025,11 @@ async function keptPullCommits(deps: ManagedHttpDeps, repoId: number, numbers: n
|
|
|
2998
3025
|
|
|
2999
3026
|
// The lines the versions wanting reviews of `answers` change, as their rows
|
|
3000
3027
|
// show them (npm-delta.js reviewBase), a patched one's none, where they are
|
|
3001
|
-
// counted already: of public versions alone,
|
|
3002
|
-
// (
|
|
3003
|
-
//
|
|
3028
|
+
// counted already: of public versions alone, kept by their names
|
|
3029
|
+
// (npmVersionDeltaStore), else, those npm answered for in a day
|
|
3030
|
+
// (npmVersionStore), by their integrities, as npmDelta keys them, then kept
|
|
3031
|
+
// by their names too. `[name, version, base, delta]` each, none counted here,
|
|
3032
|
+
// nor npm asked.
|
|
3004
3033
|
async function teamDeltas(deps: ManagedHttpDeps, answers: object[]) {
|
|
3005
3034
|
const asked = new Map<string, [string, string, string]>()
|
|
3006
3035
|
for (const answer of answers as { lockfiles?: { added?: unknown; unreviewed?: unknown }[]; review?: { required?: number; reviewedBases?: true } }[]) {
|
|
@@ -3019,6 +3048,14 @@ async function teamDeltas(deps: ManagedHttpDeps, answers: object[]) {
|
|
|
3019
3048
|
}
|
|
3020
3049
|
}
|
|
3021
3050
|
if (asked.size === 0) return []
|
|
3051
|
+
const byVersions = npmVersionDeltaStore<NpmDelta>(deps.db, deps.config.debug)
|
|
3052
|
+
const named = await keptVersionDeltas([...asked.values()].map(([name, version, base]) => versionDeltaKey(name, version, name, base)), byVersions)
|
|
3053
|
+
const told = [...asked.values()].flatMap(([name, version, base]) => {
|
|
3054
|
+
const delta = named.get(versionDeltaKey(name, version, name, base))
|
|
3055
|
+
return delta ? [[name, version, base, delta] as const] : []
|
|
3056
|
+
})
|
|
3057
|
+
for (const [key, [name, version, base]] of [...asked]) if (named.has(versionDeltaKey(name, version, name, base))) asked.delete(key)
|
|
3058
|
+
if (asked.size === 0) return told
|
|
3022
3059
|
const versions = [...asked.values()].flatMap(([name, version, base]) => [{ name, version }, ...base === '(empty)' || !isExactVersion(base) ? [] : [{ name, version: base }]])
|
|
3023
3060
|
const kept = await npmVersionStore(deps.db, deps.config.debug).readMany!(versions)
|
|
3024
3061
|
const integrity = (name: string, version: string) => {
|
|
@@ -3030,12 +3067,15 @@ async function teamDeltas(deps: ManagedHttpDeps, answers: object[]) {
|
|
|
3030
3067
|
const against = base === '(empty)' ? null : integrity(name, base), other = integrity(name, version)
|
|
3031
3068
|
return other && (base === '(empty)' || against) ? [{ name, version, base, key: [against, other] as [string | null, string] }] : []
|
|
3032
3069
|
})
|
|
3033
|
-
if (sides.length === 0) return
|
|
3070
|
+
if (sides.length === 0) return told
|
|
3034
3071
|
const counted = await keptNpmDeltas(sides.map(({ key }) => key), npmDeltaStore<NpmDelta>(deps.db, deps.config.debug))
|
|
3035
|
-
|
|
3072
|
+
const byIntegrity = sides.flatMap(({ name, version, base, key: [against, other] }) => {
|
|
3036
3073
|
const delta = counted.get(deltaKey(against, other))
|
|
3037
|
-
return delta ? [[name, version, base, delta]] : []
|
|
3074
|
+
return delta ? [[name, version, base, delta] as const] : []
|
|
3038
3075
|
})
|
|
3076
|
+
// Kept by their names too, as those npm told of are public, for a later read past the day.
|
|
3077
|
+
await Promise.all(byIntegrity.map(([name, version, base, delta]) => byVersions.write(versionDeltaKey(name, version, name, base), delta, Date.now())))
|
|
3078
|
+
return [...told, ...byIntegrity]
|
|
3039
3079
|
}
|
|
3040
3080
|
|
|
3041
3081
|
// The app's users `accounts` are, by their logins in lower case, of those
|
|
@@ -3718,6 +3758,8 @@ async function handleBundleDependencyReview(res: ServerResponse, deps: ManagedHt
|
|
|
3718
3758
|
commit = (await deps.bundleCache.summary(record))?.commit
|
|
3719
3759
|
} catch { sendJson(res, 422, { error: 'bundle-unavailable' }); return }
|
|
3720
3760
|
if (inventory === null) { sendJson(res, 413, { error: 'payload-too-large' }); return }
|
|
3761
|
+
// Skipped, one installed from a directory is one whose record is malformed.
|
|
3762
|
+
if (inventory?.skipped.some(pkg => isDirectoryEcosystem(pkg.ecosystem))) { sendJson(res, 422, { error: 'directory-package-malformed' }); return }
|
|
3721
3763
|
const bundled = (inventory?.packages ?? []).filter(pkg => pkg.ecosystem === 'npm').flatMap(pkg => pkg.versions.map(version => ({ name: pkg.name, version })))
|
|
3722
3764
|
// Its commit as GitHub names one, of SHA-1.
|
|
3723
3765
|
if (!commit || !SHA.test(commit) || bundled.length === 0) { none(); return }
|
|
@@ -3749,7 +3791,7 @@ async function bundleDependencyAnswer(deps: ManagedHttpDeps, fullName: string, t
|
|
|
3749
3791
|
const reviewed = deps.reviewedDependencies ?? null
|
|
3750
3792
|
const { baseline, unread: baselineUnread, error } = reviewed ? { baseline: null, unread: [], error: null }
|
|
3751
3793
|
: await baselineFor(fullName, token, repoId, state, baselineKept(deps), reads, asked)
|
|
3752
|
-
const { base: _base, ...answer } = await reviewedDependencies(told, state, { baseline, baselineUnread, baselineError: error, reviewed })
|
|
3794
|
+
const { base: _base, ...answer } = await reviewedDependencies(told, state, { baseline, baselineUnread, baselineError: error, reviewed, user: user.id })
|
|
3753
3795
|
return { value: { ...answer, ...bundle }, kept: !asked.github }
|
|
3754
3796
|
}
|
|
3755
3797
|
|
|
@@ -5129,17 +5171,21 @@ async function handleNpmReviews(req: IncomingMessage, res: ServerResponse, deps:
|
|
|
5129
5171
|
} finally { res.off('close', onClose) }
|
|
5130
5172
|
}
|
|
5131
5173
|
|
|
5132
|
-
// GET /api/npm/deltas?versions=[[name, version, otherVersion, patch?], …]:
|
|
5133
|
-
// each of up to MAX_ASKED_DELTAS versions changes against another,
|
|
5134
|
-
// `
|
|
5135
|
-
//
|
|
5136
|
-
//
|
|
5137
|
-
//
|
|
5138
|
-
//
|
|
5139
|
-
//
|
|
5140
|
-
//
|
|
5141
|
-
//
|
|
5142
|
-
//
|
|
5174
|
+
// GET /api/npm/deltas?versions=[[name, version, otherVersion, patch?, otherName?], …]:
|
|
5175
|
+
// the lines each of up to MAX_ASKED_DELTAS versions changes against another,
|
|
5176
|
+
// of its package or `otherName`'s, as the host may name a review's base
|
|
5177
|
+
// (reviewed-dependencies.ts `base`), or `(empty)`, as GET delta counts them,
|
|
5178
|
+
// a patched one's as its pnpm patch changes it (`patch`, `{ hash, repoId,
|
|
5179
|
+
// commit, path? }`, or null, read as Review reads it, npmPatchOf), as lines
|
|
5180
|
+
// of JSON as each is counted (`{ name, version, otherVersion, otherName?,
|
|
5181
|
+
// patchHash?, …delta }`, or the same with `error` and `status`), as a list's
|
|
5182
|
+
// rows near the viewport ask for them together (npm-delta.js),
|
|
5183
|
+
// DELTAS_AT_ONCE at a time. Each read as GET delta reads it, with the
|
|
5184
|
+
// reader's access to each package, which is checked again once it is
|
|
5185
|
+
// counted: a private one's told only to a reader who may still read it,
|
|
5186
|
+
// none told to one whose session is gone. Each of two public versions,
|
|
5187
|
+
// unpatched, kept by their names too (npmVersionDeltaStore), for a team's
|
|
5188
|
+
// Dependencies to tell it without asking npm of them (teamDeltas).
|
|
5143
5189
|
const MAX_ASKED_DELTAS = 50
|
|
5144
5190
|
const DELTAS_AT_ONCE = 2
|
|
5145
5191
|
// A version as npmDelta takes it: its integrity, and its files, loaded as
|
|
@@ -5152,36 +5198,44 @@ async function handleNpmDeltas(req: IncomingMessage, res: ServerResponse, deps:
|
|
|
5152
5198
|
if (req.method !== 'GET') { send405(res, 'GET'); return }
|
|
5153
5199
|
let asked: unknown = null
|
|
5154
5200
|
try { asked = JSON.parse(params.get('versions') ?? '') } catch {}
|
|
5155
|
-
const patchOf = (item: unknown[]) => item.length
|
|
5156
|
-
if (!Array.isArray(asked) || asked.length === 0 || asked.length > MAX_ASKED_DELTAS || !asked.every(item => Array.isArray(item) &&
|
|
5157
|
-
&& isNpmPackageName(item[0]) && isNpmPackageSpec(item[1]) && (item[2] === '(empty)' || isNpmPackageSpec(item[2])) && patchOf(item) !== 'invalid'
|
|
5201
|
+
const patchOf = (item: unknown[]) => item[3] == null && item.length !== 4 ? null : plainObject(item[3]) ? requestedPatch(item[3] as { hash: unknown }) : 'invalid'
|
|
5202
|
+
if (!Array.isArray(asked) || asked.length === 0 || asked.length > MAX_ASKED_DELTAS || !asked.every(item => Array.isArray(item) && item.length >= 3 && item.length <= 5
|
|
5203
|
+
&& isNpmPackageName(item[0]) && isNpmPackageSpec(item[1]) && (item[2] === '(empty)' || isNpmPackageSpec(item[2])) && patchOf(item) !== 'invalid'
|
|
5204
|
+
&& (item.length < 5 || (isNpmPackageName(item[4]) && item[2] !== '(empty)')))) {
|
|
5158
5205
|
sendJson(res, 400, { error: 'bad-package' }); return
|
|
5159
5206
|
}
|
|
5160
|
-
const versions = (asked as unknown[][]).map(item => [...item.slice(0, 3), patchOf(item)] as [string, string, string, RequestedPatch | null])
|
|
5207
|
+
const versions = (asked as unknown[][]).map(item => [...item.slice(0, 3), patchOf(item), item[4] ?? item[0]] as [string, string, string, RequestedPatch | null, string])
|
|
5161
5208
|
// Each patch read once, by its hash.
|
|
5162
5209
|
const patches = new Map<string, Promise<ReadPatch | Refusal>>()
|
|
5163
|
-
const reader = await npmReader(deps, cookie, [...new Set(versions.
|
|
5210
|
+
const reader = await npmReader(deps, cookie, [...new Set(versions.flatMap(([name, , , , otherName]) => [name, otherName]))], { handed: true })
|
|
5164
5211
|
if (reader == null) { sendJson(res, 401, { error: 'unauthenticated' }); return }
|
|
5165
5212
|
const controller = new AbortController()
|
|
5166
5213
|
res.once('close', () => { if (!res.writableEnded) controller.abort() })
|
|
5167
5214
|
dropIdle(res)
|
|
5168
5215
|
const kept = npmDeltaStore<NpmDelta>(deps.db, deps.config.debug), keptVersions = npmVersionStore(deps.db, deps.config.debug)
|
|
5216
|
+
const byVersions = npmVersionDeltaStore<NpmDelta>(deps.db, deps.config.debug)
|
|
5169
5217
|
const out = openLines(res)
|
|
5170
5218
|
let stopped = false
|
|
5171
|
-
await eachOf(versions, DELTAS_AT_ONCE, async ([name, version, otherVersion, patch]) => {
|
|
5219
|
+
await eachOf(versions, DELTAS_AT_ONCE, async ([name, version, otherVersion, patch, otherName]) => {
|
|
5172
5220
|
if (stopped || controller.signal.aborted) return
|
|
5173
|
-
const asOne = { name, version, otherVersion, ...patch ? { patchHash: patch.hash } : {} }
|
|
5174
|
-
|
|
5221
|
+
const asOne = { name, version, otherVersion, ...otherName === name ? {} : { otherName }, ...patch ? { patchHash: patch.hash } : {} }
|
|
5222
|
+
// Of each package, whether it is private.
|
|
5223
|
+
let isPrivate = false, line: Record<string, unknown>, oldPrivate = false
|
|
5175
5224
|
try {
|
|
5176
|
-
const
|
|
5177
|
-
const
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5225
|
+
const together = otherVersion === '(empty)' ? keptVersions : readTogether(keptVersions, [{ name, version }, { name: otherName, version: otherVersion }])
|
|
5226
|
+
const [doc, old] = await Promise.all([readNpmVersion(name, version, canReadPrivateNpm(reader, name), controller.signal, together).then(found),
|
|
5227
|
+
otherVersion === '(empty)' ? null : readNpmVersion(otherName, otherVersion, canReadPrivateNpm(reader, otherName), controller.signal, together).then(found)])
|
|
5228
|
+
isPrivate = doc.private
|
|
5229
|
+
oldPrivate = old?.private === true
|
|
5181
5230
|
const patched = patch && await (patches.get(patch.hash) ?? patches.set(patch.hash, npmPatchOf(deps, cookie, patch)).get(patch.hash)!)
|
|
5182
5231
|
const side = deltaSide(doc)
|
|
5183
|
-
|
|
5184
|
-
|
|
5232
|
+
if (patched && 'error' in patched) line = { ...asOne, error: patched.error, status: patched.status }
|
|
5233
|
+
else {
|
|
5234
|
+
const delta = await npmDelta(old ? deltaSide(old) : null,
|
|
5235
|
+
patched ? { integrity: `${side.integrity} patch:${patch.hash}`, files: async () => patchedFiles(await side.files(), patched.files) } : side, kept)
|
|
5236
|
+
if (!patched && !doc.private && !old?.private) await byVersions.write(versionDeltaKey(doc.name, doc.version, old?.name ?? name, old?.version ?? '(empty)'), delta, Date.now())
|
|
5237
|
+
line = { ...asOne, ...delta }
|
|
5238
|
+
}
|
|
5185
5239
|
} catch (err) {
|
|
5186
5240
|
if (controller.signal.aborted) return
|
|
5187
5241
|
if (!(err instanceof NpmPackageError)) console.warn('managed: a package delta failed:', err)
|
|
@@ -5189,9 +5243,9 @@ async function handleNpmDeltas(req: IncomingMessage, res: ServerResponse, deps:
|
|
|
5189
5243
|
}
|
|
5190
5244
|
// A reader who lost their session, or their access to a private one,
|
|
5191
5245
|
// while it was counted, is told nothing of it.
|
|
5192
|
-
const current = await npmReader(deps, cookie, isPrivate ? [name] : [])
|
|
5246
|
+
const current = await npmReader(deps, cookie, [...isPrivate ? [name] : [], ...oldPrivate ? [otherName] : []])
|
|
5193
5247
|
if (current == null) { stopped = true; out.cut(); return }
|
|
5194
|
-
if (isPrivate && !canReadPrivateNpm(current, name)) line = { ...asOne, error: 'package-not-found', status: 404 }
|
|
5248
|
+
if ((isPrivate && !canReadPrivateNpm(current, name)) || (oldPrivate && !canReadPrivateNpm(current, otherName))) line = { ...asOne, error: 'package-not-found', status: 404 }
|
|
5195
5249
|
if (!stopped && !await out.write(line)) stopped = true
|
|
5196
5250
|
})
|
|
5197
5251
|
if (!stopped) await out.end()
|
|
@@ -75,9 +75,10 @@ function packagesOf(format: LockfileFormat, text: string): ReadPackage[] {
|
|
|
75
75
|
if (format !== 'yarn') throw new TypeError(`lockedPackages: ${format} lockfiles are not read`)
|
|
76
76
|
// Yarn 2 and later write another format, which only the text tells apart.
|
|
77
77
|
if (/^__metadata:/mu.test(text)) throw new LockfileError('a yarn.lock of Yarn 2 or later, which is not read')
|
|
78
|
-
// Yarn 1 names an alias, `my-q@npm:q@^1.5.1`, by its own name
|
|
78
|
+
// Yarn 1 names an alias, `my-q@npm:q@^1.5.1`, by its own name, and
|
|
79
|
+
// resolves none of a directory (`file:` or `link:`).
|
|
79
80
|
return Object.values(parseYarn1Lockfile(text, { checkVersions: false }).packages)
|
|
80
|
-
.map(pkg => ({ ...pkg, name: /@npm:((?:@[^/@]+\/)?[^/@]+)/u.exec(pkg.patterns[0] ?? '')?.[1] ?? pkg.name }))
|
|
81
|
+
.map(pkg => ({ ...pkg, name: /@npm:((?:@[^/@]+\/)?[^/@]+)/u.exec(pkg.patterns[0] ?? '')?.[1] ?? pkg.name, resolution: pkg.resolution ?? { type: 'directory' as const } }))
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
// npm's registry, by either of its names, and yarn's mirror of it, as
|
|
@@ -92,10 +93,14 @@ const shown = (url: URL | null) => url ? { from: `${url.protocol}//${url.host}${
|
|
|
92
93
|
|
|
93
94
|
// Where a package read comes from (LockedPackage), with npm's registry's
|
|
94
95
|
// integrity where `review`; null for one a package bundles, with no
|
|
95
|
-
// resolution
|
|
96
|
+
// resolution. One installed from a directory of the project's own (a `file:`
|
|
97
|
+
// one, which pnpm and Yarn 1 copy into node_modules) is a file of it, for a
|
|
98
|
+
// review alone: a bundle may hold it under node_modules, by the version its
|
|
99
|
+
// package.json names, which pnpm's lockfile doesn't (bundle-dependency-reviews.ts).
|
|
96
100
|
function located({ name, version, resolution }: ReadPackage, review: boolean): LockedPackage | null {
|
|
97
101
|
const at = { name, version: version ?? null }
|
|
98
|
-
if (resolution === undefined
|
|
102
|
+
if (resolution === undefined) return null
|
|
103
|
+
if (resolution.type === 'directory') return review ? { ...at, source: 'file' } : null
|
|
99
104
|
if (resolution.type === 'git') return { ...at, source: 'git', ...shown(URL.parse(resolution.repo)) }
|
|
100
105
|
const { tarball, integrity } = resolution
|
|
101
106
|
if (resolution.gitHosted) return { ...at, source: 'git', ...shown(URL.parse(tarball ?? '')) }
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
// it (`kept`), what a version holds never changing. Access is the caller's
|
|
18
18
|
// to check.
|
|
19
19
|
import { createHash } from 'node:crypto'
|
|
20
|
-
import type
|
|
20
|
+
import { type KeptStore, VERSION_DELTA_KEPT_MS } from './npm-kept.ts'
|
|
21
21
|
import { type Lru, lru } from './lru.ts'
|
|
22
22
|
import { NpmPackageError, type NpmPackageFile, npmFileText } from './npm-packages.ts'
|
|
23
23
|
import { workerTurns } from './worker-turns.ts'
|
|
@@ -104,6 +104,21 @@ type Side = { integrity: string; files: () => Promise<NpmPackageFile[]> }
|
|
|
104
104
|
// A delta's key: the integrities of the version it is against, or none, and
|
|
105
105
|
// of the version.
|
|
106
106
|
export const deltaKey = (base: string | null, other: string) => `${base ?? '(empty)'}\0${other}`
|
|
107
|
+
// The same of two public versions by their names and versions (`(empty)`
|
|
108
|
+
// for none), as npm never gives one other files: its key in
|
|
109
|
+
// npmVersionDeltaStore.
|
|
110
|
+
export const versionDeltaKey = (name: string, version: string, otherName: string, otherVersion: string) =>
|
|
111
|
+
`${name}@${version}\0${otherVersion === '(empty)' ? '(empty)' : `${otherName}@${otherVersion}`}`
|
|
112
|
+
// Those of `keys` (versionDeltaKey) kept, by key, as of `now`: one kept past
|
|
113
|
+
// VERSION_DELTA_KEPT_MS not, though no write has pruned it yet.
|
|
114
|
+
export async function keptVersionDeltas(keys: string[], kept: KeptStore<NpmDelta>, now = Date.now()): Promise<Map<string, NpmDelta>> {
|
|
115
|
+
const found = new Map<string, NpmDelta>()
|
|
116
|
+
for (const [key, row] of keys.length > 0 ? await kept.readMany([...new Set(keys)]) : []) {
|
|
117
|
+
const known = now - row.at < VERSION_DELTA_KEPT_MS ? deltaOf(row.value) : null
|
|
118
|
+
if (known) found.set(key, known)
|
|
119
|
+
}
|
|
120
|
+
return found
|
|
121
|
+
}
|
|
107
122
|
|
|
108
123
|
// The delta of `other` (its integrity, and how to read its files) against
|
|
109
124
|
// `base`, or none, as held, else shared with one asked before it, else
|
|
@@ -215,6 +215,12 @@ export const pullDependencyStore = <T>(db: UpstreamCacheStore, debug = false): K
|
|
|
215
215
|
// The lines a version changes against another, or none (npm-delta.ts), by
|
|
216
216
|
// both sides' integrities, each kept HISTORY_PAGE_KEPT_MS.
|
|
217
217
|
export const npmDeltaStore = <T>(db: UpstreamCacheStore, debug = false): KeptStore<T> => keptStore<T>(db, 'npm/deltas', HISTORY_PAGE_KEPT_MS, debug)
|
|
218
|
+
// The same, of public versions alone, by their names and versions
|
|
219
|
+
// (npm-delta.ts versionDeltaKey), which npm never gives other files: read
|
|
220
|
+
// without their integrities, so without asking npm, or keeping what it tells
|
|
221
|
+
// of them, for them. Each read for VERSION_DELTA_KEPT_MS alone, pruned or not.
|
|
222
|
+
export const VERSION_DELTA_KEPT_MS = 30 * 24 * 60 * 60_000
|
|
223
|
+
export const npmVersionDeltaStore = <T>(db: UpstreamCacheStore, debug = false): KeptStore<T> => keptStore<T>(db, 'npm/version-deltas', VERSION_DELTA_KEPT_MS, debug)
|
|
218
224
|
// The versions a repository's lockfiles locked at the commit its dependencies
|
|
219
225
|
// are reviewed since (pull-dependency-reviews.ts reviewBaseline), by the
|
|
220
226
|
// commit, which never change: kept as its history's pages are, never stored
|
|
@@ -57,7 +57,7 @@ const READ_PARALLEL = 4
|
|
|
57
57
|
// told or read by others is told or read again, as those read before pnpm's
|
|
58
58
|
// patches' files were, and those told before their lockfiles' directories,
|
|
59
59
|
// or read with the files of patches pnpm 9 names by an md5.
|
|
60
|
-
export const PULL_DEPENDENCIES_READ =
|
|
60
|
+
export const PULL_DEPENDENCIES_READ = 6
|
|
61
61
|
|
|
62
62
|
type Format = 'npm' | 'pnpm' | 'yarn' | 'bun'
|
|
63
63
|
|
|
@@ -98,8 +98,11 @@ export type AddedPackage = LockedPackage & { was?: string[]; base?: { name: stri
|
|
|
98
98
|
// (`lockfile-unsupported`, Bun's) or GitHub having none at a commit compared.
|
|
99
99
|
// A stasis.config.json a review holds to is told as one too, by its own path
|
|
100
100
|
// (stasis-dependencies.ts stasisDirectory), or as `stasis-pending` or `stasis-failed`.
|
|
101
|
-
export type DirectoryDependencies = { paths: string[] } & ({ added: AddedPackage[]; more: number; locked: LockedPackage[]; moreLocked: number }
|
|
101
|
+
export type DirectoryDependencies = { paths: string[]; builds?: StasisBuild[] } & ({ added: AddedPackage[]; more: number; locked: LockedPackage[]; moreLocked: number }
|
|
102
102
|
| { error: string; detail?: string })
|
|
103
|
+
// A Stasis build a stasis.config.json's directory reads (stasis-dependencies.ts
|
|
104
|
+
// stasisDirectory): of the commit, and whether it is made, or failed, as kept.
|
|
105
|
+
export interface StasisBuild { commit: string; built: boolean }
|
|
103
106
|
// What a pull request's lockfiles add: the commits compared (`base`, its
|
|
104
107
|
// merge base, and `head`); each directory's, of those it changes a lockfile
|
|
105
108
|
// in; and `cut` where it changes more files than GitHub lists, or lockfiles
|
|
@@ -160,7 +160,10 @@ export function askedOf(pkg: LockedPackage): [string, ReviewedDependency] {
|
|
|
160
160
|
// nor needing none, as only one that can be reviewed may.
|
|
161
161
|
type Review = { unsupported: Unsupported } | { baseline: true } | { reviewed: true } | { reviews: number; rejected?: true; commented?: number; reviewers?: Reviewer[] }
|
|
162
162
|
| Record<string, never>
|
|
163
|
-
|
|
163
|
+
// The reader's own latest published review of a version, whether or not it
|
|
164
|
+
// counts (`yours`): its verdict, and whether it is partial.
|
|
165
|
+
type Yours = { status: PublishedReview['status']; partial?: true }
|
|
166
|
+
interface Judged { review: Review; wants: boolean; yours?: Yours }
|
|
164
167
|
type Judge = (pkg: LockedPackage, bases: string[] | 'any') => Judged
|
|
165
168
|
// One of npm's registry locked with no integrity passes where the host's
|
|
166
169
|
// `lookup` passed it as it is (`vouched`, by what it was asked).
|
|
@@ -210,11 +213,12 @@ function reviewedDirectory(dir: DirectoryDependencies, review: Judge | null, bas
|
|
|
210
213
|
// Each row against the base of the way it is locked that it is told by.
|
|
211
214
|
const row = ({ pkg, judged }: (typeof own)[number]) => {
|
|
212
215
|
const { base: _base, ...rest } = shown(pkg as AddedPackage), { base } = judged.variant as AddedPackage
|
|
213
|
-
return { ...rest, ...base ? { base } : {}, ...judged.review }
|
|
216
|
+
return { ...rest, ...base ? { base } : {}, ...judged.review, ...judged.yours ? { yours: judged.yours } : {} }
|
|
214
217
|
}
|
|
215
218
|
return { ...told, ...baseless ? { more: Math.max(0, listed.length - MAX_ADDED) } : {}, added: listed.slice(0, MAX_ADDED).map(row),
|
|
216
219
|
toReview: own.flatMap(({ wanting }) => wanting.map(shown)),
|
|
217
|
-
unreviewed: others.filter(({ judged }) => judged.wants).map(({ pkg, judged }) => ({ ...shown(pkg), ...judged.review }
|
|
220
|
+
unreviewed: others.filter(({ judged }) => judged.wants).map(({ pkg, judged }) => ({ ...shown(pkg), ...judged.review, ...judged.yours ? { yours: judged.yours } : {} })),
|
|
221
|
+
unsupported, moreLocked }
|
|
218
222
|
}
|
|
219
223
|
function capped<T extends { toReview: unknown[]; unreviewed: unknown[]; unsupported: unknown[] }>({ toReview: _toReview, ...dir }: T) {
|
|
220
224
|
return { ...dir, unreviewed: dir.unreviewed.slice(0, MAX_UNREVIEWED), moreUnreviewed: Math.max(0, dir.unreviewed.length - MAX_UNREVIEWED),
|
|
@@ -259,7 +263,8 @@ export function heldDependencies<T extends PullDependencies>(told: T, scope: Loc
|
|
|
259
263
|
|
|
260
264
|
// A pull request's dependencies as the client is told them: without the
|
|
261
265
|
// versions its directories lock; with `state`, a repository's review in
|
|
262
|
-
// effect, each version's review (reviewedDirectory),
|
|
266
|
+
// effect, each version's review (reviewedDirectory), with `user`'s own
|
|
267
|
+
// latest published review of it, whether it counts or not (`yours`), those wanting one asked
|
|
263
268
|
// of the registered reviewed dependencies (`reviewed`), those they don't pass
|
|
264
269
|
// of their `base` (onto `namedBases`), and those still
|
|
265
270
|
// wanting one of the reviews its comments make (`commentReviews`, where the
|
|
@@ -281,9 +286,9 @@ export function heldDependencies<T extends PullDependencies>(told: T, scope: Loc
|
|
|
281
286
|
// lockfiles the review holds to (`lockfiles`, lockfile-scope.ts, told in its
|
|
282
287
|
// terms where not every one) are left out (heldDependencies).
|
|
283
288
|
export async function reviewedDependencies(told: PullDependencies, state: RepoReviewState | null,
|
|
284
|
-
{ baseline = null, baselineUnread = [], baselineError = null, reviewed = null, commentReviews = null, namedBases = new Map(), wantedIn = new Map() }: {
|
|
285
|
-
baselineUnread?: string[]; baselineError?: string | null; reviewed?: ReviewedDependencies | null; commentReviews?: CommentReviews | null
|
|
286
|
-
wantedIn?: Map<string[], number
|
|
289
|
+
{ baseline = null, baselineUnread = [], baselineError = null, reviewed = null, commentReviews = null, namedBases = new Map(), wantedIn = new Map(), user = null }: {
|
|
290
|
+
baseline?: Set<string> | null; baselineUnread?: string[]; baselineError?: string | null; reviewed?: ReviewedDependencies | null; commentReviews?: CommentReviews | null
|
|
291
|
+
namedBases?: Map<string, ReviewedBase>; wantedIn?: Map<string[], number>; user?: string | null } = {}) {
|
|
287
292
|
const scope = state?.lockfiles ?? EVERY_LOCKFILE
|
|
288
293
|
const answered = heldDependencies(told, scope)
|
|
289
294
|
const baseless = told.baseless === true
|
|
@@ -344,9 +349,18 @@ export async function reviewedDependencies(told: PullDependencies, state: RepoRe
|
|
|
344
349
|
context = { ...context, reviews: reviewsByVersion([...published, ...comments.reviews.map(review => ({ ...review, comment: true as const }))]) }
|
|
345
350
|
await ask(new Map([...wanting()].filter(([key]) => !asked.has(key))))
|
|
346
351
|
}
|
|
352
|
+
// `user`'s own published reviews, each version told its latest of them
|
|
353
|
+
// whatever it was compared with, and whether or not it counts: one they
|
|
354
|
+
// reviewed that wants reviews still, others' or the host's, is labelled
|
|
355
|
+
// theirs.
|
|
356
|
+
const mine = reviewsByVersion(user ? state.reviews.filter(review => review.id !== undefined && review.reviewer === user) : [])
|
|
357
|
+
const yours = (pkg: LockedPackage) => {
|
|
358
|
+
const latest = reviewsOf(pkg, mine).reduce<PublishedReview | null>((one, other) => one && one.time >= other.time ? one : other, null)
|
|
359
|
+
return latest ? { yours: { status: latest.status, ...latest.full ? {} : { partial: true as const } } } : {}
|
|
360
|
+
}
|
|
347
361
|
const dirs = held.map(dir => reviewedDirectory(dir, (pkg, bases) => {
|
|
348
362
|
const judged = judge(pkg, bases, context)
|
|
349
|
-
return judged.wants && passed.has(askedOf(pkg)[0]) ? { review: { reviewed: true }, wants: false } : judged
|
|
363
|
+
return { ...judged.wants && passed.has(askedOf(pkg)[0]) ? { review: { reviewed: true as const }, wants: false } : judged, ...yours(pkg) }
|
|
350
364
|
}, baseless, vouching.passed))
|
|
351
365
|
const unread = baselineUnread.filter(path => heldTo(scope, path))
|
|
352
366
|
const listed = dirs.filter(dir => 'unreviewed' in dir)
|
|
@@ -67,7 +67,7 @@ type Node = ReviewNode & { number?: unknown; title?: unknown; createdAt?: unknow
|
|
|
67
67
|
isDraft?: unknown; reviewDecision?: unknown; additions?: unknown; deletions?: unknown; headRefName?: unknown; baseRefName?: unknown; baseRefOid?: unknown; isCrossRepository?: unknown
|
|
68
68
|
commits?: { nodes?: { commit?: { statusCheckRollup?: { state?: unknown } | null } | null }[] }
|
|
69
69
|
files?: { totalCount?: unknown; nodes?: ({ path?: unknown } | null)[] } | null }
|
|
70
|
-
type Page = { repository?: { open?: { totalCount?: unknown }; closed?: { totalCount?: unknown }; page?: Connection<Node
|
|
70
|
+
type Page = { repository?: { open?: { totalCount?: unknown }; closed?: { totalCount?: unknown }; page?: Connection<Node>; defaultBranchRef?: { name?: unknown } | null } | null }
|
|
71
71
|
|
|
72
72
|
const REVIEWS: Record<string, string> = { APPROVED: 'approved', CHANGES_REQUESTED: 'changes', REVIEW_REQUIRED: 'required' }
|
|
73
73
|
const CHECKS: Record<string, string> = { SUCCESS: 'success', FAILURE: 'failure', ERROR: 'failure', PENDING: 'pending', EXPECTED: 'pending' }
|
|
@@ -230,14 +230,16 @@ export async function repositoryIssues(fullName: string, token: string, kind: Is
|
|
|
230
230
|
// A page of the open pull requests a team's Dependencies reads (http.ts
|
|
231
231
|
// teamOpenPulls), those carrying `$labels` alone where it names some: each by
|
|
232
232
|
// what its card there and its popup's heading tell (its number, title and
|
|
233
|
-
// author, when it was opened and last updated, whether it is a draft
|
|
234
|
-
// files by which whether it changes a
|
|
235
|
-
// head's commits, by which what its
|
|
236
|
-
//
|
|
233
|
+
// author, when it was opened and last updated, whether it is a draft, the
|
|
234
|
+
// branch it is to merge into), the files by which whether it changes a
|
|
235
|
+
// lockfile is told, and its base's and head's commits, by which what its
|
|
236
|
+
// lockfiles add is read, with the branches they are of (commitsOf); and the
|
|
237
|
+
// repository's default branch, by its name. Nothing else a tile shows (its labels, comments,
|
|
237
238
|
// size, checks, reviews, threads and comments), which GitHub is slow enough
|
|
238
239
|
// to gather for fifty of a large repository's to fail the page.
|
|
239
240
|
const openPullsQuery = (labelled: boolean) => `query($owner: String!, $name: String!, $first: Int!, $after: String${labelled ? ', $labels: [String!]' : ''}) {
|
|
240
241
|
repository(owner: $owner, name: $name) {
|
|
242
|
+
defaultBranchRef { name }
|
|
241
243
|
page: pullRequests(states: [OPEN], first: $first, after: $after, ${labelled ? 'labels: $labels, ' : ''}orderBy: { field: UPDATED_AT, direction: DESC }) {
|
|
242
244
|
pageInfo { hasNextPage endCursor }
|
|
243
245
|
nodes { number title createdAt updatedAt author { ${ACTOR} } state isDraft baseRefOid headRefOid baseRefName headRefName isCrossRepository ${files} }
|
|
@@ -245,7 +247,7 @@ const openPullsQuery = (labelled: boolean) => `query($owner: String!, $name: Str
|
|
|
245
247
|
}
|
|
246
248
|
}`
|
|
247
249
|
// What a kept page of them was read as: kept ones read before differ.
|
|
248
|
-
export const OPEN_PULLS_READ =
|
|
250
|
+
export const OPEN_PULLS_READ = 2
|
|
249
251
|
// How many a page asks for: ISSUES_PAGE, then, where GitHub fails to answer
|
|
250
252
|
// that many in its time, fewer, and fewer again.
|
|
251
253
|
export const OPEN_PULLS_SIZES = [ISSUES_PAGE, 20, 5]
|
|
@@ -256,7 +258,8 @@ const tooSlow = (err: unknown) => err instanceof GithubApiError && SLOW.has(err.
|
|
|
256
258
|
|
|
257
259
|
// A page of the repository's open pull requests, the latest updated first,
|
|
258
260
|
// after the page `after` ended (null for the first), those carrying `label`
|
|
259
|
-
// alone where it names one: its `items`, their commits (`commits`, commitsOf)
|
|
261
|
+
// alone where it names one: its `items`, their commits (`commits`, commitsOf),
|
|
262
|
+
// the repository's default branch (`defaultBranch`, null where it tells none)
|
|
260
263
|
// and, where more follow, the cursor reading them (`after`). As many as
|
|
261
264
|
// `size` asked for, then, GitHub too slow to answer, as many as each smaller
|
|
262
265
|
// of OPEN_PULLS_SIZES, the last one's failure the read's; how many were
|
|
@@ -281,7 +284,10 @@ async function openPullsPage(fullName: string, token: string, after: string | nu
|
|
|
281
284
|
const next = info?.hasNextPage === true && typeof info.endCursor === 'string' && ISSUES_CURSOR.test(info.endCursor) ? info.endCursor : null
|
|
282
285
|
const pulls = (repository.page?.nodes ?? []).flatMap(node => {
|
|
283
286
|
const named = itemOf(node)
|
|
284
|
-
|
|
287
|
+
const base = nameOf(node?.baseRefName)
|
|
288
|
+
return node && named ? [{ node, tile: { ...named, createdAt: timeOf(node.createdAt), updatedAt: timeOf(node.updatedAt), ...pullState(node.state, node.isDraft),
|
|
289
|
+
...base ? { base } : {}, ...lockfileTouched(node) } }] : []
|
|
285
290
|
})
|
|
286
|
-
return { items: pulls.map(({ tile }) => tile), commits: pulls.flatMap(({ node, tile }) => commitsOf(tile.number, node)),
|
|
291
|
+
return { items: pulls.map(({ tile }) => tile), commits: pulls.flatMap(({ node, tile }) => commitsOf(tile.number, node)), defaultBranch: nameOf(repository.defaultBranchRef?.name),
|
|
292
|
+
more: next !== null, after: next, size: first }
|
|
287
293
|
}
|