@@ -12,22 +12,22 @@ async function run() {
1212 // Get the download URL for the release
1313 const releaseUrl = `https://api.github.com/repos/apppackio/apppack/releases/${ version } ` ;
1414 const data = await downloadJson ( releaseUrl ) ;
15-
15+
1616 // Validate the API response
1717 if ( ! data || ! data . tag_name ) {
1818 throw new Error (
1919 `Failed to fetch release information for version '${ version } '. ` +
20- `Please check if the version exists or try 'latest'.`
20+ `Please check if the version exists or try 'latest'.` ,
2121 ) ;
2222 }
23-
23+
2424 if ( ! data . assets || data . assets . length === 0 ) {
2525 throw new Error (
2626 `No assets found for release ${ data . tag_name } . ` +
27- `This may be a draft release or the release process may have failed.`
27+ `This may be a draft release or the release process may have failed.` ,
2828 ) ;
2929 }
30-
30+
3131 // strip the leading "v" from the tag name
3232 version = data . tag_name . slice ( 1 ) ;
3333 // Determine the platform-specific asset name
@@ -42,7 +42,7 @@ async function run() {
4242
4343 if ( ! asset ) {
4444 throw new Error (
45- `Could not find AppPack CLI asset in release ${ data . tag_name } `
45+ `Could not find AppPack CLI asset in release ${ data . tag_name } ` ,
4646 ) ;
4747 }
4848
@@ -57,7 +57,7 @@ async function run() {
5757 join ( pathToCLI , "apppack" ) ,
5858 "apppack" ,
5959 "apppack" ,
60- data . tag_name
60+ data . tag_name ,
6161 ) ;
6262
6363 // Add the AppPack CLI directory to the PATH
@@ -74,46 +74,52 @@ async function downloadJson(url) {
7474 return new Promise ( ( resolve , reject ) => {
7575 const headers = {
7676 "User-Agent" : "apppackio/setup-apppack" ,
77- " Accept" : "application/vnd.github+json"
77+ Accept : "application/vnd.github+json" ,
7878 } ;
79-
79+
8080 // Use GitHub token if available for higher rate limits
8181 const token = process . env . GITHUB_TOKEN ;
8282 if ( token ) {
8383 headers [ "Authorization" ] = `Bearer ${ token } ` ;
8484 }
85-
86- const req = https . get (
87- url ,
88- { headers } ,
89- ( res ) => {
90- let data = "" ;
91-
92- // Check for non-success status codes
93- if ( res . statusCode !== 200 ) {
94- if ( res . statusCode === 404 ) {
95- reject ( new Error ( `Release not found (404). Please check if the version exists.` ) ) ;
96- } else if ( res . statusCode === 403 ) {
97- const rateLimitMsg = token
98- ? `GitHub API rate limit exceeded (403). Even with authentication, you may have hit the limit.`
99- : `GitHub API rate limit exceeded (403). Consider setting GITHUB_TOKEN to increase rate limits from 60 to 5000 requests/hour.` ;
100- reject ( new Error ( rateLimitMsg ) ) ;
101- } else {
102- reject ( new Error ( `GitHub API request failed with status ${ res . statusCode } ` ) ) ;
103- }
104- return ;
85+
86+ const req = https . get ( url , { headers } , ( res ) => {
87+ let data = "" ;
88+
89+ // Check for non-success status codes
90+ if ( res . statusCode !== 200 ) {
91+ if ( res . statusCode === 404 ) {
92+ reject (
93+ new Error (
94+ `Release not found (404). Please check if the version exists.` ,
95+ ) ,
96+ ) ;
97+ } else if ( res . statusCode === 403 ) {
98+ const rateLimitMsg = token
99+ ? `GitHub API rate limit exceeded (403). Even with authentication, you may have hit the limit.`
100+ : `GitHub API rate limit exceeded (403). Consider setting GITHUB_TOKEN to increase rate limits from 60 to 5000 requests/hour.` ;
101+ reject ( new Error ( rateLimitMsg ) ) ;
102+ } else {
103+ reject (
104+ new Error (
105+ `GitHub API request failed with status ${ res . statusCode } ` ,
106+ ) ,
107+ ) ;
105108 }
106-
107- res . on ( "data" , ( chunk ) => ( data += chunk ) ) ;
108- res . on ( "end" , ( ) => {
109- try {
110- resolve ( JSON . parse ( data ) ) ;
111- } catch ( e ) {
112- reject ( new Error ( `Failed to parse GitHub API response: ${ e . message } ` ) ) ;
113- }
114- } ) ;
109+ return ;
115110 }
116- ) ;
111+
112+ res . on ( "data" , ( chunk ) => ( data += chunk ) ) ;
113+ res . on ( "end" , ( ) => {
114+ try {
115+ resolve ( JSON . parse ( data ) ) ;
116+ } catch ( e ) {
117+ reject (
118+ new Error ( `Failed to parse GitHub API response: ${ e . message } ` ) ,
119+ ) ;
120+ }
121+ } ) ;
122+ } ) ;
117123 req . on ( "error" , ( e ) => {
118124 reject ( new Error ( `Network error accessing GitHub API: ${ e . message } ` ) ) ;
119125 } ) ;
0 commit comments