@@ -14,6 +14,7 @@ const OUT_DIR = path.resolve('public/data');
1414const PUBLIC_ASSETS = path . resolve ( 'public/assets' ) ;
1515const REPO_OWNER = 'hiero-ledger' ;
1616const REPO_NAME = 'hiero-improvement-proposals' ;
17+ const REQUIRE_LIVE_DRAFT_HIPS = process . env . REQUIRE_LIVE_DRAFT_HIPS === 'true' ;
1718
1819fs . mkdirSync ( OUT_DIR , { recursive : true } ) ;
1920
@@ -88,26 +89,39 @@ async function getDraftPRs() {
8889 } ,
8990 body : JSON . stringify ( { query } ) ,
9091 } ) ;
92+ if ( ! res . ok ) {
93+ throw new Error ( `GitHub GraphQL request failed with HTTP ${ res . status } ` ) ;
94+ }
9195 const json = await res . json ( ) ;
92- if ( json . errors ) {
93- console . warn ( ` Draft-HIP PR fetch: ${ json . errors [ 0 ] ?. message || 'GraphQL error' } — falling back to committed data` ) ;
94- } else {
95- const nodes = json . data ?. repository ?. pullRequests ?. nodes || [ ] ;
96- // Keep only PRs that ADD a new HIP/hip-*.md file — the same filter the
97- // old update-draft-hips.yml workflow used to produce _data/draft_hips.json.
98- const drafts = nodes . filter ( pr =>
99- ( pr . files ?. edges || [ ] ) . some ( e =>
100- e . node . changeType === 'ADDED' &&
101- / ^ H I P \/ h i p - [ A - Z a - z 0 - 9 - ] + \. m d $ / . test ( e . node . path )
102- )
103- ) ;
104- console . log ( `Fetched ${ drafts . length } open draft-HIP PRs from GitHub` ) ;
105- return drafts ;
96+ if ( json . errors ?. length ) {
97+ throw new Error ( json . errors [ 0 ] ?. message || 'GitHub GraphQL request failed' ) ;
98+ }
99+
100+ const nodes = json . data ?. repository ?. pullRequests ?. nodes ;
101+ if ( ! Array . isArray ( nodes ) ) {
102+ throw new Error ( 'GitHub GraphQL response did not include pull requests' ) ;
106103 }
104+
105+ // Keep only PRs that ADD a new HIP/hip-*.md file — the same filter the
106+ // old update-draft-hips.yml workflow used to produce _data/draft_hips.json.
107+ const drafts = nodes . filter ( pr =>
108+ ( pr . files ?. edges || [ ] ) . some ( e =>
109+ e . node . changeType === 'ADDED' &&
110+ / ^ H I P \/ h i p - [ A - Z a - z 0 - 9 - ] + \. m d $ / . test ( e . node . path )
111+ )
112+ ) ;
113+ console . log ( `Fetched ${ drafts . length } open draft-HIP PRs from GitHub` ) ;
114+ return drafts ;
107115 } catch ( e ) {
116+ if ( REQUIRE_LIVE_DRAFT_HIPS ) {
117+ throw new Error ( `Required live draft-HIP fetch failed: ${ e . message } ` ) ;
118+ }
108119 console . warn ( ` Draft-HIP PR fetch failed (${ e . message } ) — falling back to committed data` ) ;
109120 }
110121 } else {
122+ if ( REQUIRE_LIVE_DRAFT_HIPS ) {
123+ throw new Error ( 'GITHUB_TOKEN is required when REQUIRE_LIVE_DRAFT_HIPS=true' ) ;
124+ }
111125 console . log ( 'No GITHUB_TOKEN set — using committed _data/draft_hips.json if present' ) ;
112126 }
113127
@@ -404,4 +418,7 @@ async function main() {
404418 if ( Object . keys ( prReviews ) . length ) console . log ( ` ${ Object . keys ( prReviews ) . length } PR review threads cached` ) ;
405419}
406420
407- main ( ) ;
421+ main ( ) . catch ( ( error ) => {
422+ console . error ( `Site data build failed: ${ error . message } ` ) ;
423+ process . exitCode = 1 ;
424+ } ) ;
0 commit comments