Skip to content

Commit

Permalink
fix: Invalid name for request
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jul 28, 2024
1 parent 34dde0d commit 2e110b5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
10 changes: 5 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46268,17 +46268,17 @@ _context.next=8;return octokit.rest.repos.getReleaseByTag({owner:owner,repo:repo
function uploadFile(_x2,_x3,_x4,_x5){return _uploadFile.apply(this,arguments);}// Function to upload the file
function _uploadFile(){_uploadFile=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(owner,repo,releaseId,filePath){var myToken,octokit,fileContent,fileStat,fileName,headers,response;return _regeneratorRuntime().wrap(function _callee2$(_context2){while(1)switch(_context2.prev=_context2.next){case 0:myToken=getInput('token');octokit=getOctokit(myToken);fileContent=fs.readFileSync(filePath);// Read file content as Buffer
fileStat=fs.statSync(filePath);fileName=path.basename(filePath);headers={'content-type':'application/octet-stream','content-length':fileStat.size};_context2.next=8;return octokit.rest.repos.uploadReleaseAsset({owner:owner,repo:repo,release_id:releaseId,headers:headers,name:fileName,data:fileContent.toString()// Use file content directly
});case 8:response=_context2.sent;return _context2.abrupt("return",response);case 10:case"end":return _context2.stop();}},_callee2);}));return _uploadFile.apply(this,arguments);}function requestUploadFile(_x6,_x7){return _requestUploadFile.apply(this,arguments);}function _requestUploadFile(){_requestUploadFile=(0,asyncToGenerator/* default */.A)(/*#__PURE__*/(0,regeneratorRuntime/* default */.A)().mark(function _callee3(upload_url,filePath){var myToken,octokit,fileStream,fileName,form,headers,response;return (0,regeneratorRuntime/* default */.A)().wrap(function _callee3$(_context3){while(1)switch(_context3.prev=_context3.next){case 0:myToken=(0,core.getInput)('token');octokit=(0,github.getOctokit)(myToken);fileStream=external_fs_default().createReadStream(filePath);fileName=external_path_default().basename(filePath);form=new (form_data_default())();form.append('file',fileStream,{filename:fileName,contentType:'application/octet-stream'});headers=(0,objectSpread2/* default */.A)((0,objectSpread2/* default */.A)({},form.getHeaders()),{},{'Authorization':"token ".concat(myToken)});_context3.next=9;return octokit.request({method:'POST',url:upload_url,headers:headers,data:form,params:{name:fileName}});case 9:response=_context3.sent;return _context3.abrupt("return",response);case 11:case"end":return _context3.stop();}},_callee3);}));return _requestUploadFile.apply(this,arguments);}
});case 8:response=_context2.sent;return _context2.abrupt("return",response);case 10:case"end":return _context2.stop();}},_callee2);}));return _uploadFile.apply(this,arguments);}function requestUploadFile(_x6,_x7){return _requestUploadFile.apply(this,arguments);}function _requestUploadFile(){_requestUploadFile=(0,asyncToGenerator/* default */.A)(/*#__PURE__*/(0,regeneratorRuntime/* default */.A)().mark(function _callee3(uploadUrl,filePath){var myToken,octokit,fileStream,fileName,form,headers,url,response;return (0,regeneratorRuntime/* default */.A)().wrap(function _callee3$(_context3){while(1)switch(_context3.prev=_context3.next){case 0:myToken=(0,core.getInput)('token');octokit=(0,github.getOctokit)(myToken);fileStream=external_fs_default().createReadStream(filePath);fileName=external_path_default().basename(filePath);form=new (form_data_default())();form.append('file',fileStream,{filename:fileName,contentType:'application/octet-stream'});headers=(0,objectSpread2/* default */.A)((0,objectSpread2/* default */.A)({},form.getHeaders()),{},{'Authorization':"token ".concat(myToken)});url=new URL(uploadUrl);url.searchParams.append('name',fileName);(0,core.info)("URL: ".concat(url.toString()));_context3.next=12;return octokit.request({method:'POST',url:url.toString(),headers:headers,data:form});case 12:response=_context3.sent;return _context3.abrupt("return",response);case 14:case"end":return _context3.stop();}},_callee3);}));return _requestUploadFile.apply(this,arguments);}
;// CONCATENATED MODULE: ./src/index.ts
;(0,asyncToGenerator/* default */.A)(/*#__PURE__*/(0,regeneratorRuntime/* default */.A)().mark(function _callee(){var assetPath,tagName,myToken,files,release,downloadURLs,i,assetFile,requestUploadResponse;return (0,regeneratorRuntime/* default */.A)().wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:/**
;(0,asyncToGenerator/* default */.A)(/*#__PURE__*/(0,regeneratorRuntime/* default */.A)().mark(function _callee(){var assetPath,tagName,files,release,downloadURLs,i,assetFile,requestUploadResponse;return (0,regeneratorRuntime/* default */.A)().wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:/**
* Get the path to the file to upload
*/assetPath=getAssetName((0,core.getInput)('asset-path',{required:true}));tagName=(0,core.getInput)('tag')||undefined;myToken=(0,core.getInput)('token');_context.prev=3;if(!(!assetPath||assetPath.length===0)){_context.next=6;break;}throw new Error('asset-path must contain a JSON array of quoted paths');case 6:_context.next=8;return glob(assetPath,{});case 8:files=_context.sent;if(!(files.length===0)){_context.next=11;break;}throw new Error('No files found');case 11:_context.next=13;return getReleaseURL(tagName);case 13:release=_context.sent;// release.upload_url
downloadURLs=[];i=0;case 16:if(!(i<files.length)){_context.next=26;break;}assetFile=files[i];(0,core.info)("Uploading asset(".concat(github.context.repo.owner,"/").concat(github.context.repo.repo,"): ").concat(assetFile));_context.next=21;return requestUploadFile(release.upload_url,assetFile);case 21:requestUploadResponse=_context.sent;(0,core.info)("requestUploadResponse: ".concat(JSON.stringify(requestUploadResponse)));// const response = await uploadFile(context.repo.owner, context.repo.repo, release.id, assetFile);
*/assetPath=getAssetName((0,core.getInput)('asset-path',{required:true}));tagName=(0,core.getInput)('tag')||undefined;_context.prev=2;if(!(!assetPath||assetPath.length===0)){_context.next=5;break;}throw new Error('asset-path must contain a JSON array of quoted paths');case 5:_context.next=7;return glob(assetPath,{});case 7:files=_context.sent;if(!(files.length===0)){_context.next=10;break;}throw new Error('No files found');case 10:_context.next=12;return getReleaseURL(tagName);case 12:release=_context.sent;// release.upload_url
downloadURLs=[];i=0;case 15:if(!(i<files.length)){_context.next=25;break;}assetFile=files[i];(0,core.info)("Uploading asset(".concat(github.context.repo.owner,"/").concat(github.context.repo.repo,"): ").concat(assetFile));_context.next=20;return requestUploadFile(release.upload_url,assetFile);case 20:requestUploadResponse=_context.sent;(0,core.info)("requestUploadResponse: ".concat(JSON.stringify(requestUploadResponse)));// const response = await uploadFile(context.repo.owner, context.repo.repo, release.id, assetFile);
// downloadURLs.push(response.data.browser_download_url)
// if (response.status < 200 || response.status > 299) {
// new Error(`Asset upload failed "${assetPath}. Response:" ${response}`)
// }
case 23:i++;_context.next=16;break;case 26:_context.next=31;break;case 28:_context.prev=28;_context.t0=_context["catch"](3);(0,core.setFailed)(_context.t0);case 31:case"end":return _context.stop();}},_callee,null,[[3,28]]);}))();
case 22:i++;_context.next=15;break;case 25:_context.next=30;break;case 27:_context.prev=27;_context.t0=_context["catch"](2);(0,core.setFailed)(_context.t0);case 30:case"end":return _context.stop();}},_callee,null,[[2,27]]);}))();
})();

