diff --git a/.github/workflows/check-version-bump.yml b/.github/workflows/check-version-bump.yml index 6180f58..ff84f11 100644 --- a/.github/workflows/check-version-bump.yml +++ b/.github/workflows/check-version-bump.yml @@ -13,7 +13,8 @@ jobs: id: check uses: EndBug/version-check@v2 with: - diff-search: true + file-url: "https://raw.githubusercontent.com/opensearch-project/automation-app/refs/heads/${{ github.event.pull_request.base.ref }}/package.json" + static-checking: localIsNew - name: Log when changed if: steps.check.outputs.changed == 'true' diff --git a/package-lock.json b/package-lock.json index 45415e0..b7e074d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "opensearch-automation-app", - "version": "0.1.11", + "version": "0.1.12", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "opensearch-automation-app", - "version": "0.1.11", + "version": "0.1.12", "dependencies": { "@aws-sdk/client-cloudwatch": "^3.664.0", "@aws-sdk/client-opensearch": "^3.658.1", diff --git a/package.json b/package.json index 4b1341d..2bc1443 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "opensearch-automation-app", - "version": "0.1.11", + "version": "0.1.12", "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 487ebcd..6749364 100644 --- a/src/call/github-events-to-s3.ts +++ b/src/call/github-events-to-s3.ts @@ -19,6 +19,7 @@ export default async function githubEventsToS3(app: Probot, context: any, resour if (!(await validateResourceConfig(app, context, resource))) return; const repoName = context.payload.repository?.name; + const eventName = context.payload.action === undefined ? context.name : `${context.name}.${context.payload.action}`; const now = new Date(); const [day, month, year] = [now.getDate(), now.getMonth() + 1, now.getFullYear()].map((num) => String(num).padStart(2, '0')); @@ -28,7 +29,7 @@ export default async function githubEventsToS3(app: Probot, context: any, resour const putObjectCommand = new PutObjectCommand({ Bucket: String(process.env.OPENSEARCH_EVENTS_BUCKET), Body: JSON.stringify(context), - Key: `${context.name}.${context.payload.action}/${year}-${month}-${day}/${repoName}-${context.id}`, + Key: `${eventName}/${year}-${month}-${day}/${repoName}-${context.id}`, }); await s3Client.send(putObjectCommand); app.log.info('GitHub Event uploaded to S3 successfully.'); diff --git a/test/call/create-issue-comment.test.ts b/test/call/create-issue-comment.test.ts index 13fbcac..ca08d25 100644 --- a/test/call/create-issue-comment.test.ts +++ b/test/call/create-issue-comment.test.ts @@ -70,6 +70,10 @@ describe('createIssueCommentFunctions', () => { }; }); + afterEach(() => { + jest.clearAllMocks(); + }); + describe('createIssueComment', () => { it('should write comments based on user defined text', async () => { await createIssueComment(app, context, resource, args); diff --git a/test/call/github-activity-events-monitor.test.ts b/test/call/github-activity-events-monitor.test.ts index 863e518..2b544d1 100644 --- a/test/call/github-activity-events-monitor.test.ts +++ b/test/call/github-activity-events-monitor.test.ts @@ -50,6 +50,10 @@ describe('githubActivityEventsMonitor', () => { }; }); + afterEach(() => { + jest.clearAllMocks(); + }); + it('should index events', async () => { const mockClient = { index: jest.fn().mockResolvedValue({}), diff --git a/test/call/github-events-to-s3.test.ts b/test/call/github-events-to-s3.test.ts index 43f3557..4c5259b 100644 --- a/test/call/github-events-to-s3.test.ts +++ b/test/call/github-events-to-s3.test.ts @@ -13,7 +13,7 @@ import githubEventsToS3 from '../../src/call/github-events-to-s3'; jest.mock('@aws-sdk/client-s3'); -describe('githubWorkflowRunsMonitor', () => { +describe('githubEventsToS3', () => { let app: Probot; let context: any; let resource: any; @@ -53,6 +53,10 @@ describe('githubWorkflowRunsMonitor', () => { (S3Client as jest.Mock).mockImplementation(() => mockS3Client); }); + afterEach(() => { + jest.clearAllMocks(); + }); + it('should upload to S3 on event listened', async () => { mockS3Client.send.mockResolvedValue({}); @@ -69,4 +73,55 @@ describe('githubWorkflowRunsMonitor', () => { expect(app.log.error).toHaveBeenCalledWith('Error uploading GitHub Event to S3 : Error: S3 error'); }); + + it('S3 key name set with action', async () => { + context = { + name: 'name', + id: 'id', + payload: { + repository: { + name: 'repo', + owner: { login: 'org' }, + }, + action: 'action', + }, + }; + + jest.spyOn(Date.prototype, 'getDate').mockReturnValue(4); + jest.spyOn(Date.prototype, 'getMonth').mockReturnValue(8); + jest.spyOn(Date.prototype, 'getFullYear').mockReturnValue(2024); + + await githubEventsToS3(app, context, resource); + + expect(PutObjectCommand).toHaveBeenCalledWith( + expect.objectContaining({ + Key: expect.stringMatching(`name.action/2024-09-04/repo-id`), + }), + ); + }); + + it('S3 key name set without action', async () => { + context = { + name: 'name', + id: 'id', + payload: { + repository: { + name: 'repo', + owner: { login: 'org' }, + }, + }, + }; + + jest.spyOn(Date.prototype, 'getDate').mockReturnValue(4); + jest.spyOn(Date.prototype, 'getMonth').mockReturnValue(8); + jest.spyOn(Date.prototype, 'getFullYear').mockReturnValue(2024); + + await githubEventsToS3(app, context, resource); + + expect(PutObjectCommand).toHaveBeenCalledWith( + expect.objectContaining({ + Key: expect.stringMatching(`name/2024-09-04/repo-id`), + }), + ); + }); }); diff --git a/test/call/github-merged-pulls-monitor.test.ts b/test/call/github-merged-pulls-monitor.test.ts index 6260c0e..f40e5b9 100644 --- a/test/call/github-merged-pulls-monitor.test.ts +++ b/test/call/github-merged-pulls-monitor.test.ts @@ -82,6 +82,10 @@ describe('githubMergedPullsMonitor', () => { }; }); + afterEach(() => { + jest.clearAllMocks(); + }); + it('should skip processing if the pull request is not merged', async () => { context.payload.pull_request.merged = false; await githubMergedPullsMonitor(app, context, resource); diff --git a/test/call/github-workflow-runs-monitor.test.ts b/test/call/github-workflow-runs-monitor.test.ts index d0494cf..24c3c5a 100644 --- a/test/call/github-workflow-runs-monitor.test.ts +++ b/test/call/github-workflow-runs-monitor.test.ts @@ -78,6 +78,10 @@ describe('githubWorkflowRunsMonitor', () => { (CloudWatchClient as jest.Mock).mockImplementation(() => mockCloudWatchClient); }); + afterEach(() => { + jest.clearAllMocks(); + }); + it('should skip indexing when the event is not relevant', async () => { const events = ['pull_request', 'release']; const workflows = ['Publish snapshots to maven']; diff --git a/test/call/print-to-console.test.ts b/test/call/print-to-console.test.ts index fcfe4bf..7126be4 100644 --- a/test/call/print-to-console.test.ts +++ b/test/call/print-to-console.test.ts @@ -52,6 +52,10 @@ describe('printToConsoleFunctions', () => { }; }); + afterEach(() => { + jest.clearAllMocks(); + }); + describe('printToConsole', () => { it('should print defined text in task', async () => { await printToConsole(app, context, resource, args);