@preventive/triage 1.0.0-alpha.60 → 1.0.0-alpha.62
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/default-scan-models.ts +6 -5
- package/common/managed/comments.ts +9 -0
- package/out/activity.js +3 -3
- package/out/brotli-fallback.js +1 -1
- package/out/chunk-4ISO5F7Y.js +1 -1
- package/out/chunk-65PLAG3I.js +12 -0
- package/out/chunk-6CCSTJWB.js +1 -0
- package/out/chunk-7GJNLCXF.js +15 -0
- package/out/chunk-BZP3CT2V.js +244 -0
- package/out/{chunk-TZS7KERJ.js → chunk-DCBXCBLL.js} +2 -2
- package/out/chunk-E3LFSUDJ.js +1 -1
- package/out/chunk-EQ5EQXV5.js +1 -0
- package/out/chunk-F3UI65ZI.js +42 -0
- package/out/chunk-FAG6E5RC.js +3 -0
- package/out/chunk-HAZKDK4M.js +1 -1
- package/out/chunk-IZ6MYRYB.js +1 -1
- package/out/{chunk-VZJIHHTQ.js → chunk-K2QJLP3E.js} +1 -1
- package/out/chunk-NXATZJQ2.js +1 -1
- package/out/chunk-OBNHCORJ.js +2 -0
- package/out/chunk-OGNTXZYM.js +4 -0
- package/out/chunk-QRKFPLA4.js +2 -2
- package/out/chunk-QVKFY4FA.js +1 -0
- package/out/chunk-TOXMUOIW.js +2 -2
- package/out/chunk-WMFDQS2L.js +2 -2
- package/out/chunk-Y5ZHFNBD.js +1 -1
- package/out/client-managed-import.js +1 -1
- package/out/client-managed.js +7 -7
- package/out/client-sync.js +3 -3
- package/out/compare.js +19 -14
- package/out/dialogs.js +38 -38
- package/out/graph.js +12 -12
- package/out/index.html +5 -5
- package/out/prism.js +2 -2
- package/out/scan.js +2 -2
- package/out/terminal.js +150 -148
- package/out/view.css +1 -1
- package/out/view.js +5 -5
- package/package.json +21 -18
- package/risk/files/runs-code.js +2 -2
- package/server-e2e/static.ts +1 -1
- package/server-managed/activity.ts +23 -43
- package/server-managed/agent-merges.ts +2 -2
- package/server-managed/blob-store.ts +10 -1
- package/server-managed/bundle-advisories.ts +3 -2
- package/server-managed/bundle-advisory-inventory.ts +1 -1
- package/server-managed/bundle-build-worker.js +41 -6
- package/server-managed/bundle-build.ts +26 -14
- package/server-managed/bundle-cache.ts +29 -41
- package/server-managed/bundle-catalog.ts +11 -11
- package/server-managed/bundle-commits.ts +9 -16
- package/server-managed/bundle-dependency-reviews.ts +5 -11
- package/server-managed/bundle-summary-cache.ts +23 -14
- package/server-managed/bundle-validation.ts +2 -1
- package/server-managed/combined.ts +1 -5
- package/server-managed/comments.ts +15 -28
- package/server-managed/commit-coauthors.ts +4 -5
- package/server-managed/commit-lockfiles.ts +6 -5
- package/server-managed/comparison.ts +3 -5
- package/server-managed/config.ts +1 -2
- package/server-managed/db-methods.ts +163 -244
- package/server-managed/db-neon.ts +82 -178
- package/server-managed/db-schema.ts +15 -0
- package/server-managed/db.ts +5 -11
- package/server-managed/dependabot-access.ts +2 -1
- package/server-managed/dependabot-alerts.ts +7 -12
- package/server-managed/dependency-review-comments.ts +7 -13
- package/server-managed/dependency-reviews.ts +14 -15
- package/server-managed/github-accounts.ts +4 -5
- package/server-managed/github-actions.ts +6 -6
- package/server-managed/github-app.ts +19 -48
- package/server-managed/github-graphql.ts +5 -2
- package/server-managed/github-issue-links.ts +62 -42
- package/server-managed/github-issue-oauth.ts +7 -24
- package/server-managed/github-issues.ts +9 -7
- package/server-managed/github-link-oauth.ts +7 -20
- package/server-managed/github-oauth.ts +38 -12
- package/server-managed/github-pulls.ts +37 -26
- package/server-managed/github-requests.ts +21 -8
- package/server-managed/github-values.ts +26 -0
- package/server-managed/history-windows.ts +7 -7
- package/server-managed/http.ts +495 -554
- package/server-managed/index.ts +6 -6
- package/server-managed/link-reports.ts +6 -19
- package/server-managed/lockfile-scope.ts +1 -1
- package/server-managed/management.ts +14 -3
- package/server-managed/npm-delta.ts +22 -57
- package/server-managed/npm-insights.ts +31 -26
- package/server-managed/npm-kept.ts +9 -8
- package/server-managed/npm-loads.ts +2 -7
- package/server-managed/npm-manifest.ts +6 -4
- package/server-managed/npm-packages.ts +17 -9
- package/server-managed/npm-patch.ts +8 -16
- package/server-managed/npm-provenance.ts +12 -8
- package/server-managed/npm-risk.ts +9 -7
- package/server-managed/object-storage-disk.ts +2 -3
- package/server-managed/object-storage-vercel.ts +15 -11
- package/server-managed/object-storage.ts +7 -0
- package/server-managed/pretty-print.ts +8 -19
- package/server-managed/public-workspace.ts +50 -46
- package/server-managed/pull-comment-reviews.ts +2 -2
- package/server-managed/pull-dependencies.ts +20 -31
- package/server-managed/pull-dependency-reviews.ts +17 -24
- package/server-managed/pull-reviews.ts +4 -7
- package/server-managed/queue.ts +14 -0
- package/server-managed/release-commits.ts +9 -8
- package/server-managed/rename-diff.ts +17 -60
- package/server-managed/report-migration.ts +5 -8
- package/server-managed/report-sources.ts +6 -10
- package/server-managed/report-store.ts +2 -10
- package/server-managed/repository-actions.ts +7 -8
- package/server-managed/repository-agents.ts +31 -57
- package/server-managed/repository-aliases.ts +3 -9
- package/server-managed/repository-browser.ts +18 -16
- package/server-managed/repository-changes.ts +33 -37
- package/server-managed/repository-code.ts +5 -5
- package/server-managed/repository-dependency-reviews.ts +6 -13
- package/server-managed/repository-discovery.ts +2 -1
- package/server-managed/repository-history.ts +47 -51
- package/server-managed/repository-issues.ts +59 -30
- package/server-managed/repository-pulls.ts +7 -12
- package/server-managed/repository-pulse.ts +51 -45
- package/server-managed/repository-risk-assess.ts +5 -2
- package/server-managed/repository-risk-audit.ts +1 -1
- package/server-managed/repository-risk-read.ts +6 -6
- package/server-managed/repository-risk.ts +32 -40
- package/server-managed/repository-squashes.ts +7 -15
- package/server-managed/request-timing.ts +1 -1
- package/server-managed/sql.ts +18 -0
- package/server-managed/storage-encryption.ts +5 -7
- package/server-managed/team-app.ts +4 -7
- package/server-managed/team-npm-scopes.ts +5 -8
- package/server-managed/team-reports.ts +15 -15
- package/server-managed/type-only-proof.js +108 -0
- package/server-managed/type-only-worker.js +26 -14
- package/server-managed/type-only.ts +90 -60
- package/server-managed/uploads.ts +3 -3
- package/server-managed/upstream-cache.ts +5 -7
- package/server-managed/worker-turns.ts +76 -0
- package/server-managed/workspace-shares.ts +1 -2
- package/strip-types-loader.js +13 -10
- package/out/chunk-2SY4PYUQ.js +0 -4
- package/out/chunk-4HI2MSAV.js +0 -17
- package/out/chunk-4TQKM3JC.js +0 -42
- package/out/chunk-6VDDCFHT.js +0 -3
- package/out/chunk-EEQHVKR3.js +0 -1
- package/out/chunk-HNQNDNIE.js +0 -12
- package/out/chunk-OFPDMZJF.js +0 -244
- package/out/chunk-OQRSIBSC.js +0 -1
- package/out/chunk-YGRRXC2L.js +0 -1
- package/out/chunk-YTO6AQZM.js +0 -2
|
@@ -13,12 +13,12 @@ import { type AgentSignals, agentSignals } from '../common/managed/agent-tasks.t
|
|
|
13
13
|
import { githubAgent } from '../common/managed/github-agents.ts'
|
|
14
14
|
import { AGENT_MARKS_READ, APP_AGENTS } from './app-agents.ts'
|
|
15
15
|
import { type CommitFacts, MAX_COAUTHORS, type Maker, coauthorFacts, coauthorTrailers } from './commit-coauthors.ts'
|
|
16
|
-
import { GithubApiError
|
|
16
|
+
import { GithubApiError } from './github-errors.ts'
|
|
17
17
|
import { type GraphActor, accountOf, commitAccount, linkNoreplyUsers } from './github-accounts.ts'
|
|
18
18
|
import { githubGraphql } from './github-graphql.ts'
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
import { githubJson, repoApi } from './github-requests.ts'
|
|
20
|
+
import { MAX_NAME, SHA, nameOf, timeOf } from './github-values.ts'
|
|
21
|
+
import { inTurns } from './queue.ts'
|
|
22
22
|
|
|
23
23
|
export const HISTORY_PAGE = 100
|
|
24
24
|
// The deepest page read, as far as Older commits goes.
|
|
@@ -33,8 +33,6 @@ const ALL_TAGS = 100
|
|
|
33
33
|
const REF_TIPS = 100
|
|
34
34
|
const MAX_PARENTS = 8
|
|
35
35
|
const MAX_SUBJECT = 1000
|
|
36
|
-
const MAX_NAME = 256
|
|
37
|
-
const SHA = /^[a-f\d]{40}$/u
|
|
38
36
|
|
|
39
37
|
// A commit, its author by name, address (`authorEmail`) and their account's
|
|
40
38
|
// login and numeric id (`authorId`), and who it names beside them
|
|
@@ -48,16 +46,10 @@ const SHA = /^[a-f\d]{40}$/u
|
|
|
48
46
|
// (coauthorsOf, historyMarks), never kept.
|
|
49
47
|
export interface HistoryCommit extends CommitFacts { sha: string; parents: string[]; subject: string; committedAt: number | null; additions?: number | null
|
|
50
48
|
deletions?: number | null; authoredAt?: number | null; authorZone?: number | null; marks?: AgentSignals; marked?: number }
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const textOf = (value: unknown, max: number) => typeof value === 'string' && value.trim() ? value.trim().slice(0, max) : null
|
|
54
|
-
const timeOf = (value: unknown) => {
|
|
55
|
-
const at = typeof value === 'string' ? Date.parse(value) : Number.NaN
|
|
56
|
-
return Number.isSafeInteger(at) ? at : null
|
|
57
|
-
}
|
|
49
|
+
interface HistoryRef { name: string; sha: string }
|
|
58
50
|
|
|
59
51
|
// The address Claude's own commits are authored with.
|
|
60
|
-
|
|
52
|
+
const CLAUDE_EMAIL = 'noreply@anthropic.com'
|
|
61
53
|
|
|
62
54
|
const marking = (marks: AgentSignals) => marks.claude || marks.codex || marks.agents.length > 0 || marks.sessions.length > 0 || marks.tasks.length > 0
|
|
63
55
|
|
|
@@ -86,7 +78,8 @@ const lineCount = (value: unknown) => Number.isSafeInteger(value) && (value as n
|
|
|
86
78
|
// The minutes east of UTC an ISO 8601 time is given in: `Z` none.
|
|
87
79
|
const zoneOf = (value: unknown) => {
|
|
88
80
|
const zone = typeof value === 'string' ? /(?:Z|([+-])(\d{2}):?(\d{2}))$/u.exec(value) : null
|
|
89
|
-
|
|
81
|
+
if (!zone) return null
|
|
82
|
+
return zone[1] ? (zone[1] === '-' ? -1 : 1) * (Number(zone[2]) * 60 + Number(zone[3])) : 0
|
|
90
83
|
}
|
|
91
84
|
|
|
92
85
|
// A commit as the Commits tab reads it, its subject the message's first
|
|
@@ -105,8 +98,8 @@ function historyCommit(sha: unknown, parents: unknown[], message: unknown, autho
|
|
|
105
98
|
sha,
|
|
106
99
|
parents: parents.filter((parent): parent is string => typeof parent === 'string' && SHA.test(parent)).slice(0, MAX_PARENTS),
|
|
107
100
|
subject: typeof message === 'string' ? message.replaceAll('\r\n', '\n').split('\n', 1)[0]!.trim().slice(0, MAX_SUBJECT) : '',
|
|
108
|
-
authorName:
|
|
109
|
-
authorEmail:
|
|
101
|
+
authorName: nameOf(author.name),
|
|
102
|
+
authorEmail: nameOf(author.email),
|
|
110
103
|
authorLogin: author.account.login,
|
|
111
104
|
authorId: author.account.id,
|
|
112
105
|
...coauthorFacts(message, listed),
|
|
@@ -124,8 +117,6 @@ const restCommit = (item: RestCommit, listed: Maker[] | null = null) => historyC
|
|
|
124
117
|
item?.commit?.message, { name: item?.commit?.author?.name, email: item?.commit?.author?.email, account: accountOf(item?.author) }, item?.commit?.committer?.date,
|
|
125
118
|
null, listed)
|
|
126
119
|
|
|
127
|
-
const repoApi = (fullName: string) => `https://api.github.com/repos/${fullName.split('/').map(encodeURIComponent).join('/')}`
|
|
128
|
-
|
|
129
120
|
// A page of the commits `commit` reaches, newest first as GitHub lists them,
|
|
130
121
|
// those touching `path` alone where it names a directory; `more` where a
|
|
131
122
|
// full page leaves some for the next, one that may be read. GitHub links
|
|
@@ -198,13 +189,18 @@ export const COMMIT_FRAGMENT = `fragment historyCommit on Commit { oid message c
|
|
|
198
189
|
authors(first: ${MAX_COAUTHORS + 1}) { nodes { name email user { login databaseId } } } parents(first: ${MAX_PARENTS}) { nodes { oid } } }`
|
|
199
190
|
// A query's variables `$<prefix><n>` of `type`, as many as `count`.
|
|
200
191
|
export const variablesOf = (prefix: string, count: number, type: string) => Array.from({ length: count }, (_, at) => `$${prefix}${at}: ${type}`).join(', ')
|
|
201
|
-
|
|
202
|
-
//
|
|
203
|
-
const
|
|
192
|
+
// A query of commits by their ids, `$o<n>` the `n`th's (commitIds), each read
|
|
193
|
+
// by `fields`, `<alias><n>` the `n`th.
|
|
194
|
+
export const commitsQuery = (count: number, alias: string, fields: string) => `query($owner: String!, $name: String!, ${variablesOf('o', count, 'GitObjectID!')}) {
|
|
204
195
|
repository(owner: $owner, name: $name) {
|
|
205
|
-
${Array.from({ length: count }, (_, at) =>
|
|
196
|
+
${Array.from({ length: count }, (_, at) => `${alias}${at}: object(oid: $o${at}) { ... on Commit { ${fields} } }`).join('\n ')}
|
|
206
197
|
}
|
|
207
|
-
}
|
|
198
|
+
}`
|
|
199
|
+
// Its variables of `shas`: `$o<n>` the `n`th of them.
|
|
200
|
+
export const commitIds = (shas: string[]) => Object.fromEntries(shas.map((sha, at) => [`o${at}`, sha]))
|
|
201
|
+
|
|
202
|
+
// The latest commits of each tip, by its id, `b<n>` the `n`th's.
|
|
203
|
+
const historiesQuery = (count: number) => `${commitsQuery(count, 'b', `history(first: ${ALL_DEPTH}) { pageInfo { hasNextPage } nodes { ...historyCommit } }`)}
|
|
208
204
|
${COMMIT_FRAGMENT}`
|
|
209
205
|
|
|
210
206
|
export type GraphCommit = { oid?: unknown; message?: unknown; committedDate?: unknown; additions?: unknown; deletions?: unknown
|
|
@@ -212,10 +208,17 @@ export type GraphCommit = { oid?: unknown; message?: unknown; committedDate?: un
|
|
|
212
208
|
parents?: { nodes?: { oid?: unknown }[] } }
|
|
213
209
|
type GraphTarget = { __typename?: unknown; oid?: unknown; committedDate?: unknown; target?: GraphTarget | null }
|
|
214
210
|
type GraphRef = { name?: unknown; target?: GraphTarget | null }
|
|
215
|
-
type HeadsPage = { repository?: { defaultBranchRef?: GraphRef | null
|
|
216
|
-
branches?: { pageInfo?: { hasNextPage?: unknown; endCursor?: unknown }; nodes?: GraphRef[] }; tags?: { nodes?: GraphRef[] } } | null }
|
|
211
|
+
type HeadsPage = { repository?: { defaultBranchRef?: GraphRef | null; branches?: Connection<GraphRef>; tags?: { nodes?: GraphRef[] } } | null }
|
|
217
212
|
type Histories = { repository?: Record<string, { history?: { pageInfo?: { hasNextPage?: unknown }; nodes?: GraphCommit[] } } | null> | null }
|
|
218
213
|
|
|
214
|
+
// A page of a connection, as GitHub's GraphQL API answers one: whether
|
|
215
|
+
// another follows and where, and its nodes.
|
|
216
|
+
export type Connection<T> = { pageInfo?: { hasNextPage?: unknown; endCursor?: unknown }; nodes?: (T | null)[] }
|
|
217
|
+
// Where a connection's next page starts, as its page tells it; null where
|
|
218
|
+
// none follows.
|
|
219
|
+
export const nextCursor = (page: { hasNextPage?: unknown; endCursor?: unknown } | null | undefined) =>
|
|
220
|
+
page?.hasNextPage === true && typeof page.endCursor === 'string' ? page.endCursor : null
|
|
221
|
+
|
|
219
222
|
// The repository's branches, as many as MAX_HEAD_PAGES of them list, each
|
|
220
223
|
// with its tip's time, its default branch and latest tags (an annotated tag
|
|
221
224
|
// by the commit it tags), and whether any branch is left out.
|
|
@@ -232,9 +235,8 @@ async function repositoryHeads(owner: string, name: string, token: string, fetch
|
|
|
232
235
|
const sha = ref?.target?.oid
|
|
233
236
|
if (typeof ref?.name === 'string' && ref.name && typeof sha === 'string' && SHA.test(sha)) heads.push({ name: ref.name.slice(0, MAX_NAME), sha, at: timeOf(ref.target?.committedDate) })
|
|
234
237
|
}
|
|
235
|
-
|
|
236
|
-
if (
|
|
237
|
-
after = next.endCursor
|
|
238
|
+
after = nextCursor(repository.branches?.pageInfo)
|
|
239
|
+
if (after === null) return { heads, repository: first, cut: false }
|
|
238
240
|
}
|
|
239
241
|
return { heads, repository: first, cut: true }
|
|
240
242
|
}
|
|
@@ -259,7 +261,7 @@ async function readPages(fullName: string, token: string | null, tops: string[],
|
|
|
259
261
|
}
|
|
260
262
|
const [owner, name] = fullName.split('/') as [string, string]
|
|
261
263
|
await inBatches(tops, PAGES_PER_QUERY, PAGES_PARALLEL, async batch => {
|
|
262
|
-
const data = await githubGraphql(historiesQuery(batch.length), { owner, name, ...
|
|
264
|
+
const data = await githubGraphql(historiesQuery(batch.length), { owner, name, ...commitIds(batch) }, token, fetchImpl) as Histories
|
|
263
265
|
const nodes = batch.map((_, at) => data?.repository?.[`b${at}`]?.history?.nodes ?? [])
|
|
264
266
|
await linkNoreplyUsers(nodes.flat().flatMap(commitActors), token, fetchImpl)
|
|
265
267
|
await Promise.all(batch.map((top, at) => got(top, nodes[at]!.flatMap(node => graphCommit(node) ?? []))))
|
|
@@ -330,7 +332,7 @@ export type AllHeads = { heads: (HistoryRef & { at: number | null })[]; defaultB
|
|
|
330
332
|
export async function repositoryAllHeads(fullName: string, token: string, fetchImpl: typeof fetch = globalThis.fetch): Promise<AllHeads> {
|
|
331
333
|
const [owner, name] = fullName.split('/') as [string, string]
|
|
332
334
|
const { heads, repository, cut } = await repositoryHeads(owner, name, token, fetchImpl)
|
|
333
|
-
const defaultBranch =
|
|
335
|
+
const defaultBranch = nameOf(repository?.defaultBranchRef?.name)
|
|
334
336
|
// The default branch, where its name sorts past the heads read.
|
|
335
337
|
const defaultTip = repository?.defaultBranchRef?.target?.oid
|
|
336
338
|
if (defaultBranch && typeof defaultTip === 'string' && SHA.test(defaultTip) && !heads.some(head => head.name === defaultBranch)) {
|
|
@@ -379,27 +381,21 @@ const SLOW = new Set(['github-timeout', 'github-status-502', 'github-status-504'
|
|
|
379
381
|
// so that what they read is kept.
|
|
380
382
|
export async function inBatches<T>(items: T[], size: number, parallel: number, run: (batch: T[]) => Promise<void>) {
|
|
381
383
|
const failed: unknown[] = []
|
|
382
|
-
const
|
|
383
|
-
let halved = 0
|
|
384
|
-
const turn = () => {
|
|
385
|
-
if (running < parallel) { running++; return Promise.resolve() }
|
|
386
|
-
return new Promise<void>(resolve => { waiting.push(resolve) })
|
|
387
|
-
}
|
|
388
|
-
// A turn done, handed to the batch waiting longest.
|
|
389
|
-
const done = () => {
|
|
390
|
-
const next = waiting.shift()
|
|
391
|
-
if (next) next()
|
|
392
|
-
else running--
|
|
393
|
-
}
|
|
384
|
+
const inTurn = inTurns(parallel)
|
|
385
|
+
let halved = 0
|
|
394
386
|
const attempt = async (batch: T[]): Promise<void> => {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
387
|
+
// Whether it is run again in halves, once its turn is done.
|
|
388
|
+
const halve = await inTurn(async () => {
|
|
389
|
+
try {
|
|
390
|
+
if (failed.length === 0) await run(batch)
|
|
391
|
+
return false
|
|
392
|
+
} catch (err) {
|
|
393
|
+
if (batch.length === 1 || halved >= 2 * parallel || !(err instanceof GithubApiError && SLOW.has(err.message))) { failed.push(err); return false }
|
|
394
|
+
halved++
|
|
395
|
+
return true
|
|
396
|
+
}
|
|
397
|
+
})
|
|
398
|
+
if (!halve) return
|
|
403
399
|
const half = Math.ceil(batch.length / 2)
|
|
404
400
|
await Promise.all([attempt(batch.slice(0, half)), attempt(batch.slice(half))])
|
|
405
401
|
}
|
|
@@ -8,29 +8,32 @@
|
|
|
8
8
|
// packages are told (pull-dependencies.ts touchesLockfile), and its reviews
|
|
9
9
|
// (pull-reviews.ts), each reviewer's; and an open one's base's and head's
|
|
10
10
|
// commits, kept with its page but never told, by which what its lockfiles
|
|
11
|
-
// add is read (http.ts teamRepositoryDependencies)
|
|
11
|
+
// add is read (http.ts teamRepositoryDependencies), of those carrying a
|
|
12
|
+
// label alone where one is named, as a team's Dependencies names the
|
|
13
|
+
// repository's DEPENDENCIES_LABEL where it has one. A nonpublic repository's
|
|
12
14
|
// are read with its GitHub App's installation, which reads pull requests only
|
|
13
15
|
// with their own permission (doc/code-viewer.md).
|
|
14
|
-
import {
|
|
16
|
+
import { ACTOR, type GraphAccount, actorOf } from './github-accounts.ts'
|
|
17
|
+
import { GithubApiError } from './github-errors.ts'
|
|
18
|
+
import { type GraphqlError, githubGraphql } from './github-graphql.ts'
|
|
19
|
+
import { SHA, count, nameOf, timeOf } from './github-values.ts'
|
|
15
20
|
import { touchesLockfile } from './pull-dependencies.ts'
|
|
16
|
-
import { ACTOR, type GraphAccount, type GraphqlError, actorOf, githubGraphql } from './repository-history.ts'
|
|
17
21
|
import { ITEM_THREADS, type ReviewNode, TILE_THREADS, pullReviews, reviewFields, reviewsRefused } from './pull-reviews.ts'
|
|
22
|
+
import type { Connection } from './repository-history.ts'
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
const ISSUES_PAGE = 50
|
|
20
25
|
// What a kept page or item was read as: kept ones read before differ.
|
|
21
26
|
export const ISSUES_READ_VERSION = 4
|
|
22
27
|
const MAX_LABELS = 20
|
|
23
28
|
const MAX_TITLE = 1000
|
|
24
|
-
const MAX_NAME = 256
|
|
25
29
|
const COLOR = /^[a-f\d]{6}$/iu
|
|
26
|
-
const SHA = /^[a-f\d]{40}$/u
|
|
27
30
|
// A page's cursor as GitHub gives it, to read on from: opaque, base64 or
|
|
28
31
|
// base64url as it is now (`…rOrK_u7Q==`), passed back to GitHub alone, so any
|
|
29
32
|
// printable one is, but none with spaces or control characters.
|
|
30
33
|
export const ISSUES_CURSOR = /^[!-~]{1,256}$/u
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
type IssuesKind = 'issues' | 'pulls'
|
|
36
|
+
type IssuesState = 'open' | 'closed'
|
|
34
37
|
|
|
35
38
|
const shared = `number title createdAt updatedAt closedAt author { ${ACTOR} } comments { totalCount } labels(first: ${MAX_LABELS}) { totalCount nodes { name color } }`
|
|
36
39
|
const fields = {
|
|
@@ -47,12 +50,13 @@ const states = { issues: { open: '[OPEN]', closed: '[CLOSED]' }, pulls: { open:
|
|
|
47
50
|
|
|
48
51
|
// A page of `kind`, those in `state`, after the page `after` ends, and how
|
|
49
52
|
// many of each state there are; open pull requests with their commits and
|
|
50
|
-
// their reviews.
|
|
51
|
-
|
|
53
|
+
// their reviews. `labelled`, of those carrying a label of `$labels` alone,
|
|
54
|
+
// the counts still of all.
|
|
55
|
+
const pageQuery = (kind: IssuesKind, state: IssuesState, labelled = false) => `query($owner: String!, $name: String!, $after: String${labelled ? ', $labels: [String!]' : ''}) {
|
|
52
56
|
repository(owner: $owner, name: $name) {
|
|
53
57
|
open: ${connection[kind]}(states: ${states[kind].open}) { totalCount }
|
|
54
58
|
closed: ${connection[kind]}(states: ${states[kind].closed}) { totalCount }
|
|
55
|
-
page: ${connection[kind]}(states: ${states[kind][state]}, first: ${ISSUES_PAGE}, after: $after, orderBy: { field: UPDATED_AT, direction: DESC }) {
|
|
59
|
+
page: ${connection[kind]}(states: ${states[kind][state]}, first: ${ISSUES_PAGE}, after: $after, ${labelled ? 'labels: $labels, ' : ''}orderBy: { field: UPDATED_AT, direction: DESC }) {
|
|
56
60
|
pageInfo { hasNextPage endCursor }
|
|
57
61
|
nodes { ${fields[kind]}${kind === 'pulls' && state === 'open' ? ` baseRefOid headRefOid ${files} ${reviewFields(TILE_THREADS, false)}` : ''} }
|
|
58
62
|
}
|
|
@@ -64,37 +68,43 @@ type Node = ReviewNode & { number?: unknown; title?: unknown; createdAt?: unknow
|
|
|
64
68
|
isDraft?: unknown; reviewDecision?: unknown; additions?: unknown; deletions?: unknown; headRefName?: unknown; baseRefName?: unknown; baseRefOid?: unknown
|
|
65
69
|
commits?: { nodes?: { commit?: { statusCheckRollup?: { state?: unknown } | null } | null }[] }
|
|
66
70
|
files?: { totalCount?: unknown; nodes?: ({ path?: unknown } | null)[] } | null }
|
|
67
|
-
type Page = { repository?: { open?: { totalCount?: unknown }; closed?: { totalCount?: unknown }
|
|
68
|
-
page?: { pageInfo?: { hasNextPage?: unknown; endCursor?: unknown }; nodes?: (Node | null)[] } } | null }
|
|
71
|
+
type Page = { repository?: { open?: { totalCount?: unknown }; closed?: { totalCount?: unknown }; page?: Connection<Node> } | null }
|
|
69
72
|
|
|
70
|
-
const count = (value: unknown) => Number.isSafeInteger(value) && (value as number) >= 0 ? value as number : 0
|
|
71
|
-
const timeOf = (value: unknown) => {
|
|
72
|
-
const at = typeof value === 'string' ? Date.parse(value) : Number.NaN
|
|
73
|
-
return Number.isSafeInteger(at) ? at : null
|
|
74
|
-
}
|
|
75
|
-
const nameOf = (value: unknown, max = MAX_NAME) => typeof value === 'string' && value.trim() ? value.trim().slice(0, max) : null
|
|
76
73
|
const REVIEWS: Record<string, string> = { APPROVED: 'approved', CHANGES_REQUESTED: 'changes', REVIEW_REQUIRED: 'required' }
|
|
77
74
|
const CHECKS: Record<string, string> = { SUCCESS: 'success', FAILURE: 'failure', ERROR: 'failure', PENDING: 'pending', EXPECTED: 'pending' }
|
|
78
|
-
|
|
75
|
+
// Why an issue was closed, as GitHub tells it: completed, not planned or a duplicate.
|
|
76
|
+
export type IssueReason = 'completed' | 'not-planned' | 'duplicate'
|
|
77
|
+
export const ISSUE_REASONS: Record<string, IssueReason> = { COMPLETED: 'completed', NOT_PLANNED: 'not-planned', DUPLICATE: 'duplicate' }
|
|
78
|
+
|
|
79
|
+
// An issue or pull request by its number, title and author, as its tile and
|
|
80
|
+
// the Pulse's lists (repository-pulse.ts) name it; null for one GitHub names
|
|
81
|
+
// no number for.
|
|
82
|
+
export function itemOf(node: { number?: unknown; title?: unknown; author?: GraphAccount } | null) {
|
|
83
|
+
if (!node || !Number.isSafeInteger(node.number) || (node.number as number) <= 0) return null
|
|
84
|
+
const author = actorOf(node.author)
|
|
85
|
+
return { number: node.number as number, title: nameOf(node.title, MAX_TITLE) ?? '', author: author.login, authorId: author.id }
|
|
86
|
+
}
|
|
87
|
+
// An issue's state as a tile tells it, and why it was closed; a pull
|
|
88
|
+
// request's, and whether it is a draft.
|
|
89
|
+
export const issueState = (state: unknown, reason: unknown) => ({ state: state === 'OPEN' ? 'open' : 'closed', reason: ISSUE_REASONS[String(reason)] ?? null })
|
|
90
|
+
export const pullState = (state: unknown, draft: unknown) => ({ state: state === 'MERGED' ? 'merged' : state === 'OPEN' ? 'open' : 'closed', draft: draft === true })
|
|
79
91
|
|
|
80
92
|
// An issue or pull request as a tile shows it; null for one GitHub names no
|
|
81
93
|
// number for.
|
|
82
94
|
function item(kind: IssuesKind, node: Node | null) {
|
|
83
|
-
|
|
84
|
-
|
|
95
|
+
const named = itemOf(node)
|
|
96
|
+
if (!node || !named) return null
|
|
85
97
|
const labels = (node.labels?.nodes ?? []).flatMap(label => {
|
|
86
98
|
const name = nameOf(label?.name)
|
|
87
99
|
return name ? [{ name, color: typeof label?.color === 'string' && COLOR.test(label.color) ? label.color.toLowerCase() : null }] : []
|
|
88
100
|
})
|
|
89
|
-
const common = {
|
|
101
|
+
const common = { ...named, createdAt: timeOf(node.createdAt), updatedAt: timeOf(node.updatedAt),
|
|
90
102
|
closedAt: timeOf(node.closedAt), comments: count(node.comments?.totalCount), labels, moreLabels: Math.max(0, count(node.labels?.totalCount) - labels.length) }
|
|
91
|
-
if (kind === 'issues') {
|
|
92
|
-
return { ...common, state: node.state === 'OPEN' ? 'open' : 'closed', reason: REASONS[String(node.stateReason)] ?? null }
|
|
93
|
-
}
|
|
103
|
+
if (kind === 'issues') return { ...common, ...issueState(node.state, node.stateReason) }
|
|
94
104
|
const checks = node.commits?.nodes?.[0]?.commit?.statusCheckRollup?.state
|
|
95
105
|
const listed = node.files?.nodes
|
|
96
106
|
const paths = Array.isArray(listed) ? listed.flatMap(file => typeof file?.path === 'string' ? [file.path] : []) : null
|
|
97
|
-
return { ...common,
|
|
107
|
+
return { ...common, ...pullState(node.state, node.isDraft), mergedAt: timeOf(node.mergedAt),
|
|
98
108
|
review: REVIEWS[String(node.reviewDecision)] ?? null, checks: CHECKS[String(checks)] ?? null, additions: count(node.additions), deletions: count(node.deletions),
|
|
99
109
|
head: nameOf(node.headRefName), base: nameOf(node.baseRefName),
|
|
100
110
|
...paths ? { touchesLockfile: touchesLockfile(paths, count(node.files?.totalCount)) } : {} }
|
|
@@ -169,14 +179,33 @@ export async function repositoryItem(fullName: string, token: string, number: nu
|
|
|
169
179
|
const commitsOf = (number: number, { baseRefOid: base, headRefOid: head }: Node) =>
|
|
170
180
|
typeof base === 'string' && SHA.test(base) && typeof head === 'string' && SHA.test(head) ? [{ number, base, head }] : []
|
|
171
181
|
|
|
182
|
+
// The label the pull requests changing a repository's dependencies carry,
|
|
183
|
+
// as Dependabot's do: where it has one, a team's Dependencies reads its open
|
|
184
|
+
// pull requests carrying it alone (http.ts teamOpenPulls).
|
|
185
|
+
export const DEPENDENCIES_LABEL = 'dependencies'
|
|
186
|
+
const LABEL_QUERY = `query($owner: String!, $name: String!, $label: String!) { repository(owner: $owner, name: $name) { label(name: $label) { name } } }`
|
|
187
|
+
const labelRefused = (error: GraphqlError) => error?.type === 'FORBIDDEN' && Array.isArray(error.path) && error.path.includes('label')
|
|
188
|
+
|
|
189
|
+
// The repository's label named `label`, by its name as the repository has
|
|
190
|
+
// it, which its pull requests are read by; null where it has none, or GitHub
|
|
191
|
+
// refuses to tell.
|
|
192
|
+
export async function repositoryLabel(fullName: string, token: string, label: string, fetchImpl: typeof fetch = globalThis.fetch) {
|
|
193
|
+
const [owner, name] = fullName.split('/') as [string, string]
|
|
194
|
+
const data = await githubGraphql(LABEL_QUERY, { owner, name, label }, token, fetchImpl, labelRefused) as { repository?: { label?: { name?: unknown } | null } | null }
|
|
195
|
+
const named = data?.repository?.label?.name
|
|
196
|
+
return { label: typeof named === 'string' && named !== '' ? named : null }
|
|
197
|
+
}
|
|
198
|
+
|
|
172
199
|
// A page of the repository's issues or pull requests in `state`, after the
|
|
173
200
|
// page `after` ended (null for the first): its `items`, how many are open and
|
|
174
201
|
// closed (`counts`), and, where more follow, the cursor reading them
|
|
175
202
|
// (`after`); open pull requests' commits (`commits`, commitsOf) too, which
|
|
176
|
-
// the code viewer is never told (http.ts handleRepositoryIssues).
|
|
177
|
-
|
|
203
|
+
// the code viewer is never told (http.ts handleRepositoryIssues). With
|
|
204
|
+
// `label`, those carrying it alone.
|
|
205
|
+
export async function repositoryIssues(fullName: string, token: string, kind: IssuesKind, state: IssuesState, after: string | null, fetchImpl: typeof fetch = globalThis.fetch,
|
|
206
|
+
label: string | null = null) {
|
|
178
207
|
const [owner, name] = fullName.split('/') as [string, string]
|
|
179
|
-
const data = await githubGraphql(pageQuery(kind, state), { owner, name, after }, token, fetchImpl, partRefused) as Page
|
|
208
|
+
const data = await githubGraphql(pageQuery(kind, state, label !== null), { owner, name, after, ...label === null ? {} : { labels: [label] } }, token, fetchImpl, partRefused) as Page
|
|
180
209
|
const repository = data?.repository
|
|
181
210
|
if (!repository) throw new GithubApiError(404, 'github-not-found')
|
|
182
211
|
const info = repository.page?.pageInfo
|
|
@@ -20,7 +20,10 @@ import { type AgentIssue, type AgentPull, labelAgents } from '../common/managed/
|
|
|
20
20
|
import { GITHUB_AGENTS, agentOperated } from '../common/managed/github-agents.ts'
|
|
21
21
|
import { AGENT_BRANCH_PREFIXES } from './app-agents.ts'
|
|
22
22
|
import { AGENT_ISSUE_FIELDS, AGENT_PULL_FIELDS, type IssueNode, type PullNode, issue, pull } from './repository-agents.ts'
|
|
23
|
-
import { githubGraphql } from './
|
|
23
|
+
import { githubGraphql } from './github-graphql.ts'
|
|
24
|
+
import { SHA, count, timeOf } from './github-values.ts'
|
|
25
|
+
import { type Connection, nextCursor } from './repository-history.ts'
|
|
26
|
+
import { ISSUE_REASONS, type IssueReason } from './repository-issues.ts'
|
|
24
27
|
|
|
25
28
|
// What the pull requests kept are read by, its version: bumped as what a
|
|
26
29
|
// page reads, or how one is told, changes, its pull requests read again
|
|
@@ -40,13 +43,7 @@ const TOP_UP_PAGE = 10
|
|
|
40
43
|
const LIST_QUERIES = 5
|
|
41
44
|
const MERGED_COMMITS = 100
|
|
42
45
|
const LABEL_AGENTS = Object.keys(GITHUB_AGENTS)
|
|
43
|
-
const SHA = /^[a-f\d]{40}$/u
|
|
44
46
|
|
|
45
|
-
const count = (value: unknown) => Number.isSafeInteger(value) && (value as number) >= 0 ? value as number : 0
|
|
46
|
-
const timeOf = (value: unknown) => {
|
|
47
|
-
const at = typeof value === 'string' ? Date.parse(value) : Number.NaN
|
|
48
|
-
return Number.isSafeInteger(at) ? at : null
|
|
49
|
-
}
|
|
50
47
|
|
|
51
48
|
// A pull request as read: its row on the Agents tab, whether a GitHub App's
|
|
52
49
|
// bot opened it (`bot`, GitHub's GraphQL API naming one by its app's login
|
|
@@ -65,8 +62,6 @@ export interface Merged { sha: string; at: number; agent: boolean; own?: string[
|
|
|
65
62
|
// (`bot`, as a pull request's), when it was closed, and why (`reason`, as
|
|
66
63
|
// GitHub tells it: completed, not planned or a duplicate).
|
|
67
64
|
export type KeptIssue = AgentIssue & { bot?: true; closedAt: number | null; reason: IssueReason | null }
|
|
68
|
-
export type IssueReason = 'completed' | 'not-planned' | 'duplicate'
|
|
69
|
-
export const ISSUE_REASONS: Record<string, IssueReason> = { COMPLETED: 'completed', NOT_PLANNED: 'not-planned', DUPLICATE: 'duplicate' }
|
|
70
65
|
// The pull requests or issues updated since a year's start (`since`) as
|
|
71
66
|
// read so far (readList), the most recently updated first (`rows`); when the
|
|
72
67
|
// newest read was last updated, those updated since read again (`through`,
|
|
@@ -107,7 +102,7 @@ const ISSUES_QUERY = `query($owner: String!, $name: String!, $after: String, $fi
|
|
|
107
102
|
}`
|
|
108
103
|
type ClosedNode = IssueNode & { stateReason?: unknown; closedAt?: unknown; author?: IssueNode['author'] & { __typename?: unknown } }
|
|
109
104
|
const botOf = (author: { __typename?: unknown } | null | undefined) => author?.__typename === 'Bot' ? { bot: true as const } : {}
|
|
110
|
-
type ListPage<Node> = { repository?: Record<string,
|
|
105
|
+
type ListPage<Node> = { repository?: Record<string, Connection<Node> | null> | null }
|
|
111
106
|
|
|
112
107
|
const agentBranch = (name: unknown) => typeof name === 'string' && AGENT_BRANCH_PREFIXES.some(prefix => name.startsWith(prefix))
|
|
113
108
|
// Whether a pull request is an agent's: by its branch, a label naming one,
|
|
@@ -187,7 +182,7 @@ async function readList<Node extends { updatedAt?: unknown }, Row extends { numb
|
|
|
187
182
|
for (let queries = 0; queries < LIST_QUERIES; queries++) {
|
|
188
183
|
const first = topping && queries === 0 ? TOP_UP_PAGE : LIST_PAGE
|
|
189
184
|
const page = (await githubGraphql(spec.query, { owner, name, after, first }, token, fetchImpl) as ListPage<Node> | null)?.repository?.[spec.connection]
|
|
190
|
-
const
|
|
185
|
+
const cursor = nextCursor(page?.pageInfo), end = cursor === null
|
|
191
186
|
let crossed = false
|
|
192
187
|
for (const node of page?.nodes ?? []) {
|
|
193
188
|
const updated = timeOf(node?.updatedAt)
|
|
@@ -203,7 +198,7 @@ async function readList<Node extends { updatedAt?: unknown }, Row extends { numb
|
|
|
203
198
|
// read; else as far as those read before reached. Read to the last
|
|
204
199
|
// the repository has, every one of them.
|
|
205
200
|
if (crossed || end) return result(from ?? stop, null, stop > since ? kept?.reach : undefined, (end && !crossed) || (whole && stop > since))
|
|
206
|
-
after =
|
|
201
|
+
after = cursor
|
|
207
202
|
// Read as far back as `need`: finished, so far back, those updated
|
|
208
203
|
// since read by the next as ever.
|
|
209
204
|
if (need > since && to !== null && to < need) return result(Math.max(from ?? stop, kept?.through ?? Number.NEGATIVE_INFINITY), null, to)
|
|
@@ -13,11 +13,15 @@
|
|
|
13
13
|
// week `weeks` weeks earlier, the pull requests merged and opened and the
|
|
14
14
|
// issues closed and opened, how many and the latest of each.
|
|
15
15
|
import { agentOperated, githubAgent } from '../common/managed/github-agents.ts'
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
16
|
+
import { ACTOR, type GraphAccount, accountOf } from './github-accounts.ts'
|
|
17
|
+
import { GithubApiError } from './github-errors.ts'
|
|
18
|
+
import { githubGraphql } from './github-graphql.ts'
|
|
19
|
+
import { githubJson, repoApi, shareGithubRead } from './github-requests.ts'
|
|
20
|
+
import { SHA, count, timeOf } from './github-values.ts'
|
|
18
21
|
import { coauthorsOf } from './commit-coauthors.ts'
|
|
19
22
|
import { windowsOn } from './history-windows.ts'
|
|
20
|
-
import {
|
|
23
|
+
import { type HistoryCommit, type HistoryPages, historyFrom } from './repository-history.ts'
|
|
24
|
+
import { issueState, itemOf, pullState } from './repository-issues.ts'
|
|
21
25
|
|
|
22
26
|
export const PULSE_WEEKS = [1, 4, 13, 52]
|
|
23
27
|
// What a year counted from its commits holds, its version: kept years of
|
|
@@ -43,8 +47,6 @@ const YEAR_STARTS = 10
|
|
|
43
47
|
// not always later than its parents': one dated before the year may have a
|
|
44
48
|
// parent dated in it.
|
|
45
49
|
const YEAR_SKEW_MS = 30 * DAY_MS
|
|
46
|
-
const MAX_TITLE = 1000
|
|
47
|
-
const SHA = /^[a-f\d]{40}$/u
|
|
48
50
|
|
|
49
51
|
// GitHub still computing a statistic.
|
|
50
52
|
export class StatsPending extends Error {
|
|
@@ -58,7 +60,7 @@ export class StatsPending extends Error {
|
|
|
58
60
|
// agent made or co-authored (`agentDays`), and those pushed to the branch
|
|
59
61
|
// directly (`directDays`, agent-merges.ts directCommits), which GitHub's
|
|
60
62
|
// statistics don't count.
|
|
61
|
-
|
|
63
|
+
interface PulseWeek { week: number; days: number[]; commits: number; additions: number | null; deletions: number | null; dayLines?: [number, number][]
|
|
62
64
|
agentDays?: number[]; releaseDays?: number[]; directDays?: number[] }
|
|
63
65
|
// A contributor, by their login and their account's numeric id (`id`, where
|
|
64
66
|
// GitHub named it), else by the name their commits carry, and their weeks,
|
|
@@ -67,12 +69,12 @@ export interface PulseWeek { week: number; days: number[]; commits: number; addi
|
|
|
67
69
|
// agents, releases, direct]`, `releases` those that release the repository,
|
|
68
70
|
// `agents`, of the rest, those an agent took part in (withAgent), and
|
|
69
71
|
// `direct` those pushed to the branch directly.
|
|
70
|
-
|
|
72
|
+
interface PulseContributor { login: string | null; id?: number | null; name: string | null; weeks: [number, number, number, number][]
|
|
71
73
|
days?: [number, number, number, number, number, number, number][] }
|
|
72
74
|
// A commit pushed to the branch directly, as Pulse lists it: its id, when it
|
|
73
75
|
// was committed, its subject, its author, by account, else name, and what it
|
|
74
76
|
// is: a release, else one an agent took part in, else one without.
|
|
75
|
-
|
|
77
|
+
interface PulseCommit { sha: string; at: number; subject: string; login: string | null; id: number | null; name: string | null
|
|
76
78
|
kind: 'agent' | 'without' | 'release' }
|
|
77
79
|
// Commits by day of the week and hour (`punch[day][hour]`, Sunday first), in
|
|
78
80
|
// each commit's own time zone, and, counted from its commits, each period's
|
|
@@ -85,21 +87,15 @@ export interface PulseStats { weeks: PulseWeek[]; contributors: PulseContributor
|
|
|
85
87
|
directCommits?: PulseCommit[]; from?: number }
|
|
86
88
|
// The lines added and removed a week, and each contributor's, as GitHub's
|
|
87
89
|
// statistics count them, `lines` false where it counts none.
|
|
88
|
-
|
|
90
|
+
interface PulseLines { weeks: [number, number, number][]; contributors: { login: string; weeks: [number, number, number][] }[]; lines: boolean }
|
|
89
91
|
// The days (`from`, `to`, both days, UTC; `to` none, on) and the authors (GitHub
|
|
90
92
|
// logins, any of them) a period's pull requests and issues are narrowed to.
|
|
91
93
|
export interface PulseNarrowing { from: number; to: number | null; authors: string[] }
|
|
92
94
|
// The year's commits read so far: all of them, or as far back as asked
|
|
93
95
|
// (`commits`, `from`), else how many (`read`), and whether past
|
|
94
96
|
// YEAR_COMMITS (`tooMany`).
|
|
95
|
-
|
|
97
|
+
type YearCommits = { complete: true; commits: HistoryCommit[]; passed: HistoryCommit[]; from: number | null } | { complete: false; read: number; tooMany: boolean }
|
|
96
98
|
|
|
97
|
-
const count = (value: unknown) => Number.isSafeInteger(value) && (value as number) >= 0 ? value as number : 0
|
|
98
|
-
const timeOf = (value: unknown) => {
|
|
99
|
-
const at = typeof value === 'string' ? Date.parse(value) : Number.NaN
|
|
100
|
-
return Number.isSafeInteger(at) ? at : null
|
|
101
|
-
}
|
|
102
|
-
const repoApi = (fullName: string) => `https://api.github.com/repos/${fullName.split('/').map(encodeURIComponent).join('/')}`
|
|
103
99
|
const emptyPunch = () => Array.from({ length: 7 }, () => Array.from({ length: 24 }, () => 0))
|
|
104
100
|
|
|
105
101
|
// One statistic: its rows once GitHub has computed it, 'pending' while it
|
|
@@ -269,6 +265,34 @@ const withAgent = (commit: HistoryCommit, merges: ReadonlySet<string>, direct: R
|
|
|
269
265
|
|| githubAgent(commit.authorLogin, commit.authorId ?? null, commit.authorName) !== null || bot(commit.authorLogin, commit.authorName)
|
|
270
266
|
|| coauthorsOf(commit).some(coauthor => Boolean(coauthor.agent) || bot(coauthor.login, coauthor.name))
|
|
271
267
|
|
|
268
|
+
// A contributor as commitStats counts them: by the login, id and name the
|
|
269
|
+
// first of their commits listed names, every login they committed as
|
|
270
|
+
// (`logins`), and their commits' counts, by week and by day, to which
|
|
271
|
+
// addCounts adds those `made` at `at`.
|
|
272
|
+
type Counts = Map<number, number[]>
|
|
273
|
+
type Person = { login: string | null; logins: Set<string>; id: number | null; name: string | null; weeks: Counts; days: Counts; commits: number }
|
|
274
|
+
const addCounts = (counts: Counts, at: number, made: number[]) => counts.set(at, made.map((value, index) => (counts.get(at)?.[index] ?? 0) + value))
|
|
275
|
+
|
|
276
|
+
// A login one account committed as, those of its commits read before ids
|
|
277
|
+
// were that account's; one more did, theirs apart, no one's. Those of
|
|
278
|
+
// `people` counted so, out of it, each by its key the account it is.
|
|
279
|
+
function mergedLogins(people: Map<string, Person>) {
|
|
280
|
+
const merged = new Map<string, Person>()
|
|
281
|
+
const accounts = Map.groupBy([...people.values()].filter(person => person.id !== null).flatMap(person => [...person.logins].map(login => ({ login, person }))),
|
|
282
|
+
({ login }) => login)
|
|
283
|
+
for (const [key, person] of people) {
|
|
284
|
+
const [owner, ...others] = person.login !== null && person.id === null ? accounts.get(person.login.toLowerCase()) ?? [] : []
|
|
285
|
+
if (!owner || others.length > 0) continue
|
|
286
|
+
const account = owner.person
|
|
287
|
+
for (const [week, counts] of person.weeks) addCounts(account.weeks, week, counts)
|
|
288
|
+
for (const [day, counts] of person.days) addCounts(account.days, day, counts)
|
|
289
|
+
account.commits += person.commits
|
|
290
|
+
people.delete(key)
|
|
291
|
+
merged.set(key, account)
|
|
292
|
+
}
|
|
293
|
+
return merged
|
|
294
|
+
}
|
|
295
|
+
|
|
272
296
|
// The year from `first` (pulseSince(52, …)) of `commits`, as GitHub's
|
|
273
297
|
// statistics count them, merges left out: a week a row, its commits each day
|
|
274
298
|
// (UTC) and in all and the lines they added and removed, in all and each day,
|
|
@@ -291,14 +315,10 @@ export function commitStats(commits: HistoryCommit[], first: number, merges: Rea
|
|
|
291
315
|
const weeks = Array.from({ length: 52 }, (_, at) => ({ week: first + at * WEEK_MS, days: Array.from({ length: 7 }, () => 0), commits: 0, additions: 0, deletions: 0,
|
|
292
316
|
dayLines: Array.from({ length: 7 }, () => [0, 0] as [number, number]), agentDays: Array.from({ length: 7 }, () => 0), releaseDays: Array.from({ length: 7 }, () => 0),
|
|
293
317
|
directDays: Array.from({ length: 7 }, () => 0) }))
|
|
294
|
-
|
|
295
|
-
const people = new Map<string, { login: string | null; logins: Set<string>; id: number | null; name: string | null; weeks: Counts; days: Counts; commits: number }>()
|
|
318
|
+
const people = new Map<string, Person>()
|
|
296
319
|
const punches = Object.fromEntries(PULSE_WEEKS.map(span => [span, emptyPunch()]))
|
|
297
|
-
// Each commit's author, by the key their commits are counted by
|
|
298
|
-
// login an account took on, that account (`merged`).
|
|
320
|
+
// Each commit's author, by the key their commits are counted by.
|
|
299
321
|
const keys = new Map<string, string>()
|
|
300
|
-
const merged = new Map<string, { login: string | null; id: number | null; name: string | null }>()
|
|
301
|
-
const add = (counts: Counts, at: number, made: number[]) => counts.set(at, made.map((value, index) => (counts.get(at)?.[index] ?? 0) + value))
|
|
302
322
|
for (const commit of commits) {
|
|
303
323
|
if (commit.parents.length > 1 || commit.committedAt === null || commit.committedAt < first) continue
|
|
304
324
|
const at = Math.floor((commit.committedAt - first) / WEEK_MS)
|
|
@@ -326,25 +346,13 @@ export function commitStats(commits: HistoryCommit[], first: number, merges: Rea
|
|
|
326
346
|
const person = people.get(key) ?? { login: commit.authorLogin, logins: new Set<string>(), id: commit.authorId ?? null, name: commit.authorName,
|
|
327
347
|
weeks: new Map(), days: new Map(), commits: 0 }
|
|
328
348
|
if (commit.authorLogin) person.logins.add(commit.authorLogin.toLowerCase())
|
|
329
|
-
|
|
330
|
-
|
|
349
|
+
addCounts(person.weeks, week.week, [1, additions, deletions])
|
|
350
|
+
addCounts(person.days, Math.floor(commit.committedAt / DAY_MS) * DAY_MS, [1, additions, deletions, agent ? 1 : 0, release ? 1 : 0, direct.has(commit.sha) ? 1 : 0])
|
|
331
351
|
person.commits++
|
|
332
352
|
people.set(key, person)
|
|
333
353
|
}
|
|
334
|
-
//
|
|
335
|
-
|
|
336
|
-
const accounts = Map.groupBy([...people.values()].filter(person => person.id !== null).flatMap(person => [...person.logins].map(login => ({ login, person }))),
|
|
337
|
-
({ login }) => login)
|
|
338
|
-
for (const [key, person] of people) {
|
|
339
|
-
const [owner, ...others] = person.login !== null && person.id === null ? accounts.get(person.login.toLowerCase()) ?? [] : []
|
|
340
|
-
if (!owner || others.length > 0) continue
|
|
341
|
-
const account = owner.person
|
|
342
|
-
for (const [week, counts] of person.weeks) add(account.weeks, week, counts)
|
|
343
|
-
for (const [day, counts] of person.days) add(account.days, day, counts)
|
|
344
|
-
account.commits += person.commits
|
|
345
|
-
people.delete(key)
|
|
346
|
-
merged.set(key, account)
|
|
347
|
-
}
|
|
354
|
+
// Of a login an account took on, that account.
|
|
355
|
+
const merged = mergedLogins(people)
|
|
348
356
|
const rows = (counts: Counts) => [...counts].toSorted(([a], [b]) => a - b).map(([at, made]) => [at, ...made])
|
|
349
357
|
const contributors = [...people.values()].toSorted((a, b) => b.commits - a.commits).slice(0, MAX_CONTRIBUTORS).map(({ login, id, name, weeks: theirs, days }) => ({
|
|
350
358
|
login, id, name, weeks: rows(theirs) as [number, number, number, number][], days: rows(days) as [number, number, number, number, number, number, number][] }))
|
|
@@ -418,18 +426,16 @@ fragment issue on Issue { number title issueState: state stateReason createdAt c
|
|
|
418
426
|
type SearchNode = { number?: unknown; title?: unknown; pullState?: unknown; issueState?: unknown; isDraft?: unknown; stateReason?: unknown
|
|
419
427
|
createdAt?: unknown; mergedAt?: unknown; closedAt?: unknown; author?: GraphAccount } | null
|
|
420
428
|
type Search = { issueCount?: unknown; nodes?: SearchNode[] } | null | undefined
|
|
421
|
-
const REASONS: Record<string, string> = { COMPLETED: 'completed', NOT_PLANNED: 'not-planned', DUPLICATE: 'duplicate' }
|
|
422
429
|
|
|
423
430
|
// An issue or pull request a search lists, as the popup's preview of it
|
|
424
431
|
// takes one, `at` when it was merged, opened or closed.
|
|
425
432
|
function listed(node: SearchNode, at: unknown) {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
const
|
|
429
|
-
const common = { number: node.number as number, title, author: author.login, authorId: author.id, at: timeOf(at), createdAt: timeOf(node.createdAt) }
|
|
433
|
+
const named = itemOf(node)
|
|
434
|
+
if (!node || !named) return null
|
|
435
|
+
const common = { ...named, at: timeOf(at), createdAt: timeOf(node.createdAt) }
|
|
430
436
|
return node.pullState === undefined
|
|
431
|
-
? { ...common, kind: 'issues',
|
|
432
|
-
: { ...common, kind: 'pulls',
|
|
437
|
+
? { ...common, kind: 'issues', ...issueState(node.issueState, node.stateReason) }
|
|
438
|
+
: { ...common, kind: 'pulls', ...pullState(node.pullState, node.isDraft) }
|
|
433
439
|
}
|
|
434
440
|
|
|
435
441
|
// The pull requests merged and opened and the issues closed and opened since
|
|
@@ -5,7 +5,7 @@ import { setTimeout as delay } from 'node:timers/promises'
|
|
|
5
5
|
import { NpmRiskError, SEVERITIES, type Severity } from '../risk/index.js'
|
|
6
6
|
import { GithubApiError } from './github-errors.ts'
|
|
7
7
|
import { NpmPackageError, type NpmVersionDocument } from './npm-packages.ts'
|
|
8
|
-
import type {
|
|
8
|
+
import type { RiskLine } from './repository-risk.ts'
|
|
9
9
|
|
|
10
10
|
// An assessment refused as busy (`npm-busy`, by npm-risk.ts or the npm reads
|
|
11
11
|
// beneath it), or that npm asked to ask later (risk's `upstream-busy`, as its
|
|
@@ -28,7 +28,6 @@ export function highestSeverity(findings: readonly { severity: Severity }[]): Se
|
|
|
28
28
|
// Why a step failed, as a line says it: an error's code, and for a lockfile
|
|
29
29
|
// refused, what of it its reader refused.
|
|
30
30
|
export type RiskFailure = { error: string; detail?: string }
|
|
31
|
-
type RiskLine = Extract<RepositoryRiskLine, { type: 'risk' }>
|
|
32
31
|
|
|
33
32
|
// What an error is known by: a GitHub or npm failure's code, or `failed`;
|
|
34
33
|
// GitHub not reached with what failed (githubUnreachable), while `doing` what
|
|
@@ -51,8 +50,12 @@ export type Assessment = { published: string | null; findings: { id: string; sev
|
|
|
51
50
|
|
|
52
51
|
// What of a scan's source assessing a package asks (RepositoryRiskSource).
|
|
53
52
|
export interface AssessingSource {
|
|
53
|
+
// npm's document of a version; an NpmPackageError where npm has none.
|
|
54
54
|
version(name: string, version: string, signal: AbortSignal): Promise<NpmVersionDocument>
|
|
55
55
|
assess(doc: NpmVersionDocument, teamScoped: boolean, signal: AbortSignal): Promise<Assessment>
|
|
56
|
+
// A version npm has no document of, as risk tells one npm removed: its
|
|
57
|
+
// malware alone, its package taken down by npm; an NpmRiskError where
|
|
58
|
+
// nothing tells of it (npm-risk.ts npmRiskRemoved).
|
|
56
59
|
removed(name: string, version: string, teamScoped: boolean, signal: AbortSignal): Promise<Assessment>
|
|
57
60
|
}
|
|
58
61
|
|