Skip to content

Commit

Permalink
Issue one request per uploaded file (#33)
Browse files Browse the repository at this point in the history
While this isn't the most elegant solution, it helps us avoid some HTTP
413 errors when uploading large numbers of Sonar issues/hotspots. Later
we might wish to upload compressed inputs in one form or another.
  • Loading branch information
drdavella authored Sep 25, 2024
1 parent 0bd9aa1 commit 80a884a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
41 changes: 23 additions & 18 deletions src/pixee-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,34 @@ import { TOOL_PATH } from "./inputs";
import { getGitHubContext, getRepositoryInfo } from "./github";

export async function uploadInputFiles(tool: TOOL_PATH, files: Array<string>) {
const form = new FormData();

const path = require("path");

// Append each file to the form data
files.forEach((file) => {
form.append("files", fs.readFileSync(file), path.basename(file));
});

const pixeeUrl = core.getInput("pixee-api-url");
const token = await core.getIDToken(pixeeUrl);
const url = buildUploadApiUrl(tool);

return axios
.put(url, form, {
headers: {
...form.getHeaders(),
Authorization: `Bearer ${token}`,
},
})
.then(() => {
// don't return the axios response
});
// Send each file in a separate request
const uploads = files.map(async (file) => {
const form = new FormData();
form.append("files", fs.readFileSync(file), path.basename(file));

return axios
.put(url, form, {
headers: {
...form.getHeaders(),
Authorization: `Bearer ${token}`,
},
})
.then(() => {
// don't return the axios response
console.log(`Uploaded ${file} to ${url}`);
})
.catch((error) => {
console.error(`Failed to upload ${file} to ${url}`, error);
throw new Error(`Failed to upload ${file} to ${url}`);
});
});

return Promise.all(uploads);
}

export async function triggerPrAnalysis(prNumber: number) {
Expand Down

0 comments on commit 80a884a

Please sign in to comment.