From cdd448061e9940309d99ca930dcd806c3e71ddb0 Mon Sep 17 00:00:00 2001 From: hyunnaye Date: Mon, 15 Apr 2024 15:03:26 -0400 Subject: [PATCH] pr review --- upsertGitHubTag/deployment/index.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/upsertGitHubTag/deployment/index.js b/upsertGitHubTag/deployment/index.js index fb329a8..d6744d5 100644 --- a/upsertGitHubTag/deployment/index.js +++ b/upsertGitHubTag/deployment/index.js @@ -7,6 +7,7 @@ const http = require("http"); const crypto = require("crypto"); const LAMBDA_USER_AGENT = "DockstoreLambda (NodeJs)"; const DELIVERY_ID_HEADER = "X-GitHub-Delivery"; +const client = new S3Client({}); // Verification function to check if it is actually GitHub who is POSTing here const verifyGitHub = (req, payload) => { @@ -253,22 +254,26 @@ function processEvent(event, callback) { githubEventType + " from GitHub.", }); + return; } // If bucket name is not null (had to put this for the integration test) if (process.env.BUCKET_NAME) { // Send payload to s3 - const client = new S3Client({}); + const uploadDate = new Date(); + const repository = body.repository.full_name; + const bucketPath = `${uploadDate.getDay()}-${uploadDate.getMonth()}-${uploadDate.getFullYear()}/${repository}/${deliveryId}` //formats path to DD-MM-YYYY/repository/deliveryid + const command = new PutObjectCommand({ Bucket: process.env.BUCKET_NAME, - Key: deliveryId, + Key: bucketPath, Body: JSON.stringify(body), ContentType: "application/json", }); try { const response = client.send(command); - console.log(response); + console.log("Successfully uploaded payload to bucket", response); } catch (err) { - console.error(err); + console.error("Error uploading payload to bucket", err); } } }