From 1b83dcc6578198e6b17c5fe00c13b8620e302e11 Mon Sep 17 00:00:00 2001 From: Brandon Shien <44730413+bshien@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:40:12 -0700 Subject: [PATCH] Added timestamp to raw event json (#29) Signed-off-by: Brandon Shien --- package-lock.json | 4 ++-- package.json | 2 +- src/call/github-events-to-s3.ts | 2 ++ test/call/github-events-to-s3.test.ts | 4 ++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index b7e074d..f9e3d4b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "opensearch-automation-app", - "version": "0.1.12", + "version": "0.1.13", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "opensearch-automation-app", - "version": "0.1.12", + "version": "0.1.13", "dependencies": { "@aws-sdk/client-cloudwatch": "^3.664.0", "@aws-sdk/client-opensearch": "^3.658.1", diff --git a/package.json b/package.json index 2bc1443..5edd1ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "opensearch-automation-app", - "version": "0.1.12", + "version": "0.1.13", "description": "An Automation App that handles all your GitHub Repository Activities", "author": "Peter Zhu", "homepage": "https://github.com/opensearch-project/automation-app", diff --git a/src/call/github-events-to-s3.ts b/src/call/github-events-to-s3.ts index 6749364..454bc98 100644 --- a/src/call/github-events-to-s3.ts +++ b/src/call/github-events-to-s3.ts @@ -21,6 +21,8 @@ export default async function githubEventsToS3(app: Probot, context: any, resour const repoName = context.payload.repository?.name; const eventName = context.payload.action === undefined ? context.name : `${context.name}.${context.payload.action}`; + context.uploaded_at = new Date().toISOString(); + const now = new Date(); const [day, month, year] = [now.getDate(), now.getMonth() + 1, now.getFullYear()].map((num) => String(num).padStart(2, '0')); diff --git a/test/call/github-events-to-s3.test.ts b/test/call/github-events-to-s3.test.ts index 4c5259b..0bd12d1 100644 --- a/test/call/github-events-to-s3.test.ts +++ b/test/call/github-events-to-s3.test.ts @@ -90,11 +90,13 @@ describe('githubEventsToS3', () => { jest.spyOn(Date.prototype, 'getDate').mockReturnValue(4); jest.spyOn(Date.prototype, 'getMonth').mockReturnValue(8); jest.spyOn(Date.prototype, 'getFullYear').mockReturnValue(2024); + jest.spyOn(Date.prototype, 'toISOString').mockReturnValue('2024-10-04T21:00:06.875Z'); await githubEventsToS3(app, context, resource); expect(PutObjectCommand).toHaveBeenCalledWith( expect.objectContaining({ + Body: expect.stringMatching('"uploaded_at":"2024-10-04T21:00:06.875Z"'), Key: expect.stringMatching(`name.action/2024-09-04/repo-id`), }), ); @@ -115,11 +117,13 @@ describe('githubEventsToS3', () => { jest.spyOn(Date.prototype, 'getDate').mockReturnValue(4); jest.spyOn(Date.prototype, 'getMonth').mockReturnValue(8); jest.spyOn(Date.prototype, 'getFullYear').mockReturnValue(2024); + jest.spyOn(Date.prototype, 'toISOString').mockReturnValue('2024-10-04T21:00:06.875Z'); await githubEventsToS3(app, context, resource); expect(PutObjectCommand).toHaveBeenCalledWith( expect.objectContaining({ + Body: expect.stringMatching('"uploaded_at":"2024-10-04T21:00:06.875Z"'), Key: expect.stringMatching(`name/2024-09-04/repo-id`), }), );