@@ -5,19 +5,17 @@ import type {Logger} from '@grogarden/util/log.js';
55import { wait } from '@grogarden/util/async.js' ;
66import { parse_package_meta , type PackageMeta } from '@fuz.dev/fuz_library/package_meta.js' ;
77import { request } from '@octokit/request' ;
8- import { GITHUB_TOKEN_SECRET } from '$env/static/private' ;
98
109// TODO rethink with `Package` and `FetchedPackage2`
11- export interface FetchedPackage {
10+ export interface MaybeFetchedPackage {
1211 url : Url ;
1312 package_json : PackageJson | null ; // TODO forward error
14- pulls : GithubIssue [ ] ;
13+ pulls : GithubIssue [ ] | null ;
1514}
1615
1716type GithubIssue = any ; // TODO
1817
19- // TODO obviously bad names
20- export interface FetchedPackage2 extends PackageMeta {
18+ export interface FetchedPackage extends PackageMeta {
2119 pulls : GithubIssue [ ] | null ;
2220}
2321
@@ -28,28 +26,33 @@ export interface UnfetchablePackage {
2826}
2927
3028// TODO rethink these names
31- export type FetchedPackageMeta = FetchedPackage2 | UnfetchablePackage ;
29+ export type FetchedPackageMeta = FetchedPackage | UnfetchablePackage ;
3230
3331/* eslint-disable no-await-in-loop */
3432
3533export const fetch_packages = async (
3634 urls : Url [ ] ,
35+ token ?: string ,
3736 log ?: Logger ,
3837 delay = 50 ,
39- token = GITHUB_TOKEN_SECRET ,
40- ) : Promise < FetchedPackage [ ] > => {
38+ ) : Promise < MaybeFetchedPackage [ ] > => {
4139 console . log ( `urls` , urls ) ;
42- const packages : FetchedPackage [ ] = [ ] ;
40+ const packages : MaybeFetchedPackage [ ] = [ ] ;
4341 for ( const url of urls ) {
44- const package_json = await load_package_json ( url , log ) ;
45- if ( ! package_json ) throw Error ( 'failed to load package_json: ' + url ) ;
46- await wait ( delay ) ;
47- const pkg = parse_package_meta ( url , package_json ) ;
48- if ( ! pkg ) throw Error ( 'failed to parse package_json: ' + url ) ;
49- const pulls = await fetch_github_issues ( url , pkg , log , token ) ;
50- if ( ! pulls ) throw Error ( 'failed to fetch issues: ' + url ) ;
51- await wait ( delay ) ;
52- packages . push ( { url, package_json, pulls} ) ;
42+ try {
43+ const package_json = await load_package_json ( url , log ) ;
44+ if ( ! package_json ) throw Error ( 'failed to load package_json: ' + url ) ;
45+ await wait ( delay ) ;
46+ const pkg = parse_package_meta ( url , package_json ) ;
47+ if ( ! pkg ) throw Error ( 'failed to parse package_json: ' + url ) ;
48+ const pulls = await fetch_github_issues ( url , pkg , log , token ) ;
49+ if ( ! pulls ) throw Error ( 'failed to fetch issues: ' + url ) ;
50+ await wait ( delay ) ;
51+ packages . push ( { url, package_json, pulls} ) ;
52+ } catch ( err ) {
53+ packages . push ( { url, package_json : null , pulls : null } ) ;
54+ log ?. error ( err ) ;
55+ }
5356 }
5457 return packages ;
5558} ;
0 commit comments