module.exports = __webpack_exports__;
Expand Down
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { context } from '@actions/github';
import { getInput, setOutput, setFailed, info } from '@actions/core';
import { getInput, setFailed, info } from '@actions/core';
import { glob } from 'glob';
import { getAssetName, getReleaseURL, uploadFile, requestUploadFile } from './utils';
import { getAssetName, getReleaseURL, requestUploadFile } from './utils';

;(async () => {
/**
* Get the path to the file to upload
*/
const assetPath = getAssetName(getInput('asset-path', { required: true }));
const tagName: string | undefined = getInput('tag') || undefined;
const myToken = getInput('token')
try {
if (!assetPath || assetPath.length === 0) {
throw new Error('asset-path must contain a JSON array of quoted paths');
Expand Down
12 changes: 6 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function uploadFile(owner: string, repo: string, releaseId: number,
}

// Function to upload the file
export async function requestUploadFile(upload_url: string, filePath: string) {
export async function requestUploadFile(uploadUrl: string, filePath: string) {
const myToken = getInput('token')
const octokit = getOctokit(myToken);
const fileStream = fs.createReadStream(filePath);
Expand All @@ -80,14 +80,14 @@ export async function requestUploadFile(upload_url: string, filePath: string) {
});

const headers = { ...form.getHeaders(), 'Authorization': `token ${myToken}` };
const url = new URL(uploadUrl);
url.searchParams.append('name', fileName);
info(`URL: ${url.toString()}`);
const response = await octokit.request({
method: 'POST',
url: upload_url,
url: url.toString(),
headers: headers,
data: form,
params: {
name: fileName
}
data: form
});

return response;
Expand Down

0 comments on commit 2e110b5

Please sign in to comment.