@preventive/triage 1.0.0-alpha.71 → 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/out/activity.js +4 -4
- package/out/{chunk-45HTR22K.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-CQIT5UNK.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 +12 -14
- 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 +2 -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/http.ts +105 -54
- package/server-managed/npm-delta.ts +16 -1
- package/server-managed/npm-kept.ts +6 -0
- package/server-managed/pull-dependencies.ts +4 -1
- 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-DTAR2BB6.js +0 -247
- package/out/chunk-NB4JBTKK.js +0 -2
- package/out/chunk-VFWMQ3LG.js +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preventive/triage",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.72",
|
|
4
4
|
"description": "Client & relay server for triaging of automated reports",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -341,6 +341,7 @@
|
|
|
341
341
|
"risk/files/readability.js",
|
|
342
342
|
"risk/files/runs-code.js",
|
|
343
343
|
"risk/files/script.js",
|
|
344
|
+
"risk/files/source-map-link.js",
|
|
344
345
|
"risk/files/stamps.js",
|
|
345
346
|
"risk/npm/assess.js",
|
|
346
347
|
"risk/npm/combined.js",
|
package/risk/actions/resolve.js
CHANGED
|
@@ -189,13 +189,19 @@ const RATED = new Set(['critical', 'high', 'moderate', 'low'])
|
|
|
189
189
|
// finding: malware red, else as its source rates it, one unrated yellow. One
|
|
190
190
|
// not known public is `internal`, asked of its own advisories alone, its name
|
|
191
191
|
// sent to no other source; why not (`advisories-unavailable`) where they
|
|
192
|
-
// couldn't be had, the rest resolved all the same.
|
|
192
|
+
// couldn't be had, the rest resolved all the same. Each with what tells it
|
|
193
|
+
// apart, as its row's tooltip shows it: its source, other ids, CVSS score,
|
|
194
|
+
// CWEs, the range it affects, whether its source rates it (`unrated`) and,
|
|
195
|
+
// where it is no vulnerability as such, what it is (`informational`); not
|
|
196
|
+
// its text, which its link has.
|
|
193
197
|
async function advisoryFindings(source, info, versions) {
|
|
194
198
|
if (source.advisories === undefined) return []
|
|
195
199
|
try {
|
|
196
|
-
return (await source.advisories(info.fullName, versions, info.private ?? true)).map(({ id, title, url, severity, malware, versions: affected
|
|
200
|
+
return (await source.advisories(info.fullName, versions, info.private ?? true)).map(({ id, title, url, severity, malware, versions: affected, source: from,
|
|
201
|
+
aliases, cvss, cwe, range, informational }) => ({
|
|
197
202
|
id: 'advisory', severity: malware ? 'critical' : RATED.has(severity) ? severity : 'moderate', advisory: id, ...title && { title }, ...url && { url },
|
|
198
|
-
...malware && { malware: true }, versions: affected })
|
|
203
|
+
...malware && { malware: true }, ...!malware && !RATED.has(severity) && { unrated: true }, versions: affected, ...from && { source: from }, ...aliases?.length && { aliases }, ...Number.isFinite(cvss) && { cvss },
|
|
204
|
+
...cwe?.length && { cwe }, ...range && { range }, ...informational && { informational } }))
|
|
199
205
|
} catch { return [{ id: 'advisories-unavailable', severity: 'notice' }] }
|
|
200
206
|
}
|
|
201
207
|
|
package/risk/files/characters.js
CHANGED
|
@@ -14,6 +14,17 @@
|
|
|
14
14
|
export const CONTROLS = /(?![\t\n\r])\p{Cc}|[\u202A-\u202E\u2066-\u2069]/gu
|
|
15
15
|
const NON_ASCII = /\P{ASCII}/u
|
|
16
16
|
|
|
17
|
+
// What shows as nothing, or as another character, where a viewer draws it as
|
|
18
|
+
// text: the controls but tab and line feed (C0, DEL, C1), the format
|
|
19
|
+
// characters (Cf: zero-width ones, the bidi controls, tags), lone surrogates
|
|
20
|
+
// (Cs; `u` reads a pair as the one character it spells), private use (Co) and
|
|
21
|
+
// unassigned (Cn) code points, the line and paragraph separators, spaces other
|
|
22
|
+
// than a space, the default-ignorable characters and the Braille blank. A code
|
|
23
|
+
// viewer boxes each (ui/view/control-chars.js), and a source map's listing
|
|
24
|
+
// writes a line holding one as JSON (common/sourcemap-listing.js).
|
|
25
|
+
// eslint-disable-next-line no-control-regex
|
|
26
|
+
export const UNSEEN = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u2800\u3000\p{Cf}\p{Cs}\p{Co}\p{Cn}\p{Default_Ignorable_Code_Point}]/u
|
|
27
|
+
|
|
17
28
|
// A file's text: `kind` 'ascii' or 'utf8', by whether it holds anything past
|
|
18
29
|
// ASCII, else 'binary' (which the server tells by its bytes, sending no
|
|
19
30
|
// text); `controls` the control and invisible characters a text holds, how
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// How a built file names its source map, and what a source map is: read
|
|
2
|
+
// alike where a version's map is told rebuilt with its file (npm/compare.js
|
|
3
|
+
// rebuiltWithMap) and where a map's listing is of the file beside it that
|
|
4
|
+
// names it (common/pretty-sourcemap.js).
|
|
5
|
+
|
|
6
|
+
// A `sourceMappingURL` comment and no more, on a file's last line.
|
|
7
|
+
const SOURCE_MAP_FILE = /^\s*(?:\/\/[#@] sourceMappingURL=(\S+)|\/\*[#@] sourceMappingURL=(\S+?)\s*\*\/)\s*$/u
|
|
8
|
+
// A map name a build writes (`a.js.map`, `../maps/a.map`): segments of
|
|
9
|
+
// letters, digits and `._~@+-`, as a browser reads them alike. One at a URL,
|
|
10
|
+
// from a site's root, or with an escape or a backslash names none.
|
|
11
|
+
const MAP_NAME = /^(?:[\w.~@+-]+\/)*[\w.~@+-]+\.map$/u
|
|
12
|
+
|
|
13
|
+
// The map a file's text names on its last line by a plain path from the
|
|
14
|
+
// file's own (MAP_NAME), or null: none named, or one named otherwise (a data:
|
|
15
|
+
// URL, a site's).
|
|
16
|
+
export function mapNamed(text) {
|
|
17
|
+
if (typeof text !== 'string') return null
|
|
18
|
+
const trimmed = text.trimEnd()
|
|
19
|
+
const directive = SOURCE_MAP_FILE.exec(trimmed.slice(trimmed.lastIndexOf('\n') + 1))
|
|
20
|
+
const name = directive?.[1] ?? directive?.[2]
|
|
21
|
+
return name && MAP_NAME.test(name) ? name : null
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// The path `name` names from beside `file`, or null for one above the root.
|
|
25
|
+
export function besideFile(file, name) {
|
|
26
|
+
const parts = file.split('/').slice(0, -1)
|
|
27
|
+
for (const part of name.split('/')) {
|
|
28
|
+
if (part === '..' && parts.length === 0) return null
|
|
29
|
+
if (part === '..') parts.pop()
|
|
30
|
+
else if (part !== '.') parts.push(part)
|
|
31
|
+
}
|
|
32
|
+
return parts.join('/')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Whether a text is a source map: JSON with `mappings`, or each of an
|
|
36
|
+
// indexed map's `sections` with its own.
|
|
37
|
+
export function isSourceMap(text) {
|
|
38
|
+
try {
|
|
39
|
+
const json = JSON.parse(text)
|
|
40
|
+
return typeof json?.mappings === 'string'
|
|
41
|
+
|| (Array.isArray(json?.sections) && json.sections.length > 0 && json.sections.every(section => typeof section?.map?.mappings === 'string'))
|
|
42
|
+
} catch { return false }
|
|
43
|
+
}
|
package/risk/npm/compare.js
CHANGED
|
@@ -13,6 +13,7 @@ import { npmHostFinding } from './held.js'
|
|
|
13
13
|
import { HOST_TAGS, npmHostSeverity, npmHostsTagged } from '../files/hosts.js'
|
|
14
14
|
import { npmBecameUnreadable, npmBinaryCode, npmLargeCode, npmUnreadable } from '../files/readability.js'
|
|
15
15
|
import { npmIsScript } from '../files/script.js'
|
|
16
|
+
import { besideFile, isSourceMap, mapNamed } from '../files/source-map-link.js'
|
|
16
17
|
import { SEVERITIES } from '../files/stamps.js'
|
|
17
18
|
import { CREDENTIAL_TAGS, npmFoundAdded, npmRunsCodeFlags, npmRunsCodeTagged, npmRunsCodeWithout } from '../files/runs-code.js'
|
|
18
19
|
import { npmDependencySpecs } from './dependencies.js'
|
|
@@ -126,40 +127,17 @@ function npmMajorRelease(was, now) {
|
|
|
126
127
|
// Whether the open version's file at `path` (`basePath` in the one compared
|
|
127
128
|
// with) had its source map rebuilt with it: its last line, a
|
|
128
129
|
// `sourceMappingURL` comment and no more, names a map file of the package by
|
|
129
|
-
// a plain path from the file's own (
|
|
130
|
+
// a plain path from the file's own (source-map-link.js mapNamed), a source map
|
|
130
131
|
// (its `mappings`, or each of an indexed map's `sections`, told), new or
|
|
131
132
|
// changed from the one at its path, or beside the file's own before it was
|
|
132
133
|
// renamed, as a build writes them together. An attack editing a built file
|
|
133
134
|
// leaves its map as it was.
|
|
134
|
-
const SOURCE_MAP_FILE = /^\s*(?:\/\/[#@] sourceMappingURL=(\S+)|\/\*[#@] sourceMappingURL=(\S+?)\s*\*\/)\s*$/u
|
|
135
|
-
// A map name a build writes (`a.js.map`, `../maps/a.map`): segments of
|
|
136
|
-
// letters, digits and `._~@+-`, as a browser reads them alike. One at a URL,
|
|
137
|
-
// from a site's root, or with an escape or a backslash names none.
|
|
138
|
-
const MAP_NAME = /^(?:[\w.~@+-]+\/)*[\w.~@+-]+\.map$/u
|
|
139
|
-
function besideFile(file, name) {
|
|
140
|
-
const parts = file.split('/').slice(0, -1)
|
|
141
|
-
for (const part of name.split('/')) {
|
|
142
|
-
if (part === '..' && parts.length === 0) return null
|
|
143
|
-
if (part === '..') parts.pop()
|
|
144
|
-
else if (part !== '.') parts.push(part)
|
|
145
|
-
}
|
|
146
|
-
return parts.join('/')
|
|
147
|
-
}
|
|
148
135
|
function rebuiltWithMap(base, other, path, basePath) {
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
const name = directive?.[1] ?? directive?.[2]
|
|
152
|
-
if (!name || !MAP_NAME.test(name)) return false
|
|
136
|
+
const name = mapNamed(bundleFilesAsMap(other).get(path))
|
|
137
|
+
if (!name) return false
|
|
153
138
|
const [map, was] = [bundleFilesAsMap(other).get(besideFile(path, name)), bundleFilesAsMap(base)]
|
|
154
139
|
return isSourceMap(map) && map !== was.get(besideFile(path, name)) && map !== was.get(besideFile(basePath, name))
|
|
155
140
|
}
|
|
156
|
-
const isSourceMap = text => {
|
|
157
|
-
try {
|
|
158
|
-
const json = JSON.parse(text)
|
|
159
|
-
return typeof json?.mappings === 'string'
|
|
160
|
-
|| (Array.isArray(json?.sections) && json.sections.length > 0 && json.sections.every(section => typeof section?.map?.mappings === 'string'))
|
|
161
|
-
} catch { return false }
|
|
162
|
-
}
|
|
163
141
|
|
|
164
142
|
// The files become unreadable as a finding says them: red, but orange in a
|
|
165
143
|
// major release, or where each had its source map rebuilt with it.
|
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'
|
|
@@ -2562,7 +2562,9 @@ function itemNumber(text: string | null): number | null {
|
|
|
2562
2562
|
// Up to MAX_ASKED_PULLS pull requests asked together (`numbers=1,2,3`) are
|
|
2563
2563
|
// answered together, as many read at once as PULLS_AT_ONCE, `{ pulls }`,
|
|
2564
2564
|
// each's answer, else `{ number, error }` where GitHub fails it, with one
|
|
2565
|
-
// 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.
|
|
2566
2568
|
const MAX_ASKED_PULLS = 20
|
|
2567
2569
|
const PULLS_AT_ONCE = 3
|
|
2568
2570
|
async function handleRepositoryPullDependencies(res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined, query: URLSearchParams): Promise<void> {
|
|
@@ -2578,9 +2580,12 @@ async function handleRepositoryPullDependencies(res: ServerResponse, deps: Manag
|
|
|
2578
2580
|
|| !['1', null].includes(query.get('review')) || !['1', null].includes(query.get('listed'))) { sendJson(res, 400, { error: 'bad-request' }); return }
|
|
2579
2581
|
await answerWholeRepository(res, deps, cookie, repoId, async (fullName, token, user) => {
|
|
2580
2582
|
const commits = tiles ? await keptPullCommits(deps, repoId, numbers as number[]) : new Map<number, PullCommits>()
|
|
2581
|
-
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
|
+
}
|
|
2582
2587
|
const answers = await pullDependencyAnswers(deps, fullName, token, user, repoId, numbers as number[], review, commits)
|
|
2583
|
-
return { value: { pulls: answers.value }, kept: answers.kept }
|
|
2588
|
+
return { value: { pulls: answers.value, ...review ? await withDeltas(deps, answers.value) : {} }, kept: answers.kept }
|
|
2584
2589
|
})
|
|
2585
2590
|
}
|
|
2586
2591
|
|
|
@@ -2829,10 +2834,23 @@ const TEAM_PULL_READS = TEAM_PULLS / OPEN_PULLS_SIZES.at(-1)!
|
|
|
2829
2834
|
const TEAM_PULLS_TOGETHER = 20
|
|
2830
2835
|
const PARTIAL_ACCESS = new Set(['no-directory', 'no-repository'])
|
|
2831
2836
|
type TeamDependencyLine = Record<string, unknown> & { repoId?: number }
|
|
2832
|
-
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 }
|
|
2833
2847
|
async function handleTeamDependencies(res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined, s: { session: ManagedSession; user: StoredUser },
|
|
2834
2848
|
teamId: string, query: URLSearchParams): Promise<void> {
|
|
2835
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' }
|
|
2836
2854
|
const named = query.get('repoIds')
|
|
2837
2855
|
const only = named === null ? null : new Set(named.split(',').map(Number))
|
|
2838
2856
|
if (only && (only.size === 0 || only.size > 1000 || [...only].some(id => !Number.isSafeInteger(id) || id <= 0))) { sendJson(res, 400, { error: 'bad-request' }); return }
|
|
@@ -2876,7 +2894,7 @@ async function handleTeamDependencies(res: ServerResponse, deps: ManagedHttpDeps
|
|
|
2876
2894
|
}
|
|
2877
2895
|
if (answered.length > 0 && !await send(...answered)) return
|
|
2878
2896
|
const done = await eachOf(reading, TEAM_REPOSITORIES_AT_ONCE, ({ access, setting }) => stopped || Date.now() > deadline ? Promise.resolve(false)
|
|
2879
|
-
: 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))
|
|
2880
2898
|
if (stopped) return
|
|
2881
2899
|
const unread = reading.filter((_, at) => !done[at]).map(({ access }) => access.repo.repoId)
|
|
2882
2900
|
if (!await send(unread.length === 0 ? { done: true } : { done: false, unread })) return
|
|
@@ -2886,20 +2904,21 @@ async function handleTeamDependencies(res: ServerResponse, deps: ManagedHttpDeps
|
|
|
2886
2904
|
// A repository's lines of its team's Dependencies, as handleTeamDependencies
|
|
2887
2905
|
// tells them; whether all were written, none left for its time.
|
|
2888
2906
|
async function teamRepositoryDependencies(deps: ManagedHttpDeps, access: WholeAccess, setting: RepoDependencyReview, deadline: number,
|
|
2889
|
-
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> {
|
|
2890
2908
|
// The Stasis builds its answers want, asked for a batch of pull requests at a time, its default branch's with the first.
|
|
2891
2909
|
const wants: StasisWant[] = []
|
|
2892
|
-
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) }
|
|
2893
2911
|
}
|
|
2894
2912
|
async function teamRepositoryLines(deps: ManagedHttpDeps, access: WholeAccess, setting: RepoDependencyReview, deadline: number,
|
|
2895
|
-
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> {
|
|
2896
2914
|
const repoId = access.repo.repoId
|
|
2897
|
-
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> }
|
|
2898
2916
|
const read = await readWholeRepositoryOf<Read>(deps, access, async (fullName, token, user) => {
|
|
2899
2917
|
const branch = await branchDependencyAnswer(deps, fullName, token, user, repoId, setting, wants)
|
|
2900
2918
|
if (!(branch.value as { review?: unknown }).review) return { value: { branch: null }, kept: branch.kept }
|
|
2901
2919
|
const pulls = await teamOpenPulls(deps, repoId, fullName, token, deadline)
|
|
2902
|
-
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 },
|
|
2903
2922
|
kept: branch.kept && pulls.kept }
|
|
2904
2923
|
}, reauthorize)
|
|
2905
2924
|
if ('error' in read) return send({ repoId, ...PARTIAL_ACCESS.has(read.error) ? { branch: null } : { error: read.error, status: read.status } })
|
|
@@ -2907,8 +2926,12 @@ async function teamRepositoryLines(deps: ManagedHttpDeps, access: WholeAccess, s
|
|
|
2907
2926
|
if (!branch) return send({ repoId, branch: null })
|
|
2908
2927
|
if (!await send({ repoId, branch, pulls, ...await withDeltas(deps, [branch]) })) return false
|
|
2909
2928
|
// Each by the commits its page names, where it names them, GitHub not asked
|
|
2910
|
-
// for them (pullDependencyAnswer); never told.
|
|
2911
|
-
|
|
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)
|
|
2912
2935
|
for (let at = 0; at < numbers.length; at += TEAM_PULLS_TOGETHER) {
|
|
2913
2936
|
if (Date.now() > deadline) return false
|
|
2914
2937
|
const batch = numbers.slice(at, at + TEAM_PULLS_TOGETHER)
|
|
@@ -2928,7 +2951,8 @@ const withDeltas = async (deps: ManagedHttpDeps, answers: object[]) => {
|
|
|
2928
2951
|
// A repository's open pull requests, the TEAM_PULLS updated latest, a page
|
|
2929
2952
|
// at a time (repository-issues.ts repositoryOpenPulls), each kept; each's
|
|
2930
2953
|
// base's and head's commits as its page has them (`commits`, by its number),
|
|
2931
|
-
// 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
|
|
2932
2956
|
// the repository has a label named DEPENDENCIES_LABEL (kept as a page is),
|
|
2933
2957
|
// those carrying it alone, by its name as the repository has it: a
|
|
2934
2958
|
// repository of many open pull requests, few of them its dependencies', read
|
|
@@ -2944,8 +2968,9 @@ async function teamOpenPulls(deps: ManagedHttpDeps, repoId: number, fullName: st
|
|
|
2944
2968
|
const items: TeamPull[] = []
|
|
2945
2969
|
const commits = new Map<number, PullCommits>()
|
|
2946
2970
|
let after: string | null = null, kept = labelled.kept, size = OPEN_PULLS_SIZES[0]!
|
|
2971
|
+
let defaultBranch: string | null = null
|
|
2947
2972
|
for (let page = 0; page < TEAM_PULL_READS && items.length < TEAM_PULLS; page++) {
|
|
2948
|
-
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 }
|
|
2949
2974
|
const asked = size, cursor = after
|
|
2950
2975
|
let answer
|
|
2951
2976
|
try {
|
|
@@ -2953,19 +2978,20 @@ async function teamOpenPulls(deps: ManagedHttpDeps, repoId: number, fullName: st
|
|
|
2953
2978
|
} catch (err) {
|
|
2954
2979
|
if (!(err instanceof GithubApiError) || refusedRead(err)) throw err
|
|
2955
2980
|
console.warn('managed: open pull requests read failed:', err)
|
|
2956
|
-
return { items, commits, more: true, kept: false, failed: err.message }
|
|
2981
|
+
return { items, commits, more: true, kept: false, failed: err.message, defaultBranch }
|
|
2957
2982
|
}
|
|
2958
2983
|
kept &&= answer.kept
|
|
2959
2984
|
const value = answer.value as OpenPullsPage
|
|
2960
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
|
|
2961
2987
|
items.push(...(Array.isArray(value.items) ? value.items : []).filter(item => Number.isSafeInteger(item?.number) && item.number > 0))
|
|
2962
2988
|
pageCommits(value, commits)
|
|
2963
|
-
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 }
|
|
2964
2990
|
after = value.after
|
|
2965
2991
|
}
|
|
2966
|
-
return { items, commits, more: true, kept, failed: null }
|
|
2992
|
+
return { items, commits, more: true, kept, failed: null, defaultBranch }
|
|
2967
2993
|
}
|
|
2968
|
-
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 }
|
|
2969
2995
|
// Each open pull request's base's and head's commits a page of them names,
|
|
2970
2996
|
// into `commits` by its number.
|
|
2971
2997
|
function pageCommits(page: OpenPullsPage, commits: Map<number, PullCommits>) {
|
|
@@ -2999,9 +3025,11 @@ async function keptPullCommits(deps: ManagedHttpDeps, repoId: number, numbers: n
|
|
|
2999
3025
|
|
|
3000
3026
|
// The lines the versions wanting reviews of `answers` change, as their rows
|
|
3001
3027
|
// show them (npm-delta.js reviewBase), a patched one's none, where they are
|
|
3002
|
-
// counted already: of public versions alone,
|
|
3003
|
-
// (
|
|
3004
|
-
//
|
|
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.
|
|
3005
3033
|
async function teamDeltas(deps: ManagedHttpDeps, answers: object[]) {
|
|
3006
3034
|
const asked = new Map<string, [string, string, string]>()
|
|
3007
3035
|
for (const answer of answers as { lockfiles?: { added?: unknown; unreviewed?: unknown }[]; review?: { required?: number; reviewedBases?: true } }[]) {
|
|
@@ -3020,6 +3048,14 @@ async function teamDeltas(deps: ManagedHttpDeps, answers: object[]) {
|
|
|
3020
3048
|
}
|
|
3021
3049
|
}
|
|
3022
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
|
|
3023
3059
|
const versions = [...asked.values()].flatMap(([name, version, base]) => [{ name, version }, ...base === '(empty)' || !isExactVersion(base) ? [] : [{ name, version: base }]])
|
|
3024
3060
|
const kept = await npmVersionStore(deps.db, deps.config.debug).readMany!(versions)
|
|
3025
3061
|
const integrity = (name: string, version: string) => {
|
|
@@ -3031,12 +3067,15 @@ async function teamDeltas(deps: ManagedHttpDeps, answers: object[]) {
|
|
|
3031
3067
|
const against = base === '(empty)' ? null : integrity(name, base), other = integrity(name, version)
|
|
3032
3068
|
return other && (base === '(empty)' || against) ? [{ name, version, base, key: [against, other] as [string | null, string] }] : []
|
|
3033
3069
|
})
|
|
3034
|
-
if (sides.length === 0) return
|
|
3070
|
+
if (sides.length === 0) return told
|
|
3035
3071
|
const counted = await keptNpmDeltas(sides.map(({ key }) => key), npmDeltaStore<NpmDelta>(deps.db, deps.config.debug))
|
|
3036
|
-
|
|
3072
|
+
const byIntegrity = sides.flatMap(({ name, version, base, key: [against, other] }) => {
|
|
3037
3073
|
const delta = counted.get(deltaKey(against, other))
|
|
3038
|
-
return delta ? [[name, version, base, delta]] : []
|
|
3074
|
+
return delta ? [[name, version, base, delta] as const] : []
|
|
3039
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]
|
|
3040
3079
|
}
|
|
3041
3080
|
|
|
3042
3081
|
// The app's users `accounts` are, by their logins in lower case, of those
|
|
@@ -5132,17 +5171,21 @@ async function handleNpmReviews(req: IncomingMessage, res: ServerResponse, deps:
|
|
|
5132
5171
|
} finally { res.off('close', onClose) }
|
|
5133
5172
|
}
|
|
5134
5173
|
|
|
5135
|
-
// GET /api/npm/deltas?versions=[[name, version, otherVersion, patch?], …]:
|
|
5136
|
-
// each of up to MAX_ASKED_DELTAS versions changes against another,
|
|
5137
|
-
// `
|
|
5138
|
-
//
|
|
5139
|
-
//
|
|
5140
|
-
//
|
|
5141
|
-
//
|
|
5142
|
-
//
|
|
5143
|
-
//
|
|
5144
|
-
//
|
|
5145
|
-
//
|
|
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).
|
|
5146
5189
|
const MAX_ASKED_DELTAS = 50
|
|
5147
5190
|
const DELTAS_AT_ONCE = 2
|
|
5148
5191
|
// A version as npmDelta takes it: its integrity, and its files, loaded as
|
|
@@ -5155,36 +5198,44 @@ async function handleNpmDeltas(req: IncomingMessage, res: ServerResponse, deps:
|
|
|
5155
5198
|
if (req.method !== 'GET') { send405(res, 'GET'); return }
|
|
5156
5199
|
let asked: unknown = null
|
|
5157
5200
|
try { asked = JSON.parse(params.get('versions') ?? '') } catch {}
|
|
5158
|
-
const patchOf = (item: unknown[]) => item.length
|
|
5159
|
-
if (!Array.isArray(asked) || asked.length === 0 || asked.length > MAX_ASKED_DELTAS || !asked.every(item => Array.isArray(item) &&
|
|
5160
|
-
&& 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)')))) {
|
|
5161
5205
|
sendJson(res, 400, { error: 'bad-package' }); return
|
|
5162
5206
|
}
|
|
5163
|
-
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])
|
|
5164
5208
|
// Each patch read once, by its hash.
|
|
5165
5209
|
const patches = new Map<string, Promise<ReadPatch | Refusal>>()
|
|
5166
|
-
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 })
|
|
5167
5211
|
if (reader == null) { sendJson(res, 401, { error: 'unauthenticated' }); return }
|
|
5168
5212
|
const controller = new AbortController()
|
|
5169
5213
|
res.once('close', () => { if (!res.writableEnded) controller.abort() })
|
|
5170
5214
|
dropIdle(res)
|
|
5171
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)
|
|
5172
5217
|
const out = openLines(res)
|
|
5173
5218
|
let stopped = false
|
|
5174
|
-
await eachOf(versions, DELTAS_AT_ONCE, async ([name, version, otherVersion, patch]) => {
|
|
5219
|
+
await eachOf(versions, DELTAS_AT_ONCE, async ([name, version, otherVersion, patch, otherName]) => {
|
|
5175
5220
|
if (stopped || controller.signal.aborted) return
|
|
5176
|
-
const asOne = { name, version, otherVersion, ...patch ? { patchHash: patch.hash } : {} }
|
|
5177
|
-
|
|
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
|
|
5178
5224
|
try {
|
|
5179
|
-
const
|
|
5180
|
-
const
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
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
|
|
5184
5230
|
const patched = patch && await (patches.get(patch.hash) ?? patches.set(patch.hash, npmPatchOf(deps, cookie, patch)).get(patch.hash)!)
|
|
5185
5231
|
const side = deltaSide(doc)
|
|
5186
|
-
|
|
5187
|
-
|
|
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
|
+
}
|
|
5188
5239
|
} catch (err) {
|
|
5189
5240
|
if (controller.signal.aborted) return
|
|
5190
5241
|
if (!(err instanceof NpmPackageError)) console.warn('managed: a package delta failed:', err)
|
|
@@ -5192,9 +5243,9 @@ async function handleNpmDeltas(req: IncomingMessage, res: ServerResponse, deps:
|
|
|
5192
5243
|
}
|
|
5193
5244
|
// A reader who lost their session, or their access to a private one,
|
|
5194
5245
|
// while it was counted, is told nothing of it.
|
|
5195
|
-
const current = await npmReader(deps, cookie, isPrivate ? [name] : [])
|
|
5246
|
+
const current = await npmReader(deps, cookie, [...isPrivate ? [name] : [], ...oldPrivate ? [otherName] : []])
|
|
5196
5247
|
if (current == null) { stopped = true; out.cut(); return }
|
|
5197
|
-
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 }
|
|
5198
5249
|
if (!stopped && !await out.write(line)) stopped = true
|
|
5199
5250
|
})
|
|
5200
5251
|
if (!stopped) await out.end()
|
|
@@ -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
|
|
@@ -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
|
|
@@ -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
|
}
|