Skip to content

Commit

Permalink
Added timestamp to raw event json (#29)
Browse files Browse the repository at this point in the history
Signed-off-by: Brandon Shien <[email protected]>
  • Loading branch information
bshien authored Oct 11, 2024
1 parent b3ea737 commit 1b83dcc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/call/github-events-to-s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
4 changes: 4 additions & 0 deletions test/call/github-events-to-s3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`),
}),
);
Expand All @@ -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`),
}),
);
Expand Down

0 comments on commit 1b83dcc

Please sign in to comment.