@@ -17,6 +17,25 @@ const uploadAsset = async (client: GitHub, params: ReposUploadReleaseAssetParams
1717 return response . data . value ;
1818} ;
1919
20+
21+ const prepareHeaders = ( fullPathChecked : string , mime : string ) => {
22+ return {
23+ "content-length" : fs . statSync ( fullPathChecked ) . size ,
24+ "content-type" : mime || getType ( fullPathChecked . toString ( ) ) || "application/zip" ,
25+ } ;
26+ } ;
27+
28+ const prepareParams = ( data : Buffer , headers : { "content-length" : number ; "content-type" : string ; } ,
29+ label : string , name : string , url : string ) : Octokit . Octokit . ReposUploadReleaseAssetParams => {
30+ return {
31+ data,
32+ headers,
33+ label,
34+ name,
35+ url,
36+ } ;
37+ } ;
38+
2039export const run = async ( ) => {
2140 const path = core . getInput ( "path" , { required : true } ) ;
2241
@@ -32,25 +51,15 @@ export const run = async () => {
3251
3352 const github = new GitHub ( process . env . GITHUB_TOKEN ) ;
3453 const fullPathChecked : fs . PathLike = resolve ( fs . realpathSync ( path ) ) ;
35-
36- const headers = {
37- "content-length" : fs . statSync ( fullPathChecked ) . size ,
38- "content-type" : mime || getType ( fullPathChecked . toString ( ) ) || "application/zip" ,
39- } ;
40-
54+ const headers = prepareHeaders ( fullPathChecked , mime ) ;
4155 const data = fs . readFileSync ( fullPathChecked ) ;
4256
43- const asset = await uploadAsset ( github , {
44- data,
45- headers,
46- label,
47- name,
48- url,
49- } ) ;
57+ const asset = await uploadAsset ( github , prepareParams ( data , headers , label , name , url ) ) ;
5058
5159 core . setOutput ( "id" , asset . id . toString ( ) ) ;
5260 core . setOutput ( "url" , asset . browser_download_url ) ;
5361 } catch ( error ) {
5462 core . setFailed ( error ) ;
5563 }
5664} ;
65+
0 commit comments