11// @ts -check
22import * as process from 'node:process' ;
3- import { Octokit } from '@octokit/core' ;
43import { output } from './util.mjs' ;
54
65const {
76 GITHUB_TOKEN = '' ,
87 PR_LIST = '' ,
9- owner = 'mongodb-js' ,
10- repo = 'nodejs-mongodb-legacy'
8+ REPOSITORY = ''
119} = process . env ;
1210if ( GITHUB_TOKEN === '' ) throw new Error ( 'GITHUB_TOKEN cannot be empty' ) ;
11+ if ( REPOSITORY === '' ) throw new Error ( 'REPOSITORY cannot be empty' )
1312
14- const octokit = new Octokit ( {
15- auth : GITHUB_TOKEN ,
16- log : {
17- debug : msg => console . error ( 'Octokit.debug' , msg ) ,
18- info : msg => console . error ( 'Octokit.info' , msg ) ,
19- warn : msg => console . error ( 'Octokit.warn' , msg ) ,
20- error : msg => console . error ( 'Octokit.error' , msg )
13+ const API_REQ_INFO = {
14+ headers : {
15+ Accept : 'application/vnd.github.v3+json' ,
16+ 'X-GitHub-Api-Version' : '2022-11-28' ,
17+ Authorization : `Bearer ${ GITHUB_TOKEN } `
2118 }
22- } ) ;
19+ }
2320
2421const prs = PR_LIST . split ( ',' ) . map ( pr => {
2522 const prNum = Number ( pr ) ;
@@ -35,13 +32,10 @@ async function getPullRequestContent(pull_number) {
3532
3633 let body ;
3734 try {
38- const res = await octokit . request ( 'GET /repos/{owner}/{repo}/pulls/{pull_number}' , {
39- owner,
40- repo,
41- pull_number,
42- headers : { 'X-GitHub-Api-Version' : '2022-11-28' }
43- } ) ;
44- body = res . data . body ;
35+ const response = await fetch ( new URL ( `https://api.github.com/repos/${ REPOSITORY } /pulls/${ pull_number } ` ) , API_REQ_INFO ) ;
36+ if ( ! response . ok ) throw new Error ( await response . text ( ) ) ;
37+ const pr = await response . json ( ) ;
38+ body = pr . body ;
4539 } catch ( error ) {
4640 console . log ( `Could not get PR ${ pull_number } , skipping. ${ error . status } ` ) ;
4741 return '' ;
@@ -70,7 +64,10 @@ async function pullRequestHighlights(prs) {
7064 if ( ! highlights . length ) return '' ;
7165
7266 highlights . unshift ( '## Release Notes\n\n' ) ;
73- return highlights . join ( '\n\n' ) ;
67+
68+ const highlight = highlights . join ( '\n\n' ) ;
69+ console . log ( `Total highlight is ${ highlight . length } characters long` ) ;
70+ return highlight ;
7471}
7572
7673console . log ( 'List of PRs to collect highlights from:' , prs ) ;
0 commit comments