Skip to content

Commit 082f6a5

Browse files
committed
fix: skip PVR for archived repos; treat PVR 422 as unknown
Signed-off-by: Mouad BANI <mouad-mb@outlook.com>
1 parent 85cb09d commit 082f6a5

4 files changed

Lines changed: 20 additions & 4 deletions

File tree

services/apps/packages_worker/src/security-contacts/extractors/http.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ export function registryHeaders(userAgent: string): Record<string, string> {
77
return { 'User-Agent': userAgent }
88
}
99

10-
// Genuinely-absent → null body; every other non-200 throws so transient failures (429/5xx/...)
11-
// are treated as failures and the pipeline preserves existing data instead of wiping it.
12-
const ABSENT_STATUSES = new Set([404, 410])
10+
// Genuinely-absent / not-determinable → null body; every other non-200 throws so transient
11+
// failures (429/5xx/...) are treated as failures and the pipeline preserves data instead of
12+
// wiping it. 422 is included because GitHub's PVR endpoint returns it (per-repo, non-transient)
13+
// when the flag can't be determined — that must read as "unknown", not block the whole repo.
14+
const ABSENT_STATUSES = new Set([404, 410, 422])
1315

1416
export interface FetchTextResult {
1517
status: number

services/apps/packages_worker/src/security-contacts/extractors/pvr.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export function mapPvr(
3434
}
3535

3636
export const extractPvr: Extractor = async (target, deps) => {
37+
// GitHub's PVR endpoint rejects archived (and private) repos with 422; skip the call for
38+
// known-archived repos. Non-archived-yet-unknown repos still get the 422→unknown safety net.
39+
if (target.archived) return { contacts: [], policies: {} }
40+
3741
let owner: string
3842
let name: string
3943
try {

services/apps/packages_worker/src/security-contacts/processBatch.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ interface SweepRow {
5858
id: string
5959
url: string
6060
homepage: string | null
61+
archived: boolean | null
6162
packages: RepoPackage[] | null
6263
}
6364

@@ -67,6 +68,7 @@ async function fetchBatch(qx: QueryExecutor): Promise<SweepRow[]> {
6768
SELECT r.id::text AS id,
6869
r.url,
6970
r.homepage,
71+
r.archived,
7072
json_agg(json_build_object('purl', p.purl, 'ecosystem', p.ecosystem)) AS packages
7173
FROM repos r
7274
JOIN package_repos pr ON pr.repo_id = r.id
@@ -99,7 +101,13 @@ async function fetchBatch(qx: QueryExecutor): Promise<SweepRow[]> {
99101
}
100102

101103
function toTarget(row: SweepRow): RepoTarget {
102-
return { repoId: row.id, url: row.url, homepage: row.homepage, packages: row.packages ?? [] }
104+
return {
105+
repoId: row.id,
106+
url: row.url,
107+
homepage: row.homepage,
108+
archived: row.archived,
109+
packages: row.packages ?? [],
110+
}
103111
}
104112

105113
async function processRepo(

services/apps/packages_worker/src/security-contacts/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export interface RepoTarget {
5858
repoId: string
5959
url: string
6060
homepage: string | null
61+
/** From the enricher; null = not yet enriched. Archived repos can't be queried for PVR. */
62+
archived: boolean | null
6163
packages: RepoPackage[]
6264
}
6365

0 commit comments

Comments
 (0